Naming a file

S

snoylr

I have a variable called filename
How do I create a file using the filename variable as the name of the
file?

For example if the variable is 105Markum

What statement do I need to create a file name 105Markum.txt?
 
M

Matthias Bläsing

Am Sat, 19 Jan 2008 14:14:30 -0800 schrieb snoylr:
For example if the variable is 105Markum

What statement do I need to create a file name 105Markum.txt?

filename_base = '105Markum'
filename = '%s.txt' % filename_base
f = open(filename, 'w')
f.write(<whatever you wanna write)
f.close

Should do it for you

Matthias
 
D

Diez B. Roggisch

Matthias said:
Am Sat, 19 Jan 2008 14:14:30 -0800 schrieb snoylr:


filename_base = '105Markum'
filename = '%s.txt' % filename_base
f = open(filename, 'w')
f.write(<whatever you wanna write)
f.close

You missed the cruicial parentheses here:

f.close()



Diez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top