Re: Pythong Globally Scoped Variables

  • From: Tyler Littlefield <tyler@xxxxxxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Sat, 3 Apr 2010 14:45:22 -0600

I tend to have a constants.h in my c++ and c apps, but you shouldn't use to 
many global vars if you can help it. It tends to lead to confusion and buggy 
messes later on down the road.
                Thanks,
Tyler Littlefield
        http://tds-solutions.net
        Twitter: sorressean

On Apr 3, 2010, at 2:22 PM, Donald Marang wrote:

> I just started reading Python documentation today.  However, I recently asked 
> a similar question regarding the Import statement for constants in Visual 
> Basic.  Someone suggested creating a Constant class to declare all Constants. 
>  I created a separate module that just contained this Constant class.  Is 
> this the proper way to architect an application?  I need to reread OO 
> programming techniques regarding constants and globals.  It works fine.  I 
> would think the same approach could cover Globals. 
>  
> Don Marang
> 
> From: Haden Pike
> Sent: Saturday, April 03, 2010 3:34 PM
> To: programmingblind@xxxxxxxxxxxxx
> Subject: Re: Pythong Globally Scoped Variables
> 
> From what I cam tell, you're trying to access a variable that doesn't exist, 
> because it wasn't created.  This is going to sound confusing, but I'll try to 
> explain this as best I can.
> 
> The variable MyKeyBindings was defined in the main module, not the timescript 
> module.  Therefore, you can't access it without importing the main module in 
> the timescript module.  I see that you're importing the timescript module in 
> the main module, but the MyKeyBindings variable isn't defined in the 
> timescript module, so you can't access it. Confused yet?
> 
> I can't think of a simple solution right now.
> This was most likely an extremely confusing description and no doubt there is 
> an easier way to explain it.
> Haden
> 
> On 4/3/2010 3:14 PM, Storm Dragon wrote:
>> Hi,
>> I have a slight problem. I have a variable in one python file that needs to 
>> be available to all the modules it imports. I thought using the global 
>> keyword in the modules would work, but it is still throwing errors left and 
>> right.
>> In the main code I have:
>> myKeyBindings = orca.keybindings.KeyBindings()
>> But when I import a file, something like:
>> from customizations/timescript import *
>> and have the line:
>> myKeyBindings.add(orca.keybindings.KeyBinding(
>>     "t",
>>     1 << orca.settings.MODIFIER_ORCA,
>>     1 << orca.settings.MODIFIER_ORCA,
>>     sayTimeHandler, 2))
>> I keep getting a "myKeyBindings undefined" error. When I use the global 
>> keyword it just says "global name myKeyBindings not defined". So, I am 
>> obviously doing something wrong lol I just can't figure out what.
>> Thanks for the help
>> Storm
>> 
>> -- 
>> Follow me on Twitter:
>> 
>> http://www.twitter.com/stormdragon2976
>> 
>> My blog, Thoughts of a Dragon:
>> 
>> http://www.stormdragon.us/
>> 
>> Get yourself a Frostbox:
>> 
>> http://www.frostbitesystems.com/
>> 
>> Install Windows Vista in under 2 minutes:
>> 
>> http://is.gd/am6TD
>> 
>>         
>> 
>> 
>> 
> 

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

Other related posts: