Nick Coghlan avatar Nick Coghlan committed 0840c29

Misc cleanups

Comments (0)

Files changed (1)

notes/python_concepts/import_traps.rst

 arise any time you execute a script directly from inside a package without
 using the ``-m`` switch from the parent directory in order to ensure that
 ``sys.path`` is initialised correctly (e.g. the pre-1.4 Django project
-layout gets into trouble by running ``manage.py`` from inside a package -
-the 1.4+ layout solves that by moving ``manage.py`` outside the package
-directory).
+layout gets into trouble by running ``manage.py`` from inside a package,
+which puts the package directory on ``sys.path`` and leads to this double
+import problem - the 1.4+ layout solves that by moving ``manage.py`` outside
+the package directory).
 
 The fact that most methods of invoking Python code from the command line
 break when that code is inside a package, and the two that do work are highly
 -----------------
 
 The above are the common traps, but there are others, especially if you
-start getting into the business of overriding the default import system.
+start getting into the business of extending or overriding the default
+import system.
 
 I may add more details on each of these over time:
 
 * ``__main__`` is not always a top level module (thanks to ``-m``)
 * the fact modules are allowed to replace themselves in sys.modules
   during import
+* ``__file__`` may not refer to a real filesystem location
+* since 3.2, you can't just add ``c`` or ``o`` to get the cached bytecode
+  filename
 
 .. _issues with threads: http://docs.python.org/2/library/threading#importing-in-threaded-code
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.