From: John M. <sjm...@le...> - 2007-07-11 09:51:12
|
On 11/07/2007 6:08 PM, YeungXS67 wrote: > I frequently receive this error that insists an object is a 'str' object > and that it doesn't have an attribute 'data', although it most certainly > does. Most certainly? On what is this belief based? Consider the following: >>> foo = 'xyzzy' >>> type(foo) <type 'str'> # foo refers to a 'str' object >>> foo.data Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'str' object has no attribute 'data' >>> hasattr(foo, 'data') False # a newborn 'str' object doesn't have an attribute 'data' >>> foo.data = 'plugh' Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'str' object has no attribute 'data' # a 'str' object can't even be given an attribute 'data' > This error only occurs after it's been compiled and executed as an > executable, but not as a .py file executed through the interpreter. Does > anyone know why this is? No, and we never will if you don't divulge what is in line 27 of pwcb.py. Have you considered preceding that line by print "just before error" print type(foo) # assuming foo refers to your 'str' object print hasattr(foo, 'data') print dir(foo) ? > > Traceback (most recent call last): > File "pwcb.py", line 111, in <module> > File "pwcb.py", line 27, in begin_capture > AttributeError: 'str' object has no attribute 'data' > HTH, John |