Re: [capi-sig] Embedded python, adding a path to sys.path before import, strange observations
7 Jun
2013
7 Jun
'13
10:36 p.m.
Todd Lyons <tlyons@ivenue.com> writes:
I was testing by comparing the output of Py_GetPath() before I adjusted the path, and then after I adjusted the path. It always shows the same. [...] Question A: Is it normal that Py_GetPath() doesn't show the adjusted path?
The documentation is clear:
char* Py_GetPath()
Return the *default* [emphasis mine] module search path; this is
computed from the program name (set by Py_SetProgramName() above)
and some environment variables. The returned string consists of a
series of directory names separated by a platform dependent
delimiter character. The delimiter character is ':' on Unix and Mac
OS X, ';' on Windows. The returned string points into static
storage; the caller should not modify its value. The list sys.path
is initialized with this value on interpreter startup; it can be
(and usually is) modified later to change the search path for
loading modules.
The last sentence makes it clear that sys.path is initialized from the value returned by Py_GetPath(), and not the other way around.
Question B: All three seem to work equally well, is there a reason to choose one over the other?
All are fine (I guess I'd use method 1 myself), but the code that manipulates sys.path is almost always fishy. In many cases there are better ways to achieve the same result.
4119
Age (days ago)
4119
Last active (days ago)
0 comments
1 participants
participants (1)
-
Hrvoje Niksic