open file on mac
bkjones at gmail.com
Fri Oct 8 22:24:48 CEST 2010
On Fri, Oct 8, 2010 at 10:41 AM, tinauser <tinauser at libero.it> wrote:
> hallo, i'm sorry if the question is very stupid, but i cannot
> understand what i'm doing wrong here.
> i have this myModule.py
> class Starter:
> def init(self,num):
> print "hithere!"
> print "the answer is ",num
> import sys,os
> print "path:",sys.path
> print "bye"
> ## f = open("/Users/lguerrasio/_myfold/initfile.py",'r')
> f = open("initfile.py",'r')
> print "huurray!"
> except IOError:
> print "The file does not exist, exiting gracefully"
> print "This line will always print"
> the module is in the same folder of initfile
> from terminal, i import sys and add to the path /Users/lguerrasio/
> then i import the module and call
> now,the file will be opened only if i give the full path, not if i
> give only the name of the file, although the folder is in the path.
> what am I missing?
sys.path, unless I've missed something, has nothing to do with *opening* a
file. It has to do with importing a python module, so it should have no
affect on your ability to simply open a file.
On my mac, in the interpreter, running open() on a file in the same
directory reported by os.path.abspath(os.path.curdir) succeeds without
What you might consider is doing something like
That will insure that it always tries to open the file that's in the same
directory as the module trying to open it, assuming that's what you want.
If what you want is an import and not an open(), well... let us know :)
Brian K. Jones
My Blog http://www.protocolostomy.com
Follow me http://twitter.com/bkjones
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list