Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > global variable

Reply
Thread Tools

global variable

 
 
Tom
Guest
Posts: n/a
 
      07-21-2003
Hi,

I have one "master" program which calls a small program. In this small
program I want to work with a value from the "master" program. But I
always get this error: NameError: global name 'T' is not defined

How can I define a global variable?

Thanks for your help.
Regards, Tom

 
Reply With Quote
 
 
 
 
Harry George
Guest
Posts: n/a
 
      07-21-2003
Tom <(E-Mail Removed)> writes:

> Hi,
>
> I have one "master" program which calls a small program. In this small
> program I want to work with a value from the "master" program. But I
> always get this error: NameError: global name 'T' is not defined
>
> How can I define a global variable?
>
> Thanks for your help.
> Regards, Tom
>



master.py:
my_global_var=1234

small.py:
import master
....
my_local_var=master.my_global_var * 3.14

--
http://www.velocityreviews.com/forums/(E-Mail Removed)
6-6M31 Knowledge Management
Phone: (425) 294-8757
 
Reply With Quote
 
 
 
 
Joe Francia
Guest
Posts: n/a
 
      07-21-2003
Tom wrote:
> Hi,
>
> I have one "master" program which calls a small program. In this small
> program I want to work with a value from the "master" program. But I
> always get this error: NameError: global name 'T' is not defined
>
> How can I define a global variable?
>
> Thanks for your help.
> Regards, Tom


You can't (well, there is a way, but you probably don't want to be
messing with that).

By "program" I assume you mean "module". You can do something like:

#master.py
T = 'Some value'

#small.py
import master
doSomething(master.T)

However, if master.py is also importing small.py, you'll get a circular
reference, which may cause hard to track bugs, in which case it's best
to have a third module for common (global) variables (and functions, if
you'd like), and have both master.py and small.py import that.

jf

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Initialize global variable before any other global variables jubelbrus C++ 5 07-20-2007 06:38 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 1 10-25-2006 06:50 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 0 10-25-2006 01:04 PM
Is mymodule.myvariable a 'global'? (What is proper definition of 'global variable'?) seberino@spawar.navy.mil Python 1 08-21-2005 09:21 PM
Use Global Variable or Global Struct??? Bryan Parkoff C++ 2 11-27-2004 02:46 AM



Advertisments