Luis M. González a écrit :
(snip)
> OK, so I should include the global only if I plan to modify it.
> Otherwise, I don't need to include it. Am I right?
s/modify/rebind/
--
http://mail.python.org/mailman/listinfo/python-list
Luis M. González a écrit :
> Bruno Desthuilliers wrote:
>
>>def doIt(name=None):
>> global gname
>> if name is None:
>>name = gname
>> else:
>>gname = name
>>
>
>
> Sorry for this very basic question, but I don't understand why I should
> add the global into the function body before u
Markus Wankus wrote:
> On Fri, 07 Jul 2006 19:41:36 -0400, Luis M. González <[EMAIL PROTECTED]>
> wrote:
> .
> .
> > OK, so I should include the global only if I plan to modify it.
> > Otherwise, I don't need to include it. Am I right?
> >
>
> Correct. Globals are always available to read from.
On Fri, 07 Jul 2006 19:41:36 -0400, Luis M. González <[EMAIL PROTECTED]>
wrote:
.
.
> OK, so I should include the global only if I plan to modify it.
> Otherwise, I don't need to include it. Am I right?
>
Correct. Globals are always available to read from. You need to declare
them if you wan
> OK, so I should include the global only if I plan to modify it.
> Otherwise, I don't need to include it. Am I right?
I guess you could say that's true. I'm hardly an expert so I couldn't
say there aren't other potential ramifications. (anyone?)
But, as a rule I would declare the global varia
nate wrote:
> try this:
>
> gname = 'nate'
> def test():
>gname = 'amy'
>print gname
>
> test()
> print gname
>
> outputs:
> 'amy'
> 'nate'
>
> whereas this:
> gname = 'nate'
> def test():
>global gname
>gname = 'amy'
>print gname
>
> test()
> print gname
>
> outputs:
> 'amy'
>
try this:
gname = 'nate'
def test():
gname = 'amy'
print gname
test()
print gname
outputs:
'amy'
'nate'
whereas this:
gname = 'nate'
def test():
global gname
gname = 'amy'
print gname
test()
print gname
outputs:
'amy'
'amy'
Luis M. González wrote:
> Bruno Desthuilliers wrote:
Bruno Desthuilliers wrote:
>
> def doIt(name=None):
> global gname
> if name is None:
> name = gname
> else:
> gname = name
>
Sorry for this very basic question, but I don't understand why I should
add the global into the function body before using it.
This function works even if I
meridian wrote:
> Thanks Bruno. Not only do you give solutions to my problem but also
> throw in great MVC tutorials too.
> You're a gent.
(blush)
> I'm using
> controller -> A CherryPy app
> views -> Cheetah Templating for the html & data
> model -> mostly SQLite DB using pysqlite
> also Config
Thanks Bruno. Not only do you give solutions to my problem but also
throw in great MVC tutorials too.
You're a gent.
I'm using
controller -> A CherryPy app
views -> Cheetah Templating for the html & data
model -> mostly SQLite DB using pysqlite
also Config
It's only a desk-web app for single-user
meridian a écrit :
> You mentioned earlier that
> "Modifying globals from within a function is usually a very bad idea."
>
> Most of my app consists of functions or class/object functions, that's
> all I do in OOP.
> Did you mean that modifying globals from anywhere is bad?
Yes, definitively. Ev
meridian a écrit :
> Bruno Desthuilliers wrote:
>
>>meridian wrote:
>>
>>>Bruno Desthuilliers wrote:
>>>
>>>
def doIt(name=None):
global gname
if name is None:
name = gname
else:
gname = name
>>>
>>>
>>>Thanks Bruno, works a treat...
>>>
>>
>>But still very pr
You mentioned earlier that
"Modifying globals from within a function is usually a very bad idea."
Most of my app consists of functions or class/object functions, that's
all I do in OOP.
Did you mean that modifying globals from anywhere is bad? or globals
are bad? or don't code using methods/funct
Bruno Desthuilliers wrote:
> meridian wrote:
> > Bruno Desthuilliers wrote:
> >
> >>def doIt(name=None):
> >> global gname
> >> if name is None:
> >>name = gname
> >> else:
> >>gname = name
> >>
> >
> >
> > Thanks Bruno, works a treat...
> >
> But still very probably a bad idea.
>
Ok, m
meridian wrote:
> Bruno Desthuilliers wrote:
>
>>def doIt(name=None):
>> global gname
>> if name is None:
>>name = gname
>> else:
>>gname = name
>>
>
>
> Thanks Bruno, works a treat...
>
But still very probably a bad idea.
--
bruno desthuilliers
python -c "print '@'.join(['.'.join(
Bruno Desthuilliers wrote:
> def doIt(name=None):
> global gname
> if name is None:
> name = gname
> else:
> gname = name
>
Thanks Bruno, works a treat...
--
http://mail.python.org/mailman/listinfo/python-list
meridian wrote:
> I thought I had 'got' globals but this one seems strange.
> I want my example function 'doIt' to use and optionally modify a module
> variable 'gname', so I declare 'global gname' in the function, but when
> modified it doesn't stay modified.
>
> gname = 'Sue'
> def doIt(name = g
I thought I had 'got' globals but this one seems strange.
I want my example function 'doIt' to use and optionally modify a module
variable 'gname', so I declare 'global gname' in the function, but when
modified it doesn't stay modified.
gname = 'Sue'
def doIt(name = gname):
global gname
gn
18 matches
Mail list logo