Gregor Lingl | 1 Mar 2004 01:11
Picon

[Fwd: Re: what is an object?]


Betreff: 	Re: [Tutor] what is an object?
Datum: 	Sun, 29 Feb 2004 07:36:08 -0800 (PST)
Von: 	Martin Gandhi <bioinfo_python <at> yahoo.com>
An: 	Gregor Lingl <glingl <at> aon.at>

Hi Gregor,
Thanks for your explnation. It was clear. However, I have one simple 
question that I often stumbled upon. I have read Guido's tutorial and 
also learning pyton and I see that every where.

What exactly both semantic and logical meaning of "callable".

In your explantion you mentioned that instance attributed are not "callable"

Sorry for asking a lame question.  It will really make a difference to 
understand better, though..

Thanks
MG

*//*

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Gregor Lingl | 1 Mar 2004 01:32
Picon

Re: [Fwd: Re: what is an object?]


Martin Ghandi schrieb:

> ... I have one simple question that I often stumbled upon. I have read 
> Guido's tutorial and also learning pyton and I see that every where.
>
> What exactly both semantic and logical meaning of "callable".
>
>
Formally an object f is called callable ;-) if you can call it using the 
syntax

f()

or

f(arg1, args, ...)

Semantically than means that f  contains some code which is executed
when f is called.

There is a built in function callable, which you can use to determine if
some object is callable or not:

 >>> callable(3)
False
 >>> callable( [1,2,3] )
False
 >>> callable(len)    # built-in function
True
(Continue reading)

Alan Gauld | 1 Mar 2004 01:59
Picon
Favicon

Re: Eureka!

> I copied the UserDict module and created a module
> called UserDict2.  Inside this module, I created the
> following class and definition:
> 
> class ODict(UserDict):

Why did you copy the UserDict module?

You don't need to copy the module to access the class, 
just import it.

> their position in the list.  I do have a question
> though.  In the past, when I entered something like:
> 
> class ODict(UserDict):
>     order = []
>     def __setitem__(self, key, item):
> 
> I would get some sort of error about the order
> variable.  Can anyone explain this?  I wish I remember
> what I wrote, but it's all a big blur to me.  Should I
> have used __init__ to declare the order variable? 
> What is the purpose of __init__ anyway?

If you want each instance of your class to have its own order 
- and presumably you do! - then you need to set order, or more 
precisely self.order within the __init__ method. Otherwise all 
instances of your class will share the same order list.

The purpose of init is to initialise the variables of a new 
(Continue reading)

Alan Gauld | 1 Mar 2004 02:02
Picon
Favicon

Re: Eureka!

> Im not gonna try to answer your question because I'm not a tutor,
and
> there are many others on here who will answer better than I could.

I'd just like to point out that anyone on the list can be "a tutor".
There is no formal distinction between the taught and the teachers.
If you know the answer to a question feel free to fire away!

Alan G.
Who is definitely not a tutor except when he is... ;-)

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Alan Gauld | 1 Mar 2004 02:05
Picon
Favicon

Re: importing another classes's __init__

> import UserList
> 
> class UList(UserList.UserList):
>     def __init__(self, initlist=None):
>         UserList.UserList.__init__(self,
>                                    initlist=None)
> 
> >>> a = UList.UList(list)
> >>> a
> []
> 
> What gives?  I thought the line
> UserList.UserList.__init__(self, initlist=None) would
> import UserList's __init__ method.

It doesn't import it, it calls it. And you passed a list 
value of None so that's what it gave you...

I suspect you meant to do this:

class UList(UserList.UserList):
  def __init__(self, initlist=None):
     UserList.UserList.__init__(self, initlist)

Note no "=None" in the call to UserList.__init__()

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld

(Continue reading)

Alan Gauld | 1 Mar 2004 02:07
Picon
Favicon

Re: problem creating a subclass

> > class UList(UserList.UserList):
> >     def __init__(self, initlist=None):
>                                   ^^^^^ defines a default value
> >         UserList.UserList.__init__(self,
> > initlist=None)
>            ^^^^^ passes None
> 
> You want (the slightly odd looking) initlist=initlist

Actually just passing initlist will do the job fine. There is 
no need to explicitly assign any value. The value is coming 
in as an argument to UList.__init__()

Alan G.

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Alan Gauld | 1 Mar 2004 02:11
Picon
Favicon

Re: problem creating a subclass


> Maybe I'm missing something obvious here but I don't see how Chris'
> UList class is going to work at all. The class has no UList method,
so
> how is 'a = UList.UList(alist)' going to work ?

Because this is in another file from ULIst(actually the >>> prompt).
So he imported the ULIst module and is accessing the ULIst class
within the UList module:

import UList
L = UList.Ulist()  # Ulist class within Ulist module

Compare with:

import sys
sys.exit()

HTH
Alan G.

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Terry Carroll | 1 Mar 2004 03:21

Re: importing another classes's __init__

On Mon, 1 Mar 2004, Karl Pflästerer wrote:

> On 29 Feb 2004, Christopher Spears <- cspears2002 <at> yahoo.com wrote:
> 
> > I am trying to make a class called UList based on the
> > class UserList.  This is an example of how UserList
> > works:
> 
> Since some of your questions refer to homework I'm curious why your
> teacher does not use the features of modern Python but teaches you to
> use UserDict or UserList.

Well, if I was the instructor, I could defend that; it's instructive to be 
able to look at the UserDict.py and UserList.py code.

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Terry Carroll | 1 Mar 2004 03:23

Re: answer to indexing problem

On Sun, 29 Feb 2004, Christopher Spears wrote:

> Several people have asked my why did I make a copy of
> the UserDict module called UserDict2, which I then
> modified to solve my homework problem.  The answer is
> simple:IGNORANCE.  I didn't know any better.  After I
> did this, several people have told me that modifying
> the module directly is a bad idea.  I now know better,
> and for my second homework problem concerning classes,
> I simply created my own to file to contain the classes
> instead of modifying a module.

That's great.  The most wonderful thing about ignorance is that it's a 
curable condition.

You don't want to see what some of *my* early programs looked like, when I 
was a student!  Some of those were *really* ugly.

--

-- 
Terry Carroll
Santa Clara, CA
carroll <at> tjc.com
Modell delendus est

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Kirk Bailey | 1 Mar 2004 06:37
Favicon

set the mode of a file

I want to set the mode of a text file to 666. How do I do it?

--

-- 

Respectfully,
              Kirk D Bailey
              Pinellas county Florida USA

   think   http://www.tinylist.org/ - $FREE$ software for liberty
+-------+ http://www.pinellasintergroupsociety.org/ - In Her Service
|  BOX  | http://www.listville.net/ - $FREE$ list hosting services
+-------+ http://www.howlermonkey.net/ - $FREE$ email service
   kniht   http://www.sacredelectron.org/ - My personal SCREED pit

          (C)2004 Kirk D Bailey, all rights reserved- but ask!

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor


Gmane