[Tutor] Tutor Digest, Vol 162, Issue 42

Howard Lawrence 1019shaun at gmail.com
Thu Aug 17 07:43:27 EDT 2017


On Aug 17, 2017 3:17 AM, <tutor-request at python.org> wrote:

Send Tutor mailing list submissions to
        tutor at python.org

To subscribe or unsubscribe via the World Wide Web, visit
        https://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
        tutor-request at python.org

You can reach the person managing the list at
        tutor-owner at python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."

Today's Topics:

   1. Object takes no parameters (Howard Lawrence)
   2. Re: (no subject) (Zachary Ware)
   3. Re: Object takes no parameters (Alan Gauld)
   4. Re: (no subject) (Alan Gauld)
   5. Re: "Path tree" (Abdur-Rahmaan Janhangeer)
   6. Re: "Path tree" (Michael C)


---------- Forwarded message ----------
From: Howard Lawrence <1019shaun at gmail.com>
To: tutor at python.org
Cc:
Bcc:
Date: Wed, 16 Aug 2017 17:08:47 -0700
Subject: [Tutor] Object takes no parameters
class Human:
     def _init_(self, n, o)
          self.name = n
          self.occupation = o

     def do_work(self):
         if self.occupation== 'tennis player':
            print(self.name, 'plays tennis')

         elif self.occupation == 'actor':
            print(self.name, 'shoots film')

     def speaks(self):
         print(self.name, 'how are you')

tom = Human('tom cruise', 'actor')
tom.do_work()
tom.speak()

Traceback most recent call last
File "c:\users\shaun\python\python35\human_class.py"line 16 in module
tom =Human('tom cruise', 'actor')
TypeError: object() takes no parameters

how to fix this?why it happens?
this happens whenever i try to do
class,this is from a tutorial



---------- Forwarded message ----------
From: Zachary Ware <zachary.ware+pytut at gmail.com>
To: tutor <tutor at python.org>
Cc: Howard Lawrence <1019shaun at gmail.com>
Bcc:
Date: Wed, 16 Aug 2017 20:02:23 -0500
Subject: Re: [Tutor] (no subject)
Hi Howard,

On Wed, Aug 16, 2017 at 5:36 PM, Howard Lawrence <1019shaun at gmail.com>
wrote:
> class Address:
>         def _init_(self,Hs,St,Town,Zip):

Your issue is in this line, it should be `__init__` rather than
`_init_` (that is, two underscores before and after "init").

Hope this helps,
--
Zach



---------- Forwarded message ----------
From: Alan Gauld <alan.gauld at yahoo.co.uk>
To: tutor at python.org
Cc:
Bcc:
Date: Thu, 17 Aug 2017 02:11:43 +0100
Subject: Re: [Tutor] Object takes no parameters
On 17/08/17 01:08, Howard Lawrence wrote:
> class Human:
>      def _init_(self, n, o)
>           self.name = n
>           self.occupation = o
>

>
> tom = Human('tom cruise', 'actor')
>
> Traceback most recent call last
> File "c:\users\shaun\python\python35\human_class.py"line 16 in module
> tom =Human('tom cruise', 'actor')
> TypeError: object() takes no parameters
>
> how to fix this?why it happens?

If you look closely at your tutorial you will find that init()
has two underscores before and after the name:

def __init__()

rather than

def _init_()

The reason for your error is that all classes inherit from object.
So when you call Human() the interpreter looks for an __init__()
method and, not finding one(because yours only has one undercore),
it looks at the one defined in object. But the object init()
takes no parameters and so there is a mismatch between your
call to Human() and the object.__init__() definition.
Hence the error message.

To fix it use two underscores.

All of the "magic" methods used by Python have these double
underscores and  hence are often referred to as "dunder" methods.
You should avoid defining any new methods (ie new names) with
double underscores yourself, in case Python introduces  a
similar method in a future version.

HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos





---------- Forwarded message ----------
From: Alan Gauld <alan.gauld at yahoo.co.uk>
To: tutor at python.org
Cc:
Bcc:
Date: Thu, 17 Aug 2017 02:16:19 +0100
Subject: Re: [Tutor] (no subject)
On 16/08/17 23:36, Howard Lawrence wrote:
> class Address:
>         def _init_(self,Hs,St,Town,Zip):
>                       self.HsNunber=Hs
>                       self.Street=St
>                       self.Town=Town
>                       self.Zip=Zip
> Addr=Address (7, ' high st', 'anytown', ' 123 456')

That looks suspiciously like my tutorial ;-)

The answer is to use two underscores around init():

def __init__(...)

not

def _init_(...)

This is explained in more detail in a box at the end
of the data topic:

http://www.alan-g.me.uk/l2p/tutdata.htm

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


Hey it worked, two underscore did the job, :-) , it's your tutorial! so
look out there is more to come!.. thanks for your help


---------- Forwarded message ----------
From: Abdur-Rahmaan Janhangeer <arj.python at gmail.com>
To: Michael C <mysecretrobotfactory at gmail.com>
Cc: tutor <tutor at python.org>
Bcc:
Date: Thu, 17 Aug 2017 07:22:08 +0400
Subject: Re: [Tutor] "Path tree"
in addition to the answers i'd say now you have the motivation to learn
python data structures and algorithms

http://interactivepython.org/runestone/static/pythonds/index.html

barnum and miller

it is free though i have not found a good pdf book form from where to
download, but you have the site anyway !

Now, the website has more materials than when i first knew it.

hope it helps !

Abdur-Rahmaan Janhangeer,
Mauritius
abdurrahmaanjanhangeer.wordpress.com

On 14 Aug 2017 02:28, "Michael C" <mysecretrobotfactory at gmail.com> wrote:

Hi all:

I am trying to formulate a "path-finding" function, and I am stuck on this
problem:

Please look at the picture attached: Those dots are coordinates of (x,y),
and this tree can be thought of as a list of tuples, with each tuple
consisting of (x,y).  Now I am trying to make a function go through this
list of tuples and then return the "path." to go from, say, 4 to 8. If I
simply compute for the dot for shortest distance, then the solution would
be to go from 4 to 8 direct, but that doesn't work, because the correct
solution should have been 4,3,2,5,6,8.


How do I do this?

Thanks!
_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



---------- Forwarded message ----------
From: Michael C <mysecretrobotfactory at gmail.com>
To: Abdur-Rahmaan Janhangeer <arj.python at gmail.com>
Cc: python tutor <tutor at python.org>
Bcc:
Date: Wed, 16 Aug 2017 20:23:35 -0700
Subject: Re: [Tutor] "Path tree"
Ok, I will work with all these. Thx all!

On Aug 16, 2017 20:22, "Abdur-Rahmaan Janhangeer" <arj.python at gmail.com>
wrote:

> in addition to the answers i'd say now you have the motivation to learn
> python data structures and algorithms
>
> http://interactivepython.org/runestone/static/pythonds/index.html
>
> barnum and miller
>
> it is free though i have not found a good pdf book form from where to
> download, but you have the site anyway !
>
> Now, the website has more materials than when i first knew it.
>
> hope it helps !
>
> Abdur-Rahmaan Janhangeer,
> Mauritius
> abdurrahmaanjanhangeer.wordpress.com
>
> On 14 Aug 2017 02:28, "Michael C" <mysecretrobotfactory at gmail.com> wrote:
>
> Hi all:
>
> I am trying to formulate a "path-finding" function, and I am stuck on this
> problem:
>
> Please look at the picture attached: Those dots are coordinates of (x,y),
> and this tree can be thought of as a list of tuples, with each tuple
> consisting of (x,y).  Now I am trying to make a function go through this
> list of tuples and then return the "path." to go from, say, 4 to 8. If I
> simply compute for the dot for shortest distance, then the solution would
> be to go from 4 to 8 direct, but that doesn't work, because the correct
> solution should have been 4,3,2,5,6,8.
>
>
> How do I do this?
>
> Thanks!
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
>
>


_______________________________________________
Tutor maillist  -  Tutor at python.org
https://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list