 |
BOOK: Python Projects
 | This is the forum to discuss the Wrox book Python Projects Laura Cassell, Alan Gauld; ISBN: 978-1-118-90866-2 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Python Projects section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 2nd, 2015, 04:00 PM
|
|
Registered User
|
|
Join Date: Aug 2015
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
P31. Step 5. Code error(s)?
I think Step 5 should start with:
>>> c2 = tc.Circle2(42)
Rather than:
>>> c2 = Circle2(42)
Otherwise you get:
>>> c2 = Circle2(42)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Circle2' is not defined
Or did I miss something?
The downloaded code also generated this error:
>>> c2.area()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'float' object is not callable
Thanks.
|
|

August 2nd, 2015, 05:22 PM
|
|
Wrox Author
|
|
Join Date: Feb 2015
Posts: 25
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
You are quite right. My fault entirely, the error is in the original manuscript.
Thanks for pointing it out. The first line should indeed read
>>> c2 = tc.Circle2(42)
My apologies,
Alan G.
|
|

August 2nd, 2015, 05:36 PM
|
|
Wrox Author
|
|
Join Date: Feb 2015
Posts: 25
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
The downloaded code issue is slightly different. If you look closely at the
text you will see that the correct usage is
>>> c2.area
No parens after area.
That's the point of using the @property.
It means you can access area as if it were a data attribute even though,
in reality, its calling a method.
Alan G.
|
|

August 3rd, 2015, 03:41 AM
|
|
Registered User
|
|
Join Date: Aug 2015
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for both replies Alan, and for being so quick. Oh yes, I see what you mean now about c2.area. My mistake!
|
|

February 29th, 2016, 12:08 PM
|
|
Registered User
|
|
Join Date: Feb 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Still seems to be a problem
When I do step 5, I don't get the expected result, even with the correction. The line c2.radius = 12 seems to have no effect. c2.area prints out 5541.76476 just as before. c2.radius = -4 does not generate the error message, and the radius is apparently unchanged.
I thought this might be the little ARM board I am trying this on, so I tried it on my laptop, with the code downloaded from the web to make sure I had no typo. Same result.
|
|

February 29th, 2016, 09:24 PM
|
|
Wrox Author
|
|
Join Date: Feb 2015
Posts: 25
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
> When I do step 5, I don't get the expected result, even with the correction.
> The line c2.radius = 12 seems to have no effect. c2.area prints out
> 5541.76476 just as before. c2.radius = -4 does not generate the
> error message, and the radius is apparently unchanged.
That's odd, I don't know what's happening there. Can you cut 'n paste
the transcript of your interpreter session to me so I can see exactly
what you get? Either post it here, or send by email to
[email protected]
|
|

March 1st, 2016, 06:17 PM
|
|
Registered User
|
|
Join Date: Feb 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have realized that I have python 2.7 on both computers.
Here is the interpreter sesioun:
Code:
odroid@odroid:~/Documents/tests/programming/python/test01$ python
Python 2.7.6 (default, Mar 22 2014, 23:30:12)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import testcircle as tc
>>> c2 = Circle2(42)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Circle2' is not defined
>>> c2 = tc.Circle2(42)
>>> c2.area
5541.76476
>>> print(c2.radius)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: unreadable attribute
>>> c2.radius = 12
>>> c2.area
5541.76476
>>> c2.radius = -4
>>> c2.area
5541.76476
>>>
|
|

March 1st, 2016, 08:21 PM
|
|
Wrox Author
|
|
Join Date: Feb 2015
Posts: 25
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Quote:
Originally Posted by Paul_Friesen
I have realized that I have python 2.7 on both computers.
Here is the interpreter sesioun:
Code:
odroid@odroid:~/Documents/tests/programming/python/test01$ python
Python 2.7.6 (default, Mar 22 2014, 23:30:12)
[GCC 4.8.2] on linux2
|
Yep, that's the problem. The book is written for Python v3.
The problems you are hitting are due to Python v2.
Properties only work on "new style classes" in v2 (in v3 all
classes are "new style"). To fix it you need to explicitly
inherit from 'object' in the class definition:
class Circle2(object):
... as before
That should work.
But I strongly recommend grabbing a copy of v3 for the rest of the
book because there are a lot of subtle changes like that as you
go through it.
Regards,
Alan G.
Last edited by Alan G; March 1st, 2016 at 08:22 PM..
Reason: fix typo
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Syntax error in Gruntfile.js (Chapter 1, Step 2) |
matthiku |
BOOK: Professional AngularJS |
1 |
May 6th, 2015 06:16 AM |
| Error: Chapter 5 page 156 Example, Step 6 |
aojiku01 |
BOOK: Professional Microsoft SQL Server 2008 Integration Services ISBN: 978-0-470-24795-2 |
1 |
October 24th, 2014 06:18 AM |
| How do I step through the source code of a DLL that is loaded on the fly? |
Bill_Thompson |
BOOK: Professional C# 4.0 and .NET 4 |
0 |
February 16th, 2011 03:15 AM |
| SQL Error, p. 456, step 16 |
member4953 |
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 |
2 |
April 8th, 2009 01:19 PM |
| SQL Error, p. 412, step 11 |
member4953 |
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 |
3 |
April 6th, 2009 03:11 PM |
|
 |
|