wasm-demo/demo/ermis-f/python_m/cur/1917

56 lines
1.9 KiB
Plaintext

From: tismer at appliedbiometrics.com (Christian Tismer)
Date: Thu, 13 May 1999 17:50:58 GMT
Subject: How to compile a multi-line function definition ?
References: <373B0720.FE771511@unice.fr>
Message-ID: <373B1102.DE2EA277@appliedbiometrics.com>
Content-Length: 1596
X-UID: 1917
Jerome ALET wrote:
>
> Hi there,
>
> I've just read the complete Python's documentation (well, almost :-) and
> I've found nothing to solve my problem. This doc is very good but lacks
> examples, IMHO.
>
> Given the following sample of code which works fine in Python 1.5.2, I
> want to know how to define a multi-line "my_function". Every time I try
> something I get a syntaxerror or something similar.
>
> -------- CUT ------------
> # mytest.py
> # module to do some testing
> class MyClass :
> loc = locals()
> def __init__(self) :
> exec(compile("def my_function(self, a, b) : print a, b,
> '<==>', b, a""", "<string>", "exec"), self.loc)
> ---------- CUT ----------
Your code string is missing a "\n" at its end.
BTW, what are you trying to achieve? It doesn't look like
the right path, I guess. Where do you want to put "my_function",
shall that become a new method for your instance?
Will not work, although there are ways to do this.
But before, I suggest to play more with classes and instances
in the way they are designed for, then you might be able to
avoid tricks like generating code.
cheers - chris
--
Christian Tismer :^) <mailto:tismer at appliedbiometrics.com>
Applied Biometrics GmbH : Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101 : *Starship* http://starship.python.net
10553 Berlin : PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF
we're tired of banana software - shipped green, ripens at home