Re: problem with import / namespace





When you try to import a module, python starts to search for it. The was it does the search is very well defined. It mostly depends on the current directory and sys.path. You can read more about this here:
"The was it" -> "The way it"
- inside your app.py file either make sure that the current dir is /app, or insert /app in the first place in sys.path
Example:

import os,sys
mydir = os.split(os.abspath(__file__)[0]
os.chdir(mydir) # Option 1 - chdir to dir. containing your app
sys.path.insert(0,mydir) # Option 2 - add to your sys.path

Good things to know:

- In Python, it is recommended not to use upper case module/package names. It is a convention. However, some 3rd party packages (like wxPython or PIL) break this rule.
- Obviously, you should not use numbers, reserved words for module or package names. The name should tell what is it for.
- It is good to know the standard library, and avoid overwriting names from the standard lib. For example, you can create your own 'os.py' module but it would be very silly.

I personally tend to use absolute package names for libraries that are not tied to a specific project but it does not need to be that way.

You can find many threads in python-list about how applications and packages should be constructed.

Best,

Laszlo

.



Relevant Pages

  • Re: Cheese Shop -> BSOL?
    ... people complained about how nearly every Python ... not being able to scan long lists of packages comfortably, ... look at distinctively named packages, we can see that they often ... of the technology, is sensibly avoided in this case. ...
    (comp.lang.python)
  • Re: mac grapher for linux
    ... means a lot of extra packages). ... Let me put in a plug for ROOT. ... Or if you prefer Python over C++, you can instead (after installing the ...
    (Debian-User)
  • Re: mac grapher for linux
    ... means a lot of extra packages). ... Let me put in a plug for ROOT. ... Or if you prefer Python over C++, you can instead (after installing the ...
    (Debian-User)
  • Re: xmlrpclib hangs execution
    ... the Python command line 'hangs' until I kill the server. ... 'str': 'Connection accepted. ... At this point, Python 'hangs' until I kill the server, and then these last packages are send: ...
    (comp.lang.python)
  • Re: FC4
    ... >> your regular user account was getting python 2.4.1. ... I am not sure about rpm but I know yum uses python. ... I have 39 packages with python in the name. ... M Mode differs ...
    (Fedora)