PyDev multiple source files?

Sells, Fred fred.sells at adventistcare.org
Fri May 30 14:52:53 EDT 2008


the short answer is

a file is a module; therefore to 'include' access to 'myclass' in file xyz.py from another file called 'abc.py'  you would put this in abc.py

import xyz  #note no '.py'
x = xyz.myclass()
or
from xyz import myclass  #if you're lazy use ... import *
x = myclass()

see the basic tutorial on modules and importing

> -----Original Message-----
> From: python-list-bounces+frsells=adventistcare.org at python.org
> [mailto:python-list-bounces+frsells=adventistcare.org at python.org]On
> Behalf Of RossGK
> Sent: Friday, May 30, 2008 2:10 PM
> To: python-list at python.org
> Subject: PyDev multiple source files?
> 
> 
> Newbie questions on PyDev project setup.   Things are going fine -
> writing python code in eclipse/pydev and running them with various
> imports etc, doing wxpython stuff blah, blah, blah. My .py code is in
> a module, in a package, in a project. It runs fine.
> 
> Now I want to be able to break my single source file up into multiple
> files to segregate functions, divide up with others, etc, but I don't
> know how to configure it. I pulled one simple class definition out of
> my single source file and created a new .py file with just that in
> there. But now I'm stalled...
> 
> What is the equivalent of an 'include' statement. I assume there's
> something I put into one .py file to say I'm using stuff in another
> local .py file.   I tried using "import" but it doesn't seem to work -
> ie code doesn't know about the class in the other file.
> 
> Also, how about global vars that are needed across multiple .py files?
> Where do I declare them to be understood in all the files that use
> that global.
> 
> I suspect there is something I do in __init__.py - perhaps the
> equivalent of 'include' statements in there with all my globals
> stuffed in there too???   I'm lost here, but will continue to play
> with it.  Any hints appreciated.  Surely all python developers don't
> cram everything into one huge file (I hope).
> 
> Ross.
> --
> http://mail.python.org/mailman/listinfo/python-list
> 



More information about the Python-list mailing list