problem with str()

Terry Reedy tjreedy at udel.edu
Thu Mar 15 16:35:35 EDT 2007


"7stud" <bbxx789_05ss at yahoo.com> wrote in message 
news:1173988141.493995.196780 at n76g2000hsh.googlegroups.com...
|I can't get the str() method to work in the following code(the last
| line produces an error):

If you 'print str' here

| methodList = [str for str in names if callable(getattr(obj, str))]

and again here, you will see the problem; you have reassigned the name 
'str' to something else by using it in the list comp.  Hence the advice to 
never reuse
builtin names unless you mean to lose access to the builtin object.

|print str(getattr(obj, methodList[0]).__doc__)

Here I presume you want the builtin function.  Too bad... ;-)

Terry Jan Reedy






More information about the Python-list mailing list