What is the best way to print the usage string ?
Peter Otten
__peter__ at web.de
Thu Aug 3 13:14:15 EDT 2006
Leonel Gayard wrote:
> Notice that the string messes the indentation in my script. The
> indentation is correct, and if the script is invoked without
> arguments, the usage string is printed correctly.
>
> Now, how can I achieve the same result while keeping a clean
> indentation ? How is this done in python world ? In C, I would do
> this:
>
> ;; This buffer is for notes you don't want to save, and for Lisp
> evaluation. ;; If you want to create a file, visit that file with C-x C-f,
> ;; then enter the text in that file's own buffer.
>
> if (argc < N) {
> printf("Usage: blah blah blah\n"
> "Some more lines in the usage text\n"
> "Some more lines here too\n");
> exit(1);
> }
>
> The whitespace at the beginning of the string helps me keep the
> indentation clean, and the construct "a" "b" is syntactic sugar that
> allows me to create a large string without concatenating them at
> runtime.
>
> How can I get this in Python ?
>>> print ("You can do that in Python too.\n"
... "Personally, though,\n"
... "I wouldn't bother.")
You can do that in Python too.
Personally, though,
I wouldn't bother.
Like in C, you get a single string:
>>> "a" "b"
'ab'
The parentheses are just there to allow you to spread that string over
multiple lines.
Peter
More information about the Python-list
mailing list