Forum Archive

How to import a bunch of functions I typed from within pythonista into another script

Raph

Sorry if the question is very basic. Maybe I overlooked something in the documentation.I tried
import filename

With no luck, whether the filename was x or x.py does not change a thing.

keimina

'import' works propely in my enviroment.

a.py

  def afunc():
    print 'afunc called'

b.py

  import a
  a.afunc()

Run b.py.
It'll work.

Raph

When I try to run b.py, the interpretor stops at "import a" and gives that as an error message:

ImportError: No module named a

keimina

Probabily your "a.py" may be "a.py.py"
If so, Delete ".py" extension.
Pythonista automatically add .py extension to its filename.

Raph

Yes that did it! Thanks alot. The strange thing is that I tried that before, but I guess at that time the file I wished to import was still in a sub-folder.