[IronPython] Embedding IronPython 2.0

Michael Foord fuzzyman at voidspace.org.uk
Fri Jan 30 18:31:28 CET 2009


Severin wrote:
> yes, thats what I did.
>
>
> but then I have relative path's in the python code. to open a file for 
> instance.
>
> lets say ./py is my subdirectory.
>
> there I have a settings.ini and a main.py file. adding ./py to the 
> path I am able to run main.py with the DLR but not doing something 
> like open('settings.ini','r') in the python code.

Have a function that does the path relivatisation for you. The call can 
then be:

    open(getpath('settings.ini'),'r')

or even:

    open_from('settings.ini','r')

>
> so basically what I want is that calling os.getcwd() returns the ./py 
> subdirectory.
>
> well, I try to change the current working directory in the python code 
> (or just put the python files in the main directory). this should do 
> the job, but is not really nice. I guess the whole thing is a hack 
> anyway :)

Well - running Python code from a hosted environment need not be a hack. 
But depending on the current directory probably is...

Michael

>
> Severin
>
> On Fri, Jan 30, 2009 at 6:16 PM, Slide <slide.o.mix at gmail.com 
> <mailto:slide.o.mix at gmail.com>> wrote:
>
>     On Fri, Jan 30, 2009 at 10:01 AM, Severin <seob at gmx.ch> wrote:
>     > Good point! I forgot that I was having the *.py files in a
>     subdirectory.
>     > Is it also possible to set the 'current' directory for the engine?
>     > For instance I would like to have the engine living in a
>     subfolder of my
>     > project and then all path's would be relative to this subfolder.
>     > thank you,
>     > Severin
>
>     <snip>
>
>     You could add the subdirectory to sys.path.
>
>     slide
>     _______________________________________________
>     Users mailing list
>     Users at lists.ironpython.com <mailto:Users at lists.ironpython.com>
>     http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>   




More information about the Ironpython-users mailing list