Steven D'Aprano wrote:
On Mon, 21 Feb 2011 14:23:10 +0100, Jean-Michel Pichavant wrote:
What is not legit, is to return different objects for which the caller
has to test the type to know what attributes he can use.
Well, I don't know... I'm of two minds.
On the one hand, I find it
alex23 wrote:
Jean-Michel Pichavant jeanmic...@sequans.com wrote:
You simply don't return inconsistent types with a return statement. This
is a general rule in programming that has probably exceptions but
regarding what you're saying, you clearly don't want to do that.
I don't think
On Mon, 21 Feb 2011 14:23:10 +0100, Jean-Michel Pichavant wrote:
What is not legit, is to return different objects for which the caller
has to test the type to know what attributes he can use.
Well, I don't know... I'm of two minds.
On the one hand, I find it *really annoying* when this
Richard Thomas chards...@gmail.com writes:
If you don't want to use a factory function I believe you can do this:
class MyNumber(object):
def __new__(cls, n):
if n = 100:
cls = SmallNumbers
else:
cls = BigNumbers
return
s...@uce.gov wrote:
How can I do something like this in python:
#!/usr/bin/python3.1
class MyNumbers:
def __init__(self, n):
self.original_value = n
if n = 100:
self = SmallNumers(self)
else:
self = BigNumbers(self)
class SmallNumbers:
def __init__(self, n):
Karim wrote:
[snip]
If you don't want to use a factory function I believe you can do this:
class MyNumber(object):
def __new__(cls, n):
if n= 100:
cls = SmallNumbers
else:
cls = BigNumbers
return object.__new__(cls, n)
...
Chard.
On Thu, 17 Feb 2011 12:02:28 +0100, Jean-Michel Pichavant wrote:
Karim wrote:
[snip]
If you don't want to use a factory function I believe you can do this:
class MyNumber(object):
def __new__(cls, n):
if n= 100:
cls = SmallNumbers
else:
Steven D'Aprano wrote:
On Thu, 17 Feb 2011 12:02:28 +0100, Jean-Michel Pichavant wrote:
Karim wrote:
[snip]
If you don't want to use a factory function I believe you can do this:
class MyNumber(object):
def __new__(cls, n):
if n= 100:
cls =
On Thu, 2011-02-17 at 11:43 +, Steven D'Aprano wrote:
On Thu, 17 Feb 2011 12:02:28 +0100, Jean-Michel Pichavant wrote:
Karim wrote:
[snip]
If you don't want to use a factory function I believe you can do this:
class MyNumber(object):
def __new__(cls, n):
if n=
On 17/02/2011 14:39, Westley Martínez wrote:
On Thu, 2011-02-17 at 11:43 +, Steven D'Aprano wrote:
On Thu, 17 Feb 2011 12:02:28 +0100, Jean-Michel Pichavant wrote:
Karim wrote:
[snip]
If you don't want to use a factory function I believe you can do this:
class MyNumber(object):
On Thu, 2011-02-17 at 15:56 +, MRAB wrote:
On 17/02/2011 14:39, Westley Martínez wrote:
On Thu, 2011-02-17 at 11:43 +, Steven D'Aprano wrote:
On Thu, 17 Feb 2011 12:02:28 +0100, Jean-Michel Pichavant wrote:
Karim wrote:
[snip]
If you don't want to use a factory function I
Jean-Michel Pichavant jeanmic...@sequans.com wrote:
You simply don't return inconsistent types with a return statement. This
is a general rule in programming that has probably exceptions but
regarding what you're saying, you clearly don't want to do that.
I don't think they were intended to be
On Thu, 17 Feb 2011 15:53:14 -0800, Westley Martínez wrote:
Python 3 removed longs because they were ... cryptonic!
Strictly speaking, they weren't removed. ints were removed and long was
renamed int.
My point stands.
Your point is wrong. Ints and longs weren't unified because it is
On Fri, 2011-02-18 at 02:25 +, Steven D'Aprano wrote:
On Thu, 17 Feb 2011 15:53:14 -0800, Westley Martínez wrote:
Python 3 removed longs because they were ... cryptonic!
Strictly speaking, they weren't removed. ints were removed and long was
renamed int.
My point stands.
Your
On 02/16/2011 06:05 AM, Richard Thomas wrote:
On Feb 16, 2:23 am, s...@uce.gov wrote:
How can I do something like this in python:
#!/usr/bin/python3.1
class MyNumbers:
def __init__(self, n):
self.original_value = n
if n= 100:
self = SmallNumers(self)
else:
On Tue, 15 Feb 2011 19:23:39 -0700, spam wrote:
How can I do something like this in python:
#!/usr/bin/python3.1
class MyNumbers:
def __init__(self, n):
self.original_value = n
if n = 100:
self = SmallNumers(self)
else:
self = BigNumbers(self)
(1)
On Tue, 15 Feb 2011 22:17:13 -0700, spam wrote:
I didn't explain my problem, chose a terrible example. This is more what
I'm trying to do:
[snip thingy class]
No, your first example was better. This one is terrible -- it's so
generic it's meaningless.
In any case, you don't explain why it
How can I do something like this in python:
#!/usr/bin/python3.1
class MyNumbers:
def __init__(self, n):
self.original_value = n
if n = 100:
self = SmallNumers(self)
else:
self = BigNumbers(self)
class SmallNumbers:
def __init__(self, n):
self.size = 'small'
On 16/02/2011 02:23, s...@uce.gov wrote:
How can I do something like this in python:
#!/usr/bin/python3.1
class MyNumbers:
def __init__(self, n):
self.original_value = n
if n = 100:
self = SmallNumers(self)
else:
self = BigNumbers(self)
class SmallNumbers:
def
s...@uce.gov writes:
How can I do something like this in python:
#!/usr/bin/python3.1
class MyNumbers:
def __init__(self, n):
self.original_value = n
if n = 100:
self = SmallNumers(self)
else:
self = BigNumbers(self)
A class defines a type of object. If you
On Feb 16, 12:23 pm, s...@uce.gov wrote:
How can I do something like this in python:
#!/usr/bin/python3.1
class MyNumbers:
def __init__(self, n):
self.original_value = n
if n = 100:
self = SmallNumers(self)
else:
self = BigNumbers(self)
class
alex23 wuwe...@gmail.com wrote:
self.__class__ = BigNumbers if n 100 else SmallThing
That should, of course, be SmallNumbers :)
--
http://mail.python.org/mailman/listinfo/python-list
er
I think you need a NumberFactory that makes SmallNumber and BigNumber
according to the initial value.
?? 2011-2-16 10:23, s...@uce.gov :
How can I do something like this in python:
#!/usr/bin/python3.1
class MyNumbers:
def __init__(self, n):
self.original_value
On Feb 16, 2:23 am, s...@uce.gov wrote:
How can I do something like this in python:
#!/usr/bin/python3.1
class MyNumbers:
def __init__(self, n):
self.original_value = n
if n = 100:
self = SmallNumers(self)
else:
self = BigNumbers(self)
class
On 11-02-15 07:45 PM, alex23 wrote:
Firstly, does MyNumbers _have_ to be a class? Or would a function
acting as a class factory be sufficient?
Yes it does. I didn't explain my problem, chose a terrible example. This is
more what I'm trying to do:
class thingy:
def __init__(self,
I didn't explain my problem, chose a terrible example. This is more what I'm
trying to do:
class thingy:
def __init__(self, athingy):
self.basic_extract()
if self.typeof = A
.../...
def basic_extract(self):
# complicated logic to extract data out of the thingy here
s...@uce.gov writes:
I didn't explain my problem, chose a terrible example. This is more
what I'm trying to do:
Unfortunately, it's still very contrived, and the names don't give any
suggestion as to what you're trying to achieve. Can you improve on that?
class ThingyTypeA:
def
I didn't explain my problem, chose a terrible example. This is more
what I'm trying to do:
Basically the subclass I want to use is based on some of the data I extract
from a blob of data. If I use a function to extract the data before I create
the objects, then I need to do a bunch of
s...@uce.gov writes:
Perhaps you want those classes to inherit from your base class. Have
you done the Python tutorial? It covers inheritance and how to use
it.
Yes, I have done subclasing before, and yes ThingyTypeA and B should
be subclassing Thingy
Then your example still gives no
29 matches
Mail list logo