Re: [Tutor] How to write strings with new line character in a file OOPS CORRECTION

2006-10-13 Thread Bob Gailer
Bob Gailer wrote: > Asrarahmed Kadri wrote: > >> Here is the complete code: >> fd is the file handle. >> >> import sys >> >> def check_dup(fd1): >> print fd1 >> fd1.seek(0,0) >> done = 0 >> list1 = [] >> while not done: >> x = fd1.readline() >> if x == "":

Re: [Tutor] How to write strings with new line character in a file

2006-10-13 Thread Bob Gailer
Asrarahmed Kadri wrote: > Here is the complete code: > fd is the file handle. > > import sys > > def check_dup(fd1): > print fd1 > fd1.seek(0,0) > done = 0 > list1 = [] > while not done: > x = fd1.readline() > if x == "": > done = 1 > else:

Re: [Tutor] How to write strings with new line character in a file

2006-10-13 Thread Danny Yoo
> fname = raw_input("Enter the file name to write data to:\t") > > fd = open(fname,'a+') > print fd > done = 0 Ok, good, that helps a lot: that's exactly what we need to diagnose the problem. There appears to be something funky that happens with append-plus mode. This problem has come up befor

Re: [Tutor] How to write strings with new line character in a file

2006-10-13 Thread Kent Johnson
Asrarahmed Kadri wrote: > Here is the complete code: > fd is the file handle. > > import sys > > def check_dup(fd1): > print fd1 > fd1.seek(0,0) > done = 0 > list1 = [] > while not done: > x = fd1.readline() > if x == "": > done = 1 > else

Re: [Tutor] How to write strings with new line character in a file

2006-10-13 Thread Asrarahmed Kadri
Here is the complete code: fd is the file handle.  import sys  def check_dup(fd1):    print fd1    fd1.seek(0,0)    done = 0    list1 = []    while not done:    x = fd1.readline()    if x == "":    done = 1    else:     list1.append(x)    return list1     fname = raw_in

Re: [Tutor] How to write strings with new line character in a file

2006-10-12 Thread Bob Gailer
Asrarahmed Kadri wrote: > Folks, > > I am trying to enter names in a file; each on a new line with this > code, but not working: > > done = 0 > *while not done: > str = raw_input("Enter login name:\t to quit type 'q': ") > if str == 'q': > done = 1 > else: * > * str

Re: [Tutor] How to write strings with new line character in a file

2006-10-12 Thread Danny Yoo
> > while not done: >str = raw_input("Enter login name:\t to quit type 'q': ") >if str == 'q': > done = 1 >else: > str = str + '\n' > fd.write(str) Hi Asrarahmed, What's 'fd'? Where is it defined? (I have a guess, but I'd rather that you show where fd is being defi

[Tutor] How to write strings with new line character in a file

2006-10-12 Thread Asrarahmed Kadri
Folks,   I am trying to enter names in a file; each on a new line with this code, but not working:   done = 0 while not done:    str = raw_input("Enter login name:\t to quit type 'q': ")if str == 'q':    done = 1    else:     str = str + '\n'    fd.write(str) The traceback is as un