[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Naming a file

snoylr

1/19/2008 10:15:00 PM

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?

2 Answers

Matthias Bläsing

1/19/2008 10:21:00 PM

0

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

Diez B. Roggisch

1/20/2008 2:14:00 AM

0

Matthias Bläsing schrieb:
> 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

You missed the cruicial parentheses here:

f.close()



Diez