LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-31-2018, 01:18 AM   #16
Myk267
Member
 
Registered: Apr 2012
Location: California
Posts: 422
Blog Entries: 16

Rep: Reputation: Disabled

Quote:
Originally Posted by vysero View Post
Okay well that worked, thanks; however, I am not sure why. In the video tutorial his code worked for him just fine. Is this some new convention in my newer version of Python as compared with his older version of Python?
I wasn't able to pin down why Derek's incorrect code nevertheless worked. I even pulled down Python 3.4.2 but I still get the same error. It's possible it was a macos/32 bug. Though, interestingly, in the video's description box there's a link to a 'cheatsheet' that has corrected code.

Anyone out there with a 32 bit mac want to run an experiment?
 
Old 06-01-2018, 08:19 AM   #17
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,242

Rep: Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322
I noticed some antipatterns.

First, he's using toString and not __str__

Code:
class Dog(Animal):
    def __init__(self):
        def __init__(self)

a = Animal()
print a
Note that __str__ is called automatically when you call print.

If he's using Python 3, then he should be using Python 3's super syntax:

Code:
class Dog(Animal):
    def __init__(self, name):
        super().__init__(name)
And if he was using Python 2 he should have been deriving his base classes from object:

Code:
class Animal(object):

Last edited by dugan; 06-01-2018 at 08:27 AM.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to find out in which file variable has been defined. manoj.linux Linux - Enterprise 1 12-05-2014 10:01 AM
[SOLVED] variable defined in awk, not working. !!! Sha_unix Solaris / OpenSolaris 15 09-23-2011 05:06 AM
Get value for variable name defined as string webquinty Programming 4 11-18-2009 05:30 AM
Replace variable with user defined variable ce124 Programming 10 04-13-2007 09:29 AM
Trouble Python Code Gerardoj Programming 0 11-30-2003 04:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration