[Tutor] switch statements

Karthikesh Raju karthik at james.hut.fi
Fri Jul 9 09:56:45 CEST 2004


Hi All,

We were implementing a switch satetement like

testfile.py
dec = 1
perf = { \
	1:bigfile.func1(), \
	2:bigfile.fun2()}[dec]

now bigfile.py has

def func1():
   print "In func1"
   return 5

def func2():
   print "In func2"
   return 42

Now when we run the testfile.py we get:

In func1
In func2

which implies that the switch does not actually switch, as it goes through
both the functions and retains the one that we asked for. Am I missing
something here, why should it step into every function.

With warm regards
karthik




-----------------------------------------------------------------------
Karthikesh Raju,		    email: karthik at james.hut.fi
Researcher,			    http://www.cis.hut.fi/karthik
Helsinki University of Technology,  Tel: +358-9-451 5389
Laboratory of Comp. & Info. Sc.,    Fax: +358-9-451 3277
Department of Computer Sc.,
P.O Box 5400, FIN 02015 HUT,
Espoo, FINLAND
-----------------------------------------------------------------------


More information about the Tutor mailing list