open file on mac

tinauser tinauser at libero.it
Mon Oct 11 08:12:40 CEST 2010


On Oct 10, 11:44 pm, Benjamin Kaplan <benjamin.kap... at case.edu> wrote:
> On Sun, Oct 10, 2010 at 5:29 PM, tinauser <tinau... at libero.it> 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 i21g2000yqg.googlegroups.com>,
>
> >> 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.
> os.path.dirname(os.path.abspath(__file__))
> 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
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
>

thanks a lot!



More information about the Python-list mailing list