Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > BOOK: Python Projects
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 2nd, 2015, 04:00 PM
jc. jc. is offline
Registered User
Points: 53, Level: 1
Points: 53, Level: 1 Points: 53, Level: 1 Points: 53, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2015
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
Reply With Quote
  #2 (permalink)  
Old August 2nd, 2015, 05:22 PM
Wrox Author
Points: 109, Level: 2
Points: 109, Level: 2 Points: 109, Level: 2 Points: 109, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2015
Location: Stirling, Scotland
Posts: 22
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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.
Reply With Quote
  #3 (permalink)  
Old August 2nd, 2015, 05:36 PM
Wrox Author
Points: 109, Level: 2
Points: 109, Level: 2 Points: 109, Level: 2 Points: 109, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2015
Location: Stirling, Scotland
Posts: 22
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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.
Reply With Quote
  #4 (permalink)  
Old August 3rd, 2015, 03:41 AM
jc. jc. is offline
Registered User
Points: 53, Level: 1
Points: 53, Level: 1 Points: 53, Level: 1 Points: 53, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2015
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for both replies Alan, and for being so quick. Oh yes, I see what you mean now about c2.area. My mistake!
Reply With Quote
  #5 (permalink)  
Old February 29th, 2016, 11:08 AM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
Reply With Quote
  #6 (permalink)  
Old February 29th, 2016, 08:24 PM
Wrox Author
Points: 109, Level: 2
Points: 109, Level: 2 Points: 109, Level: 2 Points: 109, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2015
Location: Stirling, Scotland
Posts: 22
Thanks: 0
Thanked 3 Times in 3 Posts
Default

> 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

alan.gauld@btinternet.com
Reply With Quote
  #7 (permalink)  
Old March 1st, 2016, 05:17 PM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
>>>
Reply With Quote
  #8 (permalink)  
Old March 1st, 2016, 07:21 PM
Wrox Author
Points: 109, Level: 2
Points: 109, Level: 2 Points: 109, Level: 2 Points: 109, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2015
Location: Stirling, Scotland
Posts: 22
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Quote:
Originally Posted by Paul_Friesen View Post
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 07:22 PM. Reason: fix typo
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 02: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



All times are GMT -4. The time now is 01:10 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.