-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import not working inside def (function) #25
Comments
It may seem counter-intuitive but try placing the imports after the call to parse() The magic behind this lib is that it hijacks the imp module, preprocesses the source in memory, they imports the postprocessed source directly from memory. Producing a bytecode file that reflects the postprocessed source. That means any imports that happen prior to the call to parse() are invisible to the postprocessed source. If you don't like the 'magic' behavior, you could always opt to define the preprocessing step as it's own script and apply it to an external file. There should be no side-effects to this approach. |
Calling |
I managed to run an external code with import, but still have the same issue. I will keep editing the source file and executing the output postprocessed |
I used the debug2production.py script as a base. When I try to use a function from an import inside a function that I created, it says the name of the import (time, in my example) is not defined (line 40). Everything works fine when I don't use functions. Also, the script only runs directly if __name__ == 'pypreprocessor'. If only __name__ =='__main__' is used, it only runs on the output file without preprocessing.
The text was updated successfully, but these errors were encountered: