[Tutor] how do I input " as part of a string?

Robert H. Haener IV humbolt at comcast.net
Fri Jul 13 19:40:55 CEST 2007


elis aeris wrote:
> def winlist(title):
>     f.write("winlist(\"title\")")
> 
> 
> 
> how about if "title" is a variable?

I assume, from your example, that you want to write the value of the variable 'title' enclosed in quotation marks.  We once again use an escape sequence to output quotation marks, but this example also utilizes string formatting to convert the value of 'title' to a string and place it between the quotation marks in the output:

def winlist(title):
    f.write("\"%s\"" % title)

Please note that I have never used the write function before, but I just ran a quick test with the python interpreter and that appears to be valid code.

For more information on string formatting, see here:

http://docs.python.org/lib/typesseq-strings.html


-Robert


More information about the Tutor mailing list