Thanks, I find the "type" function and effectively the type is a dict. I didn't know this type before ! :-}
The program normally try to get the value of SP between the <> in the string1. Here, it's 136. The string1 is normally longer and had a lot of "<value>" but only one with "<value>=". I find str() and applied it to tranform the type 'dict' in a sting type. Thus, I arrived to get "136" with regular expression. Thanks > -----Message d'origine----- > De : Nathan Harmston [mailto:[EMAIL PROTECTED] > Envoyé : jeudi 27 septembre 2007 18:16 > À : Eric BOUVIER > Cc : python-list@python.org > Objet : Re: Pb with an AttributeError > > Hi, > > I m not sure what your trying to do, but this is where your > problem is: > > string1 is not a string it is actually a dict because of your eval. > When you call > string1["param"] inside the string.split() > > it is returning a dictionary and not a string.... > 'param': {'key': 'SP<136>=', 'value': ['SD:<0> ']} > > since {'key': 'SP<136>=', 'value': ['SD:<0> ']} is inside curly > brackets it is a dictionary. > > I still dont get what your trying to have as your final result, but > hope this helps. > > Thanks > > Nathan > > On 27/09/2007, Eric BOUVIER <[EMAIL PROTECTED]> wrote: > > > > > > > > Hello, > > > > First, sorry for my english. > > > > I've just been assigned a project written in Python which > contains bug(s). > > I've never programmed in Python, but I've read the code > > and understood basically what the different source codes do. > > > > I've traced the code and found where the problem is but I don't > > know how to solve the problem. > > > > Here it is : > > > > I've got a string issued from a CSV file : > > string1 = eval(line[4]) > > print " * string1 = (", string1 ,") \n" > > => * string1 = ( {'header': 'X-Score', 'param': > {'key': 'SP<136>=', > > 'value': ['SD:<0> ']} ) > > > > Then, there is a split with the equal : > > TheParts = string.split(string1["param"], "=") > > print " * TheParts = (", TheParts ,") \n" > > > > But, running the program returns : > > > > Traceback (most recent call last): > > File "C:\test\helper.py", line 136, in Action_handler > > Score_eval(line, OutputFile_SP, This_Host) > > File "C:\test\helper.py", line 66, in Score_eval > > TheParts = string.split(string1["param"], "=") > > File "C:\ActiveState\Python25\lib\string.py", line 290, > > in split > > return s.split(sep, maxsplit) > > AttributeError: 'dict' object has no attribute 'split' !?! > > > > I've found that it works when I put directly the string in the split > > expression : > > > > TheParts = string.split(" {'key': 'ESP<136>=', 'value': > ['SHA:<0> ']} ", > > "=") > > => * TheParts = ["{'key': 'ESP<136>", "', 'value': > ['SHA:<0> ']}"] > > > > But the code isn't dynamic anymore ! > > I think it's a problem with the type, but the different > syntax I've tried > > didn't work. > > Is somebody could help me ? > > > > Thank you > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > -- http://mail.python.org/mailman/listinfo/python-list