Passing parameters to eval.
Hi, I appreciate all replies to my previous quesions. This time, I am trying to pass two parameter to eval function so it can evaluate and return the result base on the parameter i gave. For examples:
********func.py*************** def fun (): print v1+v2
**************pro.py*********** from func import * funname = "fun()" v1 = "Hello " v2 = "World" eval(funname) **************************** I know these code will not run. If i put fun in the same file as pro.py, it works. What i want is to let fun in func.py to have access to variable v1 and v2 which are declared in pro.py. How can i do this? Any guidance or suggestion is highly appreciated.
I know this construct is weird. The reason i do this is the following: I have a cgi page that maintain the step to perform based on the form fields it receives. There are many fields this main cgi will receive. But each page pointing to this main page may send different set of fields. So base on the fields main cgi page get, it can determine which page to run next. My plan is to get the name of the function and pass it to eval. But that particular function passed to eval will use some parameters received by main page. That is why i wish to make all the variables in main page to be visible by other functions so i don't have to worry what parameters to be passed. Any good alternative to this problem? Thanks a lot. Kim Titu __________________________________________________ Do You Yahoo!? Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger. http://im.yahoo.com
by other functions so i don't have to worry what parameters to be passed. Any good alternative to this problem? Thanks a lot.
Kim Titu
cgi.FieldStorage() will contain all the passed parameters in one place when the main script is called, so why not have all your functions take a single parameter e.g. form = cgi.FieldStorage() funname = "fun" eval(funname+"(form)") Then each function can figure out what to do with the information in your single parameter object (treatable as a dictionary, i.e. with keys and values). Kirby
At 12:43 AM 9/27/2001 -0700, you wrote:
A nice quote by Chris Langreiter [Vanilla author]
... Programming is about languages much much more than about 'mathematics' -
I would agree with the quote except I don't think mathematics *has* to be infinitely abstract. One of the joys of applying programming to math is you tend to make it (math) more concrete. And that can provide a more secure basis for subsequent abstraction. Kirby
A nice quote by Chris Langreiter [Vanilla author] ... Programming is about languages much much more than about 'mathematics' - quite in sharp contrast to what they try to tell you in school. Languages provide you with a 'certain' level of abstraction, mathematics with a theoretically infinite one. Infinite abstractions are, however, pretty useless. Programming is as much fun as writing a poem or a short story or composing a song. It's putting sentences, statements, words together to form a meaningful whole. A well-written program (like much of a Smalltalk image) is like a symphony. - Jason quote source = http://static.userland.com/userLandDiscussArchive/msg016342.html Vanilla http://www.langreiter.com/cgi-bin/vanilla.r
Programming is about languages much much more than about 'mathematics' -
I would agree with the quote except I don't think mathematics *has* to be infinitely abstract. One of the joys of applying programming to math is you tend to make it (math) more concrete. And that can provide a more secure basis for subsequent abstraction.
Kirby
Kirby LOL..I hoped that would catch your attention ;-) 'Infinitely Abstract' is almost an oxymoron. Everything has its own scale, context and direction... I have been re-reading a truly brilliant book you might all enjoy. I would describe as a rare example of a new ZenScience in action: Dynamic Patterns : The Self-Organization of Brain and Behavior (Complex Adaptive Systems) by J. A. Scott Kelso Paperback - 360 pages Reprint edition (March 1997) ISBN: 0262611317 <quote1: blurb from back of book> For the past twenty years Scott Kelso's research has focused on extending the physical concepts of self- organization and the mathematical tools of nonlinear dynamics to understand how human beings (and human brains) perceive, intend, learn, control, and coordinate complex behaviors. In this book Kelso proposes a new, general framework within which to connect brain, mind, and behavior. Kelso's prescription for mental life breaks dramatically with the classical computational approach that is still the operative framework for many newer psychological and neurophysiological studies. His core thesis is that the creation and evolution of patterned behavior at all levels -- from neurons to mind -- is governed by the generic processes of self-organization. Both human brain and behavior are shown to exhibit features of pattern-forming dynamical systems, including multistability, abrupt phase transitions, crises, and intermittency. Dynamic Patterns brings together different aspects of this approach to the study of human behavior, using simple experimental examples and illustrations to convey essential concepts, strategies, and methods, with a minimum of mathematics. </quote1> The book functions on _many_ levels, representing 20 years of brilliant work. It is extremely well written in my opinion. For example: <quote2: excerpt from the preface> ... This book is a small step towards fillnig the gap between the known laws of how matter behaves and how human beings behave. Just as classical physics derived its macrsoscopic laws from observations about the motion of planets and terrestial bodies, I will describe how it is possible to construct some of the laws that appear to govern (or at least describe and occasionally predict) the dynamic behavioral patterns produced by animals and people. These are used as the foundation on which to build a deeper understanding of phenomena such as perceiving, intending, ancicipating, learning, adapting to the environment -- and as a window into the brain itelf. The centerpiece of the book is a theory of coordination, how things are put together to produce recognizable functions. The things themselves might be made of matter, such as neurons, muscles or parts of the body, or they might be mental "things" such as perceptions and ideas. Coordination, I argue, is a fundamental feature of life. Imagine a living system composed of components that ignored each other and did not interact with themselves or the environment. Such a system would possess neither structure nor function. In this book I address the basic nature of this interaction, how it occurs and why it is the way it is. The core thesis is that human behavior - from neurons to mind - is governed by the generic process of self organization. Self organization refers to the spontaneous formation of patterns and pattern change in open, nonequilibrium systems. I argue that regardless of the levels of description one chooses to study (and this I would add is always a personal choice), the same basic pattern forming principles are in evidence. ... </quote2> He is director of the Center for Complex Systems and Brain Sciences at Florida Atlantic University http://www.ccs.fau.edu/ A conference is planned http://www.ccs.fau.edu/conferencenews.htm best wishes - Jason
participants (3)
-
Jason Cunliffe
-
Kirby Urner
-
Titu Kim