Re: [Tutor] adding more text to a file (Vanam)

2010-01-20 Thread vanam
Below is the code which can be helpful for better insight: Sample: 1 For the below code, you can provide initially the number of entries (say 4) so that for four times name of person and age is prompted to enter.After writing to file we can read back the contents #Writing number of times the nam

Re: [Tutor] adding more text to a file

2010-01-18 Thread Modulok
If you're using this as an interactive command to help you populate a database, as you appear to be, don't open the file more than once. As previously suggested you should also put all your strings together and then write them to the database in one go. I don't know if you've thought about this ye

Re: [Tutor] adding more text to a file

2010-01-18 Thread wesley chun
On Sun, Jan 17, 2010 at 5:19 PM, Alan Gauld wrote: > > "Magnus Kriel" wrote > >> It might be that when you create a file for the first time with 'a', that >> it >> will through an exception. So you will have to try with 'w', and if there >> is >> an exception, you know the file does not exist and

Re: [Tutor] adding more text to a file

2010-01-17 Thread Alan Gauld
"Magnus Kriel" wrote It might be that when you create a file for the first time with 'a', that it will through an exception. So you will have to try with 'w', and if there is an exception, you know the file does not exist and you will have to create the file for the first time with 'w'. T

Re: [Tutor] adding more text to a file

2010-01-17 Thread Alan Gauld
"Shizuha Aki" wrote i need it to be able to add more entries instead of just one. my code is like this: while True: name = raw_input("what is the name ") age = raw_input("what is the age ") out_file = open("persons.txt", "w") It would work if you moved the open() call ou

Re: [Tutor] adding more text to a file

2010-01-17 Thread wesley chun
> while True: >    name = raw_input("what is the name ") >    age = raw_input("what is the age ") > >    out_file = open("persons.txt", "w") >    out_file.write("name: ") >    out_file.write(name) >    out_file.write("\n") >    out_file.write("age: ") >    out_file.w

Re: [Tutor] adding more text to a file

2010-01-17 Thread Magnus Kriel
Thanx, you are correct. And now I know that 'a' will create a file as well. Magnus On Sun, Jan 17, 2010 at 10:34 AM, Steve Willoughby wrote: > Magnus Kriel wrote: > > It might be that when you create a file for the first time with 'a', > > that it will through an exception. So you will have to t

Re: [Tutor] adding more text to a file

2010-01-17 Thread Steve Willoughby
Magnus Kriel wrote: > It might be that when you create a file for the first time with 'a', > that it will through an exception. So you will have to try with 'w', and > if there is an exception, you know the file does not exist and you will > have to create the file for the first time with 'w'. Tha

Re: [Tutor] adding more text to a file

2010-01-17 Thread Magnus Kriel
Hi, It is the way you open the text file in the beginning. This is from the python manual: open() returns a file object, and is most commonly used with two arguments: "open(filename, mode)". >>> f=open('/tmp/workfile', 'w') >>> print f The first argument is a string containing the filename. T

Re: [Tutor] adding more text to a file

2010-01-17 Thread Hugo Arts
On Sun, Jan 17, 2010 at 6:40 PM, Shizuha Aki wrote: > Hi, > > I am new to python, and i am trying to make a program that makes like a txt > file database. so i have my whole program in a while True loop, it asks for > information about the person and then writes the information about the > person