how to reference my own module ?

Terry Reedy tjreedy at udel.edu
Sat May 10 18:46:13 EDT 2008


"Stef Mientki" <stef.mientki at gmail.com> wrote in message 
news:4825F6BB.9090707 at gmail.com...
| hello,
|
| I've a library that I import as
|
|    import ppygui.api as gui
|
| the reason for this construct is that I've to use different libraries
| for different platforms.
|
| Now I like to write some examples in the library (activated by if
| __name__ == '__main__' :)
| and I would that these examples can be used in the user program just by
| copy / paste.
|
| For calling a function / class in the user program I've to write:
|
|    sizer = gui.VBox ()
|
| So also write exactly the same sentence in the library examples,
| but  "gui" is not recognized
|
| Any ideas how I can realize the above ?

Put the import statement in the example so 'gui' *is* recognized ;-)

If I understand what you meant ...
xploro/test/begin.py
-----------------------------
def start():
    print('hello')

if __name__ == '__main__':
    import xploro.test.begin as etb
    etb.start()
----------------------------
prints 'hello'|

Import is a name-binding statement that also creates a module when it does 
not exist already.  Modules can be bound to multiple names just like any 
other object.

Terry Jan Reedy






More information about the Python-list mailing list