Re: file open "no such file"
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: file open "no such file"

From: Robert Kern <robert.kern@gmail.com>
Date: Mon May 01 2006 - 02:26:19 CEST

Gary Wessle wrote:
> 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/

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

-- 
Robert Kern
robert.kern@gmail.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
Received on Mon May 1 00:48:55 2006