RE: file.readlines() - gives me error (bad file descriptor)

Discussion in 'Python' started by Vishnu, Jan 6, 2005.

  1. Vishnu

    Vishnu Guest

    logfile = file(r'test.txt','w')
    logfile.write('datetime')
    logfile.close() # <- close the file

    logfile = file(r'test.txt','r') # <- Open the file in read mode
    test=logfile.readlines()


    ~Vishnu.

    -----Original Message-----
    From: python-list-bounces+vishnube=
    [mailto:python-list-bounces+vishnube=] On Behalf Of

    Sent: Thursday, January 06, 2005 11:53 AM
    To:
    Subject: file.readlines() - gives me error (bad file descriptor)

    Hey guys,

    I can't figure this one out, why is this simple script giving me
    problems?

    logfile=file(r'test.txt','w')
    logfile.write('datetime')
    test=logfile.readlines()

    When I run it I get the error message:
    Traceback (most recent call last):
    File "C:\Documents and Settings\Gregory\My Documents\Get New Great
    Job\testfile.py", line 3, in ?
    test=logfile.readlines()
    IOError: [Errno 9] Bad file descriptor

    I'm running Windows XP, Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC
    v.1200 32 bit (Intel)] on win32
    Any help would be greatly appricated.

    Thanks,

    Greg

    --
    http://mail.python.org/mailman/listinfo/python-list
    Vishnu, Jan 6, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin
    Replies:
    4
    Views:
    1,040
    David Bolen
    Jul 7, 2003
  2. drs
    Replies:
    0
    Views:
    363
  3. Replies:
    9
    Views:
    698
    Abhijit Soman
    Jan 6, 2005
  4. lynology

    Bad File Descriptor Error on strcat/strcpy

    lynology, Aug 18, 2004, in forum: C Programming
    Replies:
    4
    Views:
    486
    Chris Torek
    Aug 18, 2004
  5. nik
    Replies:
    0
    Views:
    631
Loading...

Share This Page