![]() |
How do you "include" a file?
How do you basically include (or import) a file?
Such that if I had: a.py: Code:
print 'hello'Code:
print 'bye'Code:
<import a.py>How do I make it so that if I run c.py, it will print out: Code:
hello |
a.py:
Code:
def dummy1():Code:
def dummy2():Code:
if __name__ == '__main__':http://docs.python.org/release/2.6.6...l/modules.html usualy you need to be sure that import didn't fail and use exception but probably this will be later when you will feel confortable enought with python. Edit: two things: - change url to point to your python version instead of 2.6.6 - i assume you don't ask about something like call, eval, exec( see the docs for details) best regards |
So there's no way to import files and have the imported file automatically evaluate its contents? In other words, if I want to import files I must ONLY have functions/classes in the file(s) to be imported? Can variables also be in it as well?
Edit: Also, how would you go about importing files from other directories? Suppose you have the following files: include/libs.py conf/main.py test.py Lets say you run test.py - how would you import the libs.py and main.py? |
Quote:
why do you want to do something like this? Quote:
Quote:
best regards |
| All times are GMT +1. The time now is 05:21 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.