[Tutor] Convert values in a list back and forth from ints
prasad rao
prasadaraon50 at gmail.com
Wed Jan 7 09:45:57 CET 2009
.>>>> class Value:.... def __init__(self, vs = ""):
>... self.vs = vs
>... self.v = self.asInt()
>... def asInt(self):
>... try: self.v = int(self.vs)
>... except: self.v = None
>... return self.v
>... def asString(self):
>... vs = str(self.vs)
>... return self.vs
>... def setStringValue(self, s):
>... self.vs = s
>... self.asInt()
>... def setIntValue(self, i):
>... self.v = int(i)
>... self.vs = str(self.v)
hello
Sorry to interject.
This class seems asymmetric.
Class Value:
def __init__(self,inte='',stri=''):
self.inte=inte
self.stri=stri
def setvalue(inte='',stri=''):
self.stri=str(self.inte)
self.int=int(self.stri)
I tried. But failed.What is wrong with above code?
>>> Class Value:
def __init__(self,inte='',stri=''):
self.inte=inte
self.stri=stri
def setvalue(inte='',stri=''):
self.stri=str(self.inte)
self.int=int(self.stri)
SyntaxError: invalid syntax
Prasad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090107/bc198518/attachment-0001.htm>
More information about the Tutor
mailing list