[Tutor] really dumb questions

Andy W toodles@yifan.net
Sun, 10 Feb 2002 09:33:11 +0800

Hi Kevin,

> I know that there is writelines, but as usual i can't figure out based on
the Python documentation which hardly ever gives illustrative examples.

To use writelines, all you need to do is put all your strings in a list.

>>> scooby_file=open("scooby.txt","w")
>>> scooby_file.writelines(["Scooby","Dooby","Doo"])
>>> scooby_file.close()

Yields the file scooby.txt with the following data in it:

> My other dumb question is this: how do i print a list without the leading
and trailing brackets and commas? I just want the values separated by white
space. 1 2 3 and not [1, 2, 3] again with f.write and not print.

How about:

for item in [1,2,3]:
    print item,           #don't miss that comma on the end, else the data
will spill on to the next lines.

> Oh, one last silly question. I know how to print the time in the
interpreter with:
> >>> import time
> but using the same command with f.write and not print doesn't work. if i
add the `x` thing it works but it adds single quotes to the output. How do
you suppress those?

So you're trying to write the time to a file, is that right?
'x' thing? You've lost me there.
If you just want to write the time to a file, all you need to do is put
str() around the time result. eg.:

import time

> One last silly question. I would love to write to the output file the name
of script that generated the file. Is there a module that does that in
Python? I see where to get the curdir, but not the actual filename with the

You do realise you've asked 2 "last" silly questions now don't you? ;)

If you are running the program by itself and not importing it, the first
element of sys.argv should give you what you want. ie.:

import sys

> cheers all and Happy New Year to those in places that groove to the Lunar
New Year.

You too!


> kevin parks
> Seoul, Korea
> Thanks D-man and Danny Yoo for the stuff on random. It was helpful, but i
was also hoping that there would be 1/f noise and brownian noise as well
built in. I didn't see it in Numpy either.
> Go Get It!
> Send FREE Valentine eCards with Lycos Greetings
> http://greetings.lycos.com
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor