Re: [Tutor] HI, #Include like in python
wesley chun wrote: import listen You can use the __import__ function if you want, but generally you want the import statement as above. The equivalent to 'import listen' is: listen = __import__('listen') See the tutorial here: http://docs.python.org/tutorial/modules.html you also have to make sure that your .py file is in one of the folders/directories listed in sys.path (to see it, import sys then do print sys.path). if the file is not in one of those folders, you will also get an import error. you can either add the correct directory to your PYTHONPATH environment variable, or manually add it at run-time using sys.path.append/insert. A simpler form is to put listen.py and usbconnection.py in the same directory. In the latter you can do something like import listen listener = listen.ListenClass(param1, param2) listener.begin() # Call the 'begin' method of the ListenClass object. You can use the ListenClass like normal, just state that Python should look for it in the listen file. Albert ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] HI, #Include like in python
Hi \o I'm asking if there is any #include( C) like or any include('File.php') (php) like in python. I have 2 files: usbconnection.py and listen.py, And i want to use some classes avaiable in listen.py on my main file usbconnection.py. I've tryed to do __import__(listen.py) but obviously it gave me an error... ImportError: No module named /home/andrefsp/projects/sigre/listen.py So, if anybody knows how to do an include in python please reply me =) Bye the way, i've sent an email in last week asking how to read data from USB port. So, i've finally did it, yesterday i was able to read data from my USB port, if anybody is interested in some information about it just need to ask, i don't mind to help =) it is impossible to make eggs without omelettes ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor