self question

Schüle Daniel uval at rz.uni-karlsruhe.de
Tue Jul 25 13:39:03 EDT 2006


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,5)

I am burned by high=self.n
quick test with

cnt = 1
def foo():
	global cnt
	cnt += 1
	return cnt

def bar(x=foo()):
	print x

bar()	# 2
bar()	# 2
bar()	# 2

this is not behaviour C++ programmer would expect
does someone know why this kind of behaviour is/was choosen?

Regards, Daniel



More information about the Python-list mailing list