Pb with an AttributeError

Nathan Harmston ratchetgrid at googlemail.com
Thu Sep 27 12:15:42 EDT 2007


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 <ebouvier at jetmultimedia.fr> 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
>



More information about the Python-list mailing list