Can someone show me how to code this correctly please<br><br><div class="gmail_quote">On Wed, Jun 22, 2011 at 10:00 PM,  <span dir="ltr">&lt;<a href="mailto:tutor-request@python.org">tutor-request@python.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Send Tutor mailing list submissions to<br>
        <a href="mailto:tutor@python.org">tutor@python.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
or, via email, send a message with subject or body &#39;help&#39; to<br>
        <a href="mailto:tutor-request@python.org">tutor-request@python.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:tutor-owner@python.org">tutor-owner@python.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than &quot;Re: Contents of Tutor digest...&quot;<br>
<br>
<br>
Today&#39;s Topics:<br>
<br>
   1. Re: Class methods (Alan Gauld)<br>
   2. Re: sftp get single file (Peter Lavelle)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Wed, 22 Jun 2011 08:58:03 +0100<br>
From: &quot;Alan Gauld&quot; &lt;<a href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com</a>&gt;<br>
To: <a href="mailto:tutor@python.org">tutor@python.org</a><br>
Subject: Re: [Tutor] Class methods<br>
Message-ID: &lt;its7af$h8k$<a href="mailto:1@dough.gmane.org">1@dough.gmane.org</a>&gt;<br>
Content-Type: text/plain; format=flowed; charset=&quot;UTF-8&quot;;<br>
        reply-type=original<br>
<br>
&quot;David Merrick&quot; &lt;<a href="mailto:merrickdav@gmail.com">merrickdav@gmail.com</a>&gt; wrote<br>
<br>
&gt; class Critter(object):<br>
&gt;<br>
&gt;    def __init__(self, name, hunger = 0, boredom = 0):<br>
&gt;    def __pass_time(self):<br>
&gt;    def __str__(self):<br>
&gt;    @property<br>
&gt;    def mood(self):<br>
&gt;    def talk(self):<br>
&gt;    def eat(self):<br>
&gt;    def play(self):<br>
&gt;<br>
&gt; class Farm(Critter):<br>
<br>
I still don&#39;t think a Farm is a type of Critter...<br>
<br>
&gt;    def __init__(self,farmlet):<br>
&gt;       Critter.__init__(self,farmlet)<br>
<br>
This will set the name to farmlet, which I don&#39;t<br>
think you want.<br>
<br>
&gt;    def talk(self,farmlet):<br>
<br>
You don&#39;t need to pass farmlet in since the<br>
class has farmlet stored inside it.<br>
You can access farmlet with self.farmlet.<br>
<br>
&gt;        for critter in farmlet:<br>
&gt;            print(&quot;Hello&quot;)<br>
&gt;            Critter.talk(farmlet)<br>
<br>
You want the instance to talk not the class.<br>
So you need to use critter.talk() And the talk<br>
method does not take any arguments except<br>
self. What you are doing here is calling the<br>
class method with an instance value of farmlet.<br>
ie self in that method gets the value of farmlet.<br>
<br>
&gt; def main():<br>
&gt;    crit1 = Critter(&quot;Sweetie&quot;)<br>
&gt;    crit2 = Critter(&quot;Dave&quot;)<br>
&gt;    farmlet = [crit1,crit2]<br>
&gt;    f = Farm(farmlet)<br>
&gt;<br>
&gt;    choice = None<br>
&gt;    while choice != &quot;0&quot;:<br>
&gt;        print \<br>
&gt;        (&quot;&quot;&quot;<br>
&gt;        Critter Caretaker<br>
&gt;<br>
&gt;        0 - Quit<br>
&gt;        1 - Listen to your critter<br>
&gt;        2 - Feed your critter<br>
&gt;        3 - Play with your critter<br>
&gt;        &quot;&quot;&quot;)<br>
&gt;<br>
&gt;        choice = input(&quot;Choice: &quot;)<br>
&gt;        print()<br>
&gt;<br>
&gt;        # exit<br>
&gt;        if choice == &quot;0&quot;:<br>
&gt;            print(&quot;Good-bye.&quot;)<br>
&gt;<br>
&gt;        # listen to your critter<br>
&gt;        elif choice == &quot;1&quot;:<br>
&gt;            f.talk(farmlet)<br>
&gt;<br>
&gt;        # feed your critter<br>
&gt;        elif choice == &quot;2&quot;:<br>
&gt;            f.eat(farmlet)<br>
<br>
Note that f.eat is a method you inherit from Critter.<br>
The Critter method does not take any arguments<br>
so this will fail.<br>
<br>
&gt;        # play with your critter<br>
&gt;        elif choice == &quot;3&quot;:<br>
&gt;            f.play(farmlet)<br>
<br>
Same with f.play()<br>
<br>
&gt; Traceback (most recent call last):<br>
&gt;  File &quot;D:/David/Python/programs/critter_farm3.py&quot;, line 72, in talk<br>
&gt;    Critter.talk(farmlet)<br>
&gt;  File &quot;D:/David/Python/programs/critter_farm3.py&quot;, line 38, in talk<br>
&gt;    print(&quot;I&#39;m&quot;, <a href="http://self.name" target="_blank">self.name</a>, &quot;and I feel&quot;, self.mood, &quot;now.\n&quot;)<br>
&gt; AttributeError: &#39;list&#39; object has no attribute &#39;name&#39;<br>
<br>
This is because you are accessing the method via<br>
the class and passing farmlet as the instance value<br>
rather than sending the message to the innstance<br>
directly. Use<br>
<br>
critter.talk()   # and no farmlet needed!<br>
<br>
HTH,<br>
<br>
<br>
--<br>
Alan Gauld<br>
Author of the Learn to Program web site<br>
<a href="http://www.alan-g.me.uk/" target="_blank">http://www.alan-g.me.uk/</a><br>
<br>
<br>
<br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Wed, 22 Jun 2011 10:07:53 +0100<br>
From: Peter Lavelle &lt;<a href="mailto:lists@solderintheveins.co.uk">lists@solderintheveins.co.uk</a>&gt;<br>
To: <a href="mailto:tutor@python.org">tutor@python.org</a><br>
Subject: Re: [Tutor] sftp get single file<br>
Message-ID: &lt;<a href="mailto:4E01B0E9.8000300@solderintheveins.co.uk">4E01B0E9.8000300@solderintheveins.co.uk</a>&gt;<br>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed<br>
<br>
You could use the subprocess module to run the relevant system commands.<br>
More info on running sftp non-interactively (i.e from a script) can be<br>
found here: <a href="http://fixunix.com/ssh/238284-non-interactive-sftp-put.html" target="_blank">http://fixunix.com/ssh/238284-non-interactive-sftp-put.html</a><br>
<br>
Regards<br>
<br>
Peter Lavelle<br>
<br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
Tutor maillist  -  <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
<br>
<br>
End of Tutor Digest, Vol 88, Issue 89<br>
*************************************<br>
</blockquote></div><br><br clear="all"><br>-- <br>Dave Merrick<br><br><a href="mailto:merrickdav@gmail.com">merrickdav@gmail.com</a><br><br>Ph   03 3423 121<br>Cell 027 3089 169<br>