[BangPypers] Re :Use of module (Include file) in Python???
abhinav.sarkar at gmail.com
Sat Sep 6 21:46:29 CEST 2008
David Elsen wrote:
> Hi Venkata,
> I could do this.
> Import my first file as module and then using all my methods
> <modulename>.<methodname> format, but I would like to include my
> <modulename> file and want to use just as <methodname> not as
> Hope I am clear.
> On Sat, Sep 6, 2008 at 5:45 AM, venkata subramanian
> <venkatasubramanian at gmail.com <mailto:venkatasubramanian at gmail.com>>
> Hi Deepak,
> You can do this.
> It is using the keyword called import.
> The basic syntax is
> import <your_module_name_here>
> example: import RegDesc
> then, you can do RegDesc.foo(bar)
> My friend had the same problem. He read the tutorial till
> one point and missed the part where they talk about modules
> and packages. So, go ahead and make sure you covered those topics.
> Like other languages, your module should be in a 'path' called
> you can do import sys and then type sys.path to know the path.
> All the modules in your current directory can be imported (well,
> without going into the nittie gritties of it).
> On Sat, Sep 6, 2008 at 8:03 AM, Deepak Patel
> <dpatel_07 at rediffmail.com <mailto:dpatel_07 at rediffmail.com>> wrote:
> > Hello,
> > I am new to Python and need some help.
> > Can someone please tell me whether I can use the Python Module
> like include
> > file?
> > Is there a way to use the "include" file in Python?
> > If I try to include a file with "# include", that line is treated as
> > comment.
> > What is the directive to include the include file in Python?
> > I have created a Python prgram, say RegDesc.py for my registers
> > definitions, for example, called as:class Reg:with all the
> register methods,
> > like ReadReg(), WriteReg() etc.
> > In the same file, I have description of various registers,
> like:ConfigReg =
> > Reg(.....).
> > Now I want to treat my RegDesc.py as include file to my other
> programs and
> > use the Reg class methods in my other programs.
> > How can I do this? Do I need to use module?
> > Thanks,
> > Deepak
> > _______________________________________________
> > BangPypers mailing list
> > BangPypers at python.org <mailto:BangPypers at python.org>
> > http://mail.python.org/mailman/listinfo/bangpypers
> BangPypers mailing list
> BangPypers at python.org <mailto:BangPypers at python.org>
> BangPypers mailing list
> BangPypers at python.org
In that case you should do:
from modulename import methodname
or to import all methods at once do:
from modulename import *
This should work.
The world is a book, those who do not travel read only one page.
More information about the BangPypers