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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sullivan WxPyQtKinter

    #1

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

    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\Xiaozh ong Zheng>python "C:\Documen ts and
    Settings\Xiao
    zhong Zheng\Desktop\t .py"

    The interpretor would not find the file.

    Traceback (most recent call last):
    File "C:\Documen ts and Settings\Xiaozh ong 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.

  • Fredrik Lundh

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

    "Sullivan WxPyQtKinter" wrote:
    [color=blue]
    > 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()[/color]

    "\t" is a tab character:
    [color=blue][color=green][color=darkred]
    >>> print '\ticket.txt'[/color][/color][/color]
    icket.txt

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

    </F>



    Comment

    • Sullivan WxPyQtKinter

      #3
      Re: Can not find a file in CMD model python when everything is OK in IDLE

      Sorry, I mistyped the line. In the program it IS:
      f=open("ticket. txt"), no '\' included.

      Comment

      Working...