473,804 Members | 3,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

module global variables

hi to all!
can i load a module passing to it, automatically and as default, all
the caller's global variables to act as module's global variables?
thanks
Jun 27 '08 #1
6 1092
On May 12, 5:17 pm, pistacchio <pistacc...@gma il.comwrote:
hi to all!
can i load a module passing to it, automatically and as default, all
the caller's global variables to act as module's global variables?
thanks
module = __import__('mod ule', globals=globals ())

I think that's what you're looking for.

- alex23
Jun 27 '08 #2
On 12 Mag, 10:01, alex23 <wuwe...@gmail. comwrote:
On May 12, 5:17 pm, pistacchio <pistacc...@gma il.comwrote:
hi to all!
can i load a module passing to it, automatically and as default, all
the caller's global variables to act as module's global variables?
thanks

module = __import__('mod ule', globals=globals ())

I think that's what you're looking for.

- alex23

hmm, well, maybe yes.. should i ovveride the standard import function
of the module?
say that the module is called "pycatrix", would adding this to the
module solve the problem?

def __import__('pyc atrix', globals=globals ()):

Jun 27 '08 #3
On 12 Mag, 10:10, pistacchio <pistacc...@gma il.comwrote:
On 12 Mag, 10:01, alex23 <wuwe...@gmail. comwrote:
On May 12, 5:17 pm, pistacchio <pistacc...@gma il.comwrote:
hi to all!
can i load a module passing to it, automatically and as default, all
the caller's global variables to act as module's global variables?
thanks
module = __import__('mod ule', globals=globals ())
I think that's what you're looking for.
- alex23

hmm, well, maybe yes.. should i ovveride the standard import function
of the module?
say that the module is called "pycatrix", would adding this to the
module solve the problem?

def __import__('pyc atrix', globals=globals ()):
pardon, this:
def __import__('pyc atrix', globals=globals ()):
pass
Jun 27 '08 #4
pistacchio wrote:
On 12 Mag, 10:01, alex23 <wuwe...@gmail. comwrote:
>On May 12, 5:17 pm, pistacchio <pistacc...@gma il.comwrote:
>>hi to all!
can i load a module passing to it, automatically and as default, all
the caller's global variables to act as module's global variables?
Are you positively sure you need this?

Modifying imported modules is already quite fragile, but this.. it's
basically a reversed(import *)

It's quite messy. Where quite equals to "very"
Jun 27 '08 #5
On 12 Mag, 10:47, Marco Mariani <ma...@sferacar ta.comwrote:
pistacchio wrote:
On 12 Mag, 10:01, alex23 <wuwe...@gmail. comwrote:
On May 12, 5:17 pm, pistacchio <pistacc...@gma il.comwrote:
>hi to all!
can i load a module passing to it, automatically and as default, all
the caller's global variables to act as module's global variables?

Are you positively sure you need this?

Modifying imported modules is already quite fragile, but this.. it's
basically a reversed(import *)

It's quite messy. Where quite equals to "very"
well, i'm writing a module called pycatrix. within the module i have
compile / exec statements in a functions that work on global
variables. ( exec compiledTemplat e in globals() ).

now, i don't want to be forced (or force the end user) to import to
call the module's function with a compulsory "globals()" as argument.
Jun 27 '08 #6
On 12 Mag, 11:11, pistacchio <pistacc...@gma il.comwrote:
On 12 Mag, 10:47, Marco Mariani <ma...@sferacar ta.comwrote:
pistacchiowrote :
On 12 Mag, 10:01, alex23 <wuwe...@gmail. comwrote:
>On May 12, 5:17 pm,pistacchio<p istacc...@gmail .comwrote:
>>hi to all!
>>can i load a module passing to it, automatically and as default, all
>>the caller's global variables to act as module's global variables?
Are you positively sure you need this?
Modifying imported modules is already quite fragile, but this.. it's
basically a reversed(import *)
It's quite messy. Where quite equals to "very"

well, i'm writing a module called pycatrix. within the module i have
compile / exec statements in a functions that work on global
variables. ( exec compiledTemplat e in globals() ).

now, i don't want to be forced (or force the end user) to import to
call the module's function with a compulsory "globals()" as argument.
up
Jun 27 '08 #7

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

Similar topics

17
1890
by: Jacek Generowicz | last post by:
I have a module whose behaviour needs to be configurable. The module needs to decide, the first time it is imported, beteween alternative interfaces it presents. Currently, I set some environment variables which select the desired behaviour, and the module inspects those variables to determine the mode in which it should set itself up. I would prefer a pure Python solution, rather than one which depends on external state. Can you...
59
3957
by: seberino | last post by:
I've heard 2 people complain that word 'global' is confusing. Perhaps 'modulescope' or 'module' would be better? Am I the first peope to have thought of this and suggested it? Is this a candidate for Python 3000 yet? Chris
8
1951
by: Floris van Haaster | last post by:
Hi All! I have a question, i have a web application and I store some member information in a variable i declared in a module like: Public some_info_variable as string in module1.vb But when another user comes to my website he is getting the same values from the variable!!!
2
1734
by: tobiah | last post by:
I am making a web app, made up of many modules that all need access to some important data, like the current session data, cookies, navigation history, post/get variables, etc. I decided to go with the 'Borg' idea, by assigning the __dict__ of an object to a class variable so that each instantiation of the Borg() would share the same data. That way I can either pass the Borg around, or just Borg() it if I need it in some obscure place.
32
5833
by: Matias Jansson | last post by:
I come from a background of Java and C# where it is common practise to have one class per file in the file/project structure. As I have understood it, it is more common practice to have many classes in a Python module/file. What is the motivation behind it, would it be a bad idea to have a guideline in your project that promotes a one class per file structure (assuming most of the programmers a background similar to mine)?
5
1394
by: jonkersbart | last post by:
Dear, I have wrote a script and want to group some functions of the script in a separate modulo so that I can import the module in other scripts and use the same functions there.. The problem is that the common functions need access to some global variables defined in the script. Python uses different namespaces for different modules so I can't access the variables of the script in the module.
4
2965
by: carl.dhalluin | last post by:
Hello I am completely puzzled why the following exec code does not work: mycode = "import math\ndef f(y):\n print math.floor(y)\nf(3.14)" def execute(): exec mycode execute()
4
2204
by: rshepard | last post by:
I'm stymied by what should be a simple Python task: accessing the value of a variable assigned in one module from within a second module. I wonder if someone here can help clarify my thinking. I've re-read Chapter 16 (Module Basics) in Lutz and Ascher's "Learning Python" but it's not working for me. In one module (the "source"), variablePage.py, three wxPython widgets display values that are assigned to variables: curVar, UoDlow, and...
6
2277
by: dudeja.rajat | last post by:
Hi, I found on the net that there is something called module initialization. Unfortunately, there is not much information for this. However, small the information I found module initialization can be of use to me in my project. I'm currently messing with a problem where I'm keeping my global variables ( or symbols) in a module and the other mdoules in the project acess these global variables.
0
10578
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10077
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9152
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.