file open "no such file"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Wessle

    #1

    file open "no such file"

    I am getting this error when I try to run the code below

    *************** *
    f = open("~/m", "r")
    print f.read()
    *************** *

    *************** *
    :~$ python python/my.py
    Traceback (most recent call last):
    File "python/my.py", line 1, in ?
    f = open("~/m", "r")
    IOError: [Errno 2] No such file or directory: '~/m'
    *************** *

    but I have the "m" file in my home/username/


    thank you
  • Robert Kern

    #2
    Re: file open "no such file"

    Gary Wessle wrote:[color=blue]
    > I am getting this error when I try to run the code below
    >
    > *************** *
    > f = open("~/m", "r")
    > print f.read()
    > *************** *
    >
    > *************** *
    > :~$ python python/my.py
    > Traceback (most recent call last):
    > File "python/my.py", line 1, in ?
    > f = open("~/m", "r")
    > IOError: [Errno 2] No such file or directory: '~/m'
    > *************** *
    >
    > but I have the "m" file in my home/username/[/color]

    There is no automatic ~expansion. You will need to use the function
    os.path.expandu ser().

    --
    Robert Kern
    robert.kern@gma il.com

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco

    Comment

    Working...