3

Hi I am new to both python and bottle

I have a site

here is the structure

|root
 index.py 
     |classes
      session.py

from the index.py how do I access session.py

so I can use it as:

**from session import session**

Or is there a better way (standard) to do this?

Thanks

4

2 回答 2

1

Make everything under root into a package. Its easy.

Place blank __init__.py files in the root and classes folders and you will be able to import session.py no problem.

The __init__.py file defines everything as part of the package and then you can import anything within the package.

于 2013-11-25T22:45:24.433 回答
0

Read this instead of the answer below: Import a module from a relative path

Ignore this:

Depending on what you want all of the following methods are valid. I normally use the first one unless there are a lot of helper functions to use.

import session and then call functions by session.function1()

or from session import * and just call function1() naturally.

or even import session as whateveryouwanthere and call whateveryouwanthere.function1()

于 2012-11-22T00:21:34.513 回答