T
TheSaint
Hi,
I'm very new with classes. I still reading something around
I got started to try a concatenation of 2 type of string, which have a
particular property to start with A or D.
My class here:
""" Small class to join some strings according to the leading first
letter"""
def __init__(self):
self.valueA= ''
self.valueD= ''
def __add__(self, value):
if not isinstance(value, str): return
if value.lower().startswith('a'):
self.valueA += value
if value.lower().startswith('d'):
self.valueD += value
return self.valueA ,self.valueD
__call__= __add__
__iadd__= __add__
my test on the shell:
Traceback (most recent call last):
Traceback (most recent call last):
('aksaboi', 'daksdhksduboi')
Do I miss something?
I'd rather like to avoid class, but a function won't allow me to store so
easily data between several call.
Mostly I'd expect to pass to the built instance in a more elaborated
function. Then I mean call will be the primer goal.
I'm very new with classes. I still reading something around
I got started to try a concatenation of 2 type of string, which have a
particular property to start with A or D.
My class here:
""" Small class to join some strings according to the leading first
letter"""
def __init__(self):
self.valueA= ''
self.valueD= ''
def __add__(self, value):
if not isinstance(value, str): return
if value.lower().startswith('a'):
self.valueA += value
if value.lower().startswith('d'):
self.valueD += value
return self.valueA ,self.valueD
__call__= __add__
__iadd__= __add__
my test on the shell:
Traceback (most recent call last):
Traceback (most recent call last):
('aksaboi', 'daksdhksduboi')
Do I miss something?
I'd rather like to avoid class, but a function won't allow me to store so
easily data between several call.
Mostly I'd expect to pass to the built instance in a more elaborated
function. Then I mean call will be the primer goal.