Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><code>os.environ</code> is global. You're modifying it, and not modifying it back afterward. So, after doing <code>@patch_python_path</code> on any function, you've now done the equivalent for everything else you define after that—including in other modules and in the top-level script.</li> <li><code>sys.path</code> is also global, and again you're modifying it and not restoring it.</li> <li>You shouldn't ever need to modify both <code>PYTHONPATH</code> and <code>sys.path</code>. (In particular, it's the former that you usually shouldn't need.)</li> <li>You're adding <code>.</code> to <code>PYTHONPATH</code>, but <code>os.getcwd()</code> to <code>sys.path</code>. If you ever <em>do</em> need to modify both, everything will stop working after an <code>os.chdir()</code>, which will effectively change the <code>PYTHONPATH</code> but not the <code>sys.path</code>.</li> <li>Any wrapped function will lose its docstring, name, etc.; use <code>@functools.wraps</code> on your <code>wrap</code> function.</li> </ol> <p>Those are all just issues with your implementation, without getting into whether it's a good idea in the first place. </p> <p>The most common reasons people want something like this are (a) make Python X.Y packages work like Python V.W, and (b) allow importing a package from the source tree to work the same as importing it after install, even from the interpreter shell. The former is probably a bad idea; the latter is handy, but there are other ways to accomplish it. If you have some different higher-level goal, you'll have to tell us what that goal is before anyone can tell you whether this is the best way to accomplish it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload