Can not find a file in CMD model python when everything is OK in IDLE

Discussion in 'Python' started by Sullivan WxPyQtKinter, Mar 11, 2006.

  1. I use python in Windows XP platform. I find that if I write a .py file
    in a directory, such as windows desktop, in which a file named
    'ticket.txt' is located:

    f=open("\ticket.txt")
    print f.read()

    In IDLE, this py file work all right. But if I launch python
    interpretor in the command shell like this:

    C:\Documents and Settings\Xiaozhong Zheng>python "C:\Documents and
    Settings\Xiao
    zhong Zheng\Desktop\t.py"

    The interpretor would not find the file.

    Traceback (most recent call last):
    File "C:\Documents and Settings\Xiaozhong Zheng\Desktop\t.py", line
    1, in ?
    f=open("ticket.txt")
    IOError: [Errno 2] No such file or directory: 'ticket.txt'

    Anyone knows why?


    In addition, if I start IIS web service that runs .py file as CGI
    program, then this .py file also works.
     
    Sullivan WxPyQtKinter, Mar 11, 2006
    #1
    1. Advertising

  2. Re: Can not find a file in CMD model python when everything is OK inIDLE

    "Sullivan WxPyQtKinter" wrote:

    > I use python in Windows XP platform. I find that if I write a .py file
    > in a directory, such as windows desktop, in which a file named
    > 'ticket.txt' is located:
    >
    > f=open("\ticket.txt")
    > print f.read()


    "\t" is a tab character:

    >>> print '\ticket.txt'

    icket.txt

    try opening r"\ticket.txt" or "/ticket.txt" instead.

    </F>
     
    Fredrik Lundh, Mar 11, 2006
    #2
    1. Advertising

  3. Sorry, I mistyped the line. In the program it IS:
    f=open("ticket.txt"), no '\' included.
     
    Sullivan WxPyQtKinter, Mar 11, 2006
    #3
    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. Achim Domma (Procoders)

    read input for cmd.Cmd from file

    Achim Domma (Procoders), Jun 3, 2005, in forum: Python
    Replies:
    2
    Views:
    8,077
    Peter Otten
    Jun 3, 2005
  2. Sarir Khamsi

    Interpreter-like help in cmd.Cmd

    Sarir Khamsi, Jun 9, 2005, in forum: Python
    Replies:
    4
    Views:
    379
    Bengt Richter
    Jun 26, 2005
  3. Sullivan WxPyQtKinter
    Replies:
    3
    Views:
    379
    Sullivan WxPyQtKinter
    Mar 11, 2006
  4. Jean-Michel Pichavant

    python cmd.Cmd auto complete feature

    Jean-Michel Pichavant, Mar 8, 2011, in forum: Python
    Replies:
    0
    Views:
    318
    Jean-Michel Pichavant
    Mar 8, 2011
  5. Jean-Michel Pichavant

    Re: python cmd.Cmd auto complete feature

    Jean-Michel Pichavant, Mar 9, 2011, in forum: Python
    Replies:
    0
    Views:
    465
    Jean-Michel Pichavant
    Mar 9, 2011
Loading...

Share This Page