Forums

Can't import module from mysite

Hi,

I'm a very new programmer so this might be something very simple but I've written a short file to use with bottle.py which is stored in the directory 'mysite'. When I try to import it as a module using import filename I get an import error saying no such file exists. I've tried sys.path.append and import mysite.filename but still no luck. Any ideas?

Hard to say without knowing more about your setup. Can I take a look at your files? We can see them from our side, but we always ask before looking.

Yes feel free. As you'll see its just two simple files, one with bottle (at present just with the standard hello world template) and the other a basic script for running sessions. I want to import the latter into the former which is where I'm having the problem.

Ah, got it -- the files names need to end in .py in order to be importable. So if you rename sessions to sessions.py then everything should work.

Thanks Giles. I thought it was probably something simple!

No problem, glad to help!