473,385 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Namespace problems

Hello All,
I am kind of a beginner to python, but here is the deal.

I am writing a wxpython Application, in which I have a GUI. This GUI
imports some other modules that I have written, using the format
import mymodule as _MyModule

Now, this GUI in addition to having all it's bells and whistles has a
console (from pyshell), so that the user can run their own scripts
inside this GUI.
What I am trying to do is to get these scripts that the user runs to
be able to see all the other objects created and modules imported by
the GUI.

To make this clear, what I want to be able to do for example is in my
script, do ,
dir(mymodule),
already having imported mymodule in the GUI.
Any ideas on how to make this happen? I don't want to import
mymodule in this script, i want this script to see the mymodule that I
imported in the main GUI.

thanks a lot for your help,
Kiran

Jun 6 '06 #1
2 1030
I should note that if you use the execfile command in the console, the
script runs, but if you import the script, it says it cant find the
module

Jun 6 '06 #2
Kiran wrote:
Hello All,
I am kind of a beginner to python, but here is the deal.

I am writing a wxpython Application, in which I have a GUI. This GUI
imports some other modules that I have written, using the format
import mymodule as _MyModule

Now, this GUI in addition to having all it's bells and whistles has a
console (from pyshell), so that the user can run their own scripts
inside this GUI.
What I am trying to do is to get these scripts that the user runs to
be able to see all the other objects created and modules imported by
the GUI.

To make this clear, what I want to be able to do for example is in my
script, do ,
dir(mymodule),
already having imported mymodule in the GUI.
Any ideas on how to make this happen? I don't want to import
mymodule in this script, i want this script to see the mymodule that I
imported in the main GUI.

thanks a lot for your help,
Kiran


Well, it depends on the context. If the __main__ context is that of
PyShell it will likely contain no GUI object and you shall pass the GUI
to PyShell before a PyShell window is created ( e.g.
PyShell.__dict__["GUI"] = GUI ). Descendent objects like mymodule that
live in the GUI context will be accessible in the usual way i.e. by
GUI.mymodule.

You can experiment a little bit with contexts. Simply open a Python
session and import PyShell:
import PyShell
PyShell.main() # causes creation of main window for PyShell


Now you can inspect locals of PyShell using dir(). In this case the
__main__ context is that of the top level session in which PyShell runs
as an own session. You just have to import GUI to make it accessible to
PyShell. If PyShell is the __main__ context you might assign GUI as
described above.

Regards,
Kay

Jun 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

88
by: Tim Tyler | last post by:
PHP puts most of its functions into a big flat global namespace. That leads to short function names - but creates a namespace minefield for programmers. Lots of the functions are legacies from...
5
by: Alexander Gnauck | last post by:
Hello, i have problems with the Namespaces and the .Net XML Parser My XML looks like this: <query xmlns="jabber:iq:roster"> <item jid="srlee@localhost" name="srlee"...
32
by: toolmaster | last post by:
Since many of the modern computer languages have built-in namespace features, I can't understand why not add this feature into standard C. I've heard many people complain of the lacking of...
7
by: zahy[dot]bnaya[At]gmail[dot]com | last post by:
Hi all, Since I am always confusing this, I want to know once and for all what is the right way of doing this. I've noticed that some programs use: std::cout<< "yadayada"<<endl;
30
by: Pep | last post by:
Is it best to include the code "using namespace std;" in the source or should each keyword in the std namespace be qualified by the namespace tag, such as std::cout << "using std namespace" <<...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.