473,486 Members | 2,407 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Naming a file

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?

Jan 19 '08 #1
2 1138
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
Jan 19 '08 #2
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
Jan 20 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3221
by: Melissa Wallis | last post by:
I am using python and omniORB for a client program. The server is on another machine using an ACE TAO orb. I have been unable to figure out how to talk to a different naming service without using...
6
2870
by: clintonG | last post by:
Microsoft recommends CompanyName.TechnologyName and it all comes down to not breaking the inheritence model if I am not mistaken. VSN2003 however tells the compiler to use the name of the project...
9
2312
by: Sandeep Sharma | last post by:
For many years I have been following the convention of naming all class attributes with a leading underscore. This enables me to quickly identify the class attributes when I encounter them in the...
0
1149
by: Steve Jorgensen | last post by:
In a schema I've been working on recently, a convention I evolved was to use a consistent naming pattern such that, for instance, a Resident could appear in a ResidentSet, and could be referred to...
8
1523
by: Jason | last post by:
In my ASP.NET 1.1 solutions, I created several web projects and compiled them each into an assembly. The assembly names reflected the functionality of the feature (Membership.dll, Dues.dll, etc)....
6
4041
by: dm1608 | last post by:
I'm relatively new to ASP.NET 2.0 and am struggling with trying to find the best naming convention for the BAL and DAL objects within my database. Does anyone have any recommendations or best...
8
2070
by: Daz | last post by:
Hi all! This question may hopefully spark a little debate, but my problem is this: I am sure it's not just me who struggles to think up names for variables. Obviously, thinking up a name...
35
12124
by: Smithers | last post by:
Is it common practise to begin the name of form classes with "frm" (e.g., frmOneForm, frmAnotherForm). Or is that generally considered an outdated convention? If not "frm" what is a common or...
8
2277
by: mrashidsaleem | last post by:
Can anyone guide me what is wrong with the naming conventions suggested below? I know that this is not recommended by many (including Microsoft) but I need to know what exactly is the rationale...
8
6137
oll3i
by: oll3i | last post by:
it worked but suddenly when i run it and click a button it throws exception ? D:\SR>java Producent queue1 queue2 queue3 queue4 queue1,queue2,queue3,queue4...
0
7126
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5434
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3070
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.