johnf [EMAIL PROTECTED] wrote
def someMethod():
class MyClass(object):
.
if something:
.
return someval
Did you try it?
def f():
... class C: pass
... return C
...
def g(x):
... class C: pass
... if x == 42:
... return C
... else: return 666
...
bob gailer [EMAIL PROTECTED] wrote
So the question becomes why would you want to do that?
The main reason I could think of was to create a factory
method for dynamically creating classes based on input
parameters - for example currency convertors or similar.
Equally you could change method
johnf [EMAIL PROTECTED] wrote
1 and 3 are my reasons. I'm creating a Dabo app. When I attempted
to create
a special class that contained a dialog box I discovered that the
dialog
class created an indepentant type of window and allowed my program
to
continue running without waiting
On Thursday 03 January 2008 12:22:25 am Alan Gauld wrote:
Are you sure you made it a modal dialog?
Any dialog will do that if it is opened modelessly, you need to
use the modal version to make it block the app.
Yes. I believe the way I have coded the dialog causes a bug. If I create a
johnf [EMAIL PROTECTED] wrote
If the user types in a partial of the key then the dialog
appears and the user picks from the list. The details of the dialog
are
dynamic for each call (based on some meta data) of the showModal().
This might be a valid case for defining the class in the
On Thursday 03 January 2008 10:13:18 am Alan Gauld wrote:
johnf [EMAIL PROTECTED] wrote
If the user types in a partial of the key then the dialog
appears and the user picks from the list. The details of the dialog
are
dynamic for each call (based on some meta data) of the
johnf wrote:
So I started thinking why would I need the class outside of the function. If
I instead used import class would I get a performance improvement? The
function creates an instance each time it is required and then releases and
closes.
I am very interested in this possible
def someMethod():
class MyClass(object):
.
if something:
.
return someval
--
John Fabiani
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
johnf wrote:
def someMethod():
class MyClass(object):
.
if something:
.
return someval
Legal? Well the police won't come after you!
Python allows a class statement anywhere. So this use is part of the
language.
So the question becomes why would
On Wednesday 02 January 2008 09:31:19 pm you wrote:
johnf wrote:
def someMethod():
class MyClass(object):
.
if something:
.
return someval
Legal? Well the police won't come after you!
That's a good thing!
Python allows a class statement anywhere. So
10 matches
Mail list logo