[Tutor] noob python question

Cameron Simpson cs at zip.com.au
Mon Oct 26 00:22:48 EDT 2015


On 25Oct2015 16:16, bob5487 <evolution5487 at gmail.com> wrote:
>Reading *Learn Python the Hard Way* Zed Shaw
>All good so far but got to Ex 42 dealing with classes...
>
>I get a TypeError: getattr(): attribute name must be a string when I run the
>program...
>
>I looked online, python reference manual 3rd edition, etc...
>I was wondering if anyone has experience with this book because I hit a road
>block

As always with this list, please post the code you're trying. Even if we had 
the book (I do not, personally), we don't know if your failing code matches the 
code in the book, or if the code in the book is correct.

So please post the code, and the complete error message your computer gives 
you.

Also not that getattr takes a string, per the error message. So to fetch the 
.foo attribute from some object "o" you would write:

  attribute = getattr(o, 'foo')

Note the quotes.

CHeers,
Cameron Simpson <cs at zip.com.au>


More information about the Tutor mailing list