Mike wrote:
> I think the answer is that 'def' is an executable statement in python
> rather than a definition that the compiler interprets at compile time.
>
> As a result the compiler can evaluate 'foo()' when it defines 'bar', so
> it does.
>
> The following works as expected:
> def bar():
>
Schüle Daniel wrote:
> Hi all,
>
> given python description below
>
> import random
>
> class Node:
> def __init__(self):
> self.nachbarn = []
>
> class Graph(object):
> # more code here
> def randomizeEdges(self, low=1, high=self.n):
> pas
On Tue, Jul 25, 2006 at 08:08:32PM +0200, Sch?le Daniel wrote:
> [EMAIL PROTECTED] schrieb:
> >> cnt = 1
> >> def foo():
> >>global cnt
> >>cnt += 1
> >>return cnt
> >>
> >> def bar(x=foo()):
> >>print x
> >>
> >> bar() # 2
> >> bar() # 2
> >> bar() # 2
> >
> > Looks
correction :)
> class Graph:
> settings = {
> "NumNodes" : 10,
> "MinNodes" : 2,
> "MaxNodes" : 5
> }
> def randomizeEdges(self,
> lowhigh = (settings["MinNodes"], settings["MaxNodes"])):
of course this should be
Graph.settings["MinNodes"], Graph.sett
[EMAIL PROTECTED] schrieb:
>> cnt = 1
>> def foo():
>> global cnt
>> cnt += 1
>> return cnt
>>
>> def bar(x=foo()):
>> print x
>>
>> bar()# 2
>> bar()# 2
>> bar()# 2
>
> Looks to me like you want to use the following programming pattern to
> get dynamic
> cnt = 1
> def foo():
> global cnt
> cnt += 1
> return cnt
>
> def bar(x=foo()):
> print x
>
> bar() # 2
> bar() # 2
> bar() # 2
Looks to me like you want to use the following programming pattern to
get dynamic default arguments:
cnt = 1
def foo():
global cnt
Hi all,
given python description below
import random
class Node:
def __init__(self):
self.nachbarn = []
class Graph(object):
# more code here
def randomizeEdges(self, low=1, high=self.n):
pass
graph = Graph(20)
graph.randomizeEdges(2