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

Robert H. Haener IV humbolt at comcast.net
Sat Jul 14 01:07:23 CEST 2007


elis aeris wrote:
> def send(string):
>     f.write("send( \"%s\"\n' % string )" )
> 
> 
> 
> 
> f = open ("data.ini")
> 
> send("string is very nice and all those things are pretty cool")
> 
> 
> 
> 
> 
> this one is wrong, i guess i didn't ask you how to add things after this
> 
> 
> \"%s\"\n' % title)

It appears that you have a fundamental misunderstanding of how to define a function, your code calls the function in the definition of the function:


def send(string):
    f.write("send(...)")


Do you see how the function depends on itself in order to define itself?  This is the same mistake you made in a earlier message (the one you sent a little over 6 hours ago), in my response to that message I corrected the mistake but forgot to point it out.

Here is the corrected version of your example, note that I have changed the opening quote of f.write() to a singe quote in order to avoid confusion with regard to the escaped double quotes:


def send(string):
    f.write('\"%s\"\n' % string)

f = open("data.ini","w")

send("string is very nice and all those things are pretty cool")


-Robert


More information about the Tutor mailing list