On 2007-08-09, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
> Neil Cerutti a écrit :
>> On 2007-08-09, special_dragonfly <[EMAIL PROTECTED]> wrote:
>>> Is there anyway for python to consider the values within a
>>> string when entering the data into a dictionary. I know that
>>> isn't very clear so here's an example:
>>>
>>> class MyClass(object):
>>>     def __init__(self,name="",age=""):
>>>         self.name=name
>>>         self.age=age
>>>
>>> data="Gary,50"
>>> d={0:[MyClass(data)]}
>>> data="Adam,25"
>>> d[0].append(MyClass(data))
>>>
>>> The data is coming from a text file working on a line by line
>>> basis. I've just tried and I'm just getting the full string in
>>> the first field. That seems logical, now I don't want it to
>>> though!
>> 
>> That's what happens if you use 0 for the key every time. ;)
>
> Hmmm... Neil, I may be wrong but I think you didn't get the
> point here. As I understand it,  Dominic's problem is that it
> gets strings like "Gary,50" and would like to call MyClass
> initializer this way : MyClass("Gary", "50")

My guess was he doesn't need a class at all, but needed to decide
what he's mapping from->to. It seems far-fetched to me that he
*really* wants a mapping between an index and MyClass objects
containing name and age.

So I tried to cut out the middle-man. Hopefully we can get some
closure on this.

-- 
Neil Cerutti
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to