views:

57

answers:

2

I am writing a GAE application and have run into an import problem.

My app.yaml has the following lines:

- url: /py/classes/  
  static_dir: py/classes

- url: /py/lib  
  static_dir: py/lib

- url: /py/bin/signin  
  script: py/bin/signin.py

I am keeping a python file, titled employee.py, containing the class employee, in the classes folder, and a signin.py script in the bin folder which tries - at the moment unsuccessfully - to import the employee class. I have tried, amongst others:

import employee  
import py.classes.employee

Neither option works. Could you please let me know what I am doing wrong?

Thank you in advance.

+3  A: 

The static_dir configuration option can not be used to extend PYTHONPATH. Using it you can serve static files like images, stylesheet, or Javascript files.

If you want to use normal Python modules just put them next to your main Python files.

Edit:

Are your directories Python packages that include the necessary __init__.py files?

I have empty \_\_init\_\_.py files in the /py and /py/classes paths. Trying import py.classes.employee or import classes.employee hasn't helped.
Kapil Kaisare
Correction: import py.classes.employee seems to work now. My bad. The \_\_init\_\_.py files seemed to be the problem.Thanks!
Kapil Kaisare
A: 

Any files specified as static files get uploaded separately from your code - they're not accessible by your Python code, so even with the PYTHONPATH set correctly, you won't be able to import them.

Nick Johnson