open file on mac

Benjamin Kaplan benjamin.kaplan at
Sun Oct 10 23:44:46 CEST 2010

On Sun, Oct 10, 2010 at 5:29 PM, tinauser <tinauser at> wrote:
> On Oct 10, 6:54 am, Lawrence D'Oliveiro <l... at geek-
> central.gen.new_zealand> wrote:
>> In message
>> <d38a6549-379b-4ece-b391-904e15412... at>,
>> tinauser wrote:
>> > 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?
>> The fact that sys.path is not used for that.
> ok,then could you tell me if there is a way to have the folder of the
> module where the "open" command is?
> this module is called from C, and user could install the python code
> folder (where both the module and the file are) where he wants.

open uses the current working directory, which is available through
the os.getcwd() function in Python.
If you want to use a path relative to the current module, you can use
that module's __file__ attribute.
will give you the absolute path to the directory with the current module in it.

So if you want to open the foo.txt file in the same directory as the
module, you use
os.path.join(os.path.dirname(__file__), 'foo.txt')

> thank you in advance
> --

More information about the Python-list mailing list