importing modules from a folder in portable python -


i've python in usb stick , i'm designing recursive descent parser.

the main script recursive.py run following code command prompt.

python.exe compiler\recursive.py<compiler\rd_input 

my directory structure

python.exe compiler\     recursive.py     rd_input 

in code i'm generating python script 3 functions.

compiler\        recursive_header.py 

which need import in main script recursive.py later.

i've tried import recursive_header , import compiler\recursive_header , import compiler/recursive_header it's showing error

traceback (most recent call last):   file "compiler\recursive.py", line 74, in <module>     import recursive_header importerror: no module named recursive_header 

i've tried solution given here. same error.

also tried

import sys sys.path.append('/compiler') import recursive_header 

here error numbers increased mentioning sys.

how can import compiler\recursive_header.py in script.

you need empty __init__.py file in \compiler (to tell python compiler module) , do:

import compiler.recursive_header 

however if generating module try generating in different module , loading that, i.e have following structure:

python.exe compiler    __init__.py    recursive.py compiled    __init__.py    compiled_file_1.py    compiled_file_2.py 

for more detail on why works way see this post


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -