[Tutor] really dumb questions

kevin parks kp87@lycos.com
Sat, 09 Feb 2002 20:25:57 +0900


Hi. It's new years here in Korea and I plan on spending mine with the Python interpreter.

I am hung up on a few dumb items that i was hoping to get some help with.

1. How can one write (not print) multiple things with one f.write statement?

I have lots of code that scrolls down endlessly because it has to do silly stuff like:

f.write('foo = ')
f.write(`foo`)
f.write('/n/n') # pretend these are newlines i can't find the forward slash on this computer
f.write('bar = ')
f.write(`bar`)
f.write('/n/n')

is there anyway to combine these on fewer lines without using ; ?
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.

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.

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?

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 path.

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

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