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. Advertisements

  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. Advertisements

  3. Sorry, I mistyped the line. In the program it IS:
    f=open("ticket.txt"), no '\' included.
     
    Sullivan WxPyQtKinter, Mar 11, 2006
    #3
    1. Advertisements

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,351
    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:
    559
    Bengt Richter
    Jun 26, 2005
  3. =?ISO-8859-1?Q?Sch=FCle_Daniel?=

    [exec cmd for cmd in cmds]

    =?ISO-8859-1?Q?Sch=FCle_Daniel?=, Mar 8, 2006, in forum: Python
    Replies:
    3
    Views:
    595
    Scott David Daniels
    Mar 8, 2006
  4. Sullivan WxPyQtKinter
    Replies:
    3
    Views:
    442
    Sullivan WxPyQtKinter
    Mar 11, 2006
  5. Gregory Bloom
    Replies:
    4
    Views:
    571
    Steve Holden
    Apr 28, 2007
  6. Diez B. Roggisch

    pydb remote debugging/cmd.Cmd over socket?

    Diez B. Roggisch, May 28, 2008, in forum: Python
    Replies:
    2
    Views:
    729
    Diez B. Roggisch
    May 29, 2008
  7. Diez B. Roggisch

    cmd.Cmd bug or at least docu-bug

    Diez B. Roggisch, May 29, 2008, in forum: Python
    Replies:
    1
    Views:
    469
    Michele Simionato
    May 29, 2008
  8. Jean-Michel Pichavant

    python cmd.Cmd auto complete feature

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