[Tutor] really dumb questions

Andy W toodles@yifan.net
Mon, 11 Feb 2002 14:13:42 +0800


> > for item in [1,2,3]:
> >     print item,           #don't miss that comma on the end,
>
> But he asked for f.write not print so...

Ack, Sorry! Thanks for pointing out the error, Alan.

>
> s = ''
> for item in [1,2,3]:
>     s = s+str(item) # just convert to a string and concatenate
> f.write(s)          # then write the final string

Just to go on from my example, you could redirect print-output to a file
like such:

for item in [1,2,3]:
    print >> f, str(item),

That's starting to look a little less like Python to me, though. <grin>

Andy W.