Hi all,
I am sorry if this is the second message about this you get; I typed
this and hit send (on gmail website) but I got a 404 error, so I am
not sure if the previous message made it out or not.
Anyway, I have about fifteen vars in a function which have to be
global. Is there a faster and more space-efficient way of doing this
than putting each var on its own line; that is, fifteen "global
varName" declarations? Thanks.
--
Have a great day,
Alex (msg sent from GMail website)
mehgcap@gmail.com; http://www.facebook.com/mehgcap
|
|
0
|
|
|
|
Reply
|
Alex
|
5/8/2010 2:08:08 PM |
|
On 8 May, 15:08, Alex Hall <mehg...@gmail.com> wrote:
> Hi all,
> I am sorry if this is the second message about this you get; I typed
> this and hit send (on gmail website) but I got a 404 error, so I am
> not sure if the previous message made it out or not.
> Anyway, I have about fifteen vars in a function which have to be
> global. Is there a faster and more space-efficient way of doing this
> than putting each var on its own line; that is, fifteen "global
> varName" declarations? Thanks.
>
> --
> Have a great day,
> Alex (msg sent from GMail website)
> mehg...@gmail.com;http://www.facebook.com/mehgcap
About 15 that *need* to be global; smells bad to me. However, you can
amend a function's .func_globals attribute. Just wouldn't be going
there myself. Why do you have this many? What's your use case?
Jon.
|
|
0
|
|
|
|
Reply
|
Jon
|
5/8/2010 2:26:16 PM
|
|
On 5/8/10, Jon Clements <joncle@googlemail.com> wrote:
> On 8 May, 15:08, Alex Hall <mehg...@gmail.com> wrote:
>> Hi all,
>> I am sorry if this is the second message about this you get; I typed
>> this and hit send (on gmail website) but I got a 404 error, so I am
>> not sure if the previous message made it out or not.
>> Anyway, I have about fifteen vars in a function which have to be
>> global. Is there a faster and more space-efficient way of doing this
>> than putting each var on its own line; that is, fifteen "global
>> varName" declarations? Thanks.
>>
>> --
>> Have a great day,
>> Alex (msg sent from GMail website)
>> mehg...@gmail.com;http://www.facebook.com/mehgcap
>
> About 15 that *need* to be global; smells bad to me. However, you can
> amend a function's .func_globals attribute.
How do you do this exactly?
> Just wouldn't be going there myself. Why do you have this many? What's your
> use case?
They are in a "setOptions" function in config.py, which reads from an
ini file and sets up all options for the program. All other files then
can read these options. For example, anyone else can import config,
then, if they are rounding a number, they can know how many places to
round to by looking at config.rnd. I have everything in a function
instead of being initialized upon importing since I offer a function
to reload the ini file if the user changes something. Eventually I
will have a gui for setting options, and that gui, to save options,
will write an ini file then call setOptions so all options are then
reset according to the newly created ini. If I do not make everything
in setOptions global, no other file seems able to read it; I get an
exception the first time another file tries to access a setting.
Thanks.
>
> Jon.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
Have a great day,
Alex (msg sent from GMail website)
mehgcap@gmail.com; http://www.facebook.com/mehgcap
|
|
0
|
|
|
|
Reply
|
Alex
|
5/8/2010 3:03:04 PM
|
|
On 8 May, 16:03, Alex Hall <mehg...@gmail.com> wrote:
> On 5/8/10, Jon Clements <jon...@googlemail.com> wrote:
>
> > On 8 May, 15:08, Alex Hall <mehg...@gmail.com> wrote:
> >> Hi all,
> >> I am sorry if this is the second message about this you get; I typed
> >> this and hit send (on gmail website) but I got a 404 error, so I am
> >> not sure if the previous message made it out or not.
> >> Anyway, I have about fifteen vars in a function which have to be
> >> global. Is there a faster and more space-efficient way of doing this
> >> than putting each var on its own line; that is, fifteen "global
> >> varName" declarations? Thanks.
>
> >> --
> >> Have a great day,
> >> Alex (msg sent from GMail website)
> >> mehg...@gmail.com;http://www.facebook.com/mehgcap
>
> > About 15 that *need* to be global; smells bad to me. However, you can
> > amend a function's .func_globals attribute.
>
> How do you do this exactly?> Just wouldn't be going there myself. Why do you have this many? What's your
> > use case?
>
> They are in a "setOptions" function in config.py, which reads from an
> ini file and sets up all options for the program. All other files then
> can read these options. For example, anyone else can import config,
> then, if they are rounding a number, they can know how many places to
> round to by looking at config.rnd. I have everything in a function
> instead of being initialized upon importing since I offer a function
> to reload the ini file if the user changes something. Eventually I
> will have a gui for setting options, and that gui, to save options,
> will write an ini file then call setOptions so all options are then
> reset according to the newly created ini. If I do not make everything
> in setOptions global, no other file seems able to read it; I get an
> exception the first time another file tries to access a setting.
> Thanks.
>
>
>
> > Jon.
>
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> --
> Have a great day,
> Alex (msg sent from GMail website)
> mehg...@gmail.com;http://www.facebook.com/mehgcap
Umm, okay at least now we know the context.
Similar to what James suggested just have a dict object in your config
module called 'settings' or something and access that. I still prefer
the "giveth rather than taketh" approach though. But heck, if it
works, who cares?
Jon.
|
|
0
|
|
|
|
Reply
|
Jon
|
5/8/2010 5:04:30 PM
|
|
On Sat, 08 May 2010 10:08:08 -0400, Alex Hall wrote:
> Hi all,
> I am sorry if this is the second message about this you get; I typed
> this and hit send (on gmail website) but I got a 404 error, so I am not
> sure if the previous message made it out or not. Anyway, I have about
> fifteen vars in a function which have to be global. Is there a faster
> and more space-efficient way of doing this than putting each var on its
> own line; that is, fifteen "global varName" declarations? Thanks.
global google, for_, global_, variables, considered, harmful
--
Steven
|
|
0
|
|
|
|
Reply
|
Steven
|
5/8/2010 6:47:32 PM
|
|
In message <mailman.2771.1273327690.23598.python-list@python.org>, Alex Hall
wrote:
> ... I have about fifteen vars in a function which have to be
> global.
Why not make them class variables, e.g.
class my_namespace :
var1 = ...
var2 = ...
#end my_namespace
def my_function(...) :
... can directly read/assign my_namespace.var1 etc here ...
#end my_function
Also has the benefit of minimizing pollution of the global namespace.
|
|
0
|
|
|
|
Reply
|
Lawrence
|
5/11/2010 5:46:56 AM
|
|
|
5 Replies
91 Views
(page loaded in 0.174 seconds)
|