From glingl@aon.at  Sun Dec  1 06:51:11 2002
From: glingl@aon.at (Gregor Lingl)
Date: Sun Dec  1 06:51:11 2002
Subject: [Tutor] Tkinter
References: <20021130205139.GA17747@pumuckl.redwitz79.de>
Message-ID: <3DE9F796.3010305@aon.at>

Hans Gubitz schrieb:

>A Tkinter.Button is an attribute of a class I defined. event.widget
>returns this button, but is it even possible to get the instance the
>button is belonging to?
>
I'm not sure, if I understand what you want. But maybe this:
event.widget.master

Example:

 >>> from Tkinter import *
 >>> wurzel = Tk()
 >>> knopf = Button(wurzel, text="Drücken!")
 >>> knopf.pack()
 >>> def show(event):
    global a
    a = event.widget.master

   
 >>> a = None
 >>> knopf.bind("<Button-1>", show)
'9385208show'       # now PRESS THE BUTTON!!
 >>> a
<Tkinter.Tk instance at 0x009F9890>
 >>>

Regards, Gregor

>
>Hans
>  
>






From gubitz@netcologne.de  Sun Dec  1 07:54:02 2002
From: gubitz@netcologne.de (Hans Gubitz)
Date: Sun Dec  1 07:54:02 2002
Subject: [Tutor] Tkinter
In-Reply-To: <3DE9F796.3010305@aon.at>
References: <20021130205139.GA17747@pumuckl.redwitz79.de> <3DE9F796.3010305@aon.at>
Message-ID: <20021201130944.GA6900@pumuckl.redwitz79.de>

My Tkinter.Button is an attribute in the class person. In the
Application I want to get the instance of person, button is belonging
to.

My workaround is the function holePerson. Is this the way you do it in
Python?

Hans



import Tkinter
from Tkconstants import *

class person:
    def __init__(self,master,bild,r,c,callback):
        self.bild = bild
        self.button = Tkinter.Button(master,text=self.bild)
        self.button.grid(row = r, column = c)
        self.button.bind('<Button-1>',callback)

class Application:
    def __init__(self, master):
        frame = Tkinter.Frame(master)
        frame.pack(fill=BOTH,expand=1)
        
        bilder = ['baran.gif','bulenda.gif','flohe.gif','haemel.gif']
        
        self.b00=person(frame,bilder[0],0,0,self.tausche)
        self.b01=person(frame,bilder[1],0,1,self.tausche)
        self.b02=person(frame,bilder[2],0,2,self.tausche)
        self.b03=person(frame,bilder[3],0,3,self.tausche)

        self.liste = [self.b00, self.b01, self.b02, self.b03]

    def tausche(self,event):
        self.aktuellerButton   = event.widget
        self.aktuellePerson = self.holePerson(self.aktuellerButton)
        print self.aktuellePerson
    
    def holePerson(self,button):
        for l in self.liste:
            if l.button == button:
                return l

tk = Tkinter.Tk()

app = Application(tk)

tk.mainloop()
-- 
Hans Gubitz <gubitz@netcologne.de>



From din22@cox.net  Sun Dec  1 08:57:03 2002
From: din22@cox.net (david)
Date: Sun Dec  1 08:57:03 2002
Subject: [Tutor] functions
Message-ID: <000801c29941$4f4d86c0$fc550144@pn.at.cox.net>

This is a multi-part message in MIME format.

------=_NextPart_000_0005_01C2990F.0480BC20
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

why does this work:
>>> d=3D{}
>>> d
{}
>>> def myfun():
 d[0]=3D'hello'

=20
>>> myfun()
>>> d
{0: 'hello'}

but this doesnt?

>>> d=3D'hello'
>>> d
'hello'
>>> def myfun():
 d=3D'goodbye'

=20
>>> myfun()
>>> d
'hello'
>>>
=20

------=_NextPart_000_0005_01C2990F.0480BC20
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>why does this work:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&gt;&gt;&gt; d=3D{}<BR>&gt;&gt;&gt;=20
d<BR>{}<BR>&gt;&gt;&gt; def =
myfun():<BR>&nbsp;d[0]=3D'hello'</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;<BR>&gt;&gt;&gt; =
myfun()<BR>&gt;&gt;&gt;=20
d<BR>{0: 'hello'}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>but this doesnt?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&gt;&gt;&gt; =
d=3D'hello'<BR>&gt;&gt;&gt;=20
d<BR>'hello'<BR>&gt;&gt;&gt; def =
myfun():<BR>&nbsp;d=3D'goodbye'</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;<BR>&gt;&gt;&gt; =
myfun()<BR>&gt;&gt;&gt;=20
d<BR>'hello'<BR>&gt;&gt;&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;</FONT></DIV></BODY></HTML>

------=_NextPart_000_0005_01C2990F.0480BC20--



From kalle@lysator.liu.se  Sun Dec  1 09:12:02 2002
From: kalle@lysator.liu.se (Kalle Svensson)
Date: Sun Dec  1 09:12:02 2002
Subject: [Tutor] functions
In-Reply-To: <000801c29941$4f4d86c0$fc550144@pn.at.cox.net>
References: <000801c29941$4f4d86c0$fc550144@pn.at.cox.net>
Message-ID: <20021201141156.GC18311@i92.ryd.student.liu.se>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[david, slightly edited for readability]
> why does this work:
> >>> d={}
> >>> d
> {}
> >>> def myfun():
> ...     d[0]='hello'
> ...
> >>> myfun()
> >>> d
> {0: 'hello'}
> 
> but this doesnt?
> 
> >>> d='hello'
> >>> d
> 'hello'
> >>> def myfun():
> ...     d='goodbye'
> ...
> >>> myfun()
> >>> d
> 'hello'
> >>>

It's because dictionary objects are mutable and strings aren't.  A
mutable object is one that can be changed, for example by setting
items.  The line

  d[0] = 'hello'

that looks like a regular assignment really isn't.  It could be
written as

  setitem(d, 0, 'hello')

as well.

This is what happens:

>>> d={}

Bind the name d in the global namespace to a new dictionary object.

...     d[0] = 'hello'

Look up the name d.  There is no d in the function local namespace, so
we go looking in the global namespace and find the dictionary object.
Set item 0 of the dictionary object to 'hello'.

>>> d='hello'

Rebind the name d in the global namespace to a string object.

...     d='goodbye'

Bind the name d in the function local namespace to a string object
with the value 'goodbye'.  This object is then discarded when the
function returns and the local namespace disappears.

If you added the line

  print d

to the function in exaple two, it would lookup d and find a binding in
the local namespace.  It would then print this object, the string
'goodbye'.

Peace,
  Kalle
- -- 
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>

iD8DBQE96hindNeA1787sd0RAh2TAJ9zkz/QA/HhElmONJ1CONbGIGQgewCfY10q
29skGK/3xGOdGf0C/0WN000=
=iLVJ
-----END PGP SIGNATURE-----


From kalle@lysator.liu.se  Sun Dec  1 09:20:02 2002
From: kalle@lysator.liu.se (Kalle Svensson)
Date: Sun Dec  1 09:20:02 2002
Subject: [Tutor] functions
In-Reply-To: <20021201141156.GC18311@i92.ryd.student.liu.se>
References: <000801c29941$4f4d86c0$fc550144@pn.at.cox.net> <20021201141156.GC18311@i92.ryd.student.liu.se>
Message-ID: <20021201141902.GD18311@i92.ryd.student.liu.se>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[me]
> If you added the line
> 
>   print d
> 
> to the function in example two, it would lookup d and find a binding
> in the local namespace.  It would then print this object, the string
> 'goodbye'.

Exercise for the interested reader: What will this code print?  Why?

>>> d = 'foo'
>>> def func():
...     print d
...     d = 'bar'
...     print d
... 
>>> func()

Peace,
  Kalle
- -- 
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>

iD8DBQE96hpKdNeA1787sd0RAl4uAJ43ZZNXH/mi1d+sQLfU0yaobUcnqQCfT7Ab
4/naJ3YiiWS26T6+SnH6a3c=
=cUZY
-----END PGP SIGNATURE-----


From din22@cox.net  Sun Dec  1 09:41:16 2002
From: din22@cox.net (david)
Date: Sun Dec  1 09:41:16 2002
Subject: [Tutor] functions
References: <000801c29941$4f4d86c0$fc550144@pn.at.cox.net> <20021201141156.GC18311@i92.ryd.student.liu.se>
Message-ID: <000d01c29947$78434f00$fc550144@pn.at.cox.net>

thanks. how do i look up d in the local namespace?

> Look up the name d.  There is no d in the function local namespace, so
> we go looking in the global namespace and find the dictionary object.






From yann@thphys.ox.ac.uk  Sun Dec  1 11:16:01 2002
From: yann@thphys.ox.ac.uk (Yann Le Du)
Date: Sun Dec  1 11:16:01 2002
Subject: [Tutor] functions
In-Reply-To: <20021201141902.GD18311@i92.ryd.student.liu.se>
Message-ID: <Pine.SUN.4.30.0212011601360.22161-100000@adonis>

> Exercise for the interested reader: What will this code print?  Why?
>
> >>> d = 'foo'
> >>> def func():
> ...     print d
> ...     d = 'bar'
> ...     print d

I thought this would print 'foo' then 'bar' but actually it just fails :

UnboundLocalError: local variable 'd' referenced before assignment

Apparently, it is the  d='bar'  assignment that conflicts with the  print
d  just above. This means that Python looks forward, understands that d is
local because of  d='bar' , then goes back to  print d  and then says that
d is not yet defined ?

Y





From kalle@lysator.liu.se  Sun Dec  1 11:53:01 2002
From: kalle@lysator.liu.se (Kalle Svensson)
Date: Sun Dec  1 11:53:01 2002
Subject: [Tutor] functions
In-Reply-To: <Pine.SUN.4.30.0212011601360.22161-100000@adonis>
References: <20021201141902.GD18311@i92.ryd.student.liu.se> <Pine.SUN.4.30.0212011601360.22161-100000@adonis>
Message-ID: <20021201165231.GE18311@i92.ryd.student.liu.se>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[Yann Le Du]
> > Exercise for the interested reader: What will this code print?
> > Why?
> >
> > >>> d = 'foo'
> > >>> def func():
> > ...     print d
> > ...     d = 'bar'
> > ...     print d
> 
> I thought this would print 'foo' then 'bar' but actually it just
> fails :
> 
> UnboundLocalError: local variable 'd' referenced before assignment
> 
> Apparently, it is the d='bar' assignment that conflicts with the
> print d just above. This means that Python looks forward,
> understands that d is local because of d='bar' , then goes back to
> print d and then says that d is not yet defined ?

Yes.  This is caused by an optimization in the Python byte code
compiler.  When compiling a function, it looks for all variables that
are defined either in the argument list (none in the example) or in
the body via assignment.  It then compiles references to these
variables to the opcode LOAD_FAST, which only looks in the local
namespace.  This makes references to arguments and other local
variables faster, but also creates the observed problem.

I'm not a Python guru, and I could well be wrong about the details.
In that case, I hope somebody will correct me.

Peace,
  Kalle
- -- 
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>

iD8DBQE96j5KdNeA1787sd0RApVtAKCU0Nyz91AirfnmvjT0yuJ2GnztMACgmx4b
DYj8OElGSrhnyJWyDDOatmw=
=spSL
-----END PGP SIGNATURE-----


From dman@dman.ddts.net  Sun Dec  1 13:06:02 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Sun Dec  1 13:06:02 2002
Subject: [Tutor] Re: functions
In-Reply-To: <20021201165231.GE18311@i92.ryd.student.liu.se>
References: <20021201141902.GD18311@i92.ryd.student.liu.se> <Pine.SUN.4.30.0212011601360.22161-100000@adonis> <20021201165231.GE18311@i92.ryd.student.liu.se>
Message-ID: <20021201181945.GA25476@dman.ddts.net>

--gKMricLos+KVdGMg
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Dec 01, 2002 at 05:52:31PM +0100, Kalle Svensson wrote:
| [Yann Le Du]
| > > Exercise for the interested reader: What will this code print?
| > > Why?
| > >
| > > >>> d =3D 'foo'
| > > >>> def func():
| > > ...     print d
| > > ...     d =3D 'bar'
| > > ...     print d
| >=20
| > I thought this would print 'foo' then 'bar' but actually it just
| > fails :
| >=20
| > UnboundLocalError: local variable 'd' referenced before assignment

| Yes.  This is caused by an optimization in the Python byte code
| compiler.

| I'm not a Python guru, and I could well be wrong about the details.
| In that case, I hope somebody will correct me.

It's not an optimization, really, it's the addition of nested lexical
scopes.  If you use python <=3D 2.1 you'll get 'foo' then 'bar'.  If you
use python 2.1 with "from __future__ import nested_scopes" or python
>=3D 2.2 you'll get the above error.  There may be some optimizations
involved, but the real change was the nested scopes.

-D

--=20
Stay away from a foolish man,
for you will not find knowledge on his lips.
        Proverbs 14:7
=20
http://dman.ddts.net/~dman/

--gKMricLos+KVdGMg
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj3qUsEACgkQO8l8XBKTpRTRiQCgnCuAz1gWLaIzMjt822GirmIW
hvEAoLhWZ+p3r5HsjXgPslqF7/t0g1g+
=fhQL
-----END PGP SIGNATURE-----

--gKMricLos+KVdGMg--


From iumarumo@eidosnet.co.uk  Sun Dec  1 13:37:01 2002
From: iumarumo@eidosnet.co.uk (Ibraheem Umaru-Mohammed)
Date: Sun Dec  1 13:37:01 2002
Subject: [Tutor] Re: functions
In-Reply-To: <20021201181945.GA25476@dman.ddts.net>
References: <20021201141902.GD18311@i92.ryd.student.liu.se> <Pine.SUN.4.30.0212011601360.22161-100000@adonis> <20021201165231.GE18311@i92.ryd.student.liu.se> <20021201181945.GA25476@dman.ddts.net>
Message-ID: <20021201183617.GA12185@btinternet.com>

* Derrick 'dman' Hudson <dman@dman.ddts.net> [2002-12-01 18:06]:
> On Sun, Dec 01, 2002 at 05:52:31PM +0100, Kalle Svensson wrote:
> | [Yann Le Du]
> | > > Exercise for the interested reader: What will this code print?
> | > > Why?
> | > >
> | > > >>> d = 'foo'
> | > > >>> def func():
> | > > ...     print d
> | > > ...     d = 'bar'
> | > > ...     print d
> | > 
> | > I thought this would print 'foo' then 'bar' but actually it just
> | > fails :
> | > 
> | > UnboundLocalError: local variable 'd' referenced before assignment
> 
> | Yes.  This is caused by an optimization in the Python byte code
> | compiler.
> 
> | I'm not a Python guru, and I could well be wrong about the details.
> | In that case, I hope somebody will correct me.
> 
> It's not an optimization, really, it's the addition of nested lexical
> scopes.  If you use python <= 2.1 you'll get 'foo' then 'bar'.  If you
> use python 2.1 with "from __future__ import nested_scopes" or python
> >= 2.2 you'll get the above error.  There may be some optimizations
> involved, but the real change was the nested scopes.
> 

Really? 

ibz@ignoramus:$ cat p.py
#!/usr/bin/python1.5

d = 'foo'
def func():
  print d
  d = 'bar'
  print d

func()

ibz@ignoramus:$ ./p.py
Traceback (innermost last):
  File "./p.py", line 9, in ?
    func()
  File "./p.py", line 5, in func
    print d
NameError: d
ibz@ignoramus:$


I think you will find that for python <= 2.1, you will get a NameError,
as opposed to the UnboundLocalError introduced by nested scopes.

You may want to read this:

,---- [ Python Warts: Discussion of Python's design flaws ]
| http://www.amk.ca/python/writing/warts.html 
`----

Kindest regards,


			--ibz.
-- 


From yann.ledu@noos.fr  Sun Dec  1 14:23:01 2002
From: yann.ledu@noos.fr (Yann Le Du)
Date: Sun Dec  1 14:23:01 2002
Subject: [Tutor] Filenames with accents (special characters)
Message-ID: <Pine.LNX.4.44.0212011950010.7477-100000@neuron.noos.fr>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

I use the French keyboard, and under Linux, I can open files with accents, 
but not under Windows (where I use IDLE).

If the variable "a" contains a string of characters with special 
characters such as accents (i.e. that don't belong to the normal ascii 
range 1-128), then open(a,"w") doesn't work under Windows.

Does anyone know how to make the open() work in that case ?

Yann



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: For info see http://quantumlab.net/pine_privacy_guard/

iD8DBQE96mDjt4mG++uo5yQRAlYOAJ9fhq50PLTiEfx6xD682ZfnxQZ9swCff6Ix
AU6hrhjBvr8oapKTpWUKEXI=
=yh5c
-----END PGP SIGNATURE-----



From aztech1200@yahoo.com  Sun Dec  1 17:43:01 2002
From: aztech1200@yahoo.com (Aztech Guy)
Date: Sun Dec  1 17:43:01 2002
Subject: [Tutor] C-like local static var in Py ?
Message-ID: <20021201224219.31796.qmail@web9807.mail.yahoo.com>

--0-456869479-1038782539=:30786
Content-Type: text/plain; charset=us-ascii


 

Hi,

(Checked docs, couldn't find relevant info)

How can I get the effect of a "local static" variable as in C - in Python ?

e.g. with this C function  ...

void f(void)

{

    static int call_count = 0;

    call_count++;

    printf("call_count = %d\n", call_count);

    /* other code */

}

... each time I call f(), the value of call_count is incremented by 1 over the previous value it had when the function was last exited, unlike an "automatic" local variable (which it would be if I omitted the "static" keyword - and which would get reset to 0 on each call to f() ). I know this can be done by using OO, i.e. a class, and retaining state with a member variable, but I want to see if it can be done in non-OO, procedural code.

 

TIA

Az

 



---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now
--0-456869479-1038782539=:30786
Content-Type: text/html; charset=us-ascii

<P>&nbsp;</P>
<P>Hi,</P>
<P>(Checked docs, couldn't find relevant info)</P>
<P>How&nbsp;can I&nbsp;get the effect of a "local static" variable as in C - in Python ?</P>
<P>e.g. with this C function&nbsp; ...</P>
<P>void f(void)</P>
<P>{</P>
<P>&nbsp;&nbsp;&nbsp; static int call_count = 0;</P>
<P>&nbsp;&nbsp;&nbsp; call_count++;</P>
<P>&nbsp;&nbsp;&nbsp; printf("call_count = %d\n", call_count);</P>
<P>&nbsp;&nbsp;&nbsp; /* other code */</P>
<P>}</P>
<P>... each time I call f(), the value of call_count is incremented by 1&nbsp;over&nbsp;the previous value&nbsp;it had when the function was last exited, unlike an "automatic" local variable (which it would be if I omitted the "static" keyword - and which would get reset to 0 on each call to f() ). I know this can be done by using OO, i.e. a class, and retaining state with a member variable, but I want to see if it can be done in non-OO, procedural code.</P>
<P>&nbsp;</P>
<P>TIA</P>
<P>Az</P>
<P>&nbsp;</P><p><br><hr size=1>Do you Yahoo!?<br>
<a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Yahoo! Mail Plus</a> - Powerful. Affordable. <a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Sign up now</a>
--0-456869479-1038782539=:30786--


From yann.ledu@noos.fr  Sun Dec  1 18:09:02 2002
From: yann.ledu@noos.fr (Yann Le Du)
Date: Sun Dec  1 18:09:02 2002
Subject: [Tutor] C-like local static var in Py ?
In-Reply-To: <20021201224219.31796.qmail@web9807.mail.yahoo.com>
Message-ID: <Pine.LNX.4.44.0212020004350.7477-100000@neuron.noos.fr>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sun, 1 Dec 2002, Aztech Guy wrote:

> (Checked docs, couldn't find relevant info)
> 
> How can I get the effect of a "local static" variable as in C - in Python ?
> e.g. with this C function  ...
> void f(void)
> 
> {
>     static int call_count = 0;
>     call_count++;
>     printf("call_count = %d\n", call_count);
>     /* other code */
> }
> 
> ... each time I call f(), the value of call_count is incremented by 1
> over the previous value it had when the function was last exited, unlike
> an "automatic" local variable (which it would be if I omitted the
> "static" keyword - and which would get reset to 0 on each call to f() ).
> I know this can be done by using OO, i.e. a class, and retaining state
> with a member variable, but I want to see if it can be done in non-OO,
> procedural code.

I suggest this :

def inc(v=[0]):
        v[0]+=1
        print v[0]

First time you call inc(), it will print 1, then 2, etc...

You can reset this by setting v=[0] outside of that function.

Y
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: For info see http://quantumlab.net/pine_privacy_guard/

iD8DBQE96pY/t4mG++uo5yQRAjygAJ4pfMaPeVM4kStZ2KK8GniHNtyoQACgsRyO
a4lQdJJOCPHJVQklnTQ0nrM=
=9Ow+
-----END PGP SIGNATURE-----



From ChuckBaker@Pokynet.com  Sun Dec  1 19:07:01 2002
From: ChuckBaker@Pokynet.com (Chuck Baker)
Date: Sun Dec  1 19:07:01 2002
Subject: [Tutor] Temerature Conversion??
Message-ID: <3DEAA3DA.19ABFFAC@Pokynet.com>

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
-----BEGIN PGP SIGNED MESSAGE-----
<br>Hash: SHA1
<p>Hello everyone.
<p>I am new to the list and have just started playing with Python. I
<br>have programed in BASIC before.
<p>I was going through and playing with it and I started out making a
<br>temperature conversion program.
<p>Converting fahrenheit to celsius I had no problem
<br>(98.6-32)/9*5 =37
<p>That worked fine. But when I tried to reverse it,
<br>37/5*9+32
<br>It came out to = 95 not 98.6
<p>and I can't figure out why??
<p>- --
<br>Chuck Baker
<br>ICQ# 1816811
<br>ChuckBaker@Pokynet.com
<br>ChuckBaker1@icqmail.com
<br>Yahoo ID: ChuckBaker11@Yahoo.com
<br><A HREF="http://Chuck_Baker.Tripod.com">http://Chuck_Baker.Tripod.com</A>
<br>Fax: 801-740-7293
<br>&nbsp;
<p>-----BEGIN PGP SIGNATURE-----
<br>Version: PGP 8.0 (Build 349) Beta
<br>Comment: Check out my website at <A HREF="http://Chuck_Baker.tripod.com">http://Chuck_Baker.tripod.com</A>
<p>iQA/AwUBPeqjxngliK6chUrEEQKP1ACg0uodVJxBGkot6vrzW5Lk24rtd+0AoP3+
<br>BfitrYVJOMaMT3iDrCvwTZkh
<br>=ZQLp
<br>-----END PGP SIGNATURE-----
<br>&nbsp;</html>



From michael@trollope.org  Sun Dec  1 19:18:02 2002
From: michael@trollope.org (Michael Powe)
Date: Sun Dec  1 19:18:02 2002
Subject: [Tutor] Naive Questions
Message-ID: <20021201161700.A6998@titan.spiretech.com>

hello,

a couple questions to which i haven't been able to find answers.

i don't seem to find a python equivalent to the "rewind" file operation
in C -- that is, i read through a file and i want to go back to the
beginning and read again.  is the only option to close & reopen?

and just from curiosity, why are there no increment/decrement operators,
and nothing equivalent to += & its friends?  i'd have thought this
would be a faq, but don't find anything about it there.

the first item actually relates to something i'm working on.  the second,
just that i'm lazy & find having to always type out i = i+1 annoying.  ;-)

thanks.

mp


From dylan.belsey@baesystems.com  Sun Dec  1 19:25:02 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Sun Dec  1 19:25:02 2002
Subject: [Tutor] Temerature Conversion??
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B98D2B58@wtntex1.baea.com.au>

 Chuck,
    I believe that the problem lies in truncation.  Because you use a
floating point number (98.6) in your first calculation, the answer that the
Python interpreter returns, is in fact a floating point number.  In the
second calc. you only use integers (whole numbers) so the interpreter
truncates the decimal part off, during the calculation.  The missing
fractional part gets compounded by the multiplication.
    See the python session below.

>>> ((98.6-32)/9)*5
37.0
>>> ((37/5)*9)+32
95
>>> 37.0/5
7.4000000000000004
>>> 37.0/5*9+32
98.600000000000009
>>> num = 37.0/5
>>> num = num*9
>>> num
66.600000000000009
>>> 

    As an additional tip, you may want to look at the order of operations
(precedence rules) for things like +, -, * and / and the use of parentheses
for equations.  It works OK for your calcs as / and * take precedence over +
and -, however this may cause a problem in the future.  On the other hand
you may already be aware of this and if so please disregard.

    HTH,

        Dylan 




From yann.ledu@noos.fr  Sun Dec  1 19:26:11 2002
From: yann.ledu@noos.fr (Yann Le Du)
Date: Sun Dec  1 19:26:11 2002
Subject: [Tutor] Temerature Conversion??
In-Reply-To: <3DEAA3DA.19ABFFAC@Pokynet.com>
Message-ID: <Pine.LNX.4.44.0212020121280.7477-100000@neuron.noos.fr>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sun, 1 Dec 2002, Chuck Baker wrote:

> That worked fine. But when I tried to reverse it,
> 37/5*9+32
> It came out to = 95 not 98.6
> 
> and I can't figure out why??

Cause you need to says you're working with floats, and not integers, and 
thus add the decimal separator to those numbers. Try :

37./5.*9.+32.

See http://www.python.org/doc/current/tut/node5.html for full explanation.

Y
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: For info see http://quantumlab.net/pine_privacy_guard/

iD8DBQE96qhVt4mG++uo5yQRAtXGAJ9nrW1R7iB22028X2ENmm3XJ6E9fwCdF1AF
Rl8o/9qVnkVzY7ngPP2M52A=
=TYrk
-----END PGP SIGNATURE-----



From michael@trollope.org  Sun Dec  1 19:31:20 2002
From: michael@trollope.org (Michael Powe)
Date: Sun Dec  1 19:31:20 2002
Subject: [Tutor] Naive Questions
In-Reply-To: <200212011823.01067.wilson@visi.com>; from wilson@visi.com on Sun, Dec 01, 2002 at 06:23:00PM -0600
References: <20021201161700.A6998@titan.spiretech.com> <200212011823.01067.wilson@visi.com>
Message-ID: <20021201163050.B6998@titan.spiretech.com>

thank you.  i didn't test, just looked in the various python books i have.
guess i need to update my library!  (anything to buy more tech books! ;-)

mp

On Sun, Dec 01, 2002 at 06:23:00PM -0600, Tim Wilson wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On Sunday 01 December 2002 18:17, Michael Powe wrote:
> > and just from curiosity, why are there no increment/decrement operators,
> > and nothing equivalent to += & its friends?  i'd have thought this
> > would be a faq, but don't find anything about it there.
> 
> There are. Doing x += 1 will increment x by 1. You can also do -=, /=, and 
> *=. I think there may be more. This is a relatively recent addition, around 
> Python 2.0 I think.
> 
> - -Tim
> 
> - -- 
> Tim Wilson
> Twin Cities, Minnesota, USA
> Science teacher, Linux fan, Zope developer, Grad. student, Daddy
> mailto:wilson@visi.com | http://qwerk.org/ | public key: 0x8C0F8813
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.7 (GNU/Linux)
> 
> iD8DBQE96qfkB56RQ4wPiBMRAnXQAJwPRLIwNMSkA0YCcqgpFiwAWGlnTACfQFzS
> Dq8XKD+EETcw/ujQTxZELu8=
> =E/1D
> -----END PGP SIGNATURE-----


From yann.ledu@noos.fr  Sun Dec  1 19:36:01 2002
From: yann.ledu@noos.fr (Yann Le Du)
Date: Sun Dec  1 19:36:01 2002
Subject: [Tutor] Naive Questions
In-Reply-To: <20021201161700.A6998@titan.spiretech.com>
Message-ID: <Pine.LNX.4.44.0212020129130.7477-100000@neuron.noos.fr>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sun, 1 Dec 2002, Michael Powe wrote:

> a couple questions to which i haven't been able to find answers.
> 
> i don't seem to find a python equivalent to the "rewind" file operation
> in C -- that is, i read through a file and i want to go back to the
> beginning and read again.  is the only option to close & reopen?

No. You can use :

f.seek(0,0)   # to go back at file's beginning

see http://diveintopython.org/fileinfo_files.html for more.

> 
> and just from curiosity, why are there no increment/decrement operators,
> and nothing equivalent to += & its friends?  i'd have thought this
> would be a faq, but don't find anything about it there.
> 
> the first item actually relates to something i'm working on.  the second,
> just that i'm lazy & find having to always type out i = i+1 annoying.  ;-)

These things work in the Python I use, i.e. 2.2

Y

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: For info see http://quantumlab.net/pine_privacy_guard/

iD8DBQE96qq3t4mG++uo5yQRArjqAKCTgw/jgW001xizAAVkNtmrakX/VACgjHd5
9tDqkh2RkZpBTuhb+7nd17o=
=7Imm
-----END PGP SIGNATURE-----



From michael@trollope.org  Sun Dec  1 19:46:00 2002
From: michael@trollope.org (Michael Powe)
Date: Sun Dec  1 19:46:00 2002
Subject: [Tutor] Naive Questions
In-Reply-To: <Pine.LNX.4.44.0212020129130.7477-100000@neuron.noos.fr>; from yann.ledu@noos.fr on Mon, Dec 02, 2002 at 01:35:02AM +0100
References: <20021201161700.A6998@titan.spiretech.com> <Pine.LNX.4.44.0212020129130.7477-100000@neuron.noos.fr>
Message-ID: <20021201164522.C6998@titan.spiretech.com>

thank you!  that is exactly what i wanted.  now back to work.  ;-)

mp

On Mon, Dec 02, 2002 at 01:35:02AM +0100, Yann Le Du wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On Sun, 1 Dec 2002, Michael Powe wrote:
> 
> > a couple questions to which i haven't been able to find answers.
> > 
> > i don't seem to find a python equivalent to the "rewind" file operation
> > in C -- that is, i read through a file and i want to go back to the
> > beginning and read again.  is the only option to close & reopen?
> 
> No. You can use :
> 
> f.seek(0,0)   # to go back at file's beginning
> 
> see http://diveintopython.org/fileinfo_files.html for more.
> 
> > 
> > and just from curiosity, why are there no increment/decrement operators,
> > and nothing equivalent to += & its friends?  i'd have thought this
> > would be a faq, but don't find anything about it there.
> > 
> > the first item actually relates to something i'm working on.  the second,
> > just that i'm lazy & find having to always type out i = i+1 annoying.  ;-)
> 
> These things work in the Python I use, i.e. 2.2
> 
> Y
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.1 (GNU/Linux)
> Comment: For info see http://quantumlab.net/pine_privacy_guard/
> 
> iD8DBQE96qq3t4mG++uo5yQRArjqAKCTgw/jgW001xizAAVkNtmrakX/VACgjHd5
> 9tDqkh2RkZpBTuhb+7nd17o=
> =7Imm
> -----END PGP SIGNATURE-----


From michael@trollope.org  Sun Dec  1 19:47:08 2002
From: michael@trollope.org (Michael Powe)
Date: Sun Dec  1 19:47:08 2002
Subject: [Tutor] Naive Questions
In-Reply-To: <Pine.LNX.4.44.0212020129130.7477-100000@neuron.noos.fr>; from yann.ledu@noos.fr on Mon, Dec 02, 2002 at 01:35:02AM +0100
References: <20021201161700.A6998@titan.spiretech.com> <Pine.LNX.4.44.0212020129130.7477-100000@neuron.noos.fr>
Message-ID: <20021201164642.D6998@titan.spiretech.com>

oh yeah, and thanks for the reference too, i'll use it.

mp


On Mon, Dec 02, 2002 at 01:35:02AM +0100, Yann Le Du wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On Sun, 1 Dec 2002, Michael Powe wrote:
> 
> > a couple questions to which i haven't been able to find answers.
> > 
> > i don't seem to find a python equivalent to the "rewind" file operation
> > in C -- that is, i read through a file and i want to go back to the
> > beginning and read again.  is the only option to close & reopen?
> 
> No. You can use :
> 
> f.seek(0,0)   # to go back at file's beginning
> 
> see http://diveintopython.org/fileinfo_files.html for more.
> 
> > 
> > and just from curiosity, why are there no increment/decrement operators,
> > and nothing equivalent to += & its friends?  i'd have thought this
> > would be a faq, but don't find anything about it there.
> > 
> > the first item actually relates to something i'm working on.  the second,
> > just that i'm lazy & find having to always type out i = i+1 annoying.  ;-)
> 
> These things work in the Python I use, i.e. 2.2
> 
> Y
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.1 (GNU/Linux)
> Comment: For info see http://quantumlab.net/pine_privacy_guard/
> 
> iD8DBQE96qq3t4mG++uo5yQRArjqAKCTgw/jgW001xizAAVkNtmrakX/VACgjHd5
> 9tDqkh2RkZpBTuhb+7nd17o=
> =7Imm
> -----END PGP SIGNATURE-----
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


From dman@dman.ddts.net  Sun Dec  1 20:24:02 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Sun Dec  1 20:24:02 2002
Subject: [Tutor] Re: Naive Questions
In-Reply-To: <20021201161700.A6998@titan.spiretech.com>
References: <20021201161700.A6998@titan.spiretech.com>
Message-ID: <20021202013823.GA28685@dman.ddts.net>

--OgqxwSJOaUobr8KG
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Dec 01, 2002 at 04:17:00PM -0800, Michael Powe wrote:
| hello,
|=20
| a couple questions to which i haven't been able to find answers.
|=20
| i don't seem to find a python equivalent to the "rewind" file operation
| in C -- that is, i read through a file and i want to go back to the
| beginning and read again.  is the only option to close & reopen?

What C function are you thinking of?  The only ones I know of are
ftell(3) and fseek(3).  Python file objects have both.

http://python.org/doc/current/lib/lib.html

| and just from curiosity, why are there no increment/decrement operators,
| and nothing equivalent to +=3D & its friends?  i'd have thought this
| would be a faq, but don't find anything about it there.

|  the second, just that i'm lazy & find having to always type out i =3D
|  i+1 annoying.  ;-)

You're not the only one :-).

http://www.python.org/peps/pep-0203.html

As of python 2.0.  The pep also explains why '++' isn't included (but
'+=3D1' isn't any worse, really).

-D

--=20
If you hold to [Jesus'] teaching, you are really [Jesus'] disciples.
Then you will know the truth, and the truth will set you free.
        John 8:31-32
=20
http://dman.ddts.net/~dman/

--OgqxwSJOaUobr8KG
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj3quY8ACgkQO8l8XBKTpRS8BACfThfB0FUatfGY6fSapyZvYc/M
1tYAnjnhyeP30ryYOTggzc0ZBHD+WqQr
=wueV
-----END PGP SIGNATURE-----

--OgqxwSJOaUobr8KG--


From dman@dman.ddts.net  Sun Dec  1 20:33:02 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Sun Dec  1 20:33:02 2002
Subject: [Tutor] Re: C-like local static var in Py ?
In-Reply-To: <20021201224219.31796.qmail@web9807.mail.yahoo.com>
References: <20021201224219.31796.qmail@web9807.mail.yahoo.com>
Message-ID: <20021202014724.GB28685@dman.ddts.net>

--jho1yZJdad60DJr+
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Dec 01, 2002 at 02:42:19PM -0800, Aztech Guy wrote:

| (Checked docs, couldn't find relevant info)
|=20
| How can I get the effect of a "local static" variable as in C - in Python=
 ?

A function by itself has no permanent state.  If you want to maintain
state, use a class.

class _f :
    def __init__( self ) :
        self.call_count =3D 0

    def __call__( self ) :
        """ Class instances can be "callable" if they define this method """

        self.call_count +=3D 1
        print "call_count =3D %d" % self.call_count

        # other code

# Here's a neat trick that python allows us to do :
# I create a name "f" that refers to an instance of the class _f.
# Clients can hardly tell the difference between this and a typical
# function named f.
f =3D _f()
# Now I get rid of the name "_f" because I don't wany any naught
# people trying to tamper with it.
del _f


Here's a demo of how it works :

>>> f()
call_count =3D 1
>>> f()
call_count =3D 2
>>> f()
call_count =3D 3
>>> f()
call_count =3D 4
>>>


Classes are a more general, (potentially) thread-safe, and
memory-efficient way of managing persistent state.  They are more
general because several functions can share the same state, and
multiple independent copies can be made (different class instances).
They can be more memory efficient because "static" variables in C are
allocated at compile-time and will always be used at runtime.  Class
instances can come and go at will and won't exist until they are
created.  Thus if a certain function (class) isn't used during a given
program run, that memory will never be allocated.  Local static
variables in C are one source of thread headaches -- multiple threads
don't get separate local static variables (for example see strtok()).
If you use a class (but don't hide it like I did above), each thread
can create its own instance and operate independently.

-D

--=20
A mouse is a device used to point at the xterm you want to type in.
  --Kim Alm, a.s.r
=20
http://dman.ddts.net/~dman/

--jho1yZJdad60DJr+
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj3qu6wACgkQO8l8XBKTpRSUdQCghz19ntMXQbaTiZ5MRiIGp0rv
Lr8An3wgstCwgGMhR1iQt+GZBdXdBQqb
=Hvs0
-----END PGP SIGNATURE-----

--jho1yZJdad60DJr+--


From dman@dman.ddts.net  Sun Dec  1 20:39:01 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Sun Dec  1 20:39:01 2002
Subject: [Tutor] Re: Inheritance : what am I doing wrong?
In-Reply-To: <004101c29733$98eeac60$b9fa3151@oemcomputer>
References: <20021126170007.13864.16605.Mailman@mail.python.org> <004101c29733$98eeac60$b9fa3151@oemcomputer>
Message-ID: <20021202015319.GC28685@dman.ddts.net>

--bAmEntskrkuBymla
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Nov 28, 2002 at 10:45:22PM +0100, Emmanuel Ruellan wrote:

| I'm having a problem with inheritance.=20
| I'm trying to derive a class from the visual.sphere class, so
| that I can add some methods. But I get an error message and I
| can't figure out why.

visual.sphere isn't a class.  It's a factory function.
(unless a recent release has changed thing considerably)
Try this to see :

import visual
print type( visual.sphere )

Thus you can't inherit from it.

-D

--=20
All a man's ways seem innocent to him,
but motives are weighed by the Lord.
        Proverbs 16:2
=20
http://dman.ddts.net/~dman/

--bAmEntskrkuBymla
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj3qvQ8ACgkQO8l8XBKTpRTZZACfa562jUtrizwYIsaYqtG48sRv
CQ8An3GvON63NftOQPXRTXihbZ7/MKJC
=leXH
-----END PGP SIGNATURE-----

--bAmEntskrkuBymla--


From ramrom@earthling.net  Sun Dec  1 21:36:00 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Sun Dec  1 21:36:00 2002
Subject: [Tutor] C-like local static var in Py ?
In-Reply-To: <Pine.LNX.4.44.0212020004350.7477-100000@neuron.noos.fr>
References: <20021201224219.31796.qmail@web9807.mail.yahoo.com>
Message-ID: <5.2.0.9.0.20021201190650.01a22268@66.28.54.253>

At 12:07 AM 12/2/2002 +0100, Yann Le Du wrote:

>def inc(v=[0]):
>         v[0]+=1
>         print v[0]
>
>First time you call inc(), it will print 1, then 2, etc...

This is an interesting side effect of the fact that a function evaluates 
its argument defaults only once. This creates in essence an anonymous list 
in the global environment, which can be operated on only within the 
function. Hoo boy.

>You can reset this by setting v=[0] outside of that function.

No; that does not work. This creates a global variable v that is 
independent of the one in inc. However this will work:

v2 = [0]
def inc(v = v2):
# rest the same

You can then reset things by resetting v2[0]. Note that if you set v2 = 0 
you create a new list assigned to v2; the original list still remains 
associated with the function default.

If one adds print id(v) to inc one sees, as expected, the same number 
(address of the object) each time. Is there some way in Python, given such 
an id, to access the object at that address?

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625



From yann.ledu@noos.fr  Sun Dec  1 21:56:00 2002
From: yann.ledu@noos.fr (Yann Le Du)
Date: Sun Dec  1 21:56:00 2002
Subject: [Tutor] C-like local static var in Py ?
In-Reply-To: <5.2.0.9.0.20021201190650.01a22268@66.28.54.253>
Message-ID: <Pine.LNX.4.44.0212020350520.7477-100000@neuron.noos.fr>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> >You can reset this by setting v=[0] outside of that function.
> 
> No; that does not work. This creates a global variable v that is 
> independent of the one in inc. However this will work:
> 
> v2 = [0]
> def inc(v = v2):
> # rest the same

Yes, you're right ! I went too fast... I thought I had understood, and had 
not.

> 
> You can then reset things by resetting v2[0]. Note that if you set v2 = 0 
> you create a new list assigned to v2; the original list still remains 
> associated with the function default.

Yes, amazing : v2[0]=0 is not the same as v2=[0].

> If one adds print id(v) to inc one sees, as expected, the same number 
> (address of the object) each time. Is there some way in Python, given such 
> an id, to access the object at that address?

I have no idea...

Y
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: For info see http://quantumlab.net/pine_privacy_guard/

iD8DBQE96suQt4mG++uo5yQRAsomAJ4lmSaOZxX3PP66oHD7hBlR9wcbqQCfQvyl
lEe7Og/+KOZo00YVSGN9aTU=
=1puk
-----END PGP SIGNATURE-----



From ramrom@earthling.net  Sun Dec  1 21:57:03 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Sun Dec  1 21:57:03 2002
Subject: [Tutor] Re: C-like local static var in Py ?
In-Reply-To: <20021202014724.GB28685@dman.ddts.net>
References: <20021201224219.31796.qmail@web9807.mail.yahoo.com>
 <20021201224219.31796.qmail@web9807.mail.yahoo.com>
Message-ID: <5.2.0.9.0.20021201195331.025a4bf8@66.28.54.253>

At 08:47 PM 12/1/2002 -0500, Derrick 'dman' Hudson wrote:
>A function by itself has no permanent state.

Oh, yeah? Try this:

 >>> def inc():
...     if inc.__dict__.has_key('a'):
...             inc.__dict__['a'] += 1
...     else:
...             inc.__dict__['a'] = 1
...     print inc.__dict__['a']
 >>> inc()
1
 >>> inc()
2
 >>> inc.a
2
 >>> inc.a = 0
 >>> inc()
1


Bob Gailer
mailto:ramrom@earthling.net
303 442 2625



From ramrom@earthling.net  Sun Dec  1 22:02:00 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Sun Dec  1 22:02:00 2002
Subject: [Tutor] Re: C-like local static var in Py ?
In-Reply-To: <5.2.0.9.0.20021201195331.025a4bf8@66.28.54.253>
References: <20021202014724.GB28685@dman.ddts.net>
 <20021201224219.31796.qmail@web9807.mail.yahoo.com>
 <20021201224219.31796.qmail@web9807.mail.yahoo.com>
Message-ID: <5.2.0.9.0.20021201195803.04157670@66.28.54.253>

At 07:56 PM 12/1/2002 -0700, Bob Gailer wrote:
> >>> def inc():
>...     if inc.__dict__.has_key('a'):
>...             inc.__dict__['a'] += 1
>...     else:
>...             inc.__dict__['a'] = 1
>...     print inc.__dict__['a']

I realize that this is a bit of overkill: A simpler version:

 >>> def inc():
...     try: inc.a += 1
...     except: inc.a = 1
...     print inc.a

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625



From idiot1@netzero.net  Sun Dec  1 22:37:02 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Sun Dec  1 22:37:02 2002
Subject: [Tutor] resolving my identity chrisis
Message-ID: <3DEA8CC3.D13C0A21@netzero.net>

ok. digging around I came up with a couple of ibntresting facts.

1. The executable is not the scrpt. The executable is the interpeter. Therefore,
the 4000 bit if it is set, is set ON PYTHON.

2. There are commands available in the language for handling these tasks, in the
os module.

from os module, process parameters page:
---------------------------------------------------------------------------------
setegid(egid) 
     Set the current process's effective group id. Availability: Unix. 

seteuid(euid) 
	Set the current process's effective user id. Availability: Unix. 

getpid() 
      Return the current process id. Availability: Unix, Windows. 

getppid() 
      Return the parent's process id. Availability: Unix. 

getuid() 
      Return the current process' user id. Availability: Unix. 

getegid() 
     Return the current process' effective group id. Availability: Unix. 
---------------------------------------------------------------------------------
I am homing in on the kill, this thing WILL be secure and it WILL operate as
root (ARG!) and it WILL create and delete lists on command in a secure manner.

You will be able to be your own miniature listbot service if you want to.

I expect to have it out, debbugged, and available in time for Yule.
I hope. This is fairly deep system sorcery I am jumping into.

-- 

end

Respectfully,
             Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                           +--------+

---------------------------------------------
Introducing NetZero Long Distance
1st month Free!
Sign up today at: www.netzerolongdistance.com


From kalle@lysator.liu.se  Sun Dec  1 22:44:01 2002
From: kalle@lysator.liu.se (Kalle Svensson)
Date: Sun Dec  1 22:44:01 2002
Subject: [Tutor] C-like local static var in Py ?
In-Reply-To: <5.2.0.9.0.20021201190650.01a22268@66.28.54.253>
References: <20021201224219.31796.qmail@web9807.mail.yahoo.com> <5.2.0.9.0.20021201190650.01a22268@66.28.54.253>
Message-ID: <20021202034357.GF18311@i92.ryd.student.liu.se>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[Bob Gailer]
> If one adds print id(v) to inc one sees, as expected, the same
> number (address of the object) each time. Is there some way in
> Python, given such an id, to access the object at that address?

Yes and no.  Officially, there is no way.  There are, however, hacks
that may or may not work.  For example, there is sys.makeref from
mxTools (http://www.egenix.com/files/python/mxTools.html).  Do note
the warnings on that page:

"""
USE WITH CARE: this is an expert-only function since it can cause
instant core dumps and many other strange things -- even ruin your
system if you don't know what you're doing !

SECURITY WARNING: This function can provide you with access to objects
that are otherwise not visible, e.g. in restricted mode, and thus be a
potential security hole.
"""

I wouldn't use it in any code I cared about, but it's a cool hack.

Peace,
  Kalle
- -- 
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>

iD8DBQE96tbydNeA1787sd0RAlePAJ43qBfpkbIw1TAFFkX8HnT82OqQGQCgg/Vi
hLB9aFhYQnEq7SBoYLTuua0=
=tO89
-----END PGP SIGNATURE-----


From idiot1@netzero.net  Mon Dec  2 01:41:01 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Mon Dec  2 01:41:01 2002
Subject: [Tutor] os.setuid(euid) function
Message-ID: <3DEB00E4.4070301@netzero.net>

Ok, in the os module, is the command 'seteuid(wuid)'. I tried this with 'root' 
and as 0 (zero) as the arguement provided, and both ways it barks.

Here is the error logged for each:
-----------------------------------------------------------------------------
Traceback (innermost last):
   File "/www/www.tinylist.org/cgi-bin/TLlistkill2.py", line 68, in ?
     os.seteuid('root')				# DIG, this is important. We are setting
AttributeError: seteuid
[Mon Dec  2 01:32:04 2002] [error] [client 65.59.82.123] Premature end of 
script headers: /www/www.tinylist.org/cgi-bin/TLlistkill2.py
Traceback (innermost last):
   File "/www/www.tinylist.org/cgi-bin/TLlistkill2.py", line 68, in ?
     os.seteuid(0)				# DIG, this is important. We are setting
AttributeError: seteuid
[Mon Dec  2 01:34:05 2002] [error] [client 65.59.82.123] Premature end of 
script headers: /www/www.tinylist.org/cgi-bin/TLlistkill2.py
-----------------------------------------------------------------------------

ok, what does it want me to provide as an attribute? For what it is worth, the 
ID function declares that when I am root, my uid is 0, and my gid is 0 (zero).
For example:
(beware wordwrap)
ns# id
uid=0(root) gid=0(wheel) groups=0(wheel), 2(kmem), 3(sys), 4(tty), 
5(operator), 20(staff), 31(guest), 100(webadmin)
ns#

Any suggestions?

-- 

end

Respectfully,
              Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                            +--------+


---------------------------------------------
Introducing NetZero Long Distance
1st month Free!
Sign up today at: www.netzerolongdistance.com


From dyoo@hkn.eecs.berkeley.edu  Mon Dec  2 01:51:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon Dec  2 01:51:01 2002
Subject: [Tutor] C-like local static var in Py ?  [default arguments,
 nested functions to OOP]
In-Reply-To: <20021201224219.31796.qmail@web9807.mail.yahoo.com>
Message-ID: <Pine.LNX.4.44.0212012224060.13802-100000@hkn.eecs.berkeley.edu>


On Sun, 1 Dec 2002, Aztech Guy wrote:

> void f(void)
>
> {
>     static int call_count = 0;
>     call_count++;
>     printf("call_count = %d\n", call_count);
>     /* other code */
> }


Hi Aztech,

We can simulate static local variables by taking advantage of default
arguments:

###
def f(call_count=[0]):
    call_count[0] = call_count[0] + 1
    print "call_count = %d" % call_count[0]
###

The techinque here is to assign call_count to a 'mutable' data structure
--- a list --- which we can revisit and increment every time we pass
through 'f'.  The values that we assign as defaults to a function are only
initialized once, so we can keep recycling call_count.

In a sense, f()'s call_count variable now has memory, and isn't
technically a "function" in the mathematical sense of the word anymore.



> I know this can be done by using OO, i.e. a class, and retaining state
> with a member variable, but I want to see if it can be done in non-OO,
> procedural code.

We might feel a little uncomfortable with the default variable stuff ---
it feels like a hacky way about going about things.  *grin* We can still
do something similar if we're familiar with nested functions:

###
>>> def _():
...     call_count = [0]
...     def f():
...         call_count[0] = call_count[0] + 1
...         print "Call count = %d" % call_count[0]
...     return f
...
>>> f = _()
>>> f()
Call count = 1
>>> f()
Call count = 2
>>> f()
Call count = 3
###


What's happening is that our f() function is being defined within another
function, so it has access to all the local variables of that outer
function.  This may look extraordinarily weird for those who haven't seen
programming languages that allow nested functions like this.


If we feel uncomfortable about having that '_()' function out there, we
can still delete it from the namespace, and f() will still continue to
work:

###
>>> del _
>>> f()
Call count = 4
>>> del _
>>> f()
Call count = 4
>>> f()
Call count = 5
###

So yes, we can simulate static local variables very easily.



In my opinion, this nested function approach is actually nicer, because we
can imagine that the outer function is actually generating whole new
counting functions for us.

That is, in C, we're stuck with the functions that we write and compile.
But in Python, we can generate functions on the fly, so stuff like:

###
>>> def makeCounter():
...     count = [0]
...     def f():
...         count[0] = count[0] + 1
...         return count[0]
...     return f
...
>>> f1, f2, f3 = makeCounter(), makeCounter(), makeCounter()
>>> f1()
1
>>> f1()
2
>>> f1()
3
>>> f2()
1
>>> f2()
2
>>> f3()
1
>>> f1()
4
###


becomes perfectly possible.  Now makeCounter() is a function that
generates miniature functions, each with their own little 'static'
counting variable.  f1(), f2() and f3() are all independent, but they've
all been created in the same "factory", with the same makeCounter()
function.


If we start feeling giddy, we can even do crazy stuff like this:

###
>>> def makePerson(name):
...     self = {'name' : name}
...     def sayHello():
...         return "hello, my name is " + self['name']
...     def dispatch(method):
...         if method == 'sayHello':
...             return sayHello()
...         else:
...             print "I don't know how to", method
...     return dispatch
...
>>> aztech = makePerson("Aztech Guy")
>>> aztech("sayHello")
'hello, my name is Aztech Guy'
>>> aztech("walkNorth")
I don't know how to walkNorth
###


And now things are suspiciously looking like OOP!  So nested functions are
extraordinarily powerful.


I hope this helps!



From dyoo@hkn.eecs.berkeley.edu  Mon Dec  2 02:05:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon Dec  2 02:05:02 2002
Subject: [Tutor] C-like local static var in Py ?  [oops]
In-Reply-To: <Pine.LNX.4.44.0212012224060.13802-100000@hkn.eecs.berkeley.edu>
Message-ID: <Pine.LNX.4.44.0212012252440.13802-100000@hkn.eecs.berkeley.edu>

> If we feel uncomfortable about having that '_()' function out there, we
> can still delete it from the namespace, and f() will still continue to
> work:
>
> ###
> >>> del _
> >>> f()
> Call count = 4
> >>> del _
> >>> f()
> Call count = 4
> >>> f()
> Call count = 5
> ###


Urk!  Bad cut and paste!  It was supposed to look like:

###
>>> del _
>>> f()
Call count = 4
###

I did not mean to paste twice.  I'm sorry about that!



I also just realized that '_' is used by the interactive interpreter to
keep track of the very last expression value:

###
>>> "hello" + "world"
'helloworld'
>>> _
'helloworld'
###


And even though the '_' variable has this special meaning only in the
interactive interpreter, it's still really bad form as an example. The
name '_' is potentially confusing, and I should have done something like:

###
def makeCallCounter():
    call_count = [0]
    def f():
        call_count[0] = call_count[0] + 1
        print "Call count = %d" % call_count[0]
    return f
###

instead.  The name 'makeCallCounter' makes it more clear that
makeCallCount() is a function that creates these miniature call_count
functions for us.



Anyway, sorry about those mistakes.  I've been reading OCaml code lately;
The people who wrote the OCaml standard library don't appear to like using
long function names.  At least, from what I can tell, the code in the
standard library is filled with lovely variable names like 'x', 'a', 'z',
and '_'.  I'm afraid that my writing style is slightly... tainted... by
that exposure.  *grin*

Good luck to you!



From dyoo@hkn.eecs.berkeley.edu  Mon Dec  2 02:08:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon Dec  2 02:08:01 2002
Subject: [Tutor] os.setuid(euid) function
In-Reply-To: <3DEB00E4.4070301@netzero.net>
Message-ID: <Pine.LNX.4.44.0212012304420.13802-100000@hkn.eecs.berkeley.edu>


On Mon, 2 Dec 2002, Kirk Bailey wrote:

> Ok, in the os module, is the command 'seteuid(wuid)'. I tried this with 'root'
> and as 0 (zero) as the arguement provided, and both ways it barks.
>
> Here is the error logged for each:
> -----------------------------------------------------------------------------
> Traceback (innermost last):
>    File "/www/www.tinylist.org/cgi-bin/TLlistkill2.py", line 68, in ?
>      os.seteuid('root')				# DIG, this is important. We are setting
          ^^^^^^^

Hi Kirk,

Check your spelling.  The code says "seteuid", but you meant to write
'setuid'.


> AttributeError: seteuid

By "AttributeError", Python is complaining that it can't find the an
"attribute", that it can't find a value that's named 'seteuid' within the
'os' module.


Good luck!



From dyoo@hkn.eecs.berkeley.edu  Mon Dec  2 02:24:03 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon Dec  2 02:24:03 2002
Subject: [Tutor] Displaying TeX in python GUI
In-Reply-To: <001401c2975d$26f2e340$ebe710ac@pc7345>
Message-ID: <Pine.LNX.4.44.0212012312540.13802-100000@hkn.eecs.berkeley.edu>


On Fri, 29 Nov 2002, Paul Hartley wrote:

> Is there a widget that will display TeX, LaTeX or MathML in a python
> widget?

Hi Paul,

Have you gotten an answer to your question yet?  You may want to ask your
question on comp.lang.python if you don't get more feedback from us.
LaTeX isn't as well known as it deserves to be, but I'm positive that
there are some LaTeX enthusiasts on the main newsgroup that can help you.


It might be possible to embed Mozilla's "Gecko" HTML widget using PyXPCOM:

    http://aspn.activestate.com/ASPN/Downloads/Komodo/PyXPCOM/readme
    http://www.mozilla.org/projects/xpcom/

Mozilla has MathML support, so this may be a nice way to approach this
problem.  That being said, I have to admit that I have no idea if this
will work.  Has anyone had luck with it?


Alternatively, you can run 'latex2pdf' or 'dvips' to transform LaTeX math
into an image that can be seen on a canvas, and you can periodically poll
when the math equation changes.  I think the 'xdvi' utility takes this
kind of polling approach to preview math equations.


Best of wishes to you!



From idiot1@netzero.net  Mon Dec  2 02:50:02 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Mon Dec  2 02:50:02 2002
Subject: [Tutor] os.setuid(euid) function
References: <Pine.LNX.4.44.0212012304420.13802-100000@hkn.eecs.berkeley.edu>
Message-ID: <3DEB10EF.70404@netzero.net>

Then I have the pleasure of reporting a typo in the documentation.

Beyond that, when in my server, I ran python, and indeed os.getuid() works 
fine, and WHEN SUPERUSER setuid(990) (which is my non su id) worked fine.
But when I was NOT su, and did os.setuid(0), it said 'operation not 
permitted'. And this is EXACTLY what I want the thing to do- assume a 
priviliged identity to go change essencial files in the mail system.

The executable is python, and it is owned by root. If I turn on the 4000 bit 
it should execute as root ALWAYS, unless it has tricks of it's own to let it 
assume a nonpriviliged identity. This script has to interact with 
/etc/mail/aliases AS ROOT because no other identity can create this file.

Sure, there are people in the audience screaming, but the first thing I did 
was pay HEAVY attention to filtering the scripts input data. I'm more worried 
with the identity thing. Any advice?




Danny Yoo wrote:
> 
> On Mon, 2 Dec 2002, Kirk Bailey wrote:
> 
> 
>>Ok, in the os module, is the command 'seteuid(wuid)'. I tried this with 'root'
>>and as 0 (zero) as the arguement provided, and both ways it barks.
>>
>>Here is the error logged for each:
>>-----------------------------------------------------------------------------
>>Traceback (innermost last):
>>   File "/www/www.tinylist.org/cgi-bin/TLlistkill2.py", line 68, in ?
>>     os.seteuid('root')				# DIG, this is important. We are setting
> 
>           ^^^^^^^
> 
> Hi Kirk,
> 
> Check your spelling.  The code says "seteuid", but you meant to write
> 'setuid'.
> 
> 
> 
>>AttributeError: seteuid
> 
> 
> By "AttributeError", Python is complaining that it can't find the an
> "attribute", that it can't find a value that's named 'seteuid' within the
> 'os' module.
> 
> 
> Good luck!
> 
> 
> 


-- 

end

Respectfully,
              Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                            +--------+


---------------------------------------------
Introducing NetZero Long Distance
1st month Free!
Sign up today at: www.netzerolongdistance.com


From dyoo@hkn.eecs.berkeley.edu  Mon Dec  2 02:53:21 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon Dec  2 02:53:21 2002
Subject: [Tutor] Saving class to a file!!
In-Reply-To: <005501c2967a$ed001fa0$e7f417c3@novo>
Message-ID: <Pine.LNX.4.44.0212012326030.13802-100000@hkn.eecs.berkeley.edu>


On Thu, 28 Nov 2002, Tiago Duarte Felix wrote:

> well.. class.. was just a name... i used a variable of course.... Code
> is really too long to be pasted... plus... variable names and comments
> are in portuguese..... but anyway.. i took some parts of it.... here it
> goes: if anyoe can tell me what i am doing wrong.. please.... thanks!!!!

Hi Tiago,

Just doing a followup: Have you been able to resolve the problem yet with
the pickling code?



> cPickle.dump((prj,conf,sim,fichs),open(prj.path+prj.n_fich,'wb'),true)

This line might be problematic.  When we open files for writing, it's
often a good idea to use an explicit name for them, so that we can call
close()  when we're done writing to the file.  This may seem a little
silly, but there may be caching behavior that may not be completely
writing the pickled stream to disk.

(I'm suspicious about it particularly because the code is writing things
as a binary stream, so buffering won't be line based, but block-based.)


You may want to try:

###
myfile = open(prj.path+prj.n_fich,'wb')
cPickle.dump((prj,conf,sim,fichs), myfile, true)
myfile.close()
###

or, better yet, make sure that the binary stuff isn't the issue, and use
the native 'pickle' module.  We're not so concerned with efficiency as we
are with correctness at the moment: let's make sure that it's not the
pickling process itself that's at fault:

###
import pickle
myfile = open(prj.path+prj.n_fich, 'w')
pickle.dump((prj,conf,sim,fichs), myfile, true)
myfile.close()
###


(In your last message, you mentioned that the system died with an
operating system error.  That's not good at all!

My best guess so far is that cPickle, the C extension module, didn't do
the right thing at all when given an incorrect pickle!  cPickle's written
in C for speed, so I wouldn't be too surprised if there were some
unbounded array bugs in that code.  You may want to send a bug report to
Sourceforge, including a copy of the pickle file as well as the class
definitions, so that the developers can take a close look.)




By the way, your code is trying to save those four objects by dumping them
into a single tuple at once.  It might be more convenient to use the
'shelve' module, which uses 'pickle' underneath the surface, but looks
much like a dictionary.

    http://www.python.org/doc/lib/module-shelve.html


So your code might look more like:

###
d = shelve.open(prj.path+prj.n_fich)
d['prj'] = prj
d['conf'] = conf
d['sim'] = sim
d['fichs'] = fichs
d.close()
###

which makes it more convenient to add additional objects to be serialized,
without having to worry as much about the order of the elements in a
tuple.



I hope that this helps!



From dyoo@hkn.eecs.berkeley.edu  Mon Dec  2 03:01:04 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon Dec  2 03:01:04 2002
Subject: [Tutor] os.setuid(euid) function
In-Reply-To: <3DEB10EF.70404@netzero.net>
Message-ID: <Pine.LNX.4.44.0212012352400.13802-100000@hkn.eecs.berkeley.edu>


On Mon, 2 Dec 2002, Kirk Bailey wrote:

> Then I have the pleasure of reporting a typo in the documentation.
>
> Beyond that, when in my server, I ran python, and indeed os.getuid()
> works fine, and WHEN SUPERUSER setuid(990) (which is my non su id)
> worked fine. But when I was NOT su, and did os.setuid(0), it said
> 'operation not permitted'. And this is EXACTLY what I want the thing to
> do- assume a priviliged identity to go change essencial files in the
> mail system.
>
> The executable is python, and it is owned by root. If I turn on the 4000
> bit it should execute as root ALWAYS, unless it has tricks of it's own
> to let it assume a nonpriviliged identity.


Hi Kirk,

Ah!  The setuid bit interacts --- or, more precisely, doesn't interact ---
with Python scripts.  That is, your operating system is mostly likely not
obeying the request to run the Python script using the setuid bit, for
security reasons.  This isn't limited to Python: all scripts are limited
in this way for protection against a potentially dangerous security hole.


You may have missed my original reply from November 21, so I'll forward it
to you again:

----

On Thu, 21 Nov 2002, Kirk Bailey wrote:

> This is driving me nuts. Well, nuts-er.
> Sayth the error log:
> IOError: [Errno 13] Permission denied: '/etc/mail/aliases.tmp'
> Traceback (innermost last):
>    File "/www/www.tinylist.org/cgi-bin/TLlistkill2.py", line 181, in ?
>      os.remove('./lists/' + mylist + '.*') # remove ALL files starting
with
> the name (mylist) and ANY name extension- but don't get a hissy fit if
there
> are none!
> OSError: [Errno 2] No such file or directory: './lists/testlist3.*'
>
> hmmm...
>
> The script is owned by root. The 4000 bit is set, so the script OUGHT to
> run as the ownening identity -root.


You're talking about the sticky bit, right?  If so, then that might be the
result of security tightening on your Unix system:

    http://www.oreillynet.com/pub/faqs/linux_faq_AEN2090
    http://www.faqs.org/faqs/unix-faq/faq/part4/section-7.html

If you want to run a certain script with elevated privileges, you may want
to use the 'sudo' command instead rather than depend on the setuid bit.



From dyoo@hkn.eecs.berkeley.edu  Mon Dec  2 03:32:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon Dec  2 03:32:02 2002
Subject: [Tutor] eval weirdness
In-Reply-To: <3DE8563C.9050609@aon.at>
Message-ID: <Pine.LNX.4.44.0212020012100.13802-100000@hkn.eecs.berkeley.edu>


> >It appears that the following code causes __builtins__.__dict__ to be
> >assigned to self.names.  Can anyone help me understand what is going on
> >here?
> >
> >
> >class testclass:
> >    def __init__(self):
> >        self.names = {}
> >        eval('5 + 5', self.names, self.names)
> >        print self.names
> >
> >if __name__ == '__main__':
> >    testclass()

Hello Poor Yorick and Gregor!


Wow, this is weird!  I never would have expected eval() to touch the
dictionary that we feed in!  I'm looking in the C source code at the
eval() function... Yup, it's intentional:


/*** Within bltinmodule.c:builtin_eval ***/
...
if (PyDict_GetItemString(globals, "__builtins__") == NULL) {
	if (PyDict_SetItemString(globals, "__builtins__",
				 PyEval_GetBuiltins()) != 0)
		return NULL;
	}
...
/******/



... Ah ha!  Found the reason.  According to:

    http://www.faqts.com/knowledge_base/view.phtml/aid/4550/fid/538

the '__builtins__' module is inserted in deliberately so that normal
functions like like int() can still be used.

###
>>> d = {}
>>> eval("int(5.0) + 3", d)
8
>>>
>>> d = {'__builtins__': {}}
>>> eval("int(5.0) + 3", d)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<string>", line 0, in ?
NameError: name 'int' is not defined
###


Wow, that was a good question.  Thank you!




>  >>> what = __builtins__.__dict__['help']
>  >>> what
> Type help() for interactive help, or help(object) for help about object.
>  >>> type(what)
> <type 'instance'>
>  >>>
>
> Which class is what an instance of?


The help() 'function' is a little tricky --- it's actually an instance of
a class that's defined within the 'site.py' that runs automatically when
Python starts up:


### within site.py:
class _Helper:
    def __repr__(self):
        return "Type help() for interactive help, " \
               "or help(object) for help about object."
    def __call__(self, *args, **kwds):
        import pydoc
        return pydoc.help(*args, **kwds)

__builtin__.help = _Helper()
###

They've overridden '__repr__', so that when we just type 'help' at the
prompt, it returns that helpful usage message.  The implementers have also
overwritten the '__call__' method of help() so that __builtin__.help()
looks like a function, but it's actually a instance in disguise.



I hope this helps!



From alan.gauld@bt.com  Mon Dec  2 06:25:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon Dec  2 06:25:02 2002
Subject: [Tutor] Inheritance : what am I doing wrong?
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0970222B@i2km11-ukbr.domain1.systemhost.net>

> I don't understand why I couldn't use this syntax
> (name=parameter) with a constructor.

OK, I was obviously tired when I replied to you.

Obviously keyword parameters do work. What I thought was 
happening was that you were getting confused with default 
parameters, instead it was me getting confused. Sorry!

> However, I've found out that visual.sphere.__init__() cannot work
> properly as a constructor because, despite all appearances,
> visual.sphere is not a class!

I seem, to rememvber this coming out before. Never having used 
the visual stuff that passed me by...

> Thanks for your help,

Hmm, not a lot helpful in my message!

Apologies again.

Alan g


From lobow@brturbo.com  Mon Dec  2 08:01:01 2002
From: lobow@brturbo.com (Diego Prestes)
Date: Mon Dec  2 08:01:01 2002
Subject: [Tutor] Punctuation
Message-ID: <-1253002020.1038833871427.JavaMail.nobody@webmail1>

---1129270052.1038833871425.JavaMail.nobody.webmail1
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

    Hello!
  
      Im trying to make a program that remove the punctuations of a txt file or string because I want to do a count of words later. But when a make my program it give Out of memory error. Someone know a better way to do this program?

Diego

from string import *
text = raw_input("Text :")
d1 = punctuation
d = split(join(d," "))
for x in range(len(d)):
    n = find(text,d[x])
    text = text[:n] + text[n+1:]
print text
---1129270052.1038833871425.JavaMail.nobody.webmail1--



From dman@dman.ddts.net  Mon Dec  2 08:31:21 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Mon Dec  2 08:31:21 2002
Subject: [Tutor] Re: Punctuation
In-Reply-To: <-1253002020.1038833871427.JavaMail.nobody@webmail1>
References: <-1253002020.1038833871427.JavaMail.nobody@webmail1>
Message-ID: <20021202134547.GA1497@dman.ddts.net>

--3V7upXqbjpZ4EhLz
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Dec 02, 2002 at 10:57:51AM -0200, Diego Prestes wrote:

| Im trying to make a program that remove the punctuations of a txt
| file or string because I want to do a count of words later. But when
| a make my program it give Out of memory error.  Someone know a
| better way to do this program?

| from string import *
| text =3D raw_input("Text :")
| d1 =3D punctuation
| d =3D split(join(d," "))
| for x in range(len(d)):
|     n =3D find(text,d[x])
|     text =3D text[:n] + text[n+1:]
| print text

What's happening is you're creating lots of copies of strings.
(namely where you add them together)  You end up with almost 4 copies
of the string in memory at one time before 3 of them are freed.  If
the input is long, that will use a lot of memory.

How about this:

import string
text =3D raw_input("Text :")
# for each punctuation character
for ch in string.punctuation :
    # replace it with the empty string
    text =3D text.replace( ch , '' )
print text


Or even :

import string , re
# the same thing as the loop above but using a regular expression
pattern =3D re.compile( "[" + re.escape( string.punctuation ) + "]" )
text =3D raw_input("Text :")
text =3D pattern.sub( "" , text )
print text

-D

--=20
How to shoot yourself in the foot with Java:
=20
You find that Microsoft and Sun have released incompatible class
libraries both implementing Gun objects. You then find that although
there are plenty of feet objects implemented in the past in many other
languages, you cannot get access to one. But seeing as Java is so cool,
you don't care and go around shooting anything else you can find.
    (written by Mark Hammond)
=20
http://dman.ddts.net/~dman/

--3V7upXqbjpZ4EhLz
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj3rZAoACgkQO8l8XBKTpRT+RwCfVEy9SMzcrEojydt2wXxPXZaC
LqYAoJ6UoUFgMGMIoDQs/8PVd0v2CXSJ
=0QR7
-----END PGP SIGNATURE-----

--3V7upXqbjpZ4EhLz--


From aztech1200@yahoo.com  Mon Dec  2 10:42:06 2002
From: aztech1200@yahoo.com (Aztech Guy)
Date: Mon Dec  2 10:42:06 2002
Subject: [Tutor] C-like local static var in Py ?  [oops]
In-Reply-To: <Pine.LNX.4.44.0212012252440.13802-100000@hkn.eecs.berkeley.edu>
Message-ID: <20021202154122.27707.qmail@web9807.mail.yahoo.com>

--0-1039696054-1038843682=:26460
Content-Type: text/plain; charset=us-ascii


 
Hey ! This is great. That was a lot of useful and interesting info from all you guys who answered. I learnt a good amount more about Python over the course of this last day alone - stuff that it's not so easy to get from the docs.
I hope to contribute something myself to the list in days to come ..
I really like this list - the signal to noise ratio is high.
Thanks again.
Az
 



---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now
--0-1039696054-1038843682=:26460
Content-Type: text/html; charset=us-ascii

<P>&nbsp;
<P>Hey ! This is great. That was a lot of useful and interesting&nbsp;info from all you guys who answered. I learnt a good amount more about Python over the course of this last day alone - stuff that it's not so easy to get from the docs.
<P>I hope to contribute something myself to the list in days to come ..
<P>I really like this list - the signal to noise ratio is high.
<P>Thanks again.
<P>Az
<P>&nbsp;</P><p><br><hr size=1>Do you Yahoo!?<br>
<a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Yahoo! Mail Plus</a> - Powerful. Affordable. <a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Sign up now</a>
--0-1039696054-1038843682=:26460--


From dyoo@hkn.eecs.berkeley.edu  Mon Dec  2 11:34:07 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon Dec  2 11:34:07 2002
Subject: [Tutor] Re: Punctuation
In-Reply-To: <20021202134547.GA1497@dman.ddts.net>
Message-ID: <Pine.LNX.4.44.0212020819040.7590-100000@hkn.eecs.berkeley.edu>


> On Mon, Dec 02, 2002 at 10:57:51AM -0200, Diego Prestes wrote:
>
> | Im trying to make a program that remove the punctuations of a txt
> | file or string because I want to do a count of words later. But when
> | a make my program it give Out of memory error.  Someone know a
> | better way to do this program?
>
> | from string import *
    ^^^^^^^^^^^^^^^^^^^^

You may want to avoid this shortcut and just use the standard:

    import string

The reason is because 'from string import *' indiscriminately pulls names
out of the string module, and someone unfamiliar with the string module
may not know, reading down in the code, where 'punctuation' or 'find'
would have come from.

It's also a little dangerous: many of the Python modules in the Standard
Library are not 'from foo import *'-safe.  For example, the 'os' module
has its own version of open() that munges up the builtin open()  that we
know about.


If we really want to save keystrokes, we can do something like this:

###
import string as s
###

This says that 's' is now an abbreviation for the string module.


Once we do this, then the rest of the code would look like:

###
text = raw_input("Text :")
d1 = s.punctuation
d = s.split(join(d," "))
for x in range(len(d)):
    n = s.find(text,d[x])
    text = text[:n] + text[n+1:]
print text
###

where it becomes easier to see where 'punctuation', 'split', and 'find'
are coming from.



On Mon, 2 Dec 2002, Derrick 'dman' Hudson wrote:

> What's happening is you're creating lots of copies of strings. (namely
> where you add them together)  You end up with almost 4 copies of the
> string in memory at one time before 3 of them are freed.  If the input
> is long, that will use a lot of memory.

I can see that the above code will cause a memory-stressing situation, but
the system would have to be pretty stressed already to raise an
OutOfMemoryError.

Diego, what does the rest of your program look like?  Are you reading your
whole text file into memory using a read()?


Good luck!



From michael.williams@st-annes.oxford.ac.uk  Mon Dec  2 12:49:02 2002
From: michael.williams@st-annes.oxford.ac.uk (Michael Williams)
Date: Mon Dec  2 12:49:02 2002
Subject: [Tutor] Testing if a number occurs more than once
Message-ID: <4118DFD5-061E-11D7-A76B-000393C5BF0A@st-annes.oxford.ac.uk>

Hi,

I think I may be missing out on something really obvious here (such as 
a built-in), but I'm trying to ascertain whether a given number occurs 
more than once in a list. My current solution involves generating a 
dictionary of the frequency with which each number occurs and then 
checking if the size of that dictionary is the same as the size of the 
original list (if it is then each number occurs once). This strikes me 
as not only convoluted, but slow (this is the dominant loop of the 
program). There must be a better way! Any suggestions?

My current solution follows:

def freqs(L):
     # dictionary of frequencies of the elements of list L
     res = {}
     for x in L:
         res[x]= res.get(x,0)+1
     return res

def morethanone(L):
     if len(freqs(L)) == len(L):
       return 0
     else:
       return 1

 >>> l1 = [5,6,7]
 >>> morethanone(l1)
0
 >>> l2 = [5,6,6]
 >>> morethanone(l2)
1

-- 
Michael



From gp@pooryorick.com  Mon Dec  2 13:00:01 2002
From: gp@pooryorick.com (Poor Yorick)
Date: Mon Dec  2 13:00:01 2002
Subject: [Tutor] Filenames with accents (special characters)
References: <Pine.LNX.4.44.0212011950010.7477-100000@neuron.noos.fr>
Message-ID: <3DEB9F8E.8060807@pooryorick.com>

Since no one has responded to your question, I'll take a very uninformed 
stab in the dark, and say that it may have something to do with your 
windows locale settings.  See the thread regarding my question about 
Chinese characters:

http://mail.python.org/pipermail/tutor/2002-July/016047.html

In a nutshell, if the character set indicated by your current Windows 
locale settings does not contain one or more characters found in a given 
filename, Python will not read that filename correctly.

Poor Yorick
gp@pooryorick.com

Yann Le Du wrote:

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Hello,
>
>I use the French keyboard, and under Linux, I can open files with accents, 
>but not under Windows (where I use IDLE).
>
>If the variable "a" contains a string of characters with special 
>characters such as accents (i.e. that don't belong to the normal ascii 
>range 1-128), then open(a,"w") doesn't work under Windows.
>
>Does anyone know how to make the open() work in that case ?
>
>Yann
>
>
>
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.2.1 (GNU/Linux)
>Comment: For info see http://quantumlab.net/pine_privacy_guard/
>
>iD8DBQE96mDjt4mG++uo5yQRAlYOAJ9fhq50PLTiEfx6xD682ZfnxQZ9swCff6Ix
>AU6hrhjBvr8oapKTpWUKEXI=
>=yh5c
>-----END PGP SIGNATURE-----
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>




From yann.ledu@noos.fr  Mon Dec  2 14:16:01 2002
From: yann.ledu@noos.fr (Yann Le Du)
Date: Mon Dec  2 14:16:01 2002
Subject: [Tutor] Testing if a number occurs more than once
In-Reply-To: <4118DFD5-061E-11D7-A76B-000393C5BF0A@st-annes.oxford.ac.uk>
Message-ID: <Pine.LNX.4.44.0212022005200.7477-100000@neuron.noos.fr>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, 2 Dec 2002, Michael Williams wrote:

> as not only convoluted, but slow (this is the dominant loop of the 
> program). There must be a better way! Any suggestions?

try :

def morethanone(l):
        for n in l:
                if l.count(n)>1:
                        return 1
        return 0


then this gives :

In [372]: l=[1,2,3,4,5]

In [373]: morethanone(l)
Out[373]: 0

In [374]: l=[1,2,3,4,5,23,2,48,23,90]

In [375]: morethanone(l)
Out[375]: 1


Yann
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: For info see http://quantumlab.net/pine_privacy_guard/

iD8DBQE966+Bt4mG++uo5yQRAlIpAKC+VwLgfyL57UfYfMxiZuhtKzWU6QCfXlbH
gdPFJF6z0oC3J0cjlaoFWoU=
=ceQX
-----END PGP SIGNATURE-----



From jeff@ccvcorp.com  Mon Dec  2 14:30:01 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Mon Dec  2 14:30:01 2002
Subject: [Tutor] Testing if a number occurs more than once
References: <4118DFD5-061E-11D7-A76B-000393C5BF0A@st-annes.oxford.ac.uk>
Message-ID: <3DEBB4B8.C7F915BE@ccvcorp.com>


Michael Williams wrote:

> Hi,
>
> I think I may be missing out on something really obvious here (such as
> a built-in), but I'm trying to ascertain whether a given number occurs
> more than once in a list.

I'd take a different approach, myself.  Since you're only looking for a
true/false for the entire list, I'd code it like this:

def morethanone(L):
    # If L has less than 2 elements, it can't have duplicates...
    if len(L) <= 1:
        return 0    #false
    # make a copy to avoid changing original
    mycopy = L[:]
    # now sort the copy...
    mycopy.sort()
    # Once sorted, duplicate elements will be next to each
    # other, so we can simply loop through and compare
    # adjacent elements.
    for n in range(1, len(mycopy)):
        if mycopy[n] == mycopy[n-1]:
            return 1   #true
    # If we have looped through the  entire list without
    # returning,  then there must be no duplicates
    return 0   #false

I don't know whether this will be significantly faster than your method,
however -- that copy and sort could take some time, especially on a long
list.  It could be more efficient if you know that your original list
doesn't rely on a particular order -- then you can sort the original list,
and spare the copying overhead.

Another approach, more like yours but with the potential to shortcut as
soon as a duplicate is found:

def morethanone(L):
    res = {}
    for item in L:
        # if item isn't already set in res
        if res.get(item, 0):
            # then set it to 1
            res[item] = 1
        else:
            # otherwise, it's a duplicate
            return 1
    # if we've found no duplicates, then return false
    return 0

The performance of this can vary greatly depending on the list you feed
it, and its worst-case performance will always be for a list with no
duplicates.  But, that worst-case performance is exactly the same as what
you're getting in your original version, and if a duplicate is found
quickly, the best-case performance on this can be very good.

I haven't done any timings (which are the only way to be sure), but I'm
pretty sure that this second version would be faster than my first
version, since it avoids the need to sort() the list.

Jeff Shannon
Technician/Programmer
Credit International




From lbrannma@cablespeed.com  Mon Dec  2 15:04:00 2002
From: lbrannma@cablespeed.com (Lance)
Date: Mon Dec  2 15:04:00 2002
Subject: [Tutor] perl to python?
Message-ID: <001501c29a3f$3c078c60$3212eb42@MYNEWBOX>

Hi All,

Is there a Perl to Python conversion program?

Thanks,
Lance




From dyoo@hkn.eecs.berkeley.edu  Mon Dec  2 17:10:03 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon Dec  2 17:10:03 2002
Subject: [Tutor] Testing if a number occurs more than once  [profiling
 a function using profile.run()]
In-Reply-To: <Pine.LNX.4.44.0212022005200.7477-100000@neuron.noos.fr>
Message-ID: <Pine.LNX.4.44.0212021326290.17204-100000@hkn.eecs.berkeley.edu>


On Mon, 2 Dec 2002, Yann Le Du wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Mon, 2 Dec 2002, Michael Williams wrote:
>
> > as not only convoluted, but slow (this is the dominant loop of the
> > program). There must be a better way! Any suggestions?
>
> try :
>
> def morethanone(l):
>         for n in l:
>                 if l.count(n)>1:
>                         return 1
>         return 0



This is an expensive way to do the uniqueness check, since l.count()
itself will be doing a loop to run through every element in l.  There are
really two nested loops that Python is running through.


If we use morethanone() on long lists, in a worst-case scenario, the time
it takes to check for uniqueness will be proportional to the number of
elements, squared.  It's squared because we can roughly estimate the cost
of l.count()ing to be len(l), and we're doing the l.count()ing len(l)
times, so the total cost is roughly len(l)**2.


We can test this performance empirically by using the nice 'profile'
module:

    http://www.python.org/doc/lib/profile-instant.html



For example:

###
>>> import profile
>>> def morethanone(l):
...     for n in l:
...         if l.count(n) > 1:
...             return 1
...     return 0
...
>>> l1, l2, l3 = range(1000), range(10000), range(100000)
>>> profile.run('morethanone(l1)')
         3 function calls in 0.180 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.140    0.140    0.140    0.140 <stdin>:1(morethanone)
        1    0.000    0.000    0.140    0.140 <string>:1(?)
        1    0.040    0.040    0.180    0.180 profile:0(morethanone(l1))
        0    0.000             0.000          profile:0(profiler)
>>> profile.run('morethanone(l2)')
         3 function calls in 15.630 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1   15.630   15.630   15.630   15.630 <stdin>:1(morethanone)
        1    0.000    0.000   15.630   15.630 <string>:1(?)
        1    0.000    0.000   15.630   15.630 profile:0(morethanone(l2))
        0    0.000             0.000          profile:0(profiler)

>>> profile.run('morethanone(l3)')
# ... time passes
###


Actually, 'morethanone(l3)' was taking way way too long, so I cancelled
it.  But already we can see the difference between the first two calls of
morethanone(l1) and morethanone(l2) --- the second call takes about 100
times as long to finish as the first, and we'd expect morethanone(l3) to
take about 0.180 seconds * (100)*2 = 1800 seconds = 30 minutes.  Ouch.




A better approach could be to first sort() the list of numbers, and run
through adjacent pairs of elements.  The duplicates, if they exist, will
clump up together during the sort, and will be easy to pick up when we
compare adjacent elements.

###
>>> def morethanone2(l):
...     l.sort()
...     for i in range(1, len(l)):
...          if l[i-1] == len[i]:
...              return 1
...     return 0
...
>>> def morethanone2(l):
...     l.sort()
...     for i in range(1, len(l)):
...          if l[i-1] == l[i]:
...              return 1
...     return 0
...
>>> profile.run('morethanone2(l1)')
         3 function calls in 0.000 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.000    0.000 <stdin>:1(morethanone2)
        1    0.000    0.000    0.000    0.000 <string>:1(?)
        1    0.000    0.000    0.000    0.000 profile:0(morethanone2(l1))
        0    0.000             0.000          profile:0(profiler)


>>> profile.run('morethanone2(l2)')
         3 function calls in 0.010 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.010    0.010    0.010    0.010 <stdin>:1(morethanone2)
        1    0.000    0.000    0.010    0.010 <string>:1(?)
        1    0.000    0.000    0.010    0.010 profile:0(morethanone2(l2))
        0    0.000             0.000          profile:0(profiler)


>>> profile.run('morethanone2(l3)')
         3 function calls in 0.160 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.160    0.160    0.160    0.160 <stdin>:1(morethanone2)
        1    0.000    0.000    0.160    0.160 <string>:1(?)
        1    0.000    0.000    0.160    0.160 profile:0(morethanone2(l3))
        0    0.000             0.000          profile:0(profiler)
###



Here, we can see that the time taken as we bump up the size of the input
grows a little faster than linear:


    size of input      time it takes
    ------------       -------------
       1000                0.0
       10000               0.010
       100000              0.160

which makes sense: sort()ing isn't too expensive, and we just need to do a
single scan across the sorted list to find duplicates.



Does anyone want to check how Michael's original morethanone() function
performs?



Good luck to you!



From marta_andrea@libero.it  Mon Dec  2 17:15:01 2002
From: marta_andrea@libero.it (Andrea Valle)
Date: Mon Dec  2 17:15:01 2002
Subject: [Tutor] Tk graphs output print to file
In-Reply-To: <86C3892A0C52D411AF5000A0C9EAA3B96320D1@wtntex1.baea.com.au>
Message-ID: <DNEFLBNHCGCPPIGNHGILKEILCHAA.marta_andrea@libero.it>

Hi pythoners,
I was asking myself: is it possible to print to file (i.e. bitmap/jpg) Tk
screen output (i.e.canvas)?

thanks!

-a-



From yduppen@xs4all.nl  Mon Dec  2 19:10:04 2002
From: yduppen@xs4all.nl (Yigal Duppen)
Date: Mon Dec  2 19:10:04 2002
Subject: [Tutor] Testing if a number occurs more than once
In-Reply-To: <4118DFD5-061E-11D7-A76B-000393C5BF0A@st-annes.oxford.ac.uk>
References: <4118DFD5-061E-11D7-A76B-000393C5BF0A@st-annes.oxford.ac.uk>
Message-ID: <200212030110.17722.yduppen@xs4all.nl>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> I think I may be missing out on something really obvious here (such as
> a built-in), but I'm trying to ascertain whether a given number occurs
> more than once in a list. 
...
> (this is the dominant loop of the program). 

Others already suggested the trick of copying, sorting and checking the 
adjacent elements.

However, if this is indeed the dominant loop of the program, it might be even 
better to change the datastructure you use; if your structure guarantees 
order (such as an ordered list), you get rid of the copying and sorting, 
requiring only one loop to check for duplicates. Unless of course you need 
the original order of your input later on.

Another approach might be to construct the frequency table you suggested 
directly from the input. Of course, the applicability of this depends on your 
other uses too.

Complexity of the first approach:
* adding n elements (O(n))
* sorting (O(n log n))
* searching for duplicates (O(n))

Complexity of the second approach:
* adding n elements (O(n log n))  (assuming a sensible implementation of the 
sorted collection)
* searching for duplicates (O(n))

Complexity of the third approach:
* adding n elements (O(n))
* searching for duplicates (O(n))

Hmmm. Now that I look at it, approaches one and to have basically the same 
complexity; so that would mean profiling both approaches for your specific 
problem.

I don't feel coherent. I'd better get some sleep... G'night

YDD
- -- 
http://www.xs4all.nl/~yduppen
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.0 (GNU/Linux)

iD8DBQE96/ZpLsKMuCf5EdwRAuL+AJ42SkXWb0l8AZkLR5FNFeti97ZJ8gCZAdg3
dwX700Z79NSnyuGjzanr87Q=
=07Tj
-----END PGP SIGNATURE-----



From loucypher@btinternet.com  Mon Dec  2 20:23:01 2002
From: loucypher@btinternet.com (loucypher)
Date: Mon Dec  2 20:23:01 2002
Subject: [Tutor] Beginner
Message-ID: <000901c29897$45aaa490$0100a8c0@trevormain>

This is a multi-part message in MIME format.

------=_NextPart_000_0006_01C29897.45789810
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi
Could you provide me with a selection of links to instructions to learn =
how to use IDLE (Python GUI) please, so I can then learn how to program =
using python.
My operating system is Microsoft XP Pro,.
Thanks for any help
loucypher.
------=_NextPart_000_0006_01C29897.45789810
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Hi<BR>Could you provide me with a selection of links =
to=20
instructions to learn how to use IDLE (Python GUI) please, so I can then =
learn=20
how to program using python.<BR>My operating system is Microsoft XP=20
Pro,.<BR>Thanks for any help<BR>loucypher.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0006_01C29897.45789810--




From loucypher@btinternet.com  Mon Dec  2 20:23:08 2002
From: loucypher@btinternet.com (loucypher)
Date: Mon Dec  2 20:23:08 2002
Subject: [Tutor] Save as
Message-ID: <000801c29900$b4e7e020$3f00a8c0@trevorone>

This is a multi-part message in MIME format.

------=_NextPart_000_0005_01C29900.B499E730
Content-Type: text/plain;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

Hi
When i save a Python file, if i try to open it again, i am asked what i =
want to open it with, can you help on this please.
------=_NextPart_000_0005_01C29900.B499E730
Content-Type: text/html;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252">
<META content=3D"MSHTML 6.00.2800.1126" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Hi</FONT></DIV>
<DIV><FONT size=3D2>When i save a Python file, if i try to open it =
again, i am=20
asked what i want to open it with, can you help on this=20
please.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0005_01C29900.B499E730--



From loucypher@btinternet.com  Mon Dec  2 20:23:20 2002
From: loucypher@btinternet.com (loucypher)
Date: Mon Dec  2 20:23:20 2002
Subject: [Tutor] Re: Save as
Message-ID: <000d01c29902$d0d77280$3f00a8c0@trevorone>

This is a multi-part message in MIME format.

------=_NextPart_000_000A_01C29902.D09427F0
Content-Type: text/plain;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

Hi
I have sorted this out now=20
thanks
  ----- Original Message -----=20
  From: loucypher=20
  To: tutor@python.org=20
  Sent: Sunday, December 01, 2002 6:13 AM
  Subject: Save as=20


  Hi
  When i save a Python file, if i try to open it again, i am asked what =
i want to open it with, can you help on this please.
------=_NextPart_000_000A_01C29902.D09427F0
Content-Type: text/html;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252">
<META content=3D"MSHTML 6.00.2800.1126" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Hi</FONT></DIV>
<DIV><FONT size=3D2>I have sorted this out now </FONT></DIV>
<DIV><FONT size=3D2>thanks</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000080 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Dloucypher@btinternet.com=20
  href=3D"mailto:loucypher@btinternet.com">loucypher</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A title=3Dtutor@python.org =

  href=3D"mailto:tutor@python.org">tutor@python.org</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Sunday, December 01, 2002 =
6:13=20
  AM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Save as </DIV>
  <DIV><BR></DIV>
  <DIV><FONT size=3D2>Hi</FONT></DIV>
  <DIV><FONT size=3D2>When i save a Python file, if i try to open it =
again, i am=20
  asked what i want to open it with, can you help on this=20
please.</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_000A_01C29902.D09427F0--



From gew75@hotmail.com  Mon Dec  2 20:23:39 2002
From: gew75@hotmail.com (Glen Wheeler)
Date: Mon Dec  2 20:23:39 2002
Subject: [Tutor] py2exe
Message-ID: <F223qZSxH4tUqsLKqew00008981@hotmail.com>

  Hi,

  Py2exe needs to be run from the dos prompt if using a windows machine.  I
find that following the steps listed on the site exactly first, and then
(unless you are an advanced user) later trying a custom build.
  There is sample code there for the required setup.py script, which you can
follow almost to the letter.

  hth,
  Glen


_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*  
http://join.msn.com/?page=features/junkmail



From ChuckBaker@pokynet.com  Mon Dec  2 20:23:56 2002
From: ChuckBaker@pokynet.com (Chuck Baker)
Date: Mon Dec  2 20:23:56 2002
Subject: [Tutor] Temerature conversion??
Message-ID: <3DEAA114.8C40D9BF@icqmail.com>

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
-----BEGIN PGP SIGNED MESSAGE-----
<br>Hash: SHA1
<p>Hello everyone.
<p>I am new to the list and have just started playing with Python. I
<br>have programed in BASIC before.
<p>I was going through and playing with it and I started out making a
<br>temperature conversion program.
<p>Converting fahrenheit to celsius I had no problem
<br>(98.6-32)/9*5 =37
<p>That worked fine. But when I tried to reverse it,
<br>37/5*9+32
<br>It came out to = 95 not 98.6
<p>and I can't figure out why??
<p>- --
<br>Chuck Baker
<br>ICQ# 1816811
<br>ChuckBaker@Pokynet.com
<br>ChuckBaker1@icqmail.com
<br>Yahoo ID: ChuckBaker11@Yahoo.com
<br><A HREF="http://Chuck_Baker.Tripod.com">http://Chuck_Baker.Tripod.com</A>
<br>Fax: 801-740-7293
<br>&nbsp;
<p>-----BEGIN PGP SIGNATURE-----
<br>Version: PGP 8.0 (Build 349) Beta
<br>Comment: Check out my website at <A HREF="http://Chuck_Baker.tripod.com">http://Chuck_Baker.tripod.com</A>
<p>iQA/AwUBPeqg8HgliK6chUrEEQIRHACdEu6D2A6oCMJiihEDt2czst9UG0IAn1tV
<br>rdBJl7piIGnYpApGOK2YmvNg
<br>=D154
<br>-----END PGP SIGNATURE-----
<br>&nbsp;</html>



From webmaster@chipsdw.com  Mon Dec  2 20:30:02 2002
From: webmaster@chipsdw.com (chipsdw.com Webmaster)
Date: Mon Dec  2 20:30:02 2002
Subject: [Tutor] Post to the list
Message-ID: <003901c29a6a$9e516320$6701a8c0@Upstairs2>

This is a multi-part message in MIME format.

------=_NextPart_000_0036_01C29A40.B4CFB1D0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

webmaster@chipsdw.com

------=_NextPart_000_0036_01C29A40.B4CFB1D0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2719.2200" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial =
size=3D2>webmaster@chipsdw.com</FONT></DIV></BODY></HTML>

------=_NextPart_000_0036_01C29A40.B4CFB1D0--



From webmaster@chipsdw.com  Mon Dec  2 20:31:09 2002
From: webmaster@chipsdw.com (chipsdw.com Webmaster)
Date: Mon Dec  2 20:31:09 2002
Subject: [Tutor] Need help with running the things I made
Message-ID: <004601c29a6b$7b30a940$6701a8c0@Upstairs2>

This is a multi-part message in MIME format.

------=_NextPart_000_0043_01C29A41.9105BFA0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I'm new here, but I have a question. Im a kid so I have made many things =
to help me with my homework... things like caculators fehrenhiet to =
celcius converters etc. When I use IDLE to run them they run fine with =
no bugs, BUT when I just click on them and that cmd prompt looking thing =
comes up, you type the first number, say 2 then u type the second number =
say 3, and it is supposed to do 2x3. All I see is a last line of white =
text that I can't see which I presume is the answer, but once it =
displays it for a fraction of a second, not enough time to read it, it =
closes the script since It has nothing more to do. How can I stop this?

------=_NextPart_000_0043_01C29A41.9105BFA0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2719.2200" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I'm new here, but I have a question. Im =
a kid so I=20
have made many things to help me with my homework... things like =
caculators=20
fehrenhiet to celcius converters etc. When I use IDLE to run them they =
run fine=20
with no bugs, BUT when I just click on them and that cmd prompt looking =
thing=20
comes up, you type the first number, say 2 then u type the second number =
say 3,=20
and it is supposed to do 2x3. All I see is a last line of white text =
that I=20
can't see which I presume is the answer, but once it displays it for a =
fraction=20
of a second, not enough time to read it, it closes the script since It =
has=20
nothing more to do. How can I stop this?</FONT></DIV></BODY></HTML>

------=_NextPart_000_0043_01C29A41.9105BFA0--



From dyoo@hkn.eecs.berkeley.edu  Mon Dec  2 20:34:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon Dec  2 20:34:02 2002
Subject: [Tutor] Post to the list
In-Reply-To: <003901c29a6a$9e516320$6701a8c0@Upstairs2>
Message-ID: <Pine.LNX.4.44.0212021731350.25730-100000@hkn.eecs.berkeley.edu>


On Mon, 2 Dec 2002, chipsdw.com Webmaster wrote:

> webmaster@chipsdw.com

The administrators of this list have set things up so you can subscribe
yourself from a Web interface.  You can visit:

    http://mail.python.org/mailman/listinfo/tutor

You should see a form that you can use to subscribe yourself.
Afterwards, you should be able to post freely to the list.



From shalehperry@attbi.com  Mon Dec  2 20:50:02 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Mon Dec  2 20:50:02 2002
Subject: [Tutor] perl to python?
In-Reply-To: <001501c29a3f$3c078c60$3212eb42@MYNEWBOX>
References: <001501c29a3f$3c078c60$3212eb42@MYNEWBOX>
Message-ID: <200212021748.29372.shalehperry@attbi.com>

On Monday 02 December 2002 12:13, Lance wrote:
> Hi All,
>
> Is there a Perl to Python conversion program?
>

nope.  For many things it is not trivial to implement.  A human can do a=20
reasonable job if he knows both languages.  However you still have to dea=
l=20
with Perl modules, Python modules, etc.


From kalle@lysator.liu.se  Mon Dec  2 21:10:02 2002
From: kalle@lysator.liu.se (Kalle Svensson)
Date: Mon Dec  2 21:10:02 2002
Subject: [Tutor] Need help with running the things I made
In-Reply-To: <004601c29a6b$7b30a940$6701a8c0@Upstairs2>
References: <004601c29a6b$7b30a940$6701a8c0@Upstairs2>
Message-ID: <20021203020949.GH18311@i92.ryd.student.liu.se>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[chipsdw.com Webmaster]
> I'm new here, but I have a question.

Welcome to the list!

> Im a kid so I have made many things to help me with my
> homework... things like caculators fehrenhiet to celcius converters
> etc. When I use IDLE to run them they run fine with no bugs, BUT
> when I just click on them and that cmd prompt looking thing comes
> up, you type the first number, say 2 then u type the second number
> say 3, and it is supposed to do 2x3. All I see is a last line of
> white text that I can't see which I presume is the answer, but once
> it displays it for a fraction of a second, not enough time to read
> it, it closes the script since It has nothing more to do. How can I
> stop this?

One solution is to add a line like

  raw_input("Press enter to close.")

to the end of your program.  This isn't very elegant, but I'm afraid I
don't know of any better way to fix this.

Peace,
  Kalle
- -- 
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>

iD8DBQE97BJqdNeA1787sd0RAlmxAKDLv2zEfLkCx6i6sdgPa4I175n7+ACggns/
l3haPRMNf2wtm+EJlzxj7A0=
=acmz
-----END PGP SIGNATURE-----


From bwinton@latte.ca  Mon Dec  2 21:56:00 2002
From: bwinton@latte.ca (Blake Winton)
Date: Mon Dec  2 21:56:00 2002
Subject: [Tutor] perl to python?
In-Reply-To: <200212021748.29372.shalehperry@attbi.com>
References: <001501c29a3f$3c078c60$3212eb42@MYNEWBOX> <200212021748.29372.shalehperry@attbi.com>
Message-ID: <20021203025444.GB8357@latte.ca>

* Sean 'Shaleh' Perry <shalehperry@attbi.com> [021202 20:50]:
> On Monday 02 December 2002 12:13, Lance wrote:
> > Is there a Perl to Python conversion program?
> nope.  For many things it is not trivial to implement.  A human
> can do a reasonable job if he knows both languages.  However
> you still have to deal with Perl modules, Python modules, etc.

And even if there was, in the end you would just get Perl code
written in Python.

Trust me, I worked on a Visual Basic to Java convertor.  The Java
it produced worked, and worked faster than the Visual Basic, but
it was neither maintainable nor half as fast as a rewrite would
have been.  Most of the time, I'm against starting from scratch.
In this instance, however, I think it would have been far better
to do the rewrite, and fix the archetecture while you're at it.

Later,
Blake.
-- 
  9:51pm  up 30 days,  2:52,  1 user,  load average: 2.00, 2.00, 2.00


From dyoo@hkn.eecs.berkeley.edu  Mon Dec  2 22:24:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon Dec  2 22:24:02 2002
Subject: [Tutor] perl to python?
In-Reply-To: <001501c29a3f$3c078c60$3212eb42@MYNEWBOX>
Message-ID: <Pine.LNX.4.44.0212021734240.25730-100000@hkn.eecs.berkeley.edu>


[Note: the post I'm writing below is more about Perl than Python, and more
about understanding Perl's parse trees than about writing a Python
converter, so it's a bit off-topic.]



On Mon, 2 Dec 2002, Lance wrote:

> Is there a Perl to Python conversion program?


Unfortunately, no, not yet.


It should be technially possible to write a program to do this, but the
code might end up looking even more miserable than the original Perl code.


Still, I wonder how hard it would be to cook a toy example up.



What makes such an automatic converter hard is that Perl's grammar doesn't
appear to be really documented anywhere except in the Perl source code.
We'd need a tool that generates a "parse tree" of Perl code; once we had a
parse tree, we might have a good chance of writing a PerlToPython
converter.


In fact, it has been said that "Only Perl can parse Perl":

  http://www.everything2.com/index.pl?node=only%20Perl%20can%20parse%20Perl


So such a converter would probably have to use Perl itself to generate the
parse tree.  Perl does provide a 'backend' module called B for this.

    http://www.perlpod.com/stable/perlcompile.html



What does a "parse tree" look like?  It's a low-level representation of
the language.  Here's an example of a such a "parse" of a simple
'hello.pl' program:

######
[dyoo@tesuque dyoo]$ cat hello.pl

print "Hello world\n";

###



It's a simple little program.  Here's its "parse tree":

###
[dyoo@tesuque dyoo]$ perl -MO=Terse hello.pl
LISTOP (0x81668b0) leave [1]
    OP (0x81668d8) enter
    COP (0x80fe8d8) nextstate
    LISTOP (0x8166868) print
        OP (0x8166890) pushmark
        SVOP (0x817bec8) const  PV (0x80f6d88) "Hello world\n"
test.pl syntax OK
######


The capitalized letters on the left hand side are "opcodes" --- operation
codes.  If we visit this "tree" in a preorder traversal, we'll see that:

    1.  Perl calls "enter", whatever that means.  I think it means that it
        will enter the program start.

    2.  It generates a nextstate, whatever that means.

    3.  It does a "pushmark" operation, whatever that is.

    4.  It puts the argument "hello world" on its stack.  The 'SV' in SVOP
        stands for "scalar variable".

    5.  It calls the 'print' list operator.

    6.  Finally, it exits, with a return value of 1, I think.



Here's a small Python program that's specifically designed to visit this
particular tree.  I know that it's incorrect and incomplete (I don't even
understand the opcodes yet!  *grin*), but it should give the flavor of
what effort a PerlToPython converter might involve:


###
"""A small program to demonstrate what might be involved in parsing
Perl into Python.

Danny Yoo (dyoo@hkn.eecs.berkeley.edu)
"""

parse_tree = ("LISTOP", "leave", 1,
	      [("OP", "enter",
		[("COP", "nextstate",
		  [("LISTOP", "print",
		    [("OP", "pushmark", []),
		     ("SVOP", "const PV", "Hello world\n", [])])])])])

## Some utility functions that we might need...
def opcode(instruction):
    return instruction[0]

def children(instruction):
    return instruction[-1]

def operands(instruction):
    return instruction[1:-1]


class PerlToPython:
    def __init__(self):
        self.stack = []
        self.lines = []

    def visit(self, instruction):
        op = opcode(instruction)
        dispatch_function = getattr(self, "visit_" + op)
        dispatch_function(instruction)


    def visit_LISTOP(self, instruction):
        for child in children(instruction):
            self.visit(child)
        args = operands(instruction)
        if args[0] == 'print':
            self.lines.append("print " + ','.join(self.stack))
        elif args[0] == 'leave':
            self.lines.append("raise SystemExit")


    def visit_OP(self, instruction):
        for child in children(instruction):
            self.visit(child)
        return  ## fixme!


    def visit_COP(self, instruction):
        for child in children(instruction):
            self.visit(child)
        return  ## fixme!

    def visit_SVOP(self, instruction):
        type, value = operands(instruction)
        if type == "const PV":
            self.stack.append("%s" % repr(value))


if __name__ == '__main__':
    converter = PerlToPython()
    converter.visit(parse_tree)
    print '\n'.join(converter.lines)
###



Here's an example of this in action:

###
[dyoo@tesuque dyoo]$ python perl_into_python.py
print 'Hello world\n'
raise SystemExit
###





Let's look at another Perl parse tree of a slightly more complicated
program:

###
[dyoo@tesuque dyoo]$ cat loops.pl

for ($i = 0; $i < 10; $i++) {
    print "$i\n";
}


[dyoo@tesuque dyoo]$ perl -MO=Terse loops.pl
LISTOP (0x80fa8c8) leave [1]
    OP (0x80fa928) enter
    COP (0x80fa8f0) nextstate
    BINOP (0x8166900) sassign
        SVOP (0x81668e0) const  IV (0x80f6d88) 0
        UNOP (0x81668c0) null [15]
            SVOP (0x817bec8) gvsv  GV (0x81025f0) *i
    BINOP (0x80fa8a0) leaveloop
        LOOP (0x80fa870) enterloop
        UNOP (0x8104820) null
            LOGOP (0x81047f8) and
                BINOP (0x8166988) lt
                    UNOP (0x8166948) null [15]
                        SVOP (0x8166928) gvsv  GV (0x81025f0) *i
                    SVOP (0x8166968) const  IV (0x8102590) 10
                LISTOP (0x8104798) lineseq
                    LISTOP (0x8104750) scope
                        OP (0x8104718) null [174]
                        LISTOP (0x8103fb8) print
                            OP (0x8103fe0) pushmark
                            UNOP (0x8103f90) null [67]
                                OP (0x8184868) null [3]
                                BINOP (0x8184840) concat [2]
                                    UNOP (0x8184720) null [15]
                                        SVOP (0x8184700) gvsv  GV
(0x81025f0) *i
                                    SVOP (0x8184740) const  PV (0x8102614)
"\n"
                    UNOP (0x8184820) preinc [1]
                        UNOP (0x8104928) null [15]
                            SVOP (0x8104908) gvsv  GV (0x81025f0) *i
                    OP (0x8104778) unstack
                    COP (0x81047c0) nextstate
loops.pl syntax OK
###


The complexity of this is a little bit deeper, but the idea is the same:
we have to handle some of these new opcodes, like LOOP, and transform them
into their Python equivalents.  We may need to keep additional track of
things like scope and nesting.  Not a particularly "hard" task, but it
might be a little complicated.



Alternatively, it might also be possible to translate a Perl parse tree
into a Python parse tree with the help of the 'compiler' module:

    http://www.python.org/doc/lib/compiler.html

and then use a program called 'decompyle' to take that Python parse tree
and reproduce human-readable text:

    http://www.crazy-compilers.com/decompyle/


But somehow, I think this might take longer to write than I anticipated.
Still, it is very possible to write this program.  It might make a nice
winter project.  *grin*



Good luck to you!



From mongo57a@comcast.net  Mon Dec  2 22:48:01 2002
From: mongo57a@comcast.net (andy surany)
Date: Mon Dec  2 22:48:01 2002
Subject: [Tutor] Temerature conversion??
Message-ID: <001501c29a7e$67e96120$18892644@emily.ewndsr01.nj.comcast.net>

This is a multi-part message in MIME format.

--Boundary_(ID_yFOo7ohLAg4o1c4BzqKUeg)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7BIT

Hi Chuck.

The reason you get 95 is that you are performing an "integer" division, i.e. 37/5=7, and 7*9+32=95. Try:

37.0/5*9+32 = 98.6 

HTH.

Regards,

Andy
  -----Original Message-----
  From: Chuck Baker <ChuckBaker@pokynet.com>
  To: tutor@python.org <tutor@python.org>
  Date: Monday, December 02, 2002 8:41 PM
  Subject: [Tutor] Temerature conversion??


  -----BEGIN PGP SIGNED MESSAGE----- 
  Hash: SHA1 
  Hello everyone. 

  I am new to the list and have just started playing with Python. I 
  have programed in BASIC before. 

  I was going through and playing with it and I started out making a 
  temperature conversion program. 

  Converting fahrenheit to celsius I had no problem 
  (98.6-32)/9*5 =37 

  That worked fine. But when I tried to reverse it, 
  37/5*9+32 
  It came out to = 95 not 98.6 

  and I can't figure out why?? 

  - -- 
  Chuck Baker 
  ICQ# 1816811 
  ChuckBaker@Pokynet.com 
  ChuckBaker1@icqmail.com 
  Yahoo ID: ChuckBaker11@Yahoo.com 
  http://Chuck_Baker.Tripod.com 
  Fax: 801-740-7293 
    

  -----BEGIN PGP SIGNATURE----- 
  Version: PGP 8.0 (Build 349) Beta 
  Comment: Check out my website at http://Chuck_Baker.tripod.com 

  iQA/AwUBPeqg8HgliK6chUrEEQIRHACdEu6D2A6oCMJiihEDt2czst9UG0IAn1tV 
  rdBJl7piIGnYpApGOK2YmvNg 
  =D154 
  -----END PGP SIGNATURE----- 
    _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor


--Boundary_(ID_yFOo7ohLAg4o1c4BzqKUeg)
Content-type: text/html; charset=iso-8859-1
Content-transfer-encoding: 7BIT

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 5.50.4522.1800" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2>Hi Chuck.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>The reason you get 95 is that you are performing an "integer" 
division, i.e. 37/5=7, and 7*9+32=95. Try:</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>37.0/5*9+32 = 98.6</FONT>&nbsp;</DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>HTH.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Regards,</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Andy</FONT></DIV>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV><FONT face=Arial size=2><B>-----Original Message-----</B><BR><B>From: 
  </B>Chuck Baker &lt;<A 
  href="mailto:ChuckBaker@pokynet.com">ChuckBaker@pokynet.com</A>&gt;<BR><B>To: 
  </B><A href="mailto:tutor@python.org">tutor@python.org</A> &lt;<A 
  href="mailto:tutor@python.org">tutor@python.org</A>&gt;<BR><B>Date: 
  </B>Monday, December 02, 2002 8:41 PM<BR><B>Subject: </B>[Tutor] Temerature 
  conversion??<BR><BR></DIV></FONT>-----BEGIN PGP SIGNED MESSAGE----- <BR>Hash: 
  SHA1 
  <P>Hello everyone. 
  <P>I am new to the list and have just started playing with Python. I <BR>have 
  programed in BASIC before. 
  <P>I was going through and playing with it and I started out making a 
  <BR>temperature conversion program. 
  <P>Converting fahrenheit to celsius I had no problem <BR>(98.6-32)/9*5 =37 
  <P>That worked fine. But when I tried to reverse it, <BR>37/5*9+32 <BR>It came 
  out to = 95 not 98.6 
  <P>and I can't figure out why?? 
  <P>- -- <BR>Chuck Baker <BR>ICQ# 1816811 <BR>ChuckBaker@Pokynet.com 
  <BR>ChuckBaker1@icqmail.com <BR>Yahoo ID: ChuckBaker11@Yahoo.com <BR><A 
  href="http://Chuck_Baker.Tripod.com">http://Chuck_Baker.Tripod.com</A> 
  <BR>Fax: 801-740-7293 <BR>&nbsp; 
  <P>-----BEGIN PGP SIGNATURE----- <BR>Version: PGP 8.0 (Build 349) Beta 
  <BR>Comment: Check out my website at <A 
  href="http://Chuck_Baker.tripod.com">http://Chuck_Baker.tripod.com</A> 
  <P>iQA/AwUBPeqg8HgliK6chUrEEQIRHACdEu6D2A6oCMJiihEDt2czst9UG0IAn1tV 
  <BR>rdBJl7piIGnYpApGOK2YmvNg <BR>=D154 <BR>-----END PGP SIGNATURE----- 
  <BR>&nbsp; _______________________________________________ Tutor maillist - 
  Tutor@python.org 
http://mail.python.org/mailman/listinfo/tutor</P></BLOCKQUOTE></BODY></HTML>

--Boundary_(ID_yFOo7ohLAg4o1c4BzqKUeg)--


From gp@pooryorick.com  Tue Dec  3 00:19:01 2002
From: gp@pooryorick.com (Poor Yorick)
Date: Tue Dec  3 00:19:01 2002
Subject: [Tutor] Need help with running the things I made
References: <004601c29a6b$7b30a940$6701a8c0@Upstairs2> <20021203020949.GH18311@i92.ryd.student.liu.se>
Message-ID: <3DEC3ED3.1000200@pooryorick.com>

--------------040703010300040201070302
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

You can also add a /k switch to the cmd.exe line, as mentioned in:

http://mail.python.org/pipermail/tutor/2001-January/003139.html

poor yorick
gp@pooryorick.com




Kalle Svensson wrote:

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>[chipsdw.com Webmaster]
>
>>I'm new here, but I have a question.
>>
>
>Welcome to the list!
>
>>Im a kid so I have made many things to help me with my
>>homework... things like caculators fehrenhiet to celcius converters
>>etc. When I use IDLE to run them they run fine with no bugs, BUT
>>when I just click on them and that cmd prompt looking thing comes
>>up, you type the first number, say 2 then u type the second number
>>say 3, and it is supposed to do 2x3. All I see is a last line of
>>white text that I can't see which I presume is the answer, but once
>>it displays it for a fraction of a second, not enough time to read
>>it, it closes the script since It has nothing more to do. How can I
>>stop this?
>>
>
>One solution is to add a line like
>
>  raw_input("Press enter to close.")
>
>to the end of your program.  This isn't very elegant, but I'm afraid I
>don't know of any better way to fix this.
>
>Peace,
>  Kalle
>- -- 
>Kalle Svensson, http://www.juckapan.org/~kalle/
>Student, root and saint in the Church of Emacs.
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.0.7 (GNU/Linux)
>Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>
>
>iD8DBQE97BJqdNeA1787sd0RAlmxAKDLv2zEfLkCx6i6sdgPa4I175n7+ACggns/
>l3haPRMNf2wtm+EJlzxj7A0=
>=acmz
>-----END PGP SIGNATURE-----
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>


--------------040703010300040201070302
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<html>
<head>
</head>
<body>
You can also add a /k switch to the cmd.exe line, as mentioned in:<br>
<br>
<a class="moz-txt-link-freetext" href="http://mail.python.org/pipermail/tutor/2001-January/003139.html">http://mail.python.org/pipermail/tutor/2001-January/003139.html</a><br>
<br>
poor yorick<br>
<a class="moz-txt-link-abbreviated" href="mailto:gp@pooryorick.com">gp@pooryorick.com</a><br>
<br>
<br>
<br>
<br>
Kalle Svensson wrote:<br>
<blockquote type="cite" cite="mid:20021203020949.GH18311@i92.ryd.student.liu.se">
  <pre wrap="">-----BEGIN PGP SIGNED MESSAGE-----<br>Hash: SHA1<br><br>[chipsdw.com Webmaster]<br></pre>
  <blockquote type="cite">
    <pre wrap="">I'm new here, but I have a question.<br></pre>
    </blockquote>
    <pre wrap=""><!----><br>Welcome to the list!<br><br></pre>
    <blockquote type="cite">
      <pre wrap="">Im a kid so I have made many things to help me with my<br>homework... things like caculators fehrenhiet to celcius converters<br>etc. When I use IDLE to run them they run fine with no bugs, BUT<br>when I just click on them and that cmd prompt looking thing comes<br>up, you type the first number, say 2 then u type the second number<br>say 3, and it is supposed to do 2x3. All I see is a last line of<br>white text that I can't see which I presume is the answer, but once<br>it displays it for a fraction of a second, not enough time to read<br>it, it closes the script since It has nothing more to do. How can I<br>stop this?<br></pre>
      </blockquote>
      <pre wrap=""><!----><br>One solution is to add a line like<br><br>  raw_input("Press enter to close.")<br><br>to the end of your program.  This isn't very elegant, but I'm afraid I<br>don't know of any better way to fix this.<br><br>Peace,<br>  Kalle<br>- -- <br>Kalle Svensson, <a class="moz-txt-link-freetext" href="http://www.juckapan.org/~kalle/">http://www.juckapan.org/~kalle/</a><br>Student, root and saint in the Church of Emacs.<br>-----BEGIN PGP SIGNATURE-----<br>Version: GnuPG v1.0.7 (GNU/Linux)<br>Comment: Processed by Mailcrypt 3.5.6 <a class="moz-txt-link-rfc2396E" href="http://mailcrypt.sourceforge.net/">&lt;http://mailcrypt.sourceforge.net/&gt;</a><br><br>iD8DBQE97BJqdNeA1787sd0RAlmxAKDLv2zEfLkCx6i6sdgPa4I175n7+ACggns/<br>l3haPRMNf2wtm+EJlzxj7A0=<br>=acmz<br>-----END PGP SIGNATURE-----<br><br>_______________________________________________<br>Tutor maillist  -  <a class="moz-txt-link-abbreviated" href="mailto:Tutor@python.org">Tutor@python.org</a><br><a cla
ss="moz-txt-link-freetext" href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a><br><br><br></pre>
      </blockquote>
      <br>
      </body>
      </html>

--------------040703010300040201070302--



From michael@trollope.org  Tue Dec  3 01:34:01 2002
From: michael@trollope.org (Michael Powe)
Date: Tue Dec  3 01:34:01 2002
Subject: [Tutor] perl to python?
In-Reply-To: <Pine.LNX.4.44.0212021734240.25730-100000@hkn.eecs.berkeley.edu>; from dyoo@hkn.eecs.berkeley.edu on Mon, Dec 02, 2002 at 07:23:24PM -0800
References: <001501c29a3f$3c078c60$3212eb42@MYNEWBOX> <Pine.LNX.4.44.0212021734240.25730-100000@hkn.eecs.berkeley.edu>
Message-ID: <20021202223334.B823@titan.spiretech.com>

well, the single thing that made perl most understandable to me was
reading larry wall's account that he designed perl to be like a
natural language. (he was a linguist before becoming a programmer.)
when you think of perl as a language like english or latin, some of
its peculiarities make a lot more sense (to me, anyway).  that would
seem to me to introduce serious complexities in converting it to a
language like python, which is on the other side of the fence
altogether.

http://www.wall.org/~larry/natural.html

having completed my first successful, useful program in python, i must
say i think differently and approach problems differently in perl than
i do in python.  some things can only be properly expressed in french,
trying to say them in english is useless.  ;-)

"Deux Fous gagnent, mais jamais trois" -- A. Alekhine

mp

On Mon, Dec 02, 2002 at 07:23:24PM -0800, Danny Yoo wrote:
> 
> 
> [Note: the post I'm writing below is more about Perl than Python, and more
> about understanding Perl's parse trees than about writing a Python
> converter, so it's a bit off-topic.]
> 
> 
> 
> On Mon, 2 Dec 2002, Lance wrote:
> 
> > Is there a Perl to Python conversion program?
> 
> 
> Unfortunately, no, not yet.
> 
> 
> It should be technially possible to write a program to do this, but the
> code might end up looking even more miserable than the original Perl code.
> 
> 
> Still, I wonder how hard it would be to cook a toy example up.
> 
> 
> 
> What makes such an automatic converter hard is that Perl's grammar doesn't
> appear to be really documented anywhere except in the Perl source code.
> We'd need a tool that generates a "parse tree" of Perl code; once we had a
> parse tree, we might have a good chance of writing a PerlToPython
> converter.
> 
> 
> In fact, it has been said that "Only Perl can parse Perl":
> 
>   http://www.everything2.com/index.pl?node=only%20Perl%20can%20parse%20Perl
> 
> 
> So such a converter would probably have to use Perl itself to generate the
> parse tree.  Perl does provide a 'backend' module called B for this.
> 
>     http://www.perlpod.com/stable/perlcompile.html
> 
> 
> 
> What does a "parse tree" look like?  It's a low-level representation of
> the language.  Here's an example of a such a "parse" of a simple
> 'hello.pl' program:
> 
> ######
> [dyoo@tesuque dyoo]$ cat hello.pl
> 
> print "Hello world\n";
> 
> ###
> 
> 
> 
> It's a simple little program.  Here's its "parse tree":
> 
> ###
> [dyoo@tesuque dyoo]$ perl -MO=Terse hello.pl
> LISTOP (0x81668b0) leave [1]
>     OP (0x81668d8) enter
>     COP (0x80fe8d8) nextstate
>     LISTOP (0x8166868) print
>         OP (0x8166890) pushmark
>         SVOP (0x817bec8) const  PV (0x80f6d88) "Hello world\n"
> test.pl syntax OK
> ######
> 
> 
> The capitalized letters on the left hand side are "opcodes" --- operation
> codes.  If we visit this "tree" in a preorder traversal, we'll see that:
> 
>     1.  Perl calls "enter", whatever that means.  I think it means that it
>         will enter the program start.
> 
>     2.  It generates a nextstate, whatever that means.
> 
>     3.  It does a "pushmark" operation, whatever that is.
> 
>     4.  It puts the argument "hello world" on its stack.  The 'SV' in SVOP
>         stands for "scalar variable".
> 
>     5.  It calls the 'print' list operator.
> 
>     6.  Finally, it exits, with a return value of 1, I think.
> 
> 
> 
> Here's a small Python program that's specifically designed to visit this
> particular tree.  I know that it's incorrect and incomplete (I don't even
> understand the opcodes yet!  *grin*), but it should give the flavor of
> what effort a PerlToPython converter might involve:
> 
> 
> ###
> """A small program to demonstrate what might be involved in parsing
> Perl into Python.
> 
> Danny Yoo (dyoo@hkn.eecs.berkeley.edu)
> """
> 
> parse_tree = ("LISTOP", "leave", 1,
> 	      [("OP", "enter",
> 		[("COP", "nextstate",
> 		  [("LISTOP", "print",
> 		    [("OP", "pushmark", []),
> 		     ("SVOP", "const PV", "Hello world\n", [])])])])])
> 
> ## Some utility functions that we might need...
> def opcode(instruction):
>     return instruction[0]
> 
> def children(instruction):
>     return instruction[-1]
> 
> def operands(instruction):
>     return instruction[1:-1]
> 
> 
> class PerlToPython:
>     def __init__(self):
>         self.stack = []
>         self.lines = []
> 
>     def visit(self, instruction):
>         op = opcode(instruction)
>         dispatch_function = getattr(self, "visit_" + op)
>         dispatch_function(instruction)
> 
> 
>     def visit_LISTOP(self, instruction):
>         for child in children(instruction):
>             self.visit(child)
>         args = operands(instruction)
>         if args[0] == 'print':
>             self.lines.append("print " + ','.join(self.stack))
>         elif args[0] == 'leave':
>             self.lines.append("raise SystemExit")
> 
> 
>     def visit_OP(self, instruction):
>         for child in children(instruction):
>             self.visit(child)
>         return  ## fixme!
> 
> 
>     def visit_COP(self, instruction):
>         for child in children(instruction):
>             self.visit(child)
>         return  ## fixme!
> 
>     def visit_SVOP(self, instruction):
>         type, value = operands(instruction)
>         if type == "const PV":
>             self.stack.append("%s" % repr(value))
> 
> 
> if __name__ == '__main__':
>     converter = PerlToPython()
>     converter.visit(parse_tree)
>     print '\n'.join(converter.lines)
> ###
> 
> 
> 
> Here's an example of this in action:
> 
> ###
> [dyoo@tesuque dyoo]$ python perl_into_python.py
> print 'Hello world\n'
> raise SystemExit
> ###
> 
> 
> 
> 
> 
> Let's look at another Perl parse tree of a slightly more complicated
> program:
> 
> ###
> [dyoo@tesuque dyoo]$ cat loops.pl
> 
> for ($i = 0; $i < 10; $i++) {
>     print "$i\n";
> }
> 
> 
> [dyoo@tesuque dyoo]$ perl -MO=Terse loops.pl
> LISTOP (0x80fa8c8) leave [1]
>     OP (0x80fa928) enter
>     COP (0x80fa8f0) nextstate
>     BINOP (0x8166900) sassign
>         SVOP (0x81668e0) const  IV (0x80f6d88) 0
>         UNOP (0x81668c0) null [15]
>             SVOP (0x817bec8) gvsv  GV (0x81025f0) *i
>     BINOP (0x80fa8a0) leaveloop
>         LOOP (0x80fa870) enterloop
>         UNOP (0x8104820) null
>             LOGOP (0x81047f8) and
>                 BINOP (0x8166988) lt
>                     UNOP (0x8166948) null [15]
>                         SVOP (0x8166928) gvsv  GV (0x81025f0) *i
>                     SVOP (0x8166968) const  IV (0x8102590) 10
>                 LISTOP (0x8104798) lineseq
>                     LISTOP (0x8104750) scope
>                         OP (0x8104718) null [174]
>                         LISTOP (0x8103fb8) print
>                             OP (0x8103fe0) pushmark
>                             UNOP (0x8103f90) null [67]
>                                 OP (0x8184868) null [3]
>                                 BINOP (0x8184840) concat [2]
>                                     UNOP (0x8184720) null [15]
>                                         SVOP (0x8184700) gvsv  GV
> (0x81025f0) *i
>                                     SVOP (0x8184740) const  PV (0x8102614)
> "\n"
>                     UNOP (0x8184820) preinc [1]
>                         UNOP (0x8104928) null [15]
>                             SVOP (0x8104908) gvsv  GV (0x81025f0) *i
>                     OP (0x8104778) unstack
>                     COP (0x81047c0) nextstate
> loops.pl syntax OK
> ###
> 
> 
> The complexity of this is a little bit deeper, but the idea is the same:
> we have to handle some of these new opcodes, like LOOP, and transform them
> into their Python equivalents.  We may need to keep additional track of
> things like scope and nesting.  Not a particularly "hard" task, but it
> might be a little complicated.
> 
> 
> 
> Alternatively, it might also be possible to translate a Perl parse tree
> into a Python parse tree with the help of the 'compiler' module:
> 
>     http://www.python.org/doc/lib/compiler.html
> 
> and then use a program called 'decompyle' to take that Python parse tree
> and reproduce human-readable text:
> 
>     http://www.crazy-compilers.com/decompyle/
> 
> 
> But somehow, I think this might take longer to write than I anticipated.
> Still, it is very possible to write this program.  It might make a nice
> winter project.  *grin*
> 
> 
> 
> Good luck to you!
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


From michael@trollope.org  Tue Dec  3 01:58:02 2002
From: michael@trollope.org (Michael Powe)
Date: Tue Dec  3 01:58:02 2002
Subject: [Tutor] Re: Naive Questions
In-Reply-To: <20021202013823.GA28685@dman.ddts.net>; from dman@dman.ddts.net on Sun, Dec 01, 2002 at 08:38:23PM -0500
References: <20021201161700.A6998@titan.spiretech.com> <20021202013823.GA28685@dman.ddts.net>
Message-ID: <20021202225704.C823@titan.spiretech.com>

On Sun, Dec 01, 2002 at 08:38:23PM -0500, Derrick 'dman' Hudson wrote:
> On Sun, Dec 01, 2002 at 04:17:00PM -0800, Michael Powe wrote:
> | hello,
> | 
> | a couple questions to which i haven't been able to find answers.
> | 
> | i don't seem to find a python equivalent to the "rewind" file operation
> | in C -- that is, i read through a file and i want to go back to the
> | beginning and read again.  is the only option to close & reopen?
> 
> What C function are you thinking of?  The only ones I know of are
> ftell(3) and fseek(3).  Python file objects have both.
> 
> http://python.org/doc/current/lib/lib.html
> 
> | and just from curiosity, why are there no increment/decrement operators,
> | and nothing equivalent to += & its friends?  i'd have thought this
> | would be a faq, but don't find anything about it there.
> 
> |  the second, just that i'm lazy & find having to always type out i =
> |  i+1 annoying.  ;-)
> 
> You're not the only one :-).

thank goodness!  it's lonely out there!

> 
> http://www.python.org/peps/pep-0203.html
> 
> As of python 2.0.  The pep also explains why '++' isn't included (but
> '+=1' isn't any worse, really).

thanks.  i didn't see mention of the increment operator but it's good to know
that the others are there.

mp





From fredm@smartypantsco.com  Tue Dec  3 02:46:00 2002
From: fredm@smartypantsco.com (Alfred Milgrom)
Date: Tue Dec  3 02:46:00 2002
Subject: [Tutor] Testing if a number occurs more than once
In-Reply-To: <4118DFD5-061E-11D7-A76B-000393C5BF0A@st-annes.oxford.ac.uk
 >
Message-ID: <5.1.0.14.0.20021203110558.00a9b220@192.168.1.1>

Hi Michael:

What about something like:

def morethanone(list):
     for i in range(len(list)):
         if list[i] in list[i+1:]:
             return 1
     return 0

list = [your list]
print morethanone(list)

This goes through each element in the list, and checks if that element 
exists in the rest of the list. (You don't have to check earlier in the 
list, because you already know that doesn't have any doubles).

HTH,
Fred Milgrom


At 05:48 PM 2/12/02 +0000, you wrote:
>Hi,
>
>I think I may be missing out on something really obvious here (such as a 
>built-in), but I'm trying to ascertain whether a given number occurs more 
>than once in a list. My current solution involves generating a dictionary 
>of the frequency with which each number occurs and then checking if the 
>size of that dictionary is the same as the size of the original list (if 
>it is then each number occurs once). This strikes me as not only 
>convoluted, but slow (this is the dominant loop of the program). There 
>must be a better way! Any suggestions?



From fredm@smartypantsco.com  Tue Dec  3 02:46:07 2002
From: fredm@smartypantsco.com (Alfred Milgrom)
Date: Tue Dec  3 02:46:07 2002
Subject: [Tutor] Testing if a number occurs more than once
In-Reply-To: <4118DFD5-061E-11D7-A76B-000393C5BF0A@st-annes.oxford.ac.uk
 >
Message-ID: <5.1.0.14.0.20021203112325.00a71af0@192.168.1.1>

I've just been playing with List Comprehension and Functional Programming, 
so here is a much simpler solution which returns the duplicates in your list:

duplicates = filter((lambda x:list.count(x)>1), list)

If there are no entries doubled in your list, duplicates will be an empty 
list. Otherwise each duplicated entry will appear in duplicates (as many 
times as it appears in the list).

Best regards,
Fred Milgrom



From charlie@begeistert.org  Tue Dec  3 05:21:01 2002
From: charlie@begeistert.org (Charlie Clark)
Date: Tue Dec  3 05:21:01 2002
Subject: [Tutor] Re: Temperature conversion (number types)
In-Reply-To: <20021203013002.28265.96112.Mailman@mail.python.org>
References: <20021203013002.28265.96112.Mailman@mail.python.org>
Message-ID: <20021203112202.787.4@.1038906761.fake>

On 2002-12-03 at 02:30:02 [+0100], tutor@python.org wrote:
> Message: 13
> Date: Sun, 01 Dec 2002 17:53:56 -0600
> From: Chuck Baker <ChuckBaker@pokynet.com>
> Organization: C & C Enterprises
> To: tutor@python.org
> Subject: [Tutor] Temerature conversion??
> 
> <!doctype html public "-//w3c//dtd html 4.0 transitional//en"> <html>
> -----BEGIN PGP SIGNED MESSAGE-----
> <br>Hash: SHA1
> <p>Hello everyone.
> <p>I am new to the list and have just started playing with Python. I 
> <br>have programed in BASIC before.
> <p>I was going through and playing with it and I started out making a 
> <br>temperature conversion program.
> <p>Converting fahrenheit to celsius I had no problem <br>(98.6-32)/9*5 =37
> <p>That worked fine. But when I tried to reverse it, <br>37/5*9+32
> <br>It came out to = 95 not 98.6
> <p>and I can't figure out why??
Dear Chuck,

you're being bitten by a limitation in the way binary computers deal with 
numbers. Numbers with values right of the decimal point are called 
"floating points" and usually need to be specified as such so that the 
machinery which deals with the inexact and unreliable mapping of decimal to 
binary can be called into action. So how does this fit in your problem?

When you use a number Python attempts to identify its type so that it knows 
what to do with it. You can test this by using the built-in function type():

>>> type(1)
<type 'int'>
>>> type(1.5)
<type 'float'>

Floats take precedence over integers so that when you add them you get a 
float back:

<type 'float'>
>>> 1 + 1.5
2.5

This is why your conversion from Fahrenheit to Celsius works because you 
start with a float.

Integers don't have decimal values. Everyone knows that. What not everyone 
knows is that most programming languages expect integers to stay like that:
>>> 1 / 2
0
>>>  
Yes, divide 1 by 2 and you get 0! Everybody knows that, too!? Well, 
old-hand computer programmers at least. It's kind of logical: an operation 
involving two integers results in an integer. Divide by an equivalent float 
and you're sorted:
>>> 1 / 2.0
0.5 

However, as Tim-bot and others can explain much better than I: 2.0 is not 
2, at least not to the computer and this is why most computer languages 
don't give floats unless you explicitly request them. This shouldn't be a 
problem for languages like Python which allow object types to be changed.

So we have a problem: for compatability with other languages and lots of 
lots of code 1 / 2 gives 0 (makes sense to lots of programmers who've 
learned it) in Python whereas 1 / 2.0 gives 0.5 (makes sense to 
non-programmers).

The solution in Python is to distinguish between "natural" and "floored 
division". Future versions of Python will normally use "natural" division 
as standard but will allow "floored" if desired. 

1 / 2 = 0.5  # natural division
1 //22 = 0   # floored division

Make sense?

Charlie


From alan.gauld@bt.com  Tue Dec  3 05:31:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec  3 05:31:01 2002
Subject: [Tutor] Testing if a number occurs more than once
Message-ID: <7497DCA1C240C042B28F6657ADFD8E09702238@i2km11-ukbr.domain1.systemhost.net>

> > program). There must be a better way! Any suggestions?
> 
> try :
> 
> def morethanone(l):
    return (l.count(n) > 0)

Should do it?

Alan g.


From alan.gauld@bt.com  Tue Dec  3 05:44:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec  3 05:44:02 2002
Subject: [Tutor] Testing if a number occurs more than once [profiling
 a function using profile.run()]
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0974DA5B@i2km11-ukbr.domain1.systemhost.net>

> > def morethanone(l):
> >         for n in l:

Doh! My previous reply missed the loop. I'm obviously not 
concentrating these days - trying to read too many digests 
at once...

To try to make ammends I'll suggest an alternative approach 
to the ones I've seen so far.

Create a dictionary then check for any values higher than 1.
It effectively gives a O(2n) solution rather than O(n**2)...

def morethanone(L):
   d = {}
   for i in L: 
      try: d[i] += 1
      except: d[i] = 1
   for i in d.keys():
      if d[i] > 1: return 1
   return 0


Apologies everyone,

Alan g.


From alan.gauld@bt.com  Tue Dec  3 05:49:04 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec  3 05:49:04 2002
Subject: [Tutor] Beginner
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0970223A@i2km11-ukbr.domain1.systemhost.net>

> Could you provide me with a selection of links to instructions to 
> learn how to use IDLE (Python GUI) please, so I can then learn 
> how to program using python.

First, let me say that learning IDLE is not necessary for learning Python.
I rarely use IDLE since for short programs I just use the Command window
(aka DOS prompt) and for longer programs I type them into vim(my text
editor).

However IDLE isn't a bad place for befgoinners to be so I suggest you 
visit the IDLE page on the Python web site. There you will find a link 
to Danny Yoo's excellent tutorial plus the full "user manual"

Then progress to the newbie section of the web site to find beginners 
tutorials for Python itself.

> My operating system is Microsoft XP Pro,.

So is (one of) mine :-)

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld


From scot@possum.in-berlin.de  Tue Dec  3 05:51:01 2002
From: scot@possum.in-berlin.de (Scot Stevenson)
Date: Tue Dec  3 05:51:01 2002
Subject: [Tutor] Testing if a number occurs more than once [dict version]
In-Reply-To: <Pine.LNX.4.44.0212021326290.17204-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.44.0212021326290.17204-100000@hkn.eecs.berkeley.edu>
Message-ID: <200212031145.34961.scot@possum.in-berlin.de>

Hello Danny, 

> A better approach could be to first sort() the list of numbers, and run
> through adjacent pairs of elements.  The duplicates, if they exist, will
> clump up together during the sort, and will be easy to pick up when we
> compare adjacent elements.

But you still have to sort the whole ist, so how about a solution with 
dictionaries, which are hashed and fast (or so I have been told). Something 
like:

===============================
def morethanone(L):
    numbersfound = {}
    for number in L:
        if number in numbersfound:
            return 1
        else:
            numbersfound[number]=1
    return 0
===============================

(Acutally a set would be better than a dictionary, but Python doesn't have 
those [yet]. This is the code for Python 2.2, I think the line "if number in 
numbersfound" has to be "if numbersfound.has_key(number)" in older versions.)

If I try to profile the thing, I get: 

===============================
>> import profile
>>> def morethanone(L):
...     numbersfound = {}
...     for number in L:
...         if number in numbersfound:
...             return 1
...         else:
...             numbersfound[number]=1
...     return 0
...
>>> l1, l2, l3 = range(1000), range(10000), range(100000)
>>> profile.run('morethanone(l1)')
         3 function calls in 0.030 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.010    0.010    0.010    0.010 <stdin>:1(morethanone)
        1    0.000    0.000    0.010    0.010 <string>:1(?)
        1    0.020    0.020    0.030    0.030 profile:0(morethanone(l1))
        0    0.000             0.000          profile:0(profiler)

>> profile.run('morethanone(l2)')
         3 function calls in 0.010 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.010    0.010    0.010    0.010 <stdin>:1(morethanone)
        1    0.000    0.000    0.010    0.010 <string>:1(?)
        1    0.000    0.000    0.010    0.010 profile:0(morethanone(l2))
        0    0.000             0.000          profile:0(profiler)

>> profile.run('morethanone(l3)')
         3 function calls in 0.190 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.180    0.180    0.180    0.180 <stdin>:1(morethanone)
        1    0.010    0.010    0.190    0.190 <string>:1(?)
        1    0.000    0.000    0.190    0.190 profile:0(morethanone(l3))
        0    0.000             0.000          profile:0(profiler)

======================

Strange: Why is the call with 10,000 faster than with 1,000? Does this need to 
be averaged statistically over a few runs like other profilers, or am I 
missing something?

I'm not sure if I can compare these numbers directly to yours (profile can't 
be that good, can it?), my machine seems to be slower than yours is, because 
I get 

=======================================
>>> def morethanone(l):
...     for n in l:
...         if l.count(n)>1:
...             return 1
...     return 0
...
>>> profile.run('morethanone(l1)')
         3 function calls in 0.180 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.180    0.180    0.180    0.180 <stdin>:1(morethanone)
        1    0.000    0.000    0.180    0.180 <string>:1(?)
        1    0.000    0.000    0.180    0.180 profile:0(morethanone(l1))
        0    0.000             0.000          profile:0(profiler)
========================================

whereas you got 0.140 CPU seconds for that version. 

Anyway, your version seems to still be faster, but now I know how to profile 
functions, so it was worth it =8).

Y, Scot

-- 
  Scot W. Stevenson -- scot@possum.in-berlin.de -- Zepernick, Germany



From alan.gauld@bt.com  Tue Dec  3 05:51:11 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec  3 05:51:11 2002
Subject: [Tutor] Save as
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0970223B@i2km11-ukbr.domain1.systemhost.net>

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C29AB9.B344DB94
Content-Type: text/plain;
	charset="iso-8859-1"

>  When i save a Python file, if i try to open it again, i am asked what i
want  
>  to open it with, can you help on this please. 
 
Are you giving it a .py extension when you save it?
Thats what XP looks for in determining the program to open it.
 
The installer should have set it up to be the interpreter
(which BTW may result in it running and closing before you 
can see the output!  Fix that by putting a raw_input() line 
at the end of the file...)
 
Does the icon look like a snake?
Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld
<http://www.freenetpages.co.uk/hp/alan.gauld>  


------_=_NextPart_001_01C29AB9.B344DB94
Content-Type: text/html;
	charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 5.50.4807.2300" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2><SPAN class=550235110-03122002><FONT face="Courier New" 
color=#0000ff>&gt; &nbsp;</FONT></SPAN>When i save a Python file, if i try to 
open it again, i am asked what i want&nbsp;<SPAN class=550235110-03122002><FONT 
face="Courier New" color=#0000ff>&nbsp;</FONT></SPAN></FONT></DIV>
<DIV><FONT size=2><SPAN class=550235110-03122002><FONT face="Courier New" 
color=#0000ff>&gt; </FONT>&nbsp;</SPAN>to open it with, can you help on this 
please.<SPAN class=550235110-03122002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></DIV>
<DIV><FONT size=2><SPAN class=550235110-03122002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=2><SPAN class=550235110-03122002><FONT face="Courier New" 
color=#0000ff>Are you giving it a .py extension when you save 
it?</FONT></SPAN></FONT></DIV>
<DIV><FONT size=2><SPAN class=550235110-03122002><FONT face="Courier New" 
color=#0000ff>Thats what XP looks for in determining the program to open 
it.</FONT></SPAN></FONT></DIV>
<DIV><FONT size=2><SPAN class=550235110-03122002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=2><SPAN class=550235110-03122002><FONT face="Courier New" 
color=#0000ff>The installer should have set it up to be the 
interpreter</FONT></SPAN></FONT></DIV>
<DIV><FONT size=2><SPAN class=550235110-03122002><FONT face="Courier New" 
color=#0000ff>(which BTW may result in it running and closing before you 
</FONT></SPAN></FONT></DIV>
<DIV><FONT size=2><SPAN class=550235110-03122002><FONT face="Courier New" 
color=#0000ff>can see the output!</FONT>&nbsp;<FONT face="Courier New" 
color=#0000ff> Fix that by putting a raw_input() line 
</FONT></SPAN></FONT></DIV>
<DIV><FONT size=2><SPAN class=550235110-03122002><FONT face="Courier New" 
color=#0000ff>at the end of the file...)</FONT></SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=550235110-03122002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=550235110-03122002>Does the icon look like a snake?</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=550235110-03122002>
<P><FONT size=2>Alan g.<BR>Author of the 'Learning to Program' web site<BR><A 
target=_blank 
href="http://www.freenetpages.co.uk/hp/alan.gauld">http://www.freenetpages.co.uk/hp/alan.gauld</A></FONT> 
</P></SPAN></FONT></DIV></BODY></HTML>

------_=_NextPart_001_01C29AB9.B344DB94--


From scot@possum.in-berlin.de  Tue Dec  3 07:21:02 2002
From: scot@possum.in-berlin.de (Scot Stevenson)
Date: Tue Dec  3 07:21:02 2002
Subject: [Tutor] Testing if a number occurs more than once
In-Reply-To: <5.1.0.14.0.20021203112325.00a71af0@192.168.1.1>
References: <5.1.0.14.0.20021203112325.00a71af0@192.168.1.1>
Message-ID: <200212031155.50900.scot@possum.in-berlin.de>

Hello Fred, 

> duplicates = filter((lambda x:list.count(x)>1), list)

If I understood the previous posters here, the "list.count" part is the 
problem, because it goes thru the whole list every time, which is expensive. 
Or doesn't this apply here?

Y, Scot


-- 
  Scot W. Stevenson -- scot@possum.in-berlin.de -- Zepernick, Germany



From hall@ouhep1.nhn.ou.edu  Tue Dec  3 12:02:08 2002
From: hall@ouhep1.nhn.ou.edu (Isaac Hall)
Date: Tue Dec  3 12:02:08 2002
Subject: [Tutor] clocks?
Message-ID: <Pine.LNX.4.44.0212031053200.8576-100000@ouhep1.nhn.ou.edu>

hi list!

This question is not all that important, so if you don't know the answer 
right off the top of your head, don't feel like you have to go searching 
for it.  In Tkinter, at the top(or bottom) of some frame, I would like to 
place somewhat of a clock, not your ordinary clock, but one that tells you 
how many seconds have passed since some event happened.  I make this as a 
label....

For understandings sake, here is the class I define to hold this thing.

class notifier(Label):
    def __init__(self,parent):
        self.text=StringVar()
        self.text.set('no messages recieved')
        Label.__init__(self,parent, bg='white',textvariable=self.text)
        self.count=0
        self.end=1
    def start_count(self):
        self.count=1
        messageArrivalTime=time.time()
        self.counting()
    def counting(self):
        if not self.count:
            diff=int(time.time()-messageArrivalTime)
            self.text.set('message recieved '+str(diff)+' seconds ago')
            self.after(1000, self.counting)
        else:
            self.text.set('no messages recieved')
    def stop_count(self):
        self.count=0

My problems arise when I try to put this into a frame, pack it, then call 
the start_count() method.  When I do this, nothing appears on the screen!
why?

Ike
-- 



From hall@ouhep1.nhn.ou.edu  Tue Dec  3 12:46:11 2002
From: hall@ouhep1.nhn.ou.edu (Isaac Hall)
Date: Tue Dec  3 12:46:11 2002
Subject: [Tutor] clocks again
Message-ID: <Pine.LNX.4.44.0212031143020.8576-100000@ouhep1.nhn.ou.edu>

Please disregard my previous message.
I had a few bugs in my code (attributes that should have had a self.
in front of them), and my real problem all had to do with when I called 
mainloop(), which I figured out not long after posting the message.

Ike

-- 



From michael.williams@st-annes.oxford.ac.uk  Tue Dec  3 12:47:03 2002
From: michael.williams@st-annes.oxford.ac.uk (Michael Williams)
Date: Tue Dec  3 12:47:03 2002
Subject: [Tutor] Testing if a number occurs more than once
In-Reply-To: <200212031145.34961.scot@possum.in-berlin.de>
Message-ID: <2C018C64-06E7-11D7-8E98-000393C5BF0A@st-annes.oxford.ac.uk>

Well, the general consensus is that there isn't much general consensus 
and that the best solution depends on the form of the problem.

The problem is a trivial little thing from the British magazine ``New 
Scientist''. Each week, in a section called ``Enigma'' they set a 
number puzzle. I could see no way of solving this week's analytically, 
so threw Python at it. Here's the problem:

New Scientist wrote:
> Brits who venture to Euroland quickly discover that you get 
> one-and-a-bit Euros for every pound. I can reveal that the "bit" 
> varies between 4/3 and 11/8 because:
>    EURO * 4/3 == POUND
>    EURO * 11/8 == POUND
> These two sums are entirely distinct: any letter may or may not have 
> the same value in one sum as in the other. But within each sum digits 
> have been consistently represented by capital letters, different 
> letters being used for different digits. No number starts with a zero. 
> What were the five-digit numbers represented by pound in (a) and (b)?

So it's the same problem with two different coefficients. Let's 
consider (b). Firstly, we know the minimum possible value of POUND is 
10000 since neither number starts with a zero. Therefore, the minimum 
EURO is 10000/(11/8) == 7272. This saves some time during the program.

So here is the first solution I came up with:
========================================

coeff = 1 + 3.0/8

min_euro = 10000/coeff
solved = 0

for euro in range(min_euro, 10000, 1):
   # go through the possible EUROs.
   e = int(str(euro)[0])
   u = int(str(euro)[1])
   r = int(str(euro)[2])
   o = int(str(euro)[3])
   # go through the possible POUNDs (O and U already decided)
   for p in range(1,10,1):
     for n in range(0,10,1):
       for d in range(0,10,1):
         pound_s = str(p) + str(o) + str(u) + str(n) + str(d)
         pound = int(pound_s)
         numbers = [int(str(euro)[0]), int(str(euro)[1]),
                int(str(euro)[2]), int(str(euro)[3]),
                int(str(pound)[0]), int(str(pound)[3]),
                int(str(pound)[4])]
         if not morethanone(numbers):
           if test(euro, pound, coeff):
             solved = 1
             break
       if solved == 1: break
     if solved == 1: break
   if solved == 1: break

================================

test() is just a function that tests whether euro * coeff == pound. 
morethanone() is the function that determines whether or not an number 
occurs more than once in the list numbers. So morethanone() acts on a 
list only seven elements long, which is going to affect the way we 
write morethanone().

Having thought about it some more I realised that where I call 
morethanone() will drastically affect how much effort I put into 
optimising it. In the above form morethanone is called for *every* 
combination of the seven digits in the range. That's a lot of times.

By calling it only after establishing that euro + coeff == pound, we 
reduce the number of calls it gets to half-a-dozen times. This is 
probably the best way to do it: call test() many times, call 
morethanone() few, since test() is simple, morethanone() is not.

So, with a bit of thought on my part, I realised that the optimisation 
of morethanone is a red-herring in this case and profiling the various 
morethanone()s (summarised below) in this case would not throw up any 
significiant differences.

Here are the morethanone()s suggested:

Yann Le Du:
-----------
for n in l:
   if l.count(n) > 1:
     return 1
   return 0

Jeff Shannon (and a similar one from Danny Yoo):
------------------------------------------------
mycopy = l[:]		# as Jeff suggested this is unnecessary in this case
mycopy.sort()
for n in range(1, len(mycopy))
   if mycopy[n] == mycopy[n-1]:
     return 1
return 0

Jeff Shannon (and a similar one--I think!--from Alan Gauld)
-----------------------------------------------------------
res = {}
for item in l:
   if res.get(item, 0):
     res[item] = 1
   else:
     return 1
return 0

p.s. If anyone does the problem themselves, I make the answers:
in (a) POUND is 12056
in (b) it is 10945

-- 
Michael



From scot@possum.in-berlin.de  Tue Dec  3 17:16:02 2002
From: scot@possum.in-berlin.de (Scot Stevenson)
Date: Tue Dec  3 17:16:02 2002
Subject: [Tutor] Testing if a number occurs more than once [dict version]
In-Reply-To: <Pine.LNX.4.44.0212021326290.17204-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.44.0212021326290.17204-100000@hkn.eecs.berkeley.edu>
Message-ID: <200212031145.34961.scot@possum.in-berlin.de>

Uh, I may have screwed up here: 

===============================
def morethanone(L):
    numbersfound = {}
    for number in L:
        if number in numbersfound:
            return 1
        else:
            numbersfound[number]=1
    return 0
===============================

After rereading some stuff about dictionaries, I think the line

	if number in numbersfound:

probably should be

	if numbersfound.has_key(number):

after all: It seems that "in" does a linear search (just what we were trying 
to avoid) why "has_key" uses the hash table.

Which just goes to show: Newer isn't always better, a little knowledge is a 
dangerous thing, and it always darkest before the dawn. Or something like 
that...

Y, Scot


-- 
  Scot W. Stevenson -- scot@possum.in-berlin.de -- Zepernick, Germany




From magnus@thinkware.se  Tue Dec  3 18:25:27 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Dec  3 18:25:27 2002
Subject: [Tutor] Testing if a number occurs more than once [dict
 version]
In-Reply-To: <200212031145.34961.scot@possum.in-berlin.de>
References: <Pine.LNX.4.44.0212021326290.17204-100000@hkn.eecs.berkeley.edu>
 <Pine.LNX.4.44.0212021326290.17204-100000@hkn.eecs.berkeley.edu>
Message-ID: <5.1.0.14.0.20021204000939.02bf5b28@www.thinkware.se>

At 23:14 2002-12-03 +0100, Scot Stevenson wrote:
>After rereading some stuff about dictionaries, I think the line
>
>         if number in numbersfound:
>
>probably should be
>
>         if numbersfound.has_key(number):

Don't guess! Measure!!!

import time is your friend. It seems to me that "if x in y"
takes significantly less time than "if y.has_key(x)". This is
mainly due to the fact that you make an object lookup in the
loop to find the .has_key() method. (You might have reassigned
it since the last pass through the loop. ;)

If you put "numbersfound_has_key = numbersfound.has_key" outside
your loop, and use "if numbersfound_has_key(number):" in the loop,
it will be even a little faster than "if number in numbersfound:".


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From James.Alexander.McCarney@Cognicase.com  Tue Dec  3 19:02:02 2002
From: James.Alexander.McCarney@Cognicase.com (McCarney, James Alexander)
Date: Tue Dec  3 19:02:02 2002
Subject: [Tutor] getting 'more or less' online documentation
Message-ID: <23FD7B1A77E8D211BCB900001D108C02023FCB45@camelot>

Hope this one isn't a howler. I did rtfm, so maybe it's mere fatigue that's
preventing me from finding this. I'd like to know how to control how much
text displays when printing a doc string to the screen--a la 'more' or
'less' utilities.

I know I can use the scroll bar--but how uncool... :^)

Using IDLE 0.8, Windows 2000, Python 2.2

James Alexander McCarney, technical writer, (450) 928-3386 x2262 
COGNICASE-M3i http://www.m3isystems.com
mailto:James.Alexander.McCarney@Cognicase.com
1111 Saint-Charles Avenue West, 11th Floor, East Tower, Longueuil, Quebec,
J4K 5G4 Canada


From fredm@smartypantsco.com  Tue Dec  3 19:09:01 2002
From: fredm@smartypantsco.com (Alfred Milgrom)
Date: Tue Dec  3 19:09:01 2002
Subject: [Tutor] Testing if a number occurs more than once
In-Reply-To: <2C018C64-06E7-11D7-8E98-000393C5BF0A@st-annes.oxford.ac.uk
 >
References: <200212031145.34961.scot@possum.in-berlin.de>
Message-ID: <5.1.0.14.0.20021204104830.032182e0@192.168.1.1>

Although I cannot answer Michael's New Scientist problem, here is some more 
on the fastest solution for finding duplicates.

The function given by Danny Yoo appears to have been the fastest test 
proposed so far:

def morethanone2(l):
     l.sort()
     for i in range(1, len(l)):
          if l[i-1] == l[i]:
              return 1
     return 0

 >>> list = range(100000)
 >>> profile.run('morethanone2(list)')
          3 function calls in 0.173 CPU seconds

However, if pure speed is the issue, the following is faster :

def morethanone3(l):
     d={}
     for x in l : d[x] = 1
     return (len(d) != len(l))

 >>> list = range(100000)
 >>> profile.run('morethanone3(list)')
          3 function calls in 0.097 CPU seconds

The result is even more impressive if one uses a shuffled list, since the 
example above using a sorted list means that sort() does next to no work:

 >>> list = range(100000)
 >>> random.shuffle(list)
 >>> profile.run('morethanone2(list)')
          3 function calls in 0.532 CPU seconds


 >>> list = range(100000)
 >>> random.shuffle(list)
 >>> profile.run('morethanone3(list)')
          3 function calls in 0.162 CPU seconds

This new function of course does not tell you where the duplication occurs. 
If this is required, you can use the following function, which is a bit 
slower but still faster than Danny's original function:

def morethanone4(l):
     d={}
     for x in l : d[x] = d.setdefault(x,0)+1
     return (len(d) != len(l))

 >>> list = range(100000)
 >>> random.shuffle(list)
 >>> profile.run('morethanone4(list)')
          3 function calls in 0.293 CPU seconds

Finally, if speed of finding what or where the duplicate is an issue, here 
is a variation on Danny's function using List Comprehension which is about 
the same speed as the original function, but potentially gives more 
information:

def morethanone5(l) :
     l.sort()
     x=[l[i] for i in range(len(l)-1) if l[i]==l[i+1]]
     return len(x)

 >>> list = range(100000)
 >>> random.shuffle(list)
 >>> profile.run('morethanone5(list)')
          3 function calls in 0.594 CPU seconds

This last function gives you access to a list with all the duplicates in it 
(if x is made a global variable).

Best regards,
Fred Milgrom








From emile@fenx.com  Tue Dec  3 19:54:02 2002
From: emile@fenx.com (Emile van Sebille)
Date: Tue Dec  3 19:54:02 2002
Subject: [Tutor] Re: getting 'more or less' online documentation
References: <23FD7B1A77E8D211BCB900001D108C02023FCB45@camelot>
Message-ID: <asjitj$55m$1@main.gmane.org>

"McCarney, James Alexander" <James.Alexander.McCarney@Cognicase.com>
wrote in message
news:23FD7B1A77E8D211BCB900001D108C02023FCB45@camelot...
> Hope this one isn't a howler. I did rtfm, so maybe it's mere fatigue
that's
> preventing me from finding this. I'd like to know how to control how
much
> text displays when printing a doc string to the screen--a la 'more' or
> 'less' utilities.
>
> I know I can use the scroll bar--but how uncool... :^)
>
> Using IDLE 0.8, Windows 2000, Python 2.2
>

help() does that now -- is that what you're looking for?

import bisect
help(bisect)



--

Emile van Sebille
emile@fenx.com

---------





From lumbricus@gmx.net  Tue Dec  3 22:47:01 2002
From: lumbricus@gmx.net (lumbricus@gmx.net)
Date: Tue Dec  3 22:47:01 2002
Subject: [Tutor] getting 'more or less' online documentation
References: <23FD7B1A77E8D211BCB900001D108C02023FCB45@camelot>
Message-ID: <31904.1038973573@www40.gmx.net>

Hi!

> Hope this one isn't a howler. I did rtfm, so maybe it's mere fatigue
> that's
> preventing me from finding this. I'd like to know how to control how much
> text displays when printing a doc string to the screen--a la 'more' or
> 'less' utilities.

For a quick pager I usually do:
If "number of displayed lines" modulo "number of lines of VT",
wait for the "anykey".
But then there is no scrolling. For that you need curses.
 
> I know I can use the scroll bar--but how uncool... :^)
> 
> Using IDLE 0.8, Windows 2000, Python 2.2
> 
> James Alexander McCarney, technical writer, (450) 928-3386 x2262 

Good Luck!

J"o


-- 
sigfault

+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!



From Ian.Dickinson@ashluecker.com  Wed Dec  4 10:35:03 2002
From: Ian.Dickinson@ashluecker.com (Ian Dickinson)
Date: Wed Dec  4 10:35:03 2002
Subject: [Tutor] Bitmaps and TK
Message-ID: <D680B98BA9E68843AE4730C166D2677207EAD4@alserver01.ashluecker.com>

I am farly new to this Python / Tk thing

but I just cannot get a full colour picture to appear on a canvas at an =
X,Y position specified by me

Image.open does not appear to exist

Fredrik Lundh Introduction to Tkinter seems to be completly wrong

The documentation for PIL seems to be very bad and the things in it =
don't work

Anyway here is my code


import Image
from Tkinter import *
root =3D Tk()
root.title('Canvas')
Image.open ("C:\\Python_projects\\CRAP\\topleftcorner.bmp")
canvas =3D Canvas(root, width =3D720, height=3D576, bg=3D"#ff0000")
canvas.create_polygon(100, 100, 200, 100, 200, 200, 100, 200, =
fill=3D'yellow')
#not sure what this next line should look like
#canvas.create_image (64, 50, image=3Dim)
frm =3D Frame(canvas, borderwidth=3D0)
canvas.create_window(720, 576, window=3Dfrm, anchor=3DCENTER)
canvas.pack()
root.mainloop()

I am using Python 2.2.2 and PIL py22b1-pil-1.1.2-20011022.exe

Can Anyone help with this

Thanks in advance

Ian




From magnus@thinkware.se  Wed Dec  4 12:04:22 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec  4 12:04:22 2002
Subject: [Tutor] Bitmaps and TK
In-Reply-To: <D680B98BA9E68843AE4730C166D2677207EAD4@alserver01.ashlueck
 er.com>
Message-ID: <5.1.0.14.0.20021204171209.02ab1ea0@www.thinkware.se>

At 15:32 2002-12-04 +0000, Ian Dickinson wrote:
>I am farly new to this Python / Tk thing

Welcome. I hope the frustration will cease soon.

>Image.open does not appear to exist

I'm not sure if you refer to PIL's Image module or Tkinters Image
class here. Tkinter's Image doesn't have any open method. It's a
base class, and I think you always use subclasses. I use PIL in the
packaging provided by ReportLab, and there I would do

import PIL.Image

i = PIL.Image.open("C:\\Python_projects\\CRAP\\topleftcorner.bmp")

to open an image with PIL. This has nothing to do
with Tkinter though. Maybe you are mixing things up?

Tkinter.Image is a base class for BitmapImage and PhotoImage
as far as I know. You wouldn't use that.

PIL.Image is a more generic module used for image processing
etc. You can load an image using

"import Image" does nothing for me. (ImportError: No module named Image)

Perhaps you can tell more exactly what part of the
documentation you find confusing.

 >>> import PIL.Image
 >>> help(PIL.Image)

and

 >>> import Tkinter.Image
 >>> help(Tkinter.Image)

will tell you what you will find in the Tkinter.Image class
and the PIL.Image module.

I think you could do something like this:

# I'll avoid "from X import *" so I don't mix things up...
import PIL.Image, PIL.ImageTk
import Tkinter

im = PIL.Image.open(r'G:\WINNT\Bubblor.bmp')

root = Tkinter.Tk()

photo = PIL.ImageTk.PhotoImage(im)

l = Tkinter.Label(image = photo)
l.pack()

root.mainloop()


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From alan.gauld@bt.com  Wed Dec  4 12:48:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed Dec  4 12:48:02 2002
Subject: [Tutor] Testing if a number occurs more than once
Message-ID: <7497DCA1C240C042B28F6657ADFD8E09702241@i2km11-ukbr.domain1.systemhost.net>

> Jeff Shannon (and a similar one--I think!--from Alan Gauld)
> -----------------------------------------------------------
> res = {}
> for item in l:
>    if res.get(item, 0):
>      res[item] = 1
>    else:
>      return 1
> return 0

I posted a more inefficient version using dictionaries 
but looping twice. I actually thought of the solution above 
today and was just going to post it when I saw the latest 
digest...

Ah well, at least we got there even if not directly necessary 
for your requirement.

Alan G


From alan.gauld@bt.com  Wed Dec  4 12:55:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed Dec  4 12:55:02 2002
Subject: [Tutor] Bitmaps and TK
Message-ID: <7497DCA1C240C042B28F6657ADFD8E09702242@i2km11-ukbr.domain1.systemhost.net>

> but I just cannot get a full colour picture to appear on a 
> canvas at an X,Y position specified by me

Caveat, I have no experience of using images within canvases...

> import Image
> from Tkinter import *
> root = Tk()
> root.title('Canvas')
> Image.open ("C:\\Python_projects\\CRAP\\topleftcorner.bmp")
> canvas = Canvas(root, width =720, height=576, bg="#ff0000")

This seems odd to me. Surely you want to put the canvas inside 
a Frame, not...

> canvas.create_polygon(100, 100, 200, 100, 200, 200, 100, 200, 
> fill='yellow')
> #not sure what this next line should look like
> #canvas.create_image (64, 50, image=im)
> frm = Frame(canvas, borderwidth=0)

...a frame inside a canvas?

If you reverse the parenting of these objects does that help?

> canvas.create_window(720, 576, window=frm, anchor=CENTER)
> canvas.pack()
> root.mainloop()

But just a guess...

Alan g
(With an amazingly bad track record this week...)


From jeff@ccvcorp.com  Wed Dec  4 13:58:03 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Wed Dec  4 13:58:03 2002
Subject: [Tutor] Bitmaps and TK
References: <D680B98BA9E68843AE4730C166D2677207EAD4@alserver01.ashluecker.com>
Message-ID: <3DEE5017.9010602@ccvcorp.com>

Ian Dickinson wrote:

>import Image
>[...]
>Image.open ("C:\\Python_projects\\CRAP\\topleftcorner.bmp")
>  
>

I'm not familiar with Tkinter and I haven't messed with PIL in quite a 
while, but... don't you need to save a reference to that image?  You're 
opening the file, and then not assigning the new image object to 
anything.  Then, later, in your canvas.create_image(), you try to use an 
"im" variable that you've never created.  Try:

im = Image.open( ... )

Jeff Shannon
Technician/Programmer
Credit International





From rickp@telocity.com  Wed Dec  4 14:08:02 2002
From: rickp@telocity.com (Rick Pasotto)
Date: Wed Dec  4 14:08:02 2002
Subject: [Tutor] Bitmaps and TK
In-Reply-To: <D680B98BA9E68843AE4730C166D2677207EAD4@alserver01.ashluecker.com>
References: <D680B98BA9E68843AE4730C166D2677207EAD4@alserver01.ashluecker.com>
Message-ID: <20021204190655.GE22107@tc.niof.net>

On Wed, Dec 04, 2002 at 03:32:48PM -0000, Ian Dickinson wrote:
> I am farly new to this Python / Tk thing
> 
> but I just cannot get a full colour picture to appear on a canvas at an X,Y position specified by me
> 
> Image.open does not appear to exist
> 
> Fredrik Lundh Introduction to Tkinter seems to be completly wrong
> 
> The documentation for PIL seems to be very bad and the things in it don't work
> 
> Anyway here is my code
> 
> 
> import Image
> from Tkinter import *

One thing you might want to check into is reversing these two
statements. Evidently Tkinter has an Image module that does not include 
an open method. So:

>>> from Tkinter import *
>>> import Image
>>> 
>>> im = Image.open("imagefile.jpg")

now works.

One of the hazards of 'from xxx import *'.

-- 
"Drawing on my fine command of language, I said nothing."
		-- Mark Twain
    Rick Pasotto    rickp@telocity.com    http://www.niof.net


From Adam Vardy <anvardy@roadrunner.nf.net>  Wed Dec  4 17:22:01 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Wed Dec  4 17:22:01 2002
Subject: [Tutor] Asterisk
Message-ID: <13655039893.20021204184804@roadrunner.nf.net>

Why does this happen? It is a strange expression.

>>> '%*.*f' % (6,3,1.41421356)
' 1.414'

-- 
Adam Vardy



From glingl@aon.at  Wed Dec  4 17:36:01 2002
From: glingl@aon.at (Gregor Lingl)
Date: Wed Dec  4 17:36:01 2002
Subject: [Tutor] Asterisk
References: <13655039893.20021204184804@roadrunner.nf.net>
Message-ID: <3DEE8330.9030104@aon.at>

Adam Vardy schrieb:

>Why does this happen? It is a strange expression.
>
>  
>
>>>>'%*.*f' % (6,3,1.41421356)
>>>>        
>>>>
>' 1.414'
>
>  
>
Strange? Maybe! But first of all: useful:

 >>> "%*.*f" % (6,3,1.41421356)
' 1.414'
 >>> "%*.*f" % (10,5,1.41421356)
'   1.41421'
 >>> "%*.*f" % (10,7,1.41421356)
' 1.4142136'
 >>> "%*.*f" % (10,1,1.41421356)
'       1.4'
 >>> len("%*.*f" % (10,1,1.41421356))
10
 >>> len("%*.*f" % (6,3,1.41421356))
6
 >>>

It allows to use computed (e.g. floating-point) formats
instead of predetermined ones.

 >>> "%*.*f" % (6,3,1.41421356)
for instance uses "%6.3f" for 1.41421356
 >>> a = 7
 >>> b = 2
 >>> "%*.*f" % (a,b,1.41421356)
'   1.41'
 >>>
HTH, Gregor







From ramrom@earthling.net  Wed Dec  4 17:39:07 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Wed Dec  4 17:39:07 2002
Subject: [Tutor] Asterisk
In-Reply-To: <13655039893.20021204184804@roadrunner.nf.net>
Message-ID: <5.2.0.9.0.20021204152858.01a21c28@66.28.54.253>

--=====================_28702892==.ALT
Content-Type: text/plain; charset="us-ascii"; format=flowed

At 06:48 PM 12/4/2002 -0330, Adam Vardy wrote:
 > Why does this happen? It is a strange expression.
 > >>> '%*.*f' % (6,3,1.41421356)
 > ' 1.414'

That's what I'd expect. Did you rtfm?

"""A conversion specifier contains two or more characters and has the 
following components, which must occur in this order:
1 The "%" character, which marks the start of the specifier.
2 Mapping key value (optional), consisting of an identifier in parentheses 
(for example, (somename)).
3 Conversion flags (optional), which affect the result of some conversion 
types.
4 Minimum field width (optional). If specified as an "*" (asterisk), the 
actual width is read from the next element of the tuple in values, and the 
object to convert comes after the minimum field width and optional precision.
5 Precision (optional), given as a "." (dot) followed by the precision. If 
specified as "*" (an asterisk), the actual width is read from the next 
element of the tuple in values, and the value to convert comes after the 
precision.
6 Length modifier (optional).
7 Conversion type."""

In your example there is (1) % (4) * (5) .* (7) f. What more can I say?

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625

--=====================_28702892==.ALT
Content-Type: text/html; charset="us-ascii"

<html>
<body>
At 06:48 PM 12/4/2002 -0330, Adam Vardy wrote:<br>
&gt; Why does this happen? It is a strange expression.<br>
&gt; &gt;&gt;&gt; '%*.*f' % (6,3,1.41421356)<br>
&gt; ' 1.414'<br><br>
That's what I'd expect. Did you rtfm?<br><br>
&quot;&quot;&quot;A conversion specifier contains two or more characters
and has the following components, which must occur in this order: <br>
1 The &quot;<tt>%</tt>&quot; character, which marks the start of the
specifier. <br>
2 Mapping key value (optional), consisting of an identifier in
parentheses (for example, (somename)). <br>
3 Conversion flags (optional), which affect the result of some conversion
types. <br>
4 Minimum field width (optional). If specified as an
&quot;<tt>*</tt>&quot; (asterisk), the actual width is read from the next
element of the tuple in values, and the object to convert comes after the
minimum field width and optional precision. <br>
5 Precision (optional), given as a &quot;<tt>.</tt>&quot; (dot) followed
by the precision. If specified as &quot;<tt>*</tt>&quot; (an asterisk),
the actual width is read from the next element of the tuple in values,
and the value to convert comes after the precision. <br>
6 Length modifier (optional). <br>
7 Conversion type.&quot;&quot;&quot;<br><br>
In your example there is (1) % (4) * (5) .* (7) f. What more can I
say?<br>
<x-sigsep><p></x-sigsep>
Bob Gailer<br>
<a href="mailto:ramrom@earthling.net" eudora="autourl">mailto:ramrom@earthling.net</a><br>
303 442 2625<br>
</body>
</html>

--=====================_28702892==.ALT--



From rob@uselesspython.com  Wed Dec  4 17:49:36 2002
From: rob@uselesspython.com (Rob Andrews)
Date: Wed Dec  4 17:49:36 2002
Subject: [Tutor] Asterisk
In-Reply-To: <5.2.0.9.0.20021204152858.01a21c28@66.28.54.253>
Message-ID: <MPEOIFCOPCIHEDCLBLPBIEHECMAA.rob@uselesspython.com>

Which fm are you citing here?

I don't doubt the quotation in the slightest, but don't recognize the
context.

thanks,
Rob

-----Original Message-----
At 06:48 PM 12/4/2002 -0330, Adam Vardy wrote:
> Why does this happen? It is a strange expression.
> >>> '%*.*f' % (6,3,1.41421356)
> ' 1.414'

That's what I'd expect. Did you rtfm?

"""A conversion specifier contains two or more characters and has the
following components, which must occur in this order:
1 The "%" character, which marks the start of the specifier.

<snip />

7 Conversion type."""

In your example there is (1) % (4) * (5) .* (7) f. What more can I say?

Bob Gailer




From glingl@aon.at  Wed Dec  4 18:50:02 2002
From: glingl@aon.at (Gregor Lingl)
Date: Wed Dec  4 18:50:02 2002
Subject: [Tutor] Asterisk
References: <5.2.0.9.0.20021204152858.01a21c28@66.28.54.253>
Message-ID: <3DEE947F.7090008@aon.at>

Bob Gailer schrieb:

>   Did you rtfm?
>
Is rtfm a verb? An acronym? Probably both?
What does it mean?

Regards, Gregor





From yann.ledu@noos.fr  Wed Dec  4 18:59:02 2002
From: yann.ledu@noos.fr (Yann Le Du)
Date: Wed Dec  4 18:59:02 2002
Subject: [Tutor] Asterisk
In-Reply-To: <3DEE947F.7090008@aon.at>
Message-ID: <Pine.LNX.4.44.0212050055360.7477-100000@neuron.noos.fr>

On Thu, 5 Dec 2002, Gregor Lingl wrote:

> Bob Gailer schrieb:
> 
> >   Did you rtfm?
> >
> Is rtfm a verb? An acronym? Probably both?
> What does it mean?

I don't know, but I guess it means "Did you Read the F...... Manual".

Now don't ask me to fill in the dots !

Sorry to the original sender if I'm wrong... I'm just guessing.

Y



From Adam Vardy <anvardy@roadrunner.nf.net>  Wed Dec  4 19:40:03 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Wed Dec  4 19:40:03 2002
Subject: [Tutor] Asterisk
In-Reply-To: <5.2.0.9.0.20021204152858.01a21c28@66.28.54.253>
References: <5.2.0.9.0.20021204152858.01a21c28@66.28.54.253>
Message-ID: <292511060.20021204210928@roadrunner.nf.net>

Wednesday, December 4, 2002, 7:07:57 PM, you wrote:

>> At 06:48 PM 12/4/2002 -0330, Adam Vardy wrote:
>>  > Why does this happen? It is a strange expression.
>>  > >>> '%*.*f' % (6,3,1.41421356)
>>  > ' 1.414'

>> That's what I'd expect. Did you rtfm?

Well the answer is direct from the Python shell prompt. So anything it
says should be expected.

>
>> In your example there is (1) % (4) * (5) .* (7) f. What more can I say?

I don't follow this. I understand you're a manual kind of parsing guy.
But I just started learning Python this week. Anyone else want to explain
how it reaches the result?

If this should be obvious, the only thing I can expect to output 3
if I had an array (1,2,3) is if you said print somearray[3] or
something like that. And so it reaches for the third element. And that
is what I understand a computer can do.  It can compute. And if there
are a bunch of numbers in order, it can reach for a requested element
by adding that number from the start of the array.

I would say that a good programming language would require its
adherents to be able to paraphrase.

-- 
Adam Vardy



From kalle@lysator.liu.se  Wed Dec  4 19:42:01 2002
From: kalle@lysator.liu.se (Kalle Svensson)
Date: Wed Dec  4 19:42:01 2002
Subject: [Tutor] Asterisk
In-Reply-To: <3DEE947F.7090008@aon.at>
References: <5.2.0.9.0.20021204152858.01a21c28@66.28.54.253> <3DEE947F.7090008@aon.at>
Message-ID: <20021205004119.GO18311@i92.ryd.student.liu.se>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[Gregor Lingl]
> Bob Gailer schrieb:
> 
> >  Did you rtfm?
> 
> Is rtfm a verb? An acronym? Probably both?
> What does it mean?

Read The Fucking (or Fine) Manual.
http://www.tuxedo.org/~esr/jargon/html/entry/RTFM.html

Peace,
  Kalle
- -- 
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>

iD8DBQE97qCrdNeA1787sd0RAlO1AJ96UCWvV5GUzu0LEwZBsydu1nPITQCdHDv9
HWLGxQ+S8woLk9p5dMzbSEE=
=0EhU
-----END PGP SIGNATURE-----


From grimmtooth@softhome.net  Wed Dec  4 20:23:02 2002
From: grimmtooth@softhome.net (Jeff Grimmett)
Date: Wed Dec  4 20:23:02 2002
Subject: [Tutor] Asterisk
In-Reply-To: <292511060.20021204210928@roadrunner.nf.net>
Message-ID: <MBEOLOBBHMCCJMEHEFHAGEGCCDAA.grimmtooth@softhome.net>

> >> At 06:48 PM 12/4/2002 -0330, Adam Vardy wrote:
> >>  > Why does this happen? It is a strange expression.
> >>  > >>> '%*.*f' % (6,3,1.41421356)
> >>  > ' 1.414'
>
> >> That's what I'd expect. Did you rtfm?
>
> Well the answer is direct from the Python shell prompt. So anything it
> says should be expected.

> I don't follow this. I understand you're a manual kind of parsing guy.
> But I just started learning Python this week. Anyone else want to explain
> how it reaches the result?

Hm, well, this IS a tutor list so I'll try some tutoring :-D

I think that what the problem is that you're trying to evaluate this as an
equation, which it ain't really. My appologies in advance if I am mistaken.

The expression

  '%*.*f' % (6,3,1.41421356)

is actually a print FORMATTING statement and not an equation at all. It
breaks down into two sections. The first, the portion to the LEFT of the
second % sign, is what you want to print, including formatting placeholders.
Formatting placeholders begin with a % as well, and allows you to include
just about anything.  Common % formats are %d (placeholder for a number), %f
(placeholder for a floating point number), %s (placeholder for a string). If
you are at all familiar with C printf() formatting, these are really simple
to get your head around.

This formatting statement includes the moderately advanced '*' token. This
indicates that a number, provided in the 'arguments' will be substituted for
this asterisk. If there are more than one asterisks in a formatting
statement, the first number will be used for the first asterisk, the second
for the next, and so on.

The second % indicates that what is to follow is the actual DATA to include,
or 'arguments'.

If you supply only ONE argument, it can be provided immediately. If you need
to supply more than one, you must enclose them together inside parentheses.

So what we have above is '%*.*f' for the formatting. This translates to
'print a floating point number with some arbitrary limit to the left and
right of the decimal'.  Looking at the arguments, we see that we will print
six digits to the left of the decimal, three to the right, and the number is
the third argument.  It translates to %6.3f.

You will find a full explanation of how the formatting works at
http://www.python.org/doc/current/lib/typesseq-strings.html (section 2.2.6.2
of the Python library reference).



From glingl@aon.at  Wed Dec  4 20:38:01 2002
From: glingl@aon.at (Gregor Lingl)
Date: Wed Dec  4 20:38:01 2002
Subject: [Tutor] Asterisk
References: <MBEOLOBBHMCCJMEHEFHAGEGCCDAA.grimmtooth@softhome.net>
Message-ID: <3DEEADD2.6030002@aon.at>

Jeff Grimmett schrieb:

>So what we have above is '%*.*f' for the formatting. This translates to
>'print a floating point number with some arbitrary limit to the left and
>right of the decimal'.  Looking at the arguments, we see that we will print
>six digits to the left of the decimal, three to the right, and the number is
>the third argument.  It translates to %6.3f.
>
Really a fine explanation, only this last point isn't entirely true: the 
first 'limit'-number is the
overall length of the formatted string. So in this case you have two 
digits to the left of the
decimal (as you can see in Adam's example), then 1 for the decimal and 
three to the right.
Regards, Gregor

>You will find a full explanation of how the formatting works at
>http://www.python.org/doc/current/lib/typesseq-strings.html (section 2.2.6.2
>of the Python library reference).
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>  
>






From grimmtooth@softhome.net  Wed Dec  4 20:59:01 2002
From: grimmtooth@softhome.net (Jeff Grimmett)
Date: Wed Dec  4 20:59:01 2002
Subject: [Tutor] Asterisk
In-Reply-To: <3DEEADD2.6030002@aon.at>
Message-ID: <MBEOLOBBHMCCJMEHEFHACEGDCDAA.grimmtooth@softhome.net>

> Really a fine explanation, only this last point isn't entirely true: the
> first 'limit'-number is the
> overall length of the formatted string. So in this case you have two

You know, I've been blowing that one for 15 years on and off, in C and now
Python. Thanks for the correction.





From dyoo@hkn.eecs.berkeley.edu  Wed Dec  4 21:38:06 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed Dec  4 21:38:06 2002
Subject: [Tutor] Re: Testing if a number occurs more than once [dict version]
In-Reply-To: <200212031145.34961.scot@possum.in-berlin.de>
Message-ID: <Pine.LNX.4.44.0212041826150.9741-100000@hkn.eecs.berkeley.edu>


On Tue, 3 Dec 2002, Scot Stevenson wrote:

> Uh, I may have screwed up here:
>
> ===============================
> def morethanone(L):
>     numbersfound = {}
>     for number in L:
>         if number in numbersfound:
>             return 1
>         else:
>             numbersfound[number]=1
>     return 0
> ===============================
>
> After rereading some stuff about dictionaries, I think the line
>
> 	if number in numbersfound:
>
> probably should be
>
> 	if numbersfound.has_key(number):


Hi Scot,

No, no, you should have trusted your instincts: you had the right idea in
the first place.  *grin*


Checking to see if an key is in a dictionary, is exactly the right thing
to do: dictionaries are designed so that the act of looking a key up is
very fast.

That is, it's not the 'in' operation itself that's inherently expensive:
the data structure that we apply 'in' on makes more of a difference.

For lists, 'in' requires a scan, element by element, through the
container, till we either hit the thing we're looking for, or fall off our
list.  For dictionaries, 'in' requires a single lookup: it's either in
there, or it's not.


So the operation of membership testing --- 'in' --- itself doesn't have a
explicit cost associated to it: it's the combination of the operation and
the data structure that allows us to measure performance.



> It seems that "in" does a linear search (just what we were trying to
> avoid) why "has_key" uses the hash table.

> def morethanone(L):
>     numbersfound = {}
>     for number in L:
>         if number in numbersfound:
>             return 1
>         else:
>             numbersfound[number]=1
>     return 0

Since 'numbersfound' is a dictionary, the 'in' operation will be fast, so
no worries there.


Good luck to you!



From dyoo@hkn.eecs.berkeley.edu  Wed Dec  4 22:10:00 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed Dec  4 22:10:00 2002
Subject: [Tutor] Re: Testing if a number occurs more than once [dict
 version / What's the difference between has_key() and 'in']
In-Reply-To: <Pine.LNX.4.44.0212041826150.9741-100000@hkn.eecs.berkeley.edu>
Message-ID: <Pine.LNX.4.44.0212041840090.9741-100000@hkn.eecs.berkeley.edu>


> > After rereading some stuff about dictionaries, I think the line
> >
> > 	if number in numbersfound:
> >
> > probably should be
> >
> > 	if numbersfound.has_key(number):


Hi Scot,

Ooops!  I forgot to mention that both statements:

    if number in numbersfound:

and

    if numbersfound.has_key(number):

are functionally equivalent as of Python 1.6.1, I think; that's when
Python added a hook for using 'in' with arbitrary objects (and not just
with lists and strings):

    http://python.org/1.6.1/

If we look for the part about '__contains__', we'll see a short blurb
about it.  They're interchangable for the most part; the 'in' version uses
special syntax, while 'has_key()' goes through the normal route that any
other Python method might take.  Otherwise, no harm in using either of
them.




[The following is just for people who like reading Python's C's
implementation for fun.]

But is there a difference between them?  If we're familiar with C, we
might like to delve in to see what really is so different between them.
If we look at the Python source code:

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Objects/dictobject.c?rev=2.134&content-type=text/vnd.viewcvs-markup

we can see that has_key() and __contains__() have suspiciously similar
definitions, with one very slight difference: their return values are of
different types:

/******/
static PyObject *
dict_has_key(register dictobject *mp, PyObject *key)
{
	long hash;
	register long ok;
	if (!PyString_CheckExact(key) ||
	    (hash = ((PyStringObject *) key)->ob_shash) == -1) {
		hash = PyObject_Hash(key);
		if (hash == -1)
			return NULL;
	}
	ok = (mp->ma_lookup)(mp, key, hash)->me_value != NULL;
	return PyBool_FromLong(ok);
}

static int
dict_contains(dictobject *mp, PyObject *key)
{
	long hash;

	if (!PyString_CheckExact(key) ||
	    (hash = ((PyStringObject *) key)->ob_shash) == -1) {
		hash = PyObject_Hash(key);
		if (hash == -1)
			return -1;
	}
	return (mp->ma_lookup)(mp, key, hash)->me_value != NULL;
}
/******/

In first case, the implementation of the has_key() method returns a new
Python object, a PyBool object.  This isn't too much of a surprise, since
when we use the Python/C extension, all of the methods of an object have
to return some kind of Python object.

The second case is a little different --- the protocol that defines
__contains__ says that it must return either a true or false value, so the
low level code doesn't have to go through the effort of building
full-blown Python objects.  So, when we use the Python/C API layer, there
are some shortcuts built into the system that don't quite parallel what we
do in normal Python code.

The implementors could have just as easily defined 'in' in terms of
has_key(), but it looks like the implementers took the effort to fine-tune
their implementations, taking advantage the low-level hook for 'in'.
Even though there's a little duplication involved, the implementors felt
it was worth it --- we might suspect that the second version might go a
hairline faster than the first, since it has fewer lines of code.



From Adam Vardy <anvardy@roadrunner.nf.net>  Wed Dec  4 22:10:12 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Wed Dec  4 22:10:12 2002
Subject: [Tutor] Asterisk
In-Reply-To: <MBEOLOBBHMCCJMEHEFHAGEGCCDAA.grimmtooth@softhome.net>
References: <MBEOLOBBHMCCJMEHEFHAGEGCCDAA.grimmtooth@softhome.net>
Message-ID: <811512604.20021204233930@roadrunner.nf.net>

Wednesday, December 4, 2002, 9:53:09 PM, you wrote:

>> This formatting statement includes the moderately advanced '*' token. This
>> indicates that a number, provided in the 'arguments' will be substituted for
>> this asterisk. If there are more than one asterisks in a formatting
>> statement, the first number will be used for the first asterisk, the second
>> for the next, and so on.

So then, what you say is 6 is not printed because it has already been
'used up' somehow?  That is, 6 digits of some kind, and 3 fractional
digits. And then you have the number that is left over, which is
actually used for the expression?


-- 
Adam Vardy



From grimmtooth@softhome.net  Wed Dec  4 23:21:02 2002
From: grimmtooth@softhome.net (Jeff Grimmett)
Date: Wed Dec  4 23:21:02 2002
Subject: [Tutor] Asterisk
In-Reply-To: <811512604.20021204233930@roadrunner.nf.net>
Message-ID: <MBEOLOBBHMCCJMEHEFHAGEGECDAA.grimmtooth@softhome.net>


> So then, what you say is 6 is not printed because it has already been
> 'used up' somehow?  That is, 6 digits of some kind, and 3 fractional
> digits. And then you have the number that is left over, which is
> actually used for the expression?

More or less. I'd avoid using the * token until you get used to the whole
concept. It does come in handy once in a while, though :-)



From din22@cox.net  Thu Dec  5 00:18:02 2002
From: din22@cox.net (david)
Date: Thu Dec  5 00:18:02 2002
Subject: [Tutor] global variables
Message-ID: <001001c29c1d$75cdc740$fc550144@pn.at.cox.net>

This is a multi-part message in MIME format.

------=_NextPart_000_000D_01C29BEB.2B089DC0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

hello again!
why are global variables bad?
what are some examples of global variables=20
causing problems?=20
curiously,
david

------=_NextPart_000_000D_01C29BEB.2B089DC0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>hello again!</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>why are global variables =
bad?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>what are some examples of global =
variables=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>causing problems? </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>curiously,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>david</FONT></DIV></BODY></HTML>

------=_NextPart_000_000D_01C29BEB.2B089DC0--



From gp@pooryorick.com  Thu Dec  5 01:00:01 2002
From: gp@pooryorick.com (Poor Yorick)
Date: Thu Dec  5 01:00:01 2002
Subject: [Tutor] communication between class instances
Message-ID: <3DEEEB73.9070606@pooryorick.com>

Hi,

I've been studying Python for several months now, and it is my first 
attempt to learn how to program in any language.  I've been trying 
lately to understand some of the nuances of object oriented programming, 
but most of the resources on the web require some knowledge of c++ to 
gist.  So, I'm turning to this list :)  Direct answers or pointers to 
reference material about this question would be greatly appreciated:

Say I have the following classes:


class app:
    def __init(self):
        self.dbtype = None
        self.gui=gui(self)

class gui:
    def __init__(self, app):
        self.app = app
        self.main_menu = menu(self.app)

class menu:
    def __init__(self, app):
        self.app = app
       
    def dbtype(self):
        app.dbtype = 'metakit'


So far, instantiating classes and passing references to all other class 
instances that the instance will need to communicate with is the only 
way I've come up with to get class instances to communicate with each 
other.  This seems unwieldy and not really modular.  Is there a better 
way to pass data between class instances?  One thing I really don't like 
is having to pass a reference to the app instance all the way down to 
the menu instance, which really should only be aware of the gui instance 
which instantiates it. Right?

Right?

I'm very confused...

Poor Yorick
gp@pooryorick.com



From gp@pooryorick.com  Thu Dec  5 01:07:01 2002
From: gp@pooryorick.com (Poor Yorick)
Date: Thu Dec  5 01:07:01 2002
Subject: [Tutor] communication between class instances
References: <3DEEEB73.9070606@pooryorick.com>
Message-ID: <3DEEECFB.10202@pooryorick.com>

Correction:  

class menu:
   def __init__(self, app):
       self.app = app
 
   def dbtype(self):
       self.app.dbtype = 'metakit'




Poor Yorick wrote:

> Hi,
>
> I've been studying Python for several months now, and it is my first 
> attempt to learn how to program in any language.  I've been trying 
> lately to understand some of the nuances of object oriented 
> programming, but most of the resources on the web require some 
> knowledge of c++ to gist.  So, I'm turning to this list :)  Direct 
> answers or pointers to reference material about this question would be 
> greatly appreciated:
>
> Say I have the following classes:
>
>
> class app:
>    def __init(self):
>        self.dbtype = None
>        self.gui=gui(self)
>
> class gui:
>    def __init__(self, app):
>        self.app = app
>        self.main_menu = menu(self.app)
>
> class menu:
>    def __init__(self, app):
>        self.app = app
>          def dbtype(self):
>        app.dbtype = 'metakit'
>
>
> So far, instantiating classes and passing references to all other 
> class instances that the instance will need to communicate with is the 
> only way I've come up with to get class instances to communicate with 
> each other.  This seems unwieldy and not really modular.  Is there a 
> better way to pass data between class instances?  One thing I really 
> don't like is having to pass a reference to the app instance all the 
> way down to the menu instance, which really should only be aware of 
> the gui instance which instantiates it. Right?
>
> Right?
>
> I'm very confused...
>
> Poor Yorick
> gp@pooryorick.com
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>




From lumbricus@gmx.net  Thu Dec  5 01:13:02 2002
From: lumbricus@gmx.net (lumbricus@gmx.net)
Date: Thu Dec  5 01:13:02 2002
Subject: [OT] Re: [Tutor] Asterisk
References: <20021205004119.GO18311@i92.ryd.student.liu.se>
Message-ID: <17775.1039068744@www67.gmx.net>

Hi!

> Read The F<censored> (or Fine) Manual.
WTF?
I recently sent a message to tutor containing
this <censored> word. It was a quote about the fact that
this word occurs quite often in the Linux sources,
so these sources may be forbidden by some new laws
in certain countries. But some fscist censoring
"kindergarten" software barked at me about some 'obscenities' 
and 'apropiate actions taken'.
How did you do it?

> Peace,
>   Kalle

Greets, J"o!

-- 
sigfault

+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!



From lumbricus@gmx.net  Thu Dec  5 01:22:01 2002
From: lumbricus@gmx.net (lumbricus@gmx.net)
Date: Thu Dec  5 01:22:01 2002
Subject: [Tutor] global variables
References: <001001c29c1d$75cdc740$fc550144@pn.at.cox.net>
Message-ID: <26303.1039069249@www67.gmx.net>

Hi!

> hello again!
> why are global variables bad?

They are visible and accessible overall
in the program. So it is hard to keep
track of them.
Yet, no dogma!

> curiously,
> david

HTH, J"o!

-- 
sigfault

+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!



From michael@trollope.org  Thu Dec  5 01:41:02 2002
From: michael@trollope.org (Michael Powe)
Date: Thu Dec  5 01:41:02 2002
Subject: [Tutor] Asterisk
In-Reply-To: <811512604.20021204233930@roadrunner.nf.net>; from anvardy@roadrunner.nf.net on Wed, Dec 04, 2002 at 11:39:30PM -0330
References: <MBEOLOBBHMCCJMEHEFHAGEGCCDAA.grimmtooth@softhome.net> <811512604.20021204233930@roadrunner.nf.net>
Message-ID: <20021204224017.B9694@titan.spiretech.com>

On Wed, Dec 04, 2002 at 11:39:30PM -0330, Adam Vardy wrote:
> 
> Wednesday, December 4, 2002, 9:53:09 PM, you wrote:
> 
> >> This formatting statement includes the moderately advanced '*' token. This
> >> indicates that a number, provided in the 'arguments' will be substituted for
> >> this asterisk. If there are more than one asterisks in a formatting
> >> statement, the first number will be used for the first asterisk, the second
> >> for the next, and so on.
> 
> So then, what you say is 6 is not printed because it has already been
> 'used up' somehow?  That is, 6 digits of some kind, and 3 fractional
> digits. And then you have the number that is left over, which is
> actually used for the expression?

The 6 means 'place a total of six characters to the left of the decimal point.'
remember that a space is also a char.  the most obvious example of how you 
would want to use this feature is in lining up the decimal points of a column
of numbers.  you have a varying number of numerals to the left of the decimal 
point, so you use a formatting command like the 6 to insure that every item
in your column of numbers will take up 6 spaces.

  1234.67
123456.89
   123.45
     1.23

each item in this column has 6 characters, decimal, 2 characters.  the tricky part
is remembering that 'space' is a character, too.  adding these spaces is sometimes
referred to as padding.  in c, you can pad numbers with zeroes, as well.  i am sure
you can do the same in python.  (you are more likely to use zeroes on the right side
of the decimal, of course.)

mp

"ni!"


From michael@trollope.org  Thu Dec  5 02:21:01 2002
From: michael@trollope.org (Michael Powe)
Date: Thu Dec  5 02:21:01 2002
Subject: [Tutor] global variables
In-Reply-To: <001001c29c1d$75cdc740$fc550144@pn.at.cox.net>; from din22@cox.net on Wed, Dec 04, 2002 at 11:16:26PM -0600
References: <001001c29c1d$75cdc740$fc550144@pn.at.cox.net>
Message-ID: <20021204232056.C9694@titan.spiretech.com>

On Wed, Dec 04, 2002 at 11:16:26PM -0600, david wrote:
> hello again!
> why are global variables bad?
> what are some examples of global variables 
> causing problems? 

the common reasonings are:  you can change a global from 
any function, so that makes it easy for you to do it
inadvertently.  in a complex program with many functions,
you may lose track of what's happening to a global.  that
makes it difficult to track down bugs related to the variable's
value.  it can mean that you didn't think out your program's 
structure before hitting the keyboard, but just started typing. 
that lack of forethought may mean that your code is going to 
wander all over creation, as you try to account for situations 
you didn't plan for.

you could think of the difference between local and global variables
as the difference between putting things away when you're done with
them and just throwing them down anywhere.  when tools are put away,
they're right there when you need them.  that's your local variables.
when they're left lying around, it turns out your brother-in-law took
off with that wrench you need when he saw it lying on the kitchen
counter, and now he thinks he put it in a box by the tires under your
bench in the garage, but he can't be sure.  that's your global
variables.

there are very few cases when you need a variable to carry values throughout
the life of a program.  if it's not needed, don't do it.  


mp


From abli@freemail.hu  Thu Dec  5 04:55:01 2002
From: abli@freemail.hu (Abel Daniel)
Date: Thu Dec  5 04:55:01 2002
Subject: [Tutor] Tkinter
In-Reply-To: <20021201130944.GA6900@pumuckl.redwitz79.de>
References: <20021130205139.GA17747@pumuckl.redwitz79.de> <3DE9F796.3010305@aon.at> <20021201130944.GA6900@pumuckl.redwitz79.de>
Message-ID: <20021205095401.GA592@hooloovoo>

 Hans Gubitz (gubitz@netcologne.de) wrote:
> My Tkinter.Button is an attribute in the class person. In the
> Application I want to get the instance of person, button is belonging
> to.
> 
> My workaround is the function holePerson. Is this the way you do it in
> Python?
> 
I have two ideas:
- subclass Tkinter.Button. I think that way the callback will get
your new, modified class as event.widget .

- intercept the callback when it is called, for example like this:
(not tested)
> class person:
>     def __init__(self,master,bild,r,c,callback):
>         self.bild = bild
>         self.button = Tkinter.Button(master,text=self.bild)
>         self.button.grid(row = r, column = c)
          self.button.bind('<Button-1>',self._callback)
          self.callback=callback
          
     def _callback(self, event):
          event.widget=self
          apply(self.callback, event)

[... rest of code snipped ....]

abli
abli@freemail.hu


From abli@freemail.hu  Thu Dec  5 05:40:02 2002
From: abli@freemail.hu (Abel Daniel)
Date: Thu Dec  5 05:40:02 2002
Subject: [Tutor] Tk graphs output print to file
In-Reply-To: <DNEFLBNHCGCPPIGNHGILKEILCHAA.marta_andrea@libero.it>
References: <86C3892A0C52D411AF5000A0C9EAA3B96320D1@wtntex1.baea.com.au> <DNEFLBNHCGCPPIGNHGILKEILCHAA.marta_andrea@libero.it>
Message-ID: <20021205103924.GB592@hooloovoo>

Andrea Valle (marta_andrea@libero.it) wrote:
> Hi pythoners,
> I was asking myself: is it possible to print to file (i.e. bitmap/jpg) Tk
> screen output (i.e.canvas)?
> 
> thanks!
Canvas has a .postscript method:

In [8]: print c.postscript.__doc__
Print the contents of the canvas to a postscript
        file. Valid options: colormap, colormode, file, fontmap,
        height, pageanchor, pageheight, pagewidth, pagex, pagey,
        rotate, witdh, x, y.

abli
abli@freemail.hu



From magnus@thinkware.se  Thu Dec  5 05:45:03 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu Dec  5 05:45:03 2002
Subject: [Tutor] global variables
In-Reply-To: <001001c29c1d$75cdc740$fc550144@pn.at.cox.net>
Message-ID: <5.1.0.14.0.20021205104017.02accdc8@www.thinkware.se>

At 23:16 2002-12-04 -0600, david wrote:
>why are global variables bad?

Beacause your brain would explode if all variables were global?

When we learn programming, we naturally begin by writing small
programs. In small programs, let's say twenty lines of code and
perhaps five or ten variables, avoiding global variable doesn't
make much difference to anything. At least not if we are sure
that the program won't grow bigger. (Are we ever?)

But if you have program files spanning thousands of lines of
code and using hundreds of variables, it makes perfect sense
to avoid global variables like the plague.

In a large program, it's impossible to consider all details at the
same time. There isn't room in a normal brain at least. You need
mechanisms that help you separate concerns. Mechanisms that make it
possible to reduce the risk that a program change leads to unexpected
side effects. Local variables, functions, modules and classes are
such mechanisms.

Actually, as soon as a program gets bigger than whatever you are
able to simultaneously grasp, these mechanisms for separation of
concerns becomes relevant. If the program is bigger that a screen-
full, maybe 25 lines, it's impossible (at least on screen) to see
all details at once. But much smaller chunks of code can be diffi-
cult. It's fairly common that programmers rewrite a single line of
code to two or three lines of code to make it clearer.

Believe it or not, but programs tend to grow bigger. Certainly, all
big programs started out being very small programs. Using methods
of programming that works well in larger contexts is usually a good
idea also in smaller programs, partly because programs tend to grow
bigger than planned, and partly because we tend to work by habit.
If we make shortcuts too often in small programs, we are more likely
to make the shortcuts also when they cause problems.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From op73418@mail.telepac.pt  Thu Dec  5 07:54:01 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Thu Dec  5 07:54:01 2002
Subject: [Tutor] communication between class instances
References: <3DEEEB73.9070606@pooryorick.com>
Message-ID: <004101c29c5e$3f6ecc80$0a150dd5@violante>

From: "Poor Yorick" <gp@pooryorick.com>


> Hi,
>
> I've been studying Python for several months now, and it is my first
> attempt to learn how to program in any language.  I've been trying
> lately to understand some of the nuances of object oriented programming,
> but most of the resources on the web require some knowledge of c++ to
> gist.  So, I'm turning to this list :)  Direct answers or pointers to
> reference material about this question would be greatly appreciated:
>
> Say I have the following classes:
>
>
> class app:
>     def __init(self):
>         self.dbtype = None
>         self.gui=gui(self)
>
> class gui:
>     def __init__(self, app):
>         self.app = app
>         self.main_menu = menu(self.app)

Although this is not incorrect you should be aware that it creates what is
called a cycle: an object A references an object B that references A. In
this case, the usual way that Python (to be correct: CPython) uses to free
memory (reference counting) does not work and the garbage collector has to
kick in to free up these cycles when they are no longer in use. In other
words, if you can avoid cycles do it.

>
> class menu:
>     def __init__(self, app):
>         self.app = app
>
>     def dbtype(self):
>         app.dbtype = 'metakit'
>
>
> So far, instantiating classes and passing references to all other class
> instances that the instance will need to communicate with is the only
> way I've come up with to get class instances to communicate with each
> other.  This seems unwieldy and not really modular.  Is there a better

Why do you say "unwieldy and not really modular"? Passing as arguments to
the __init__ method what the instances need to work properly is a perfect
way of communication.

> way to pass data between class instances?  One thing I really don't like
> is having to pass a reference to the app instance all the way down to
> the menu instance, which really should only be aware of the gui instance
> which instantiates it. Right?
>
> Right?
>
> I'm very confused...
>
> Poor Yorick
> gp@pooryorick.com

With my best regards,
G. Rodrigues



From ramrom@earthling.net  Thu Dec  5 10:55:01 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Thu Dec  5 10:55:01 2002
Subject: [Tutor] global variables
In-Reply-To: <5.1.0.14.0.20021205104017.02accdc8@www.thinkware.se>
References: <001001c29c1d$75cdc740$fc550144@pn.at.cox.net>
Message-ID: <5.2.0.9.0.20021205083442.01a12be0@66.28.54.253>

>At 23:16 2002-12-04 -0600, david wrote:
>why are global variables bad?

Any program that is not trivial will have at least one global object, which 
will usually be a function definition, or a class definition with at least 
one global instance.

Within that object/definition there will likely be variables and/or 
attributes whose lifetimes are that of the function execution or of the 
instance, and whose values are needed for various durations depending on 
the nature of the program. If the program is a long-running event driven 
process, it will need to remember certain things for a long time. How and 
where one stores these things is a matter of personal choice; the effect is 
the same as having "global variables".

The arguments in the other responses to this thread are for modularization; 
keeping related things close rather than far (remember Yourdon & 
Constantine? Tight cohesion, loose coupling). I have found that breaking 
large systems into modules is really helpful; each module may have one or 
more variables/objects that retain values as long as needed.

My first Python project (in which I learned a lot) has over 20 modules, 
which are imported at various times. This lets me have lots of edit windows 
open (using Pythonwin), making it easy to find and edit code. Some modules 
are "run' once; some retain certain things (e.g. a log file) for a long time.

My conclusion is that nothing is bad or good per se. It's a matter of 
taste, style, and how easy it is to read and maintain the code. 
Modularization is (IMHO) the key.

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625



From ATrautman@perryjudds.com  Thu Dec  5 11:23:07 2002
From: ATrautman@perryjudds.com (Alan Trautman)
Date: Thu Dec  5 11:23:07 2002
Subject: [Tutor] global variables
Message-ID: <0BA95581EDA7D611841B00A0C9AD25DD2B5913@mail.pjinet.com>

why are global variables bad?

They are not always bad. As has been said in other posts all larger programs
will have some, especially if they use GUI's. It is good to have the view
that they are to be avoided to allow the programmer simplify the core items
of their program to as little as possible.

A function should depend on items passed in to function. It should return an
expected value to the calling function. The lack of a global value should
not stop this process but frequently is used to modify it. For example:

Using a simple shape drawing program that takes coordinates, and uses
functions, draws circles and squares. If a circle function is called the
response will vary according the preferences of the user. Say the current
user likes a objects filled in in blue and in the setup of the program this
value is placed in a global variable. The circle function will operate
properly given good values. It will then look to see if the global hold a
user selected value. In this case it will draw the circle with blue but if
nothing had been stored then the default color would be used.

In this example the information could be passed along with the coordinates
but since the person could draw many objects it is kept as a global to
maintain consistency throughout the program.

IMHO that is the key to successful use of global variables. They must be
needed to maintain the consistent functionality to the use throughout the
program. A global that you do not reference frequently in many classes or
functions needs to be examined. I very rarely have more that one item as a
global that is not primitive (int, float, string) when I program to keep a
program stable.

Alan 


From SWidney@ci.las-vegas.nv.us  Thu Dec  5 11:36:18 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Thu Dec  5 11:36:18 2002
Subject: [Tutor] Asterisk
Message-ID: <0E5508EBA1620743B409A2B8365DE16FDC8271@sovereign.ci.las-vegas.nv.us>

> The 6 means 'place a total of six characters to the left of 
> the decimal point.'

Not quite. The 6 means allot a "minimum field width" of 6, including all of
the following: the integer portion of the number, the decimal point, the
fractional portion of the number, and any spaces needed to pad the remainder
of the field. See "2.2.6.2 String Formatting Operations" in the Python
Reference Manual
(http://www.python.org/doc/current/lib/typesseq-strings.html#l2h-148).


Scott


From gubitz@netcologne.de  Thu Dec  5 11:55:06 2002
From: gubitz@netcologne.de (Hans Gubitz)
Date: Thu Dec  5 11:55:06 2002
Subject: [Tutor] Tkinter
In-Reply-To: <20021205095401.GA592@hooloovoo>
References: <20021130205139.GA17747@pumuckl.redwitz79.de> <3DE9F796.3010305@aon.at> <20021201130944.GA6900@pumuckl.redwitz79.de> <20021205095401.GA592@hooloovoo>
Message-ID: <20021205171021.GA25796@pumuckl.redwitz79.de>

On Thu, Dec 05, 2002 at 10:54:01AM +0100, Abel Daniel wrote:
>  Hans Gubitz (gubitz@netcologne.de) wrote:
> > My Tkinter.Button is an attribute in the class person. In the
> > Application I want to get the instance of person, button is belonging
> > to.
> > 
> > My workaround is the function holePerson. Is this the way you do it in
> > Python?
> > 
> I have two ideas:
> - subclass Tkinter.Button. I think that way the callback will get
> your new, modified class as event.widget .
> 

Ok. I had already tried this idea, but I had made a mistake. Now it's
ok. Thank you.

Hans
-- 
Hans Gubitz <gubitz@netcologne.de>



From ramrom@earthling.net  Thu Dec  5 12:26:31 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Thu Dec  5 12:26:31 2002
Subject: [Tutor] Asterisk
In-Reply-To: <0E5508EBA1620743B409A2B8365DE16FDC8271@sovereign.ci.las-ve
 gas.nv.us>
Message-ID: <5.2.0.9.0.20021205101828.02aa94b8@66.28.54.253>

I regret my prior post suggesting that the questioner "rtfm". I had felt 
some frustration at being asked a question whose explanation is in the 
manual. I neglected to take into account that different folks have 
different learning styles. I used to teach programming and related topics 
for Boeing Computer Services Education & Training division in Seattle. I 
would learn what I needed to know from the manuals, then create and teach a 
class. I often wondered "why are these students here? why don't they just 
read the manual?"

This IS a tutor list, and I will aim to be a teacher here too.

I do recommend being acquainted with the manuals and checking there first.

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625



From magnus@thinkware.se  Thu Dec  5 14:08:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu Dec  5 14:08:02 2002
Subject: [Tutor] communication between class instances
In-Reply-To: <3DEEEB73.9070606@pooryorick.com>
Message-ID: <5.1.0.14.0.20021205114922.02acda80@www.thinkware.se>

At 23:00 2002-12-04 -0700, Poor Yorick wrote:
>I've been studying Python for several months now, and it is my first 
>attempt to learn how to program in any language.  I've been trying lately 
>to understand some of the nuances of object oriented programming, but most 
>of the resources on the web require some knowledge of c++ to gist.

Unfortunately it seems OO isn't so easy to grasp. I'm not
sure whether this is due to some intrinsic complexity of
the OO concept, due to poor tutorials, poor support in the
programming languages or that people are taught to think in
ways that contradict or collide with OOP...

Whatever the reason, most programmers in so-called OOP languages
such as Java and C++ don't really understand Object-Oriented
thinking. :(

>  So, I'm turning to this list :)

Just the right thing to do. ;)

>Direct answers or pointers to reference material about this question would 
>be greatly appreciated:

I like Arthur Riel's book Object-Oriented Design Heuristics, but
it's probably not the best fit for a beginner to programming. :(

There is a lot of .py-files in your python distribution that
shows you how classes might look.

>Say I have the following classes:
>
>class app:
>    def __init(self):
>        self.dbtype = None
>        self.gui=gui(self)

I'm not sure what you mean that "app" should be but I try to
make sure that my program logic is unaware of the GUI.

>class gui:
>    def __init__(self, app):
>        self.app = app
>        self.main_menu = menu(self.app)
>
>class menu:
>    def __init__(self, app):
>        self.app = app
>
>    def dbtype(self):
>        app.dbtype = 'metakit'

It seem to me that this code doesn't actually do anything useful.
It's difficult to say a lot based on code that doesn't do anything
useful. I've never seen a Python program with a class called gui.
I don't know what that would stand for.

>So far, instantiating classes and passing references to all other class 
>instances that the instance will need to communicate with is the only way 
>I've come up with to get class instances to communicate with each 
>other.  This seems unwieldy and not really modular.

The Law of Demeter says:

       Do not refer to a class C in a method m unless C is the type of
           o an instance variable in m's class definition,
           o an argument of m,
           o an object created in m,
           o a global variable.

Lieberherr, K.J. and I.M. Holland, Assuring Good Style for Object-Oriented 
Programs. IEEE Software, 1989(September): p. 38-48.

>Is there a better way to pass data between class instances?  One thing I 
>really don't like is having to pass a reference to the app instance all 
>the way down to the menu instance, which really should only be aware of 
>the gui instance which instantiates it. Right?

Then the layer in between should have a method that shields
this I guess. But GUI programming is typically rather complex,
and usually depends on code in another language (Tcl/Tk or C++
for instance). It's probably not the best aspect of OO programming
to start with, even if it's a natural candidate for classes and
an object oriented approach.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Thu Dec  5 14:13:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu Dec  5 14:13:01 2002
Subject: [Tutor] communication between class instances
In-Reply-To: <004101c29c5e$3f6ecc80$0a150dd5@violante>
References: <3DEEEB73.9070606@pooryorick.com>
Message-ID: <5.1.0.14.0.20021205201017.02aaada8@www.thinkware.se>

At 13:00 2002-12-05 +0000, Gon=E7alo Rodrigues wrote:
>Although this is not incorrect you should be aware that it creates what =
is
>called a cycle: an object A references an object B that references A. In
>this case, the usual way that Python (to be correct: CPython) uses to fr=
ee
>memory (reference counting) does not work and the garbage collector has =
to
>kick in to free up these cycles when they are no longer in use. In other
>words, if you can avoid cycles do it.

In my experience, this is typically not a problem in Python.
There are some gotchas with these kinds of constructs though,
and most of the time, it's probably better if mutual dependencies
like this can be avoided. This isn't just an implementation
problem (garbage collection is only one side of that) but also
often a problem from a design poit of view. One of Riel's design
heuristics is: "Users of a class must be dependent on its public
interface, but a class should not be dependent on its users."


--=20
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From Jmllr891@cs.com  Thu Dec  5 17:35:02 2002
From: Jmllr891@cs.com (Jmllr891@cs.com)
Date: Thu Dec  5 17:35:02 2002
Subject: [Tutor] Working with memory in Python?
Message-ID: <195.11aefefa.2b212de2@cs.com>

--part1_195.11aefefa.2b212de2_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

I know that most of the time it requires a low level language (such as C) to 
work with memory, but is it at all possible to work with memory with Python?

An example of what I am trying to find out would be finding the address of a 
particular file on a system and then being able to modify/overwrite the 
memory that that particular file is using.

--part1_195.11aefefa.2b212de2_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

<HTML><FONT FACE=arial,helvetica><FONT  SIZE=2 FAMILY="SANSSERIF" FACE="Arial" LANG="0">I know that most of the time it requires a low level language (such as C) to work with memory, but is it at all possible to work with memory with Python?<BR>
<BR>
An example of what I am trying to find out would be finding the address of a particular file on a system and then being able to modify/overwrite the memory that that particular file is using.</FONT></HTML>

--part1_195.11aefefa.2b212de2_boundary--


From jeff@ccvcorp.com  Thu Dec  5 18:16:15 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Thu Dec  5 18:16:15 2002
Subject: [Tutor] Working with memory in Python?
References: <195.11aefefa.2b212de2@cs.com>
Message-ID: <3DEFDE23.6@ccvcorp.com>

Jmllr891@cs.com wrote:

> I know that most of the time it requires a low level language (such as 
> C) to work with memory, but is it at all possible to work with memory 
> with Python?
>
> An example of what I am trying to find out would be finding the 
> address of a particular file on a system and then being able to 
> modify/overwrite the memory that that particular file is using.


In practice, no, that sort of thing is not possible in Python.  (There 
may or may not be advanced black-magic hacks that would allow you to 
accomplish that, but it would be messy, and if you *really* need to do 
such a thing, you'd be better off doing it in C.)

However, for most practical applications of such tricks, it's possible 
to find some alternative method of acheiving the same long-range goal. 
 Most such goals can be accomplished without direct hardware access. 
 What exactly is the purpose of modifying the memory image of a file, as 
opposed to simply re-reading a modified file from disk?

Jeff Shannon
Technician/Programmer
Credit International




From gp@pooryorick.com  Thu Dec  5 19:17:02 2002
From: gp@pooryorick.com (Poor Yorick)
Date: Thu Dec  5 19:17:02 2002
Subject: [Tutor] communication between class instances
References: <5.1.0.14.0.20021205114922.02acda80@www.thinkware.se>
Message-ID: <3DEFEC69.5030808@pooryorick.com>


Magnus Lycka wrote:

 >
 > I'm not sure what you mean that "app" should be but I try to
 > make sure that my program logic is unaware of the GUI.
 >

The classes were just sort of a pseudocode for the structure I've
created.  The class that I called GUI just contains all the code for the
user interface.  I am struggling with just the thing you mentioned.  How
do I keep the program logic unaware of the GUI when the program depends
on information gathered by the GUI widgets.  Generally, the concept that
I seem to be butting up against is how should instances of objects
communicate with each other?  Of course I can have them exchange
references to each other, but if I do that, is there really a point to
keeping them separate as classes?  And what happens to flow control when
the program instance is doing its own thing and at the same time widgets
are generating calls to methods of the program instance?  G. Rodriguez
mentioned that exchanging references between instances creates a cycle,
but what is the alternative?

Poor Yorick
gp@pooryorick.com





From wesc@fuzzyorange.com  Fri Dec  6 01:55:02 2002
From: wesc@fuzzyorange.com (Wesley Chun)
Date: Fri Dec  6 01:55:02 2002
Subject: [Tutor] [Baypiggies] ANN: BayPIGgies mtg Wed 11/13 7:30pm (fwd)
Message-ID: <Pine.LNX.4.31.0212052230370.6903-100000@emperor.deirdre.org>

BayPIGgies: Silicon Valley-San Francisco Bay Area Python Users Group

When:     December 11, 2002 @ 7:30pm
Where:    Stanford University, Palo Alto, CA
Agenda:   Newbies' Nite
Speaker:  (everyone!)

Due to popular demand, we are having another Newbie Night (e.g. April
2002). This is the chance for all Python programmers to bring their
friends and colleagues who should hear about Python. It is also for
those who want to or are picking up Python and have questions! We will
have a good number of Python experts who will try and help you out. Perl
and Java experts are welcome too, as many Python developers also have
experience there and can give you an honest comparison.

The format is this: Wesley (or Danny) will give just a short half-hour
intro presentation on Python to beginners followed by a quick demo, and
then we will open it up to everyone for Q&A. Mingling and networking
will bring our meeting to a glorious conclusion. :-)

# NOTE: the next meeting on January 8, 2003 will be not be at the usual
# place... stay tuned for a location update.

# Call For Talks: We are actively seeking speakers for BayPIGgies! If you
would like to give a talk at one of our 2003 meetings (any Python related
topic), contact us to coordinate!

more info including directions:    http://www.baypiggies.net

hope to see some of you next Wednesday!

-wesley

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

"Core Python Programming", Prentice Hall PTR, =A9 2001
    http://starship.python.net/crew/wesc/cpp/

Silicon Valley-San Francisco Bay Area Python Users Group (BayPIGgies)
    http://deirdre.org/baypiggies

wesley.j.chun :: wesc at deirdre.org
cyberweb.consulting : henderson, nv : cyberweb at rocketmail.com
http://www.roadkill.com/~wesc/cyberweb/



From magnus@thinkware.se  Fri Dec  6 06:27:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri Dec  6 06:27:02 2002
Subject: [Tutor] communication between class instances
In-Reply-To: <3DEFEC69.5030808@pooryorick.com>
References: <5.1.0.14.0.20021205114922.02acda80@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021206080934.00bb6d18@www.thinkware.se>

At 17:16 2002-12-05 -0700, Poor Yorick wrote:
>Magnus Lycka wrote:
> > I'm not sure what you mean that "app" should be but I try to
> > make sure that my program logic is unaware of the GUI.
>
>The classes were just sort of a pseudocode for the structure I've
>created.  The class that I called GUI just contains all the code for the
>user interface.

What GUI tool kit did you intend to use? There's hardly any
point to try to write GUI classes until you have a GUI tool kit.
I'm not sure your pseudocode resembles any real code enough to
learn anything from.

>   I am struggling with just the thing you mentioned.  How
>do I keep the program logic unaware of the GUI when the program depends
>on information gathered by the GUI widgets.

The GUI must obviously be aware of the public interfaces of the
application logic.

The GUI will call the appropriate public method in the application
logic. Typically, things won't happen the other way around. Although
due to dynamic nature of python, you can have the application calling
the GUI without being aware of what the GUI is like... See below.

>Generally, the concept that
>I seem to be butting up against is how should instances of objects
>communicate with each other?

As little as possible! :)

Keep related data or behavoiur in one place.
Minimize the number of classes with which another class collaborates.
Minimize the amount of collaboration between a class and its collaborator.

>  Of course I can have them exchange
>references to each other, but if I do that, is there really a point to
>keeping them separate as classes?

There is nothing technical that prevents you from mixing GUI and
application logic in a class. I usually don't though. It gets very
difficult to do automatic unit tests and debugging of the logic part,
In case you realize that you want to use the logic layer with a
different GUI or some other interface such as CGI, you need a clear
separation.

>And what happens to flow control when
>the program instance is doing its own thing and at the same time widgets
>are generating calls to methods of the program instance?

Aha. You don't know how event based programs work, do you? I
can understand that this is confusing at first. In a normal
single threaded application, only one thing is happening at any
given time.

In GUI programs, you typically leave the flow control to the
event loop of the GUI tool kit. You provide methods in your GUI
code that will be called when various user initiated events occur
(key presses, mouse clicks etc). These methods in your GUI code
will call your application logic as appropriate. It will send from
the GUI to the application logic, and it will get new data back to
present in the GUI controls and windows.

This means that the routines in your application code should
typically be able to return in a short time, or the user interface
will seem dead. For longer running tasks, you need to employ some
special method, such as running that task in a separate thread, or
to divide it into several smaller tasks.

Here's a trivial GUI code example that you can try out:
---------------------------
import Tkinter

class Gui:
     def __init__(self, master):
         self.button = Tkinter.Button(master, text='1', command=self.do)
         self.button.pack()
         self.logic = Logic()

     def do(self):
         value = long(self.button['text'])
         answer = self.logic.call(value)
         self.button['text'] = str(answer)

class Logic:
     def call(self, value):
         return value * 2


root = Tkinter.Tk()

Gui(root)

root.mainloop()
---------------------------
It doesn't do much, but it shows you the general structure of a
GUI program. The "business logic" (multiply a given value with
2) is kept away from the GUI. The GUI only knows the public
interface of the logic: What method to call, what kind of
parameters to provide, and what kind of return values to expect.
Also the business logic is totally unaware of the fact that it's
being used by a button in a GUI.

In the following example, I've tried to code a simple calculator in
such a way that the GUI code and the application logic should be
independent of each other. It should be possible to write a GUI front
end for the current backend in any GUI tool kit. The current one is
wxPython, but Tkinter or Swing should certainly be possible. It
should also be possible to change backend, adding more mathematical
functions and buttons without changing the GUI code. This makes this
a bit more complex than usual, since the GUI has a limited knowledge
of what it will look like, and what it might do.

So, here I actaully let the logic layer get references to three methods
in the GUI layer. This is because the GUI isn't intended to know when to
expect various things to happen, such as display changes or application
exit. As I said, the GUI should be generic and able to handle backend
changes without being rewritten. You might call this reverse callbacks.
When an event (clicking on a button) occurs, the GUI will call a callback
function in the application layer. The conventional solution would be that
these callback methods returned different values to the GUI that could be
presented. But in this particular application the GUI doesn't know what
to expect from the various callback methods, so instead it provides the
three "reverse callback methods" to the logic layer and lets that signal
things back to the user.

This is a bit similar to the event mechanisms in advanced client server
systems like BEA Tuxedo that have features that let the server take
initatives to send messages to the clients. General rules are good,
but sometimes it's better to break them...

In other words, the logic layer here isn't completely unaware of what
context it's used in. It is only intended to be used for an application
that simulates a pocket calculator. It IS completely unaware of HOW the
GUI is implemented though. It could be wxPython, Tkinter, Swing/Jython
as a standalone app or as an applet etc. It might even be possible to
write a CGI application with HTML forms that use this backend. It can
only assume that its user provides the three functions that are needed
on instantiation, and that it understands how to handle the data returned
in getLayout.

Perhaps this isn't the best second example of GUI code to look at. It
violates the general rule of just calling the logic from the GUI and
not vice versa. It still does show a very strict separation of concern
between presentation and logic though.

Here is the logic layer. While it expects three callback methods, it
doesn't expect much of them. You can run it interactively from the
python interpreter.
-----------------------------------
# pycalc.py
from __future__ import division # Don't truncate on 2/3 etc
_copyright = 'Copyright Thinkware AB, Sweden, 2002'
_version = '0.2'

class Calculator:
     '''This is a base version of a calculator. The front end expects
     __init__ and getLayout to look the way they do, and will call any
     callback method it received from getLayout with the text in the
     button as the only parameter.'''

     def __init__(self, displayMethod, helpMethod, closeMethod):
         '''Create a (logic) calculator, and provide three callback
         methods to the GUI. (Reverse callback you might say...)
         displayMethod should be able to take a string as argument,
         and present this string to the user.
         helpMethod will be called when the user presses a button
         associated with the help method. Similarly, closeMethod will
         be called when a button associated with close method is pressed.'''
         self._display = displayMethod
         self._help = helpMethod
         self._close = closeMethod
         self._buffer = []

     def getLayout(self):
         '''Return a list of lists giving the text and callback
         method for each button on the calculator.'''
         a = self.addSymbol
         clr = self.clear
         b = self.back
         h = self.help
         clc = self.calc
         cls = self.close
         return [[('7', a), ('8', a), ('9', a), ('/', a), ('C', clr),],
                 [('4', a), ('5', a), ('6', a), ('*', a), ('CE', b),],
                 [('1', a), ('2', a), ('3', a), ('-', a), ('Off', cls),],
                 [('0', a), ('.', a), ('=', clc), ('+', a), ('?', h),]]

     def close(self, dummy):
         '''Call close method provided by UI'''
         self._close(dummy)

     def help(self, dummy):
         '''Call help method provided by UI'''
         self._help('Backend: %s %s\n%s' % (__name__, _version, _copyright))

     def _update(self):
         '''Update display with internal buffer content'''
         self._display("".join(self._buffer))

     def addSymbol(self, symbol):
         '''Add an entered symbol to the internal buffer'''
         self._buffer.append(symbol)
         self._update()

     def clear(self, dummy):
         '''Clear the internal buffer'''
         self._buffer = []
         self._update()

     def back(self, dummy):
         '''Remove last symbol in internal buffer'''
         if self._buffer:
             del self._buffer[-1]
             self._update()

     def calc(self, dummy):
         '''Replace internal buffer content with result of evaluating it'''
         try:
             expr = "".join(self._buffer)
             result = eval(expr)
             self._buffer = list(str(result))
             self._update()
         except:
             self._buffer = []
             self._display('ERROR')
-----------------------------------

Here is a little interactive experiment without a GUI.

Python 2.2.1 (#34, Sep 27 2002, 18:37:42) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> import pycalc
 >>> def close(x):
...     print "Close app"
...
 >>> def display(x):
...     print x
...
 >>> help=display
 >>> calc = pycalc.Calculator(display, help, close)
 >>> keyFunc = calc.getLayout()
 >>> print keyFunc
[[('7', <bound method Calculator.addSymbol of <pycalc.Calculator instance 
at 0x0
07B5AE8>>), ('8', <bound method Calculator.addSymbol of <pycalc.Calculator 
insta
[and so on...]
 >>> seven = keyFunc[0][0]
 >>> seven[1](seven[0])
7
 >>> seven[1](seven[0])
77
 >>> plus = keyFunc[3][3]
 >>> print plus
('+', <bound method Calculator.addSymbol of <pycalc.Calculator instance at 
0x007
B5AE8>>)
 >>> plus[1](plus[0])
77+
 >>> seven[1](seven[0])
77+7
 >>> equals = keyFunc[3][2]
 >>> print equals
('=', <bound method Calculator.calc of <pycalc.Calculator instance at 
0x007B5AE8
 >>)
 >>> equals[1](equals[0])
84
 >>> hlp = keyFunc[3][4]
 >>> hlp[1](hlp[0])
Backend: pycalc 0.2
Copyright Thinkware AB, Sweden, 2002
 >>>

Certainly not the most convenient calculator interface, but it's
possible to write test scripts, and debug things etc. It seems to
work: 77+7 = 84. If the GUI will make function calls as above, it
will be possible to display entered data and show calculation results.

Here is a presentation layer written for wxPython:
-----------------------------------
# wxpycalc.py
_copyright = 'Copyright Thinkware AB, Sweden, 2002'
_name = 'wxPyCalc'
_version = '0.2'

from wxPython.wx import *
from wxPython.lib.rcsizer import RowColSizer
from pycalc import Calculator

class MyFrame(wxFrame):
     '''This is a generic GUI for calculators. It provides the actual
     calculator with (reverse) callback methods for display, showing
     help messages and closing the application.
     On the top of the GUI it will present a display field. The content
     of this display field is determined by the display callback method
     mentioned above.
     After instanciating the calculator, it will fetch information about
     a grid of buttons to show below the display.'''
     def __init__(self, parent, title, pos=wxDefaultPosition,
                  size=wxDefaultSize, style=wxDEFAULT_FRAME_STYLE ):
         wxFrame.__init__(self, parent, -1, title, pos, size, style)
         panel = wxPanel(self, -1)
         sizer = RowColSizer()

         calculator = Calculator(self.display, self.help, self.OnCloseMe)
         numberOfColumns = len(calculator.getLayout()[0])

         self.displayBox = wxTextCtrl(panel, -1, "", style=wxTE_READONLY)
         sizer.Add(self.displayBox, row=0, col=0, colspan=numberOfColumns,
                   flag=wxEXPAND)

         x = 1
         for row in calculator.getLayout():
             y = 0
             for text, method in row:
                 button = wxButton(panel, -1, text, size=wxSize(30,30))
                 button.myMethod = method
                 sizer.Add(button, flag=wxEXPAND, row = x, col=y)
                 EVT_BUTTON(self, button.GetId(), self.callback)
                 y += 1
             x += 1

         panel.SetSizer(sizer)
         panel.SetAutoLayout(true)

         EVT_CLOSE(self, self.OnCloseWindow)

     def help(self, msg):
         dlg = wxMessageDialog(self,
                 ('A simple Python calculator\n%s %s\n%s\n\n%s' %
                  (_name, _version, _copyright, msg)),
                 'About %s' % _name, wxOK | wxICON_INFORMATION)
         dlg.ShowModal()
         dlg.Destroy()

     def callback(self, evt):
         button = evt.GetEventObject()
         button.myMethod(button.GetLabel())

     def display(self, data):
         self.displayBox.SetValue(data)

     def OnCloseMe(self, evt):
         self.Close(true)

     def OnCloseWindow(self, evt):
         self.Destroy()

class MyApp(wxApp):
     def OnInit(self):
         self.frame = MyFrame(NULL, _name, size = wxSize(160, 170))
         self.frame.Show(true)
         self.SetTopWindow(self.frame)
         return true

def main():
     app = MyApp(0)
     app.MainLoop()

if __name__ == '__main__':
     main()
-----------------------------------

It's left as an exercise to the reader to make new frontends
(Tkinter, Swing etc) or backends (hex-calculator, trigonometry
etc). It might be a good thing to be able to swap backend on
the fly as well. I guess this means the "import pycalc" needs
to be replaced with something more sofisticated. Another neat
extension would be to make it aware of key presses, at least for
the buttons that only have one character on the key top. This
can be done without changing the backend.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Fri Dec  6 06:34:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri Dec  6 06:34:02 2002
Subject: [Tutor] Working with memory in Python?
In-Reply-To: <195.11aefefa.2b212de2@cs.com>
Message-ID: <5.1.0.14.0.20021206122934.051d0b90@www.thinkware.se>

At 17:32 2002-12-05 -0500, Jmllr891@cs.com wrote:
>I know that most of the time it requires a low level language (such as C) 
>to work with memory, but is it at all possible to work with memory with Python?
>
>An example of what I am trying to find out would be finding the address of 
>a particular file on a system and then being able to modify/overwrite the 
>memory that that particular file is using.

Are you talking about primary memory (RAM) or secondary memory
(disk) here?

What are you trying to achieve?

If you are trying to make sure that some data is safely
erased, the OS can certainly play tricks with you. I'm
pretty sure there is only one OS independent way of ensuring
that sensitive data is properly removed from a computer.
But it's a pity to destroy fine hardware like that...


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From gmlloyd@onlink.net  Fri Dec  6 13:32:02 2002
From: gmlloyd@onlink.net (gmlloyd)
Date: Fri Dec  6 13:32:02 2002
Subject: [Tutor] re Python built-in methods, functions, libraries, etc.
Message-ID: <3DF0ECEB.843EA6A7@onlink.net>

Good afternoon.

Can you suggest some online lists/discussions of Python's built-in
methods & functions, Python libraries, etc.

thanks!

Geoff Lloyd



From mongo57a@comcast.net  Fri Dec  6 23:52:01 2002
From: mongo57a@comcast.net (andy surany)
Date: Fri Dec  6 23:52:01 2002
Subject: [Tutor] The case of the scrolling label....
Message-ID: <012001c29dac$92fd3a40$2502a8c0@emily.ewndsr01.nj.comcast.net>

Hello Tutors!

I am putting up a label when an improper entry is received.

Label(text='Invalid Entry').pack() # Tk

Works fine. But how do I get rid of it? Multiple improper entries yield:

Invalid Entry
Invalid Entry
Invalid Entry

I want to be able to place labels (or a "clear") over the position of
the existing label. Is this possible? Is it possible without placing the
label in its own frame?

TIA

-Andy



From magnus@thinkware.se  Sat Dec  7 03:32:04 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat Dec  7 03:32:04 2002
Subject: [Tutor] re Python built-in methods, functions, libraries,
 etc.
In-Reply-To: <3DF0ECEB.843EA6A7@onlink.net>
Message-ID: <5.1.0.14.0.20021207092720.0518ada0@www.thinkware.se>

At 13:31 2002-12-06 -0500, gmlloyd wrote:
>Good afternoon.

Good Morning

>Can you suggest some online lists/discussions of Python's built-in
>methods & functions, Python libraries, etc.

For information, look at the python library reference.
http://www.python.org/doc/current/lib/lib.html

For questions and discussion, ask here or on comp.lang.python,
or use list archives, google etc to find past discussions.

There is also a number of tutorials:
http://www.python.org/doc/current/tut/tut.html
http://www.python.org/doc/Newbies.html


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From dyoo@hkn.eecs.berkeley.edu  Sat Dec  7 03:47:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat Dec  7 03:47:02 2002
Subject: [Tutor] re Python built-in methods, functions, libraries, etc.
 [unichr()]
In-Reply-To: <3DF0ECEB.843EA6A7@onlink.net>
Message-ID: <Pine.LNX.4.44.0212062340120.27821-100000@hkn.eecs.berkeley.edu>


On Fri, 6 Dec 2002, gmlloyd wrote:

> Can you suggest some online lists/discussions of Python's built-in
> methods & functions, Python libraries, etc.

Hi Geoff,

We occasionally talk about some of the builtin functions here on Tutor;
you might be able to find some archives of our discussions here:

    http://mail.python.org/pipermail/tutor/


Is there a particular builtin that you're interested in?  Maybe we could
have some sort of "builtin-of-the-week" feature that someone can write
up...


I'll kick it off.  *grin*



Let's see... let's pick something out of the hat at random.

###
>>> import random
>>> random.choice(dir(__builtins__))
'unichr'
###


What is 'unichr'?

###
>>> type(unichr)
<type 'builtin_function_or_method'>
>>> callable(unichr)
1
###


I've used the builtin 'type()' function, that tells us what kind of thing
we're looking at.  'unichr' looks like a function, and we've verified that
it's callable.


We can find out more about unichr() by either looking at the documentation
at:

    http://www.python.org/doc/lib/built-in-funcs.html

... or, we can also take advantage of the builtin help() that lets us
query for more information:

###
>>> help(unichr)

Help on built-in function unichr:

unichr(...)
    unichr(i) -> Unicode character

    Return a Unicode string of one character with ordinal i; 0 <= i <=
0x10ffff.
###


'unichr()', then, is a function that takes an integer between 0 and
0x10fff, and returns the unicode string for that character.  For example,
I was curious, so I visited:

    http://www.unicode.org/charts/


and picked a random character out of the Hangul Syllables:

###
>>> my_unicode_char = unichr(0xc720)
>>> my_unicode_char
u'\uc720'
###

C720, according to the Unocde Code Pages, is a single Hangul character.
In ASCII-art, it sorta looks like this:


      +-+
      +-+
    -------
      | |



Unicode is meant to represent a vast majority of languages in the world,
and most web browsers support it, so even if we can't see it from our
console, we might have some success seeing it by rendering it into a Web
page, and then looking at it from our favorite browser:

###
>>> my_unicode_char = unichr(0xC720)
>>> f = open('test-unicode.html', 'w')
>>> f.write('''<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
... <html>
... <head>
... <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
... </head>
... <body>
... <h1>My first Unicode character: %s</h1>
... </body>
... </html>''' % my_unicode_char.encode('utf-8'))
>>> f.close()
###


For those who don't want to type all that, but still want to see the
results, I've put up the HTML generated by that program here:

    http://hkn.eecs.berkeley.edu/~dyoo/test-unicode.html

So, in summary, unichr() lets us write out a single unicode character if
we know its numeric code.



I hope this was somewhat interesting!



From magnus@thinkware.se  Sat Dec  7 03:48:03 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat Dec  7 03:48:03 2002
Subject: [Tutor] The case of the scrolling label....
In-Reply-To: <012001c29dac$92fd3a40$2502a8c0@emily.ewndsr01.nj.comcast.n
 et>
Message-ID: <5.1.0.14.0.20021207093509.02a87748@www.thinkware.se>

At 23:53 2002-12-06 -0500, andy surany wrote:
>I am putting up a label when an improper entry is received.
>
>Label(text='Invalid Entry').pack() # Tk
>
>Works fine. But how do I get rid of it?

Don't throw away the reference to it!

It irritates me (I've written about this before) that a lot
of GUI code relies on magic hand-hold that let people use
object instanciations as if they were some kind of procedure
calls. It gives the wrong idea.

I would do
   attention = Label(text='')
   attention.pack() # Can't do these in one line (think about it)
as a part of program init, and then
   attention['text'] = 'Invalid Entry'
when things go wrong, and
   attention['text'] = ''
when I don't want to show that any longer.

The variable must persist to be useful. If you're in a class,
use "self.attention = Label(text='Invalid Entry')" and so on.

Another option could be to do
   attention = Label(text='Invalid Entry')
   attention.pack()
when needed, and
   attention.destroy()
when you want the text to go away.

I would NOT use that. How on earth are you going to have any
control over your UI when you realize that you have to add more
things in your frame. I'd layout my windows in the beginning,
and then fill in values as appropriate.



-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From dyoo@hkn.eecs.berkeley.edu  Sat Dec  7 04:18:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat Dec  7 04:18:02 2002
Subject: [Tutor] Working with memory in Python?
In-Reply-To: <195.11aefefa.2b212de2@cs.com>
Message-ID: <Pine.LNX.4.44.0212070106400.27821-100000@hkn.eecs.berkeley.edu>


On Thu, 5 Dec 2002 Jmllr891@cs.com wrote:

> I know that most of the time it requires a low level language (such as
> C) to work with memory, but is it at all possible to work with memory
> with Python?
>
> An example of what I am trying to find out would be finding the address
> of a particular file on a system and then being able to modify/overwrite
> the memory that that particular file is using.

Hello!

Can you give a concrete reason for doing this?  I have to admit that I'm
feeling fuzzy, so a concrete example may clear up my confusion.


There's a way of mapping a file to memory using the 'mmap' module:

    http://www.python.org/doc/lib/module-mmap.html

But I'm not sure if this is what you mean; in fact, it's probably not, but
it fits all the words that you're using.  *grin*


By "memory", are you thinking of RAM, or are you thinking of the contents
of a file on your hard drive?

The problem with computer terminology is that it can be as overloaded as
English (perhaps more so!), so we need to be careful about our words.

The word "address", if taken loosely, could apply to a position in RAM, or
a position in a file.  But the way that you're using sounds like you're
looking for a file's "path" --- the position in the directory tree of your
file system --- and that's something entirely different from the other two
meanings.  Help!  *grin*


So we need more explanation of your situation to disambiguate what you
mean.  What are you trying to do?


Talk to you later!



From scot@possum.in-berlin.de  Sat Dec  7 05:36:02 2002
From: scot@possum.in-berlin.de (Scot Stevenson)
Date: Sat Dec  7 05:36:02 2002
Subject: [Tutor] Re: Testing if a number occurs more than once [dict version / What's the difference between has_key() and 'in']
In-Reply-To: <Pine.LNX.4.44.0212041840090.9741-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.44.0212041840090.9741-100000@hkn.eecs.berkeley.edu>
Message-ID: <200212071121.50186.scot@possum.in-berlin.de>

Hello Danny, 

> But is there a difference between them?  If we're familiar with C, we
> might like to delve in to see what really is so different between them.
> If we look at the Python source code:

An impressive demonstration of the use of Open Software source code. Thank you 
for the time -- I'll be using "in" without bad feelings now.

(As for the real timing -- I hope to get around to it in about a week when I'm 
back from a trip. Haven't forgotten it, and Magnus was right that I shouldn't 
be assuming, but measuring.)

Y, Scot

-- 
  Scot W. Stevenson -- scot@possum.in-berlin.de -- Zepernick, Germany



From magnus@thinkware.se  Sat Dec  7 06:25:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat Dec  7 06:25:01 2002
Subject: [Tutor] Re: Testing if a number occurs more than once
 [dict version / What's the difference between has_key() and 'in']
In-Reply-To: <200212071121.50186.scot@possum.in-berlin.de>
References: <Pine.LNX.4.44.0212041840090.9741-100000@hkn.eecs.berkeley.edu>
 <Pine.LNX.4.44.0212041840090.9741-100000@hkn.eecs.berkeley.edu>
Message-ID: <5.1.0.14.0.20021207114859.02ada160@www.thinkware.se>

At 11:21 2002-12-07 +0100, Scot Stevenson wrote:
>and Magnus was right that I shouldn't
>be assuming, but measuring.

On the other hand, you might not reach the same result
with another Python version, on another platform, or
with another set of data... :(

As Don Knuth once said: "Premature optimization is the
root of all evil."

In other words, try to keep things clear and simple, and
think about performance tricks only if measurements have
shown that it really matters.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From mongo57a@comcast.net  Sat Dec  7 07:37:02 2002
From: mongo57a@comcast.net (andy surany)
Date: Sat Dec  7 07:37:02 2002
Subject: [Tutor] The case of the scrolling label....
Message-ID: <000a01c29ded$0ffc5400$2502a8c0@emily.ewndsr01.nj.comcast.net>

Makes sense. And I think that you have cautioned me about it once
before. Thanks for the reminder.

-----Original Message-----
From: Magnus Lycka <magnus@thinkware.se>
To: andy surany <mongo57a@comcast.net>; tutor@python.org
<tutor@python.org>
Date: Saturday, December 07, 2002 3:49 AM
Subject: Re: [Tutor] The case of the scrolling label....


>At 23:53 2002-12-06 -0500, andy surany wrote:
>>I am putting up a label when an improper entry is received.
>>
>>Label(text='Invalid Entry').pack() # Tk
>>
>>Works fine. But how do I get rid of it?
>
>Don't throw away the reference to it!
>
>It irritates me (I've written about this before) that a lot
>of GUI code relies on magic hand-hold that let people use
>object instanciations as if they were some kind of procedure
>calls. It gives the wrong idea.
>
>I would do
>   attention = Label(text='')
>   attention.pack() # Can't do these in one line (think about it)
>as a part of program init, and then
>   attention['text'] = 'Invalid Entry'
>when things go wrong, and
>   attention['text'] = ''
>when I don't want to show that any longer.
>
>The variable must persist to be useful. If you're in a class,
>use "self.attention = Label(text='Invalid Entry')" and so on.
>
>Another option could be to do
>   attention = Label(text='Invalid Entry')
>   attention.pack()
>when needed, and
>   attention.destroy()
>when you want the text to go away.
>
>I would NOT use that. How on earth are you going to have any
>control over your UI when you realize that you have to add more
>things in your frame. I'd layout my windows in the beginning,
>and then fill in values as appropriate.
>
>
>
>--
>Magnus Lycka, Thinkware AB
>Alvans vag 99, SE-907 50 UMEA, SWEDEN
>phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
>http://www.thinkware.se/  mailto:magnus@thinkware.se
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor



From gp@pooryorick.com  Sat Dec  7 13:38:03 2002
From: gp@pooryorick.com (Poor Yorick)
Date: Sat Dec  7 13:38:03 2002
Subject: [Tutor] communication between class instances
References: <5.1.0.14.0.20021205114922.02acda80@www.thinkware.se> <5.1.0.14.0.20021206080934.00bb6d18@www.thinkware.se>
Message-ID: <3DF2402A.9060001@pooryorick.com>

Thank you for the extensive reply.  I am using Tkinter, and have a good 
amount of code in the GUI class already.  This is the first complete 
Python program I have attempted, and for the experience I am trying to 
do things like have multiple interfaces using different GUI tool kits 
and building all my own complex widgets.

You're right, I have many questions about event-based programs.  You 
mentioned "a general rule of just calling logic from the GUI and not 
vice versa."  This is interesting because most of the time, my program 
logic is making calls to the GUI.  For example:

dbName = self.__activeUi.call(cmd='DbName', master=self.__activeUi.parent)

In your PyCalc example, the Calculator becomes a component of MyFrame. 
 This component receives three hooks (is that the right word?) back to 
MyFrame, enabling two-way communication.  Now if calculator itself had a 
sub-component (class instance), which itself in turn had a subcomponent 
(class instance) which needed feedback from the user, I suppose that 
generally, it would be best for each component to communicate with its 
parent component via supplied hooks, and thus relay the message up to 
MyFrame.  Is that true?

I'll be studying your PyCalc example further.

Thank you,

Poor Yorick
gp@pooryorick.com 

Magnus Lycka wrote:

> At 17:16 2002-12-05 -0700, Poor Yorick wrote:
>
>> Magnus Lycka wrote:
>> > I'm not sure what you mean that "app" should be but I try to
>> > make sure that my program logic is unaware of the GUI.
>>
>> The classes were just sort of a pseudocode for the structure I've
>> created.  The class that I called GUI just contains all the code for the
>> user interface.
>
>
> What GUI tool kit did you intend to use? There's hardly any
> point to try to write GUI classes until you have a GUI tool kit.
> I'm not sure your pseudocode resembles any real code enough to
> learn anything from.
>
>>   I am struggling with just the thing you mentioned.  How
>> do I keep the program logic unaware of the GUI when the program depends
>> on information gathered by the GUI widgets.
>
>
> The GUI must obviously be aware of the public interfaces of the
> application logic.
>
> The GUI will call the appropriate public method in the application
> logic. Typically, things won't happen the other way around. Although
> due to dynamic nature of python, you can have the application calling
> the GUI without being aware of what the GUI is like... See below.
>
>> Generally, the concept that
>> I seem to be butting up against is how should instances of objects
>> communicate with each other?
>
>
> As little as possible! :)
>
> Keep related data or behavoiur in one place.
> Minimize the number of classes with which another class collaborates.
> Minimize the amount of collaboration between a class and its 
> collaborator.
>
>>  Of course I can have them exchange
>> references to each other, but if I do that, is there really a point to
>> keeping them separate as classes?
>
>
> There is nothing technical that prevents you from mixing GUI and
> application logic in a class. I usually don't though. It gets very
> difficult to do automatic unit tests and debugging of the logic part,
> In case you realize that you want to use the logic layer with a
> different GUI or some other interface such as CGI, you need a clear
> separation.
>
>> And what happens to flow control when
>> the program instance is doing its own thing and at the same time widgets
>> are generating calls to methods of the program instance?
>
>
> Aha. You don't know how event based programs work, do you? I
> can understand that this is confusing at first. In a normal
> single threaded application, only one thing is happening at any
> given time.
>
> In GUI programs, you typically leave the flow control to the
> event loop of the GUI tool kit. You provide methods in your GUI
> code that will be called when various user initiated events occur
> (key presses, mouse clicks etc). These methods in your GUI code
> will call your application logic as appropriate. It will send from
> the GUI to the application logic, and it will get new data back to
> present in the GUI controls and windows.
>
> This means that the routines in your application code should
> typically be able to return in a short time, or the user interface
> will seem dead. For longer running tasks, you need to employ some
> special method, such as running that task in a separate thread, or
> to divide it into several smaller tasks.
>
> Here's a trivial GUI code example that you can try out:
> ---------------------------
> import Tkinter
>
> class Gui:
>     def __init__(self, master):
>         self.button = Tkinter.Button(master, text='1', command=self.do)
>         self.button.pack()
>         self.logic = Logic()
>
>     def do(self):
>         value = long(self.button['text'])
>         answer = self.logic.call(value)
>         self.button['text'] = str(answer)
>
> class Logic:
>     def call(self, value):
>         return value * 2
>
>
> root = Tkinter.Tk()
>
> Gui(root)
>
> root.mainloop()
> ---------------------------
> It doesn't do much, but it shows you the general structure of a
> GUI program. The "business logic" (multiply a given value with
> 2) is kept away from the GUI. The GUI only knows the public
> interface of the logic: What method to call, what kind of
> parameters to provide, and what kind of return values to expect.
> Also the business logic is totally unaware of the fact that it's
> being used by a button in a GUI.
>
> In the following example, I've tried to code a simple calculator in
> such a way that the GUI code and the application logic should be
> independent of each other. It should be possible to write a GUI front
> end for the current backend in any GUI tool kit. The current one is
> wxPython, but Tkinter or Swing should certainly be possible. It
> should also be possible to change backend, adding more mathematical
> functions and buttons without changing the GUI code. This makes this
> a bit more complex than usual, since the GUI has a limited knowledge
> of what it will look like, and what it might do.
>
> So, here I actaully let the logic layer get references to three methods
> in the GUI layer. This is because the GUI isn't intended to know when to
> expect various things to happen, such as display changes or application
> exit. As I said, the GUI should be generic and able to handle backend
> changes without being rewritten. You might call this reverse callbacks.
> When an event (clicking on a button) occurs, the GUI will call a callback
> function in the application layer. The conventional solution would be 
> that
> these callback methods returned different values to the GUI that could be
> presented. But in this particular application the GUI doesn't know what
> to expect from the various callback methods, so instead it provides the
> three "reverse callback methods" to the logic layer and lets that signal
> things back to the user.
>
> This is a bit similar to the event mechanisms in advanced client server
> systems like BEA Tuxedo that have features that let the server take
> initatives to send messages to the clients. General rules are good,
> but sometimes it's better to break them...
>
> In other words, the logic layer here isn't completely unaware of what
> context it's used in. It is only intended to be used for an application
> that simulates a pocket calculator. It IS completely unaware of HOW the
> GUI is implemented though. It could be wxPython, Tkinter, Swing/Jython
> as a standalone app or as an applet etc. It might even be possible to
> write a CGI application with HTML forms that use this backend. It can
> only assume that its user provides the three functions that are needed
> on instantiation, and that it understands how to handle the data returned
> in getLayout.
>
> Perhaps this isn't the best second example of GUI code to look at. It
> violates the general rule of just calling the logic from the GUI and
> not vice versa. It still does show a very strict separation of concern
> between presentation and logic though.
>
> Here is the logic layer. While it expects three callback methods, it
> doesn't expect much of them. You can run it interactively from the
> python interpreter.
> -----------------------------------
> # pycalc.py
> from __future__ import division # Don't truncate on 2/3 etc
> _copyright = 'Copyright Thinkware AB, Sweden, 2002'
> _version = '0.2'
>
> class Calculator:
>     '''This is a base version of a calculator. The front end expects
>     __init__ and getLayout to look the way they do, and will call any
>     callback method it received from getLayout with the text in the
>     button as the only parameter.'''
>
>     def __init__(self, displayMethod, helpMethod, closeMethod):
>         '''Create a (logic) calculator, and provide three callback
>         methods to the GUI. (Reverse callback you might say...)
>         displayMethod should be able to take a string as argument,
>         and present this string to the user.
>         helpMethod will be called when the user presses a button
>         associated with the help method. Similarly, closeMethod will
>         be called when a button associated with close method is 
> pressed.'''
>         self._display = displayMethod
>         self._help = helpMethod
>         self._close = closeMethod
>         self._buffer = []
>
>     def getLayout(self):
>         '''Return a list of lists giving the text and callback
>         method for each button on the calculator.'''
>         a = self.addSymbol
>         clr = self.clear
>         b = self.back
>         h = self.help
>         clc = self.calc
>         cls = self.close
>         return [[('7', a), ('8', a), ('9', a), ('/', a), ('C', clr),],
>                 [('4', a), ('5', a), ('6', a), ('*', a), ('CE', b),],
>                 [('1', a), ('2', a), ('3', a), ('-', a), ('Off', cls),],
>                 [('0', a), ('.', a), ('=', clc), ('+', a), ('?', h),]]
>
>     def close(self, dummy):
>         '''Call close method provided by UI'''
>         self._close(dummy)
>
>     def help(self, dummy):
>         '''Call help method provided by UI'''
>         self._help('Backend: %s %s\n%s' % (__name__, _version, 
> _copyright))
>
>     def _update(self):
>         '''Update display with internal buffer content'''
>         self._display("".join(self._buffer))
>
>     def addSymbol(self, symbol):
>         '''Add an entered symbol to the internal buffer'''
>         self._buffer.append(symbol)
>         self._update()
>
>     def clear(self, dummy):
>         '''Clear the internal buffer'''
>         self._buffer = []
>         self._update()
>
>     def back(self, dummy):
>         '''Remove last symbol in internal buffer'''
>         if self._buffer:
>             del self._buffer[-1]
>             self._update()
>
>     def calc(self, dummy):
>         '''Replace internal buffer content with result of evaluating 
> it'''
>         try:
>             expr = "".join(self._buffer)
>             result = eval(expr)
>             self._buffer = list(str(result))
>             self._update()
>         except:
>             self._buffer = []
>             self._display('ERROR')
> -----------------------------------
>
> Here is a little interactive experiment without a GUI.
>
> Python 2.2.1 (#34, Sep 27 2002, 18:37:42) [MSC 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import pycalc
> >>> def close(x):
> ...     print "Close app"
> ...
> >>> def display(x):
> ...     print x
> ...
> >>> help=display
> >>> calc = pycalc.Calculator(display, help, close)
> >>> keyFunc = calc.getLayout()
> >>> print keyFunc
> [[('7', <bound method Calculator.addSymbol of <pycalc.Calculator 
> instance at 0x0
> 07B5AE8>>), ('8', <bound method Calculator.addSymbol of 
> <pycalc.Calculator insta
> [and so on...]
> >>> seven = keyFunc[0][0]
> >>> seven[1](seven[0])
> 7
> >>> seven[1](seven[0])
> 77
> >>> plus = keyFunc[3][3]
> >>> print plus
> ('+', <bound method Calculator.addSymbol of <pycalc.Calculator 
> instance at 0x007
> B5AE8>>)
> >>> plus[1](plus[0])
> 77+
> >>> seven[1](seven[0])
> 77+7
> >>> equals = keyFunc[3][2]
> >>> print equals
> ('=', <bound method Calculator.calc of <pycalc.Calculator instance at 
> 0x007B5AE8
> >>)
> >>> equals[1](equals[0])
> 84
> >>> hlp = keyFunc[3][4]
> >>> hlp[1](hlp[0])
> Backend: pycalc 0.2
> Copyright Thinkware AB, Sweden, 2002
> >>>
>
> Certainly not the most convenient calculator interface, but it's
> possible to write test scripts, and debug things etc. It seems to
> work: 77+7 = 84. If the GUI will make function calls as above, it
> will be possible to display entered data and show calculation results.
>
> Here is a presentation layer written for wxPython:
> -----------------------------------
> # wxpycalc.py
> _copyright = 'Copyright Thinkware AB, Sweden, 2002'
> _name = 'wxPyCalc'
> _version = '0.2'
>
> from wxPython.wx import *
> from wxPython.lib.rcsizer import RowColSizer
> from pycalc import Calculator
>
> class MyFrame(wxFrame):
>     '''This is a generic GUI for calculators. It provides the actual
>     calculator with (reverse) callback methods for display, showing
>     help messages and closing the application.
>     On the top of the GUI it will present a display field. The content
>     of this display field is determined by the display callback method
>     mentioned above.
>     After instanciating the calculator, it will fetch information about
>     a grid of buttons to show below the display.'''
>     def __init__(self, parent, title, pos=wxDefaultPosition,
>                  size=wxDefaultSize, style=wxDEFAULT_FRAME_STYLE ):
>         wxFrame.__init__(self, parent, -1, title, pos, size, style)
>         panel = wxPanel(self, -1)
>         sizer = RowColSizer()
>
>         calculator = Calculator(self.display, self.help, self.OnCloseMe)
>         numberOfColumns = len(calculator.getLayout()[0])
>
>         self.displayBox = wxTextCtrl(panel, -1, "", style=wxTE_READONLY)
>         sizer.Add(self.displayBox, row=0, col=0, colspan=numberOfColumns,
>                   flag=wxEXPAND)
>
>         x = 1
>         for row in calculator.getLayout():
>             y = 0
>             for text, method in row:
>                 button = wxButton(panel, -1, text, size=wxSize(30,30))
>                 button.myMethod = method
>                 sizer.Add(button, flag=wxEXPAND, row = x, col=y)
>                 EVT_BUTTON(self, button.GetId(), self.callback)
>                 y += 1
>             x += 1
>
>         panel.SetSizer(sizer)
>         panel.SetAutoLayout(true)
>
>         EVT_CLOSE(self, self.OnCloseWindow)
>
>     def help(self, msg):
>         dlg = wxMessageDialog(self,
>                 ('A simple Python calculator\n%s %s\n%s\n\n%s' %
>                  (_name, _version, _copyright, msg)),
>                 'About %s' % _name, wxOK | wxICON_INFORMATION)
>         dlg.ShowModal()
>         dlg.Destroy()
>
>     def callback(self, evt):
>         button = evt.GetEventObject()
>         button.myMethod(button.GetLabel())
>
>     def display(self, data):
>         self.displayBox.SetValue(data)
>
>     def OnCloseMe(self, evt):
>         self.Close(true)
>
>     def OnCloseWindow(self, evt):
>         self.Destroy()
>
> class MyApp(wxApp):
>     def OnInit(self):
>         self.frame = MyFrame(NULL, _name, size = wxSize(160, 170))
>         self.frame.Show(true)
>         self.SetTopWindow(self.frame)
>         return true
>
> def main():
>     app = MyApp(0)
>     app.MainLoop()
>
> if __name__ == '__main__':
>     main()
> -----------------------------------
>
> It's left as an exercise to the reader to make new frontends
> (Tkinter, Swing etc) or backends (hex-calculator, trigonometry
> etc). It might be a good thing to be able to swap backend on
> the fly as well. I guess this means the "import pycalc" needs
> to be replaced with something more sofisticated. Another neat
> extension would be to make it aware of key presses, at least for
> the buttons that only have one character on the key top. This
> can be done without changing the backend.
>
>




From magnus@thinkware.se  Sat Dec  7 14:41:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat Dec  7 14:41:01 2002
Subject: [Tutor] communication between class instances
In-Reply-To: <3DF2402A.9060001@pooryorick.com>
References: <5.1.0.14.0.20021205114922.02acda80@www.thinkware.se>
 <5.1.0.14.0.20021206080934.00bb6d18@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021207202006.02afaf50@www.thinkware.se>

At 11:38 2002-12-07 -0700, Poor Yorick wrote:
>This is the first complete Python program I have attempted, and for the 
>experience I am trying to do things like have multiple interfaces using 
>different GUI tool kits and building all my own complex widgets.

Hm... Remember the KISS principle: Keep It Simple, Stupid! ;)

>You're right, I have many questions about event-based programs.  You 
>mentioned "a general rule of just calling logic from the GUI and not vice 
>versa."  This is interesting because most of the time, my program logic is 
>making calls to the GUI.  For example:

:(

>dbName = self.__activeUi.call(cmd='DbName', master=self.__activeUi.parent)

I'm not sure what this means, but I suppose you have entered a
database name in a GUI control. What I would do, would be to
give that data to some object in the logic layer as soon as the
data is entered correctly.

>In your PyCalc example, the Calculator becomes a component of MyFrame. 
>This component receives three hooks (is that the right word?)

I know what these three things are, but I'm not sure
what you are supposed to call them. :)

>back to MyFrame, enabling two-way communication.

I only do this because of one unusual circumstance:

The GUI code itself doesn't know what it will look like.
It places buttons on the window based on information from
the "logic". You could say that the pycalc module is
not just program logic, but also knows an abstract layout
and function of the GUI. This is unusual, and generally
not a good idea. If this generic GUI feature is desired,
it should probably be another layer separate from the GUI
and from the logic, but in most cases it's probably better
to simply rewrite the GUI from scratch if it is to be
changed. In the pycalc example, the real "business logic"
really boils down to a single eval function, so it's not
much point in separating that... :)

But in this case, it means that the GUI layer doesn't
know when to expect display changes, popup windows etc.

Normally, the GUI knows what every control is for, and
what to expect from every call to the logic layer.

In general I don't think this "hook" style is good. Maybe
it was a bad example. (Although I got a chance to discuss
the issue!)

As you see though, the pycalc module knows extremely
little about the GUI layer. It gets three functions, and
it knows when to call them. In two cases it sends a string
to the function, in the third, it doesn't care about parameters
at all. In no case does it know anything about any further
structure or parameter names in the layer above it. There is
nothing close to the level of coupling you present in:

self.__activeUi.call(cmd='DbName', master=self.__activeUi.parent)

It seems to me that code like that in the logic layer means
that you are either helplessly tied to a particular GUI and
that your GUI related maintenace problems will spread further
than they should, or that you will need to build your GUIs
more complex than you would otherwise.

All too tight coupling.

>Now if calculator itself had a sub-component (class instance), which 
>itself in turn had a subcomponent (class instance) which needed feedback 
>from the user, I suppose that generally, it would be best for each 
>component to communicate with its parent component via supplied hooks, and 
>thus relay the message up to MyFrame.  Is that true?

No. The event mechanisms in the GUI (in other words, user actions)
should drive the logic. Not the other way around! The logic should
normally communicate with the GUI layer by return values or exceptions
only. Like in my first, tiny example.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From dyoo@hkn.eecs.berkeley.edu  Sat Dec  7 17:07:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat Dec  7 17:07:01 2002
Subject: [Tutor] Working with memory in Python? (fwd)
Message-ID: <Pine.LNX.4.44.0212071346290.13217-100000@hkn.eecs.berkeley.edu>

Hello!

Hmmmm... this sounds like an interesting project!  Let me forward this to
the tutor list so that everyone can help answer your questions.


It sounds like what you'd like to do is not only delete a file from your
system, but scribbled on it so that it's unrecoverable by undeletion
utilities.

For a simple shredder, I think you can use open() to open up the target
file, and write() to scribble all over it.  You can then rewind the file
by using seek() and then repeat this a few dozen times.  However, I am not
a security person, so perhaps there may be some complications involved!


I did some hunting with Google, and came up with a few interesting links:


The SANS institute gives a brief overview on deleting files securely:

    http://rr.sans.org/incident/deletion.php

The GNU 'fileutils' package that's distributed with most Unices contains a
utility calls 'shred' that takes a similar approach to the one outlined
above:

    http://www.gnu.org/manual/fileutils-4.1/html_node/fileutils_43.html


Along with 'shred' is a program called 'wipe':

    http://wipe.sourceforge.net/


Good luck!


---------- Forwarded message ----------
Date: Sat, 7 Dec 2002 08:31:33 EST
From: Jmllr891@cs.com
To: dyoo@hkn.eecs.berkeley.edu
Subject: Re: [Tutor] Working with memory in Python?

Sorry, I didn't mean to be so unclear.

What I mean by working with memory is finding the address of a given file and
being able to remove that file by overwriting it's address (such as the way a
computer does when it finally deletes a file).

To be specific, I am trying to write my own file shredder and I am not yet
experienced enough with C to do so, so I'm trying to do it in Python. Also, I
may not be using the correct terminology for what I'm trying to do...I'm a
complete newbie when it comes to system level programming of this nature.

I'll try to be more clear in the future, I hope this doesn't confuse you
more!



From dyoo@hkn.eecs.berkeley.edu  Sat Dec  7 17:27:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat Dec  7 17:27:02 2002
Subject: [Tutor] [Standard library documentation, strings, lists, regexes]
Message-ID: <Pine.LNX.4.44.0212071407430.13217-100000@hkn.eecs.berkeley.edu>

Hi Geoff,

I'm redirecting this to Tutor so that everyone there has a chance to help
answer your question.


It's a good idea to send replies to Tutor rather than just to me: I might
have a cold, or feel grumpy, or be hungry enough to stray from the
keyboard.  By sending to the whole list, you'll allow others the
opportunity to answer your questions.


Here are a few quick links that you can browse:

    http://www.python.org/doc/lib/
    http://www.python.org/doc/lib/string-methods.html
    http://www.python.org/doc/lib/typesseq-mutable.html
    http://www.amk.ca/python/howto/regex/

The first is the location of the Library Reference, which houses the
documentation on all the functions.  It's very useful... if a little
large.  Don't feel overwhelmed: it's more of a reference manual, so we can
just pick out the stuff we're interested in.


The second and third links describe functions that deal specifically with
strings and lists, so you might find them helpful.  (By the way, when you
see the imposing term "Mutable Sequence Types" in section 2.2.6.4, in the
documentation, think "List".  Who knows why the docs don't just go out and
say "List"?  *grin*)


The fourth is an in-depth tutorial on Python's 'regular expression'
engine.  Regular expressions are a powerful way of processing text, and
includes a more powerful split()er that can take multiple delimiters; it
takes a little getting used to though, but you may find it good enough.


Good luck!


---------- Forwarded message ----------
Date: Sat, 07 Dec 2002 08:55:36 -0500
From: gmlloyd <gmlloyd@onlink.net>
To: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] re Python built-in methods, functions, libraries,
      etc.[unichr()]

Hi Danny. Thanks!

Background: I want to write a program that will generate an index for my log
files.

I have started with several 'word-count' programs I've found, but ran into
some unfamiliar methods & functions e.g. split, sort, strip, etc.. While
the names are descriptive they don't fully reveal the command - hence my
question re online lists of Python's built-in methods & functions.

Further: I understand that Python commands are written in C - suggesting
commands can be modified.

For example: could the split command [split(s[, sep[, maxsplit]])] be
modified to accept more than one 'sep' argument? That odd suggestion
reflects my goal (generating an index for my log files): I don't see any
simple software method of distinguishing nouns & adjectives in my logs -
but splitting on the basis of connectives & aricles (to, the, in, etc.)
might leave the noun - adjective relationship intact (more meaningful
index entries I hope).

So, to summarize: I need a way to explore (& possibly modify) unfamiliar
commands. I appreciate the value of the built-in help & type function when
dealing with individual cases but I assume that complete information on
all built-in methods & functions must be gathered together somewhere (I
guess it's time to invest in a good Python manual).


Thanks you for a very interesting reply!!

Geoff Lloyd

Danny Yoo wrote:

> On Fri, 6 Dec 2002, gmlloyd wrote:
>
> > Can you suggest some online lists/discussions of Python's built-in
> > methods & functions, Python libraries, etc.
>
> Hi Geoff,
>
> We occasionally talk about some of the builtin functions here on Tutor;
> you might be able to find some archives of our discussions here:
>
>     http://mail.python.org/pipermail/tutor/
>
> Is there a particular builtin that you're interested in?  Maybe we could
> have some sort of "builtin-of-the-week" feature that someone can write
> up...
>
> I'll kick it off.  *grin*
>
> Let's see... let's pick something out of the hat at random.
>
> ###
> >>> import random
> >>> random.choice(dir(__builtins__))
> 'unichr'
> ###
>
> What is 'unichr'?
>
> ###
> >>> type(unichr)
> <type 'builtin_function_or_method'>
> >>> callable(unichr)
> 1
> ###
>
> I've used the builtin 'type()' function, that tells us what kind of thing
> we're looking at.  'unichr' looks like a function, and we've verified that
> it's callable.
>
> We can find out more about unichr() by either looking at the documentation
> at:
>
>     http://www.python.org/doc/lib/built-in-funcs.html
>
> ... or, we can also take advantage of the builtin help() that lets us
> query for more information:
>
> ###
> >>> help(unichr)
>
> Help on built-in function unichr:
>
> unichr(...)
>     unichr(i) -> Unicode character
>
>     Return a Unicode string of one character with ordinal i; 0 <= i <=
> 0x10ffff.
> ###
>
> 'unichr()', then, is a function that takes an integer between 0 and
> 0x10fff, and returns the unicode string for that character.  For example,
> I was curious, so I visited:
>
>     http://www.unicode.org/charts/
>
> and picked a random character out of the Hangul Syllables:
>
> ###
> >>> my_unicode_char = unichr(0xc720)
> >>> my_unicode_char
> u'\uc720'
> ###
>
> C720, according to the Unocde Code Pages, is a single Hangul character.
> In ASCII-art, it sorta looks like this:
>
>       +-+
>       +-+
>     -------
>       | |
>
> Unicode is meant to represent a vast majority of languages in the world,
> and most web browsers support it, so even if we can't see it from our
> console, we might have some success seeing it by rendering it into a Web
> page, and then looking at it from our favorite browser:
>
> ###
> >>> my_unicode_char = unichr(0xC720)
> >>> f = open('test-unicode.html', 'w')
> >>> f.write('''<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> ... <html>
> ... <head>
> ... <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
> ... </head>
> ... <body>
> ... <h1>My first Unicode character: %s</h1>
> ... </body>
> ... </html>''' % my_unicode_char.encode('utf-8'))
> >>> f.close()
> ###
>
> For those who don't want to type all that, but still want to see the
> results, I've put up the HTML generated by that program here:
>
>     http://hkn.eecs.berkeley.edu/~dyoo/test-unicode.html
>
> So, in summary, unichr() lets us write out a single unicode character if
> we know its numeric code.
>
> I hope this was somewhat interesting!




From dyoo@hkn.eecs.berkeley.edu  Sat Dec  7 18:05:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat Dec  7 18:05:02 2002
Subject: [Tutor] [part-of-speech tagging / montytagger / penn treebank]
In-Reply-To: <Pine.LNX.4.44.0212071407430.13217-100000@hkn.eecs.berkeley.edu>
Message-ID: <Pine.LNX.4.44.0212071438130.13217-100000@hkn.eecs.berkeley.edu>

> For example: could the split command [split(s[, sep[, maxsplit]])] be
> modified to accept more than one 'sep' argument? That odd suggestion
> reflects my goal (generating an index for my log files): I don't see any
> simple software method of distinguishing nouns & adjectives in my logs -
> but splitting on the basis of connectives & aricles (to, the, in, etc.)
> might leave the noun - adjective relationship intact (more meaningful
> index entries I hope).


Hmmm... I just did a quick check, and ran into the following:

    http://web.media.mit.edu/~hugo/research/montytagger.html

In Natural Language Processing (NLP), a common task that NLP researchers
do is take a sentence and attach part-of-speech roles to each word.


Here's a brief run through the program:

###
dyoo@coffeetable:~/montytagger-1.0/python$ python MontyTagger.py

***** INITIALIZING ******
Lexicon OK!
LexicalRuleParser OK!
ContextualRuleParser OK!
*************************

MontyTagger v1.0
--send bug reports to hugo@media.mit.edu--


> This is a test of the emergency broadcast system

This/DT is/VBZ a/DT test/NN of/IN the/DT emergency/NN broadcast/NN
system/NN
-- monty took 0.02 seconds. --

> In a hole, there lived a hobbit.

In/IN a/DT hole/NN ,/, there/EX lived/VBD a/DT hobbit/NN ./.
-- monty took 0.19 seconds.
###


Wow!  This is pretty neat!


This program takes a sentence, and tries its best to attach part-of-speech
tags to each word.  Here are the meanings of some of those tags:

    DT  --> determiner
    IN  --> preposition or subordinating conjunction
    VBZ --> verb, 3rd person singular present
    NN  --> noun, singular or mass
    EX  --> Existential there
    VBD --> Verb, past tense

I do not know a single one of these tags yet.  *grin* But there is a good
list of them in the Penn Treebank Project:

    http://www.cis.upenn.edu/~treebank/
    ftp://ftp.cis.upenn.edu/pub/treebank/doc/tagguide.ps.gz


Good luck to you!



From magnus@thinkware.se  Sat Dec  7 18:06:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat Dec  7 18:06:02 2002
Subject: [Tutor] Working with memory in Python? (fwd)
In-Reply-To: <Pine.LNX.4.44.0212071346290.13217-100000@hkn.eecs.berkeley
 .edu>
Message-ID: <5.1.0.14.0.20021207235427.00bd7c28@www.thinkware.se>

At 14:06 2002-12-07 -0800, Danny Yoo wrote:
>For a simple shredder, I think you can use open() to open up the target
>file, and write() to scribble all over it.  You can then rewind the file
>by using seek() and then repeat this a few dozen times.  However, I am not
>a security person, so perhaps there may be some complications involved!

Neither am I, but I can think of some...

If you ever opened and read the file, parts of it might
be left in a swap file / partition on the disk...

If you ever defragmented the disk, some file blocks that
used to be used by this file might now be "unused", still
containing parts of your files. Even if these blocks are
overwritten by other files, they aren't overeritten in
military grade ways...

Even if you don't defrag your disk, I imagine that if the
file gets smaller at some point of editing, the blocks no
longer used can be claimed by other files but not cleaned
from your sensitive content in a safe way.

If you edit the sensitive file with some program that keeps
temporary backup files, you will have disk blocks with your
sensitive data in places outside your file.

I think you can safely shred a dick if you just grind it
into small enough pieces, but seriously, if you get rid of
a computer that used to contain sensitive data, at least
run some shredding software that overwrites the whole disk
several times. Erasing single files can't possibly be safe.

Rule 1. Keep your secrets away from computers.

Rule 2. If you can't follow Rule 1, make sure your
computer is not networked, and that it's physically
secure.

Rule 3. There is no Rule 3. ;)


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Sat Dec  7 18:38:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat Dec  7 18:38:01 2002
Subject: [Tutor] [Standard library documentation, strings, lists,
 regexes]
In-Reply-To: <Pine.LNX.4.44.0212071407430.13217-100000@hkn.eecs.berkeley
 .edu>
Message-ID: <5.1.0.14.0.20021208000947.00bd7910@www.thinkware.se>

gmlloyd wrote:
>For example: could the split command [split(s[, sep[, maxsplit]])] be
>modified to accept more than one 'sep' argument?

Sure, but it would no longer be Python.

I'm sure there are much better ways of solving this than to
try to twist python into being Geoffthon instead. You can do
it, but you will sit there with a large maintenace burden. It
means that you must always build python from source, apply
your patches on every python upgrade, other python people
won't run your code, and will have problems helping you, and
you will probably end up being unable to run standard python
programs in the end.

The odds are very high that someone else have found a good
way of doing what you are trying to accomplish in python
withut hacking the language.

>I don't see any simple software method

I'm sure there are plenty that are a lot simpler than to
modify the language.

>of distinguishing nouns & adjectives in my logs -
>but splitting on the basis of connectives & aricles (to, the, in, etc.)
>might leave the noun - adjective relationship intact (more meaningful
>index entries I hope).

 >>> splitwords = ['to', 'the', 'in']
 >>> text = "Go to the car in the yard."
 >>> for word in splitwords:
...     text = text.replace(word, '#')
...
 >>> print text.split('#')
['Go ', ' ', ' car ', ' ', ' yard.']

I think this is equivalent with your modified split proposal.
I'm not sure it's what you really want though. Natural language
is tricky.

Actually, with the latest versions of python, you
can (if you really think it's a good idea) subclass
string, and make your own split method.

 >>> class myString(str):
...     def multiSplit(self, *args):
...             thisWontBeInTheString = "\0"
...             for word in args:
...                     self = self.replace(word, thisWontBeInTheString)
...             return self.split(thisWontBeInTheString)
...
 >>> a = myString('There was a house in New Orleans, they call the Rising Sun')
 >>> a.multiSplit('a', 'the', 'in', 'they')
['There w', 's ', ' house ', ' New Orle', 'ns, ', 'y c', 'll ', ' Ris', 'g 
Sun']
 >>> # Woops! Regular expressions are probably a better idea...


>I need a way to explore

http://www.python.org/doc/current/lib/lib.html

>(& possibly modify)

Don't bother...except by subclassing in Python.

>unfamiliar
>commands. I appreciate the value of the built-in help & type function when
>dealing with individual cases but I assume that complete information on
>all built-in methods & functions must be gathered together somewhere (I
>guess it's time to invest in a good Python manual).

If you want a paper thingie, you might appreciate
Python Essential Reference (2nd Edition) by David M. Beazley

It's probably the best reference book. Be aware that Python
develops fairly quickly these days though. The official
documentation is the only one you can count on to be properly
up-to-date.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From jimmy_130@lycos.com  Sat Dec  7 22:44:10 2002
From: jimmy_130@lycos.com (James M Lang)
Date: Sat Dec  7 22:44:10 2002
Subject: [Tutor] How different is math logic from computer logic?
Message-ID: <MHHPAJHBHCNDEAAA@mailcity.com>

I was sitting there one day at a night math class, waiting for the class to end. Just as it was time to leave, the teacher gave us a little quiz to see how much we knew about Logic. I was thinking, "Woohoo! Just like computers." Unfortunately, it seems to me that the logic my math book is talking anout has nothing (well, almost) to do with computer logic. Exactly how different are they anyway? For example:
If I work, I cannot study. Either I work or I pass Math. I pass Math. Therfore, I studied.

After calling my friend, we agreed that it would be that it was a true statement. Yet, the truth tables said that it was both. I am confused.


_____________________________________________________________
Get 25MB, POP3, Spam Filtering with LYCOS MAIL PLUS for $19.95/year.
http://login.mail.lycos.com/brandPage.shtml?pageId=plus&ref=lmtplus


From dyoo@hkn.eecs.berkeley.edu  Sun Dec  8 00:36:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun Dec  8 00:36:01 2002
Subject: [Tutor] How different is math logic from computer logic?
 [prop-0.7 released]
In-Reply-To: <MHHPAJHBHCNDEAAA@mailcity.com>
Message-ID: <Pine.LNX.4.44.0212072027490.13217-100000@hkn.eecs.berkeley.edu>


On Sat, 7 Dec 2002, James M Lang wrote:

> Unfortunately, it seems to me that the logic my math book is talking
> about has nothing (well, almost) to do with computer logic.  Exactly how
> different are they anyway?
>
> For example: If I work, I cannot study. Either I work or I pass Math. I
> pass Math. Therfore, I studied.

Hi James,


Let's pretend, for a moment, that this was some kind of program request.
The statements above are in English, and English is a highly charged
language.


Just as we'd translate a process into Python statements to keep from
getting confused, we can translate English sentences into logic statements
that we can manipulate without confusion.

Let's say that we have the following variables:

    work
    study
    pass_math

There are a few statements I saw in there, along with a conclusion:

    1.  If I work, I cannot study.
    2.  Either I work or I pass math
    3.  I pass math.
    4.  Therefore, I studied.


Let's pretend that we had a parser that can take these and turn them into
formal logic statements.

###
>>> import prop
>>> s1 = prop.parse('work implies not study')
>>> s2 = prop.parse('work or pass_math')
>>> s3 = prop.parse('pass_math')
>>> s1
implication[work, not[study]]
>>> s2
or[work, pass_math]
>>> s3
pass_math
>>> whole = prop.ImplicationNode(prop.AndNode(s1, s2, s3),
...                              prop.parse('study'))
>>> whole
implication[and[implication[work, not[study]],
                or[work, pass_math],
                pass_math],
            study]
###



> After calling my friend, we agreed that it would be that it was a true
> statement.

There are many cases where it will hold, so that's why you might feel the
whole statement is always true.  But, just as in programs, there can be
bugs in our reasoning where we don't see everything.

What if you passed math, and worked, but didn't study?  What does our
whole statement evaluate to?



I've written a tool that may help you explore logic a little more; it's a
propositional parser in Python:

    http://hkn.eecs.berkeley.edu/~dyoo/python/propositions/prop-0.7.tar.gz

It is not linked up on my web page yet, because I'm still not certain if I
ironed out all the bugs yet; it's been such a long time since I dusted it
off!  *grin* I want to double check it a bit more before announcing it
formally again.



From idiot1@netzero.net  Sun Dec  8 04:16:01 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Sun Dec  8 04:16:01 2002
Subject: [Tutor] blogs  cue the singing vikings: BLOG, BLOG BLOG BLOG, BLOG, BLOG
 BLOG BLOG...
Message-ID: <3DF30E40.5030508@netzero.net>

I THINK THEY ARE INFECTIOUS.
Blogs, that is.

Seems to be almost as popular as athlete's foot; no one really raves about 
them, every one gets it sooner or later, You just cannot avoid them, they're
EVERYWHERE; they are the web's BORG it would seem.

OK, I decided to write one as a giggle.
	http://www.tinylist.org/myblog.shtml

Still dithering on how to handle the display of a posting, at the moment it is 
accomplished 2 ways.

MAYBE I will simply dump the luser back onto the form page in some sort of a 
redirect- it's a  plain vanilla form, using a little ssi tag include to bring 
the blog file into the otherwise static web page. Displays nice, no stray bits 
flopping all over needing cleaning up. Try posting to it.

Creating the page on the fly in the script to instantly display your posting
along with the existing blog is complex and for the moment somewhat DAIM 
BRAMAGED (or is that ue to it being 4 am?), and needs more work- and why 
should I bother, if I can trick the browser and server into doing it for me?

But I am going to bed. play with it, think about it for several seconds, and 
write a letter to the tutor list. When I think it is actually worth exposing 
to the world, I will stick in  in useless python or the vaults of 
Parnissyiusumous#%&#%&%howerver ya spell it....

Good night all.
-- 

end

Respectfully,
              Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                            +--------+

---------------------------------------------
Introducing NetZero Long Distance
1st month Free!
Sign up today at: www.netzerolongdistance.com


From thomi@thomi.imail.net.nz  Sun Dec  8 04:50:01 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Sun Dec  8 04:50:01 2002
Subject: [Tutor] blogs  cue the singing vikings: BLOG, BLOG BLOG BLOG, BLOG, BLOG BLOG BLOG...
In-Reply-To: <3DF30E40.5030508@netzero.net>
References: <3DF30E40.5030508@netzero.net>
Message-ID: <20021208224938.1e546a23.thomi@thomi.imail.net.nz>

oops! and whatever you do, do not press the reload button on your
browser :-)

-- 
The software required Win95 or better, so I installed Linux.
Thomi Richards,
thomi@imail.net.nz


From GREENDAY31087@aol.com  Sun Dec  8 14:17:02 2002
From: GREENDAY31087@aol.com (GREENDAY31087@aol.com)
Date: Sun Dec  8 14:17:02 2002
Subject: [Tutor] I need a tutor
Message-ID: <4f.27f178ef.2b24f455@aol.com>

--part1_4f.27f178ef.2b24f455_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

Hello. I'm Wayne. I am a newbie but I have an Active Python so I'm prepared 
to learn. I figured I should practice DOS batch files first because they're 
so basic and it'll be easier to learn a second language. I now know that many 
commands in different languages are similar (print, echo, printf). So if 
anyone wants to teach, tell me, OK?
-Wayne 

--part1_4f.27f178ef.2b24f455_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

<HTML><FONT FACE=arial,helvetica><FONT  SIZE=2 FAMILY="SANSSERIF" FACE="Arial" LANG="0">Hello. I'm Wayne. I am a newbie but I have an Active Python so I'm prepared to learn. I figured I should practice DOS batch files first because they're so basic and it'll be easier to learn a second language. I now know that many commands in different languages are similar (print, echo, printf). So if anyone wants to teach, tell me, OK?<BR>
-Wayne </FONT></HTML>

--part1_4f.27f178ef.2b24f455_boundary--


From Adam Vardy <anvardy@roadrunner.nf.net>  Sun Dec  8 16:02:02 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Sun Dec  8 16:02:02 2002
Subject: [Tutor] How different is math logic from computer logic?  [prop-0.7 released]
In-Reply-To: <Pine.LNX.4.44.0212072027490.13217-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.44.0212072027490.13217-100000@hkn.eecs.berkeley.edu>
Message-ID: <81132961869.20021208173115@roadrunner.nf.net>

Say, anyone know a good intro webpage on Propositional logic?

James, maybe if you number your statements there, and say which one you
say/think is true, it could be easier to reflect about it.

-- 
Adam Vardy



From alan.gauld@bt.com  Sun Dec  8 18:07:23 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun Dec  8 18:07:23 2002
Subject: [Tutor] Asterisk
Message-ID: <7497DCA1C240C042B28F6657ADFD8E09702257@i2km11-ukbr.domain1.systemhost.net>

Catching up on old digests...

> >Why does this happen? It is a strange expression.
> >>>>'%*.*f' % (6,3,1.41421356)
> >' 1.414'

Had me beat!

>  >>> "%*.*f" % (6,3,1.41421356)
> ' 1.414'
>  >>> "%*.*f" % (10,5,1.41421356)
> '   1.41421'

Ah, I see!
Awesome. I've been doing it using two format strings:

fmt = "%%d.%df" % (width, precision)
print fmt % value

The asterisk notation is neat, but I'd never have guessed it!

Thanks for that one Adam and Gregor.


From alan.gauld@bt.com  Sun Dec  8 18:10:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun Dec  8 18:10:02 2002
Subject: [Tutor] Asterisk
Message-ID: <7497DCA1C240C042B28F6657ADFD8E09702258@i2km11-ukbr.domain1.systemhost.net>

> Is rtfm a verb? An acronym? Probably both?
> What does it mean?

Politely, its "Read The Fine Manual"... 
Other choices for 'F' are sometimes seen! :-)

Alan G


From alan.gauld@bt.com  Sun Dec  8 18:33:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun Dec  8 18:33:01 2002
Subject: [Tutor] communication between class instances
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0974DA5E@i2km11-ukbr.domain1.systemhost.net>

Because I'm reading this digest way late this has likely been
answered already, however here goes my take on the subject...
(regular readers probably know what I'm gonna say! )

> So far, instantiating classes and passing references to all 
> other class instances that the instance will need to 
> communicate with is the only way I've come up with to 
> get class instances to communicate with each 
> other.  

That's the normal way of doing it except...

> a better way to pass data between class instances?  

...You shouldn't be thinking about passing data you should 
think about passing messages. Its a subtle but important 
distinction. A message may of course contain a reference 
to an object.

Of course for an object to send a message to amother object 
it must somehow get a reference to it. The reference could 
come in as part of a higher level messaage or it could be 
stored as a member attribute (maybe set up during initialisation)

So we have a few alternatives. What do we do?
Think about responsibilies. Decide which classes are "managers" 
of other classes - the GUI might manage the menu in your case...
The app ultimately manages everything, but it does so my 
delegating responsibility across a relatively few subordinate 
classes which it stores and talks to itself. In your case 
the app probably should know about the database and the 
GUI but not the menu. The GUI/DB possibly want to hold references 
to the app too, so they can send messages to it(done by passing 
self in from the app during initialisation). 

Any menu things going on should be controlled by the GUI. 
When the menu is created usually a callback function 
is passed to each menu item. This is probably done by the GUI 
but the callback could be an app level function obtained by 
the GUI via the link back to the app.

At this point we begin to see why OO designers like to draw 
diagrams to show the interconnections between their classes!

> is having to pass a reference to the app instance all the way down to 
> the menu instance, which really should only be aware of the 
> gui instance which instantiates it. Right?

It needn't even be aware of the GUI. The GUI will be aware of 
the menu but the menu doesn't need to be aware of the GUI. It 
may have a callback link to a specific function but it doesn't 
care where that function/method exists

> Right?

Pretty much yeah.

> I'm very confused...

Don't worry the apparent lack of structure in an OO design is 
one of the things that makes adapting to OO thinking a steep 
learning curve. Some folks find it natural, most find the seeming 
anarchy ghard to get a grip on.

HTH,

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld


From jofet@hotmail.com  Sun Dec  8 18:38:02 2002
From: jofet@hotmail.com (jofet torrefranca)
Date: Sun Dec  8 18:38:02 2002
Subject: [Tutor] (no subject)
Message-ID: <F19Xb0zrAXBirbThA9Q00004f59@hotmail.com>


is there a way i can control my parallel or communications port on my PC 
using Python? am new to this langauge, please show me where to start. thanks



_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*  
http://join.msn.com/?page=features/junkmail



From alan.gauld@bt.com  Sun Dec  8 18:49:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun Dec  8 18:49:01 2002
Subject: [Tutor] global variables
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0970225A@i2km11-ukbr.domain1.systemhost.net>

In addition to the other answers I'll add another reason.
If you use global variables instead of passing them into 
functions via parameters then you seriously limit the 
reusability of your functions. Example:

x = 0

def add5():
   return x+5

print x, add5()  #-> 0,5  which is good

But what if we want to add5 to some other number? It gets messy:

y = 7  # our new target

temp = x         # store current x someplace
x = y            # set up x with our new target, y
print y, add5()  #-> 7,12 which is what we wanted

But now we have to remember to restore the old x again...

x = temp

Its much better to make x a parameter of add5:

def add5(x): return x+5

Now we do:

x = 0
print x,add5(x)  #-> still 0,5
y = 7
print y,add5(y)  #-> still 7,12

But the code is easier to maintain.

This becomes even more important when you get to the stage of 
trying to write programs that do things in parallel (called 
multi threading). If you use global variables you can't safely 
call a function like the original add5(), even if you set up 
x correcty because at any time the parallel thread may come 
and reset it just before you make your call to add5()... 
the result is you get the wrong value and can't see why.

Just one other reason to avoid them.

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld


From magnus@thinkware.se  Sun Dec  8 19:01:06 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sun Dec  8 19:01:06 2002
Subject: [Tutor] How different is math logic from computer logic?
In-Reply-To: <MHHPAJHBHCNDEAAA@mailcity.com>
Message-ID: <5.1.0.14.0.20021208224228.02abaff8@www.thinkware.se>

Computer logic is 19th century math logic. It's certainly
present in todays programming languages, but due to the
advanced modern computers and the level of abstraction in
programming languages like Python, you don't have to use it
all the time...

You can write something like "print 5 + 3 * 7" and let the
software and hardware turn all that into logic expressions.

At 22:43 2002-12-07 -0500, James M Lang wrote:
>If I work, I cannot study. Either I work or I pass Math. I pass Math. 
>Therfore, I studied.

I'd say this is "philosophy logic" rather than "math logic".
Although, when Aristotele invented this in the 4th century BC,
I don't think people made any distinction. Aristotele's main
interest was syllogism, the kind of conclusion drawing that you
give an example of above.

In the 19th century, british mathematician George Boole introduced
symbolic logic or Boolean Algebra as we call it today. Basically,
he made a simple and a complete algebraic system containing only two
"digits": True and False, and three operations, AND, OR and NOT. If
we use the following symbols:

True: 1
False: 0
And: *
Or: +

We end up with something very similar to ordinary algebra:

0 * 0 = 0
0 * 1 = 0
1 * 0 = 0
1 * 1 = 1

This means that if we have two statements A and B, then the
statement "A and B" will only be true if both A and B are
true.

0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 1

This means that "A or B" is only true is at least one of A or
B are true.

The last one "1+1=1" is obviously different from normal argebra, but
7 out of 8 isn't bad? ;) So, this is a slightly different system
than normal algebra, and it's purpose was to make it possible to
handle logic issues as if they where mathematical equations.

Note that there is a source of confusion here. When we normally say
"5 and 3 is 8", we mean "5 + 3 = 8", but logic AND isn't written with
'+' but with '*'. This is because logical AND resembles multiplication
very much, and logical OR is more similar to addition, as you see above.

But there is one opetaion missing: NOT. The NOT operator is often
written with a bar above the symbol, like this:
_
X

But that's inconvenient with email etc, so now we often write !
instead, and thus we get:

1 = !0 (True is not false)
0 = !1 (False is not true)

Then we can write things like "I will go out if it's not raining
and if it's warm" like:

will_go_out = !raining * warm

Normal English is a little tricky. A sentence like "I will go
out if it's not raining and if it's warm or if I have a warm
coat" might either mean...

will_go_out = (!raining * warm) + warm_coat

...or...

will_go_out = !raining * (warm + warm_coat)

...the difference being whether I will go out if I have a warm
coat, it's not warm, and it's raining. As you see, all contracts
ought to be written in Boolean Algebra instead of English etc
to avoid these kinds of ambiguities. Boolean logic binds * harder
than + just like normal algebra, so

will_go_out = !raining * warm + warm_coat

means the same as

will_go_out = (!raining * warm) + warm_coat

By making much more complex boolean equations we can perform
ordinary algebraic additions, subtractions, multiplications etc.

For instance, to be able to add two two bit positive numbers
(in other words 0, 1, 2 or 3) like this:
0 + 0 = 0
0 + 1 = 1
0 + 2 = 2
...
3 + 3 = 6

Or in binary:
00+00=000
00+01=001
00+10=010
00+11=011
01+00=001
01+01=010
01+10=011
01+11=100
10+00=010
10+01=011
10+10=100
10+11=101
11+00=011
11+01=100
11+10=101
11+11=110

You need three equations, since you need three output bits (6 is
110 in binary, a three bit value, right?)

Assuming the four input bits are called I1 to I4, and the
output bits are called O1 to O3, the following logic equation will
do the job.

O1 = I1 AND I2 AND I4 OR I2 AND I3 AND I4 OR I1 AND I3

O2 = I1 AND I2 AND I3 AND I4 OR NOT I1 AND I2 AND NOT I3 AND I4 OR
      I1 AND NOT I2 AND NOT I3 OR I1 AND NOT I3 AND NOT I4 OR NOT I1
      AND NOT I2 AND I3 OR NOT I1 AND I3 AND NOT I4

O3 = I2 AND NOT I4 OR NOT I2 AND I4

O3 is the simplest equation. It says that the output will be
odd if either input (but not both) are odd.

(A modern CPU will be slightly more complex ;) and do things like
multiply or divide two 32 bit numbers. I'm not going to show
complete equations for that... It's not your problem unless you
design a brand new CPU...)

As you know, transistors, and later integrated circuits with many
transistors (etc) on a chip of e.g. silicon, were invented in the
middle of the last century. IIRC, it was in a M.Sc. paper at MIT,
that someone suggested that the combination of transistors and
Boolean Algebra could be used to build calculation machines.

By using a convention like current on = true and current off = false
(or vice versa, or let the voltages control rather than the current)
we can model our states true and false.

Using a few transistors, we can build circuits that perform the
boolean operations AND, OR and NOT.

This URL gives an example of how to add two binary digits with
transistor based circuits that model Boolean Algebra.
http://isweb.redwoods.cc.ca.us/INSTRUCT/CalderwoodD/diglogic/full.htm

You can look at http://www.play-hookey.com/digital/ to find out more
about that kind of components that computers are built on.

Once upon a time, this was central to all programming, but as I
wrote in the beginning, we don't need to bother with this all the
time now.

We do have the tools to do it if we want though.

Python has the logic operators like and, not and or. It has
binary operators like &, | and ^. You have if-statements and
you can write expressions. So, using Python to describe logic
is typically simple. What is not so simple is to make the
computer draw conclusions based on your facts. Other programming
languages are better at that. Prolog for instance.


/Magnus


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Sun Dec  8 19:03:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sun Dec  8 19:03:01 2002
Subject: [Tutor] (no subject)
In-Reply-To: <F19Xb0zrAXBirbThA9Q00004f59@hotmail.com>
Message-ID: <5.1.0.14.0.20021209010347.02ad76d8@www.thinkware.se>

At 10:15 2002-12-08 +0800, jofet torrefranca wrote:
>is there a way i can control my parallel or communications port on my PC 
>using Python? am new to this langauge, please show me where to start. thanks

Search Google for "python serial port" and "python parallel port".


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From dyoo@hkn.eecs.berkeley.edu  Sun Dec  8 19:05:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun Dec  8 19:05:02 2002
Subject: [Tutor] I need a tutor   [We need a question]
In-Reply-To: <4f.27f178ef.2b24f455@aol.com>
Message-ID: <Pine.LNX.4.44.0212081551530.11948-100000@hkn.eecs.berkeley.edu>


On Sun, 8 Dec 2002 GREENDAY31087@aol.com wrote:

> Hello. I'm Wayne. I am a newbie but I have an Active Python so I'm
> prepared to learn. I figured I should practice DOS batch files first
> because they're so basic and it'll be easier to learn a second language.
> I now know that many commands in different languages are similar (print,
> echo, printf). So if anyone wants to teach, tell me, OK? -Wayne

Hi Wayne,

Python-tutor isn't really a one-to-one tutoring thing: it's more like a
one-to-many thing.  Think of it as education by the mob.  *grin*


If you ask a question on Tutor, you may get several replies from any of
the other list members.  This is often a good thing, since you get several
diverse perspectives.  The downside of this community effort is that we
can't just start lecturing from nothing: we really need a question to keep
our focus on.  We want to directly address the things that you're having
problems with.


Do you have a specific question on Python?  It sounds like you're very new
to Python, so if you're looking for some introductory stuff to read
through, you can look at:

    http://python.org/doc/Newbies.html

which links up with many good Python tutorials.  You can just take one and
start playing with the examples.  When some confusing point comes up, you
can always drop by here and ask a question about it.


Good luck to you!



From alan.gauld@bt.com  Sun Dec  8 19:06:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun Dec  8 19:06:02 2002
Subject: [Tutor] The case of the scrolling label....
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0970225B@i2km11-ukbr.domain1.systemhost.net>

> I am putting up a label when an improper entry is received.
> 
> Label(text='Invalid Entry').pack() # Tk

Usually its better to have an empty label already within the GUI 
design then simply set its text attribute....

> Works fine. But how do I get rid of it? Multiple improper 
> entries yield:
> 
> Invalid Entry
> Invalid Entry
> Invalid Entry

If you really must create them dynamically you should find an 
unpack() method exists (it certainly does in Tcl/Tk itself!)

> I want to be able to place labels (or a "clear") 

Just clear the text attribute of the original Label...

lError = Label(parent,.....)
lError.pack(....)
lError['text'] = "Invalid Entry"  # set it
lError['text'] = ""               # clear it


> Is it possible without placing the
> label in its own frame?

Why not use a frame? Frames are your friend when using Tk!
Especially with the packer layout manager...

Alan g.


From alan.gauld@bt.com  Sun Dec  8 19:12:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun Dec  8 19:12:01 2002
Subject: [Tutor] How different is math logic from computer logic?
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0970225C@i2km11-ukbr.domain1.systemhost.net>

> Unfortunately, it seems to me that the logic my math book is 
> talking anout has nothing (well, almost) to do with computer 
> logic. Exactly how different are they anyway? For example:
> If I work, I cannot study. Either I work or I pass Math. I 
> pass Math. Therfore, I studied.
> 
> After calling my friend, we agreed that it would be that it 
> was a true statement. Yet, the truth tables said that it was 
> both. I am confused.

In this case the 'or' is exclusive thus you do one or the other 
but not both. Backwords reasoning like your example is the modus
operandi of programming languages like Prolog. The idea being 
that you describe your problem precisely to the computer and 
it then uses the description to deduce the answer. It is a 
different style to the imperative techniques used in Python
but very powerful for some types of problem.

Hopefully that gives some ideas for further investigation...

Alan g


From magnus@thinkware.se  Sun Dec  8 20:29:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sun Dec  8 20:29:01 2002
Subject: [Tutor] I need a tutor
In-Reply-To: <4f.27f178ef.2b24f455@aol.com>
Message-ID: <5.1.0.14.0.20021209010717.02ae4078@www.thinkware.se>

At 14:15 2002-12-08 -0500, GREENDAY31087@aol.com wrote:
>Hello. I'm Wayne. I am a newbie but I have an Active Python so I'm 
>prepared to learn. I figured I should practice DOS batch files first 
>because they're so basic and it'll be easier to learn a second language.

I'd skip that and go directly to python.

>I now know that many commands in different languages are similar (print, 
>echo, printf). So if anyone wants to teach, tell me, OK?

Start PythonWin from the start menu.

Click on Help -> Python manuals

Click in the tree on "Helpful resources" and follow
"An Easy Tutorial to Python". Obviously you can skip the
pieces about installation, and where IDLE is mentioned,
you might as well use PythonWin instead.

We answer further questions here. Of course you can also
have a private tutor, but perhaps not for free... ;)


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From idiot1@netzero.net  Sun Dec  8 23:36:20 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Sun Dec  8 23:36:20 2002
Subject: [Tutor] blog, blog blog blog, BLOG, blog blog blog...
Message-ID: <3DF41DCC.2080202@netzero.net>

MAde a few minor deprovements. reading some REALLY intresting (for lack of a 
better adjective) postings. My new blog seems to work as well as a bullitin 
board. Possibly I should modify the script so it can optionally be a secured 
by password thing, not sure if I want to do that, it seems rather novel as is.
		http://www.tinylist.org/myblog.shtml
Feedback, actual serious no kidding feedback, is saught.

-- 

end

Respectfully,
              Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                            +--------+

---------------------------------------------
Introducing NetZero Long Distance
1st month Free!
Sign up today at: www.netzerolongdistance.com


From idiot1@netzero.net  Mon Dec  9 00:38:02 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Mon Dec  9 00:38:02 2002
Subject: [Tutor] blog, blog blog blog, BLOG, blog blog blog...
References: <5.1.0.14.0.20021209160151.00a77b10@192.168.1.1>
Message-ID: <3DF42C8B.60907@netzero.net>

here is the link to the code as is. This will automagically update whenever I 
update the code.
http://www.tinylist.org/myblog.txt


Alfred Milgrom wrote:
> Hi Kirk:
> 
> I just tried posting to it, and I love the idea.
> One thing though - you must allow the 'owner' to edit existing blogs. 
> Can't think of a clean and easy interface, though.
> 
> Other things that are nice (but are not so urgent) are:
> - ability to comment on an existing blog
> - adding photos
> 
> Let me know when you have it in a state that you are happy to share the 
> code.
> Best regards,
> Fred Milgrom
> 
> 
> At 11:36 PM 8/12/02 -0500, you wrote:
> 
>> MAde a few minor deprovements. reading some REALLY intresting (for 
>> lack of a better adjective) postings. My new blog seems to work as 
>> well as a bullitin board. Possibly I should modify the script so it 
>> can optionally be a secured by password thing, not sure if I want to 
>> do that, it seems rather novel as is.
>>                 http://www.tinylist.org/myblog.shtml
>> Feedback, actual serious no kidding feedback, is saught.
> 
> 
> 
> 


-- 

end

Respectfully,
              Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                            +--------+

---------------------------------------------
Introducing NetZero Long Distance
1st month Free!
Sign up today at: www.netzerolongdistance.com


From idiot1@netzero.net  Mon Dec  9 00:41:04 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Mon Dec  9 00:41:04 2002
Subject: [Tutor] blog, blog blog blog, BLOG, blog blog blog...
References: <5.1.0.14.0.20021209160151.00a77b10@192.168.1.1>
Message-ID: <3DF42D31.5020607@netzero.net>

And this for the code of the webform page
	http://www.tinylist.org/myblogform.txt


Alfred Milgrom wrote:
> Hi Kirk:
> 
> I just tried posting to it, and I love the idea.
> One thing though - you must allow the 'owner' to edit existing blogs. 
> Can't think of a clean and easy interface, though.
> 
> Other things that are nice (but are not so urgent) are:
> - ability to comment on an existing blog
> - adding photos
> 
> Let me know when you have it in a state that you are happy to share the 
> code.
> Best regards,
> Fred Milgrom
> 
> 
> At 11:36 PM 8/12/02 -0500, you wrote:
> 
>> MAde a few minor deprovements. reading some REALLY intresting (for 
>> lack of a better adjective) postings. My new blog seems to work as 
>> well as a bullitin board. Possibly I should modify the script so it 
>> can optionally be a secured by password thing, not sure if I want to 
>> do that, it seems rather novel as is.
>>                 http://www.tinylist.org/myblog.shtml
>> Feedback, actual serious no kidding feedback, is saught.
> 
> 
> 
> 


-- 

end

Respectfully,
              Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                            +--------+

---------------------------------------------
Introducing NetZero Long Distance
1st month Free!
Sign up today at: www.netzerolongdistance.com


From antonmuhin@rambler.ru  Mon Dec  9 03:48:02 2002
From: antonmuhin@rambler.ru (=?windows-1251?Q?=E1=CE=D4=CF=CE_=ED=D5=C8=C9=CE?=)
Date: Mon Dec  9 03:48:02 2002
Subject: [Tutor] How different is math logic from computer logic?
In-Reply-To: <20021207222702.18146.31471.Mailman@mail.python.org>
Message-ID: <web-24246820@mail1.rambler.ru>

Hello, James!

It seems that you didn't reason correctly (at least formally):
'I pass math' really makes 'I work' false (given your statments). 
However, in this case you cannot deduce from 'If I work, I cannot 
study' is 'I study' true or false: 'If FALSE, then TRUE' and 'If 
FALSE, then FALSE' both true in traditional formal logic. This caveat 
of implication is a trditional source of misunderstanding of fromal 
logic.

Back to formal logic and computers. I think that all of computer 
languages use at least some part of loigc. Python operators like 
'and', 'not', 'or' all have meaning from logic, not from language. 
However, subset of logic used is usually rather small (no 
implications, etc). As it was said by Magnus, there are languages 
(e.g. Prolog) that use quite a lot of logical formal apparatus. Still 
you oughtn't to have Ph.D. in logic to be an excellent programmer :)

Regards,
Anton.


From glingl@aon.at  Mon Dec  9 05:26:01 2002
From: glingl@aon.at (Gregor Lingl)
Date: Mon Dec  9 05:26:01 2002
Subject: [Tutor] blog, blog blog blog, BLOG, blog blog blog...
References: <5.1.0.14.0.20021209160151.00a77b10@192.168.1.1> <3DF42D31.5020607@netzero.net>
Message-ID: <3DF46FA0.8010803@aon.at>

Kirk Bailey schrieb:

> And this for the code of the webform page
>     http://www.tinylist.org/myblogform.txt
>
>
> Alfred Milgrom wrote:
>
>> Hi Kirk:
>>
>> I just tried posting to it, and I love the idea.
>> One thing though - you must allow the 'owner' to edit existing blogs. 
>> Can't think of a clean and easy interface, though.
>
Oh! It seems, Alfred is going to reinvent the wiki!
(Why always reinvent only the wheel?) See:
http://www.c2.com/cgi/wiki?WikiWikiWeb
and not to forget:  http://moin.sourceforge.net/

Regards, Gregor

>>
>> Other things that are nice (but are not so urgent) are:
>> - ability to comment on an existing blog
>> - adding photos
>>
>> Let me know when you have it in a state that you are happy to share 
>> the code.
>> Best regards,
>> Fred Milgrom
>>
>>
>> At 11:36 PM 8/12/02 -0500, you wrote:
>>
>>> MAde a few minor deprovements. reading some REALLY intresting (for 
>>> lack of a better adjective) postings. My new blog seems to work as 
>>> well as a bullitin board. Possibly I should modify the script so it 
>>> can optionally be a secured by password thing, not sure if I want to 
>>> do that, it seems rather novel as is.
>>>                 http://www.tinylist.org/myblog.shtml
>>> Feedback, actual serious no kidding feedback, is saught.
>>
>>
>>
>>
>>
>
>






From thomi@thomi.imail.net.nz  Mon Dec  9 05:44:02 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Mon Dec  9 05:44:02 2002
Subject: [Tutor] cgi module and checkboxes.
Message-ID: <20021209234348.7d6c8393.thomi@thomi.imail.net.nz>

Hey,

what happens if you have a check box (say called "uid"), and you submit
it to a CGI, and get the results of the form using the cgi module? I'm
trying this, and for some reason, i cannot get it to work. I'm guessing
that the result would be a dictionary, with "uid" as the key, and a list
of all the check boxes which were ticked as the value? (or maybe a
tuple?)

I flicked through the documentation, but didn't see anything very useful
there, just something about files....

-- 
The software required Win95 or better, so I installed Linux.
Thomi Richards,
thomi@imail.net.nz


From rob@uselesspython.com  Mon Dec  9 09:09:01 2002
From: rob@uselesspython.com (Rob Andrews)
Date: Mon Dec  9 09:09:01 2002
Subject: [Tutor] cgi module and checkboxes.
In-Reply-To: <20021209234348.7d6c8393.thomi@thomi.imail.net.nz>
Message-ID: <MPEOIFCOPCIHEDCLBLPBCENMCMAA.rob@uselesspython.com>

Can you show an example of the code you're having problems with? Also, does
the rest of this CGI work if you leave off the part that doesn't seem to be
working?

Rob
http://uselesspython.com

> -----Original Message-----
> what happens if you have a check box (say called "uid"), and you submit
> it to a CGI, and get the results of the form using the cgi module? I'm
> trying this, and for some reason, i cannot get it to work. I'm guessing
> that the result would be a dictionary, with "uid" as the key, and a list
> of all the check boxes which were ticked as the value? (or maybe a
> tuple?)
>
> I flicked through the documentation, but didn't see anything very useful
> there, just something about files....




From S.Huijgen@Student.TUDelft.NL  Mon Dec  9 09:17:02 2002
From: S.Huijgen@Student.TUDelft.NL (Stephan Huijgen)
Date: Mon Dec  9 09:17:02 2002
Subject: [Tutor] How to integrate Matlab with Python
References: <MPEOIFCOPCIHEDCLBLPBCENMCMAA.rob@uselesspython.com>
Message-ID: <007101c29f8d$e7cea580$6501a8c0@superyethzer>

How can i integrate Matlab with Python? I have downloaded Pymath, but still
it is not clear to me.

Stephan Huijgen



From Doug.Shawhan@gecits.ge.com  Mon Dec  9 14:17:01 2002
From: Doug.Shawhan@gecits.ge.com (Doug.Shawhan@gecits.ge.com)
Date: Mon Dec  9 14:17:01 2002
Subject: [Tutor] blog, blog blog blog, BLOG, blog blog blog...
Message-ID: <47B6167F8E69D31194BA0008C7918D4205C54FAC@msxcvg02itscge.gecits.ge.com>

Steve Jensen's TinyBlog has some anydbm love that might help.

http://sieve.net/TinyBlog/

-----Original Message-----
From: Gregor Lingl [mailto:glingl@aon.at]
Sent: Monday, December 09, 2002 4:26 AM
To: Kirk Bailey
Cc: tutor
Subject: Re: [Tutor] blog, blog blog blog, BLOG, blog blog blog...


Kirk Bailey schrieb:

> And this for the code of the webform page
>     http://www.tinylist.org/myblogform.txt
>
>
> Alfred Milgrom wrote:
>
>> Hi Kirk:
>>
>> I just tried posting to it, and I love the idea.
>> One thing though - you must allow the 'owner' to edit existing blogs. 
>> Can't think of a clean and easy interface, though.
>
Oh! It seems, Alfred is going to reinvent the wiki!
(Why always reinvent only the wheel?) See:
http://www.c2.com/cgi/wiki?WikiWikiWeb
and not to forget:  http://moin.sourceforge.net/

Regards, Gregor

>>
>> Other things that are nice (but are not so urgent) are:
>> - ability to comment on an existing blog
>> - adding photos
>>
>> Let me know when you have it in a state that you are happy to share 
>> the code.
>> Best regards,
>> Fred Milgrom
>>
>>
>> At 11:36 PM 8/12/02 -0500, you wrote:
>>
>>> MAde a few minor deprovements. reading some REALLY intresting (for 
>>> lack of a better adjective) postings. My new blog seems to work as 
>>> well as a bullitin board. Possibly I should modify the script so it 
>>> can optionally be a secured by password thing, not sure if I want to 
>>> do that, it seems rather novel as is.
>>>                 http://www.tinylist.org/myblog.shtml
>>> Feedback, actual serious no kidding feedback, is saught.
>>
>>
>>
>>
>>
>
>





_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


From Adam Vardy <anvardy@roadrunner.nf.net>  Mon Dec  9 15:04:01 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Mon Dec  9 15:04:01 2002
Subject: [Tutor] Little apps
In-Reply-To: <5.1.0.14.0.20021205104017.02accdc8@www.thinkware.se>
References: <5.1.0.14.0.20021205104017.02accdc8@www.thinkware.se>
Message-ID: <158215879247.20021209163312@roadrunner.nf.net>

Thursday, December 5, 2002, 7:17:21 AM, you wrote:

>> At 23:16 2002-12-04 -0600, david wrote:
>>why are global variables bad?

>> Beacause your brain would explode if all variables were global?

>> When we learn programming, we naturally begin by writing small
>> programs. In small programs, let's say twenty lines of code and

Does anyone want to share some like that?

What did you write in the beginning?

-- 
Adam Vardy



From mike@daboyz.org  Mon Dec  9 15:13:01 2002
From: mike@daboyz.org (Michael Barrett)
Date: Mon Dec  9 15:13:01 2002
Subject: [Tutor] Using Vi in the interpreter
Message-ID: <20021209201020.GF10444@daboyz.org>

	Howdy, so I just rebuilt my linux (now FreeBSD) system and completely forgot how to make it so that when I'm in the python interpreter it uses vi commands to edit.  Anyone know off the top of their heads how to do this?  I'm going nuts without it.  Thanks in advance. :)

-- 
     ________________________________________________________________________
                Mike Barrett | "I used to read, now I go to raves."
             mike@daboyz.org | -- Random MUNI Rider, speaking
              www.daboyz.org |    to my friend Allison.
     ------------------------+-----------------------------------------------


From thomi@thomi.imail.net.nz  Mon Dec  9 18:53:02 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Mon Dec  9 18:53:02 2002
Subject: [Tutor] cgi module and checkboxes.
In-Reply-To: <MPEOIFCOPCIHEDCLBLPBCENMCMAA.rob@uselesspython.com>
References: <20021209234348.7d6c8393.thomi@thomi.imail.net.nz>
 <MPEOIFCOPCIHEDCLBLPBCENMCMAA.rob@uselesspython.com>
Message-ID: <20021210125203.521bd103.thomi@thomi.imail.net.nz>

This is a multi-part message in MIME format.

--Multipart_Tue__10_Dec_2002_12:52:03_+1300_088a1528
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

> Can you show an example of the code you're having problems with? Also,
> does the rest of this CGI work if you leave off the part that doesn't
> seem to be working?

attached is roster.py, It's unfinished, but you should be able to see
whats happening :-)

the problem lies within the last 10 lines of code

-- 
Thomi Richards
thomi@imail.net.nz
http://thomi.imail.net.nz/
Thomi Richards,
thomi@imail.net.nz

--Multipart_Tue__10_Dec_2002_12:52:03_+1300_088a1528
Content-Type: application/octet-stream;
 name="roster.py"
Content-Disposition: attachment;
 filename="roster.py"
Content-Transfer-Encoding: base64

IyEvdXNyL2Jpbi9weXRob24KCmltcG9ydCBzeXMsb3MKc3lzLnBhdGguYXBwZW5kKG9zLmdldGN3
ZCgpKQpzeXMucGF0aC5hcHBlbmQoJy9ob21lL3Rob21pL2N2cy9uZXctYmV0YXRlc3QnKQoKZnJv
bSB0bXlzcWwgaW1wb3J0IG15c3FsCmltcG9ydCBjZ2kKCgonJydvaywgd2UgbmVlZCBzZXZlcmFs
IGRpZmZlcmVudCBjbGFzc2VzOgoKY2xhc3MgZGlzcGxheWh0bWwKCXRoaXMgY2xhc3MgaGFuZGxl
cyBBTEwgb3V0cHV0IHRvIHRoZSBzY3JlZW4sIGluY2x1ZGluZyBNRVRBIHRhZ3MsIGh0bWwgdGFn
cywgYW5kIGFueXRoaW5nIGVsc2UKY2xhc3MgcHJvY2Vzc2NnaQoJdGhpcyBjbGFzcyBoYW5kbGVz
IGFsbCB0aGUgQ0dJIHByb2Nlc3NpbmcgdGlkYml0cy4gVGhpcyBpcyB0aGUgY2xhc3Mgd2hpY2gg
d2lsbCB1dGlsaXNlIHRoZSB0bXlzcWwgbW9kdWxlIHRoZSBtb3N0CgonJycKCmRlYnVnID0gMQoK
CgpjbGFzcyBkaXNwbGF5aHRtbDoKCWRlZiBoZWFkZXJzKHNlbGYpOgoJCXByaW50ICdDb250ZW50
LVR5cGU6IHRleHQvaHRtbCcKCQlwcmludAoJCQoJZGVmIHRvcGh0bWwoc2VsZix0aXRsZT0nQkVU
QSB0ZXN0aW5nIHJvc3RlcicpOgoJCXByaW50ICc8aHRtbD48aGVhZD48dGl0bGU+JXM8L3RpdGxl
PicgJSAodGl0bGUpCgkJI3RoaXMgaXMgd2hlcmUgd2Ugd2lsbCBjYWxsIHRoZSBtZXRhdGFncyBm
dW5jdGlvbiBpbiB0aGUgZnV0dXJlOgoKCQlzZWxmLm1ldGF0YWdzKCkKCQlwcmludCAnPC9oZWFk
PicKCQkKCWRlZiBtZXRhdGFncyhzZWxmKToKCQlwYXNzCgoJZGVmIGVuZGh0bWwoc2VsZik6CgkJ
cHJpbnQgJzwvaHRtbD4nCglkZWYgcHJpbnRsaW5rcyhzZWxmKToKCQlwcmludCAnPGEgaHJlZj0i
cm9zdGVyLnB5P2FjdGlvbj1uZXdhY2NvdW50Ij5DcmVhdGUgYSBOZXcgQWNjb3VudDwvYT48YnI+
JwoJCXByaW50ICc8YSBocmVmPSJyb3N0ZXIucHk/YWN0aW9uPXByb2plY3RsaXN0Ij5MaXN0IEFj
dGl2ZSBQcm9qZWN0czwvYT48YnI+JwoJCXByaW50ICc8YSBocmVmPSJyb3N0ZXIucHkiPkxvZ291
dDwvYT48YnI+JwoJCQoJCQoJZGVmIHRhYmxldG9wKHNlbGYsdGl0bGUsZXJyb3I9Tm9uZSk6CgkJ
cHJpbnQgJzxib2R5PicKCQlpZiBlcnJvcjoKCQkJcHJpbnQgJzxoMj4lczwvaDI+JyAlIChlcnJv
cikKCQlwcmludCAnPGgxPiVzPC9oMT4nICUgKHRpdGxlKQoJCXByaW50ICc8dGFibGU+PHRyPjx0
ZD4nCgkJc2VsZi5wcmludGxpbmtzKCkKCQlwcmludCAnPC90ZD48dGQ+JwoJZGVmIGxvZ2luc2Ny
ZWVuKHNlbGYsZXJyb3I9Tm9uZSk6CgkJc2VsZi50YWJsZXRvcCgnQkVUQSB0ZXN0ZXJzIExvZ2lu
IFNjcmVlbicsZXJyb3IpCgkJcHJpbnQgJycnPGZvcm0gYWN0aW9uPSJyb3N0ZXIucHkiIG1ldGhv
ZD0icG9zdCI+CgkJCTxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9ImFjdGlvbiIgdmFsdWU9Indl
bGNvbWUiPgoJCQk8cD5Vc2VybmFtZTogPGlucHV0IHR5cGU9InRleHQiIG5hbWU9InVuYW1lIj48
L3A+CgkJCTxwPlBhc3N3b3JkOiA8aW5wdXQgdHlwZT0icGFzc3dvcmQiIG5hbWU9InBhc3MiPjwv
cD4KCQkJPGlucHV0IHR5cGU9InN1Ym1pdCIgdmFsdWU9IkxvZyBpbiI+CgkJCScnJwoJCXByaW50
ICc8L2JvZHk+JwoJZGVmIGludGVybmFsKHNlbGYsZXJyb3I9Tm9uZSk6CgkJc2VsZi50YWJsZXRv
cCgnQkVUQSB0ZXN0ZXJzIEludGVybmFscyBTY3JlZW4nLGVycm9yKQoJCXByaW50ICc8aDI+VXNl
ciBEZWF0aWxzPC9oMj4nCgkJcHJpbnQgJzxwPkhlcmUgeW91IGNhbiBjaGFuZ2UgYW55IG9mIHlv
dXIgdXNlciBzdGF0aXN0aWNzOjwvcD4nCgkJcHJpbnQgJzxmb3JtIGFjdGlvbj0icm9zdGVyLnB5
IiBtZXRob2Q9InBvc3QiPicKCQlpZiBkZWJ1ZzoKCQkJcHJpbnQgZGV0YWlscwoJCWlmIGxlbihk
ZXRhaWxzKSA+IDE6CgkJCXByaW50ICc8aDI+RXJyb3IhIG1vcmUgdGhhbiBvbmUgdXNlciB3aXRo
IHlvdXIgZGV0YWlscyE8L2gyPicKCQkJcmV0dXJuIDAKCQllbHNlOgoJCQlwcmludCAnPHA+IFVJ
RDogJWQ8L3A+JyAlIChkZXRhaWxzWzBdWzBdKQoJCQlwcmludCAnPHA+IFVzZXIgTmFtZTogJXM8
L3A+JyAlIChkZXRhaWxzWzBdWzFdKQoJCQlwcmludCAnPHA+IFBhc3N3b3JkOiBIaWRkZW4hPC9w
PicKCQkJcHJpbnQgJzxwPiBGaXJzdCBOYW1lOiA8aW5wdXQgdHlwZT0idGV4dCIgbmFtZT0iZmly
c3QiIHZhbHVlPSIlcyI+PC9wPicgJSAoZGV0YWlsc1swXVszXSkKCQkJcHJpbnQgJzxwPiBMYXN0
IE5hbWU6IDxpbnB1dCB0eXBlPSJ0ZXh0IiBuYW1lPSJsYXN0IiB2YWx1ZT0iJXMiPjwvcD4nICUg
KGRldGFpbHNbMF1bNF0pCgkJCXByaW50ICc8cD4gRW1haWwgQWRkcjogPGlucHV0IHR5cGU9InRl
eHQiIG5hbWU9ImVtYWlsIiB2YWx1ZT0iJXMiPjwvcD4nICUgKGRldGFpbHNbMF1bNV0pCgkJCXBy
aW50ICc8cD4gVGVzdGVyIENvdW50OiA8aW5wdXQgdHlwZT0idGV4dCIgbmFtZT0idGVzdGVyIiB2
YWx1ZT0iJXMiPjwvcD4nICUgKGRldGFpbHNbMF1bNl0pCgkJCXByaW50ICc8cD4gUHJlc2VuY2U6
IDxzZWxlY3QgbmFtZT0icHJlc2VuY2UiPicKCQkJaWYgZGV0YWlsc1swXVs4XSA9PSAnaGlkZGVu
JzoKCQkJCXByaW50ICc8b3B0aW9uIHNlbGVjdGVkPmhpZGRlbicKCQkJCXByaW50ICc8b3B0aW9u
PmF2YWlsYWJsZScKCQkJZWxzZToKCQkJCXByaW50ICc8b3B0aW9uIHNlbGVjdGVkPmF2YWlsYWJs
ZScKCQkJCXByaW50ICc8b3B0aW9uPmhpZGRlbicKCQkJcHJpbnQgJzwvc2VsZWN0PicKCQkJcHJp
bnQgJzxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9InVuYW1lIiB2YWx1ZT0iJXMiPicgJSAoZGV0
YWlsc1swXVsxXSkKCQkJcHJpbnQgJzxpbnB1dCB0eXBlPSJoaWRkZW4iIG5hbWU9InBhc3MiIHZh
bHVlPSIlcyI+JyAlIChkZXRhaWxzWzBdWzJdKQoJCQlwcmludCAnPGlucHV0IHR5cGU9ImhpZGRl
biIgbmFtZT0iYWN0aW9uIiB2YWx1ZT0iY2hhbmdlc3RhdHMiPicKCQkJcHJpbnQgJzxpbnB1dCB0
eXBlPSJzdWJtaXQiIHZhbHVlPSJDaGFuZ2UgU3RhdGlzdGljcyI+JwoJCQlwcmludCAnPC9mb3Jt
PicKCQkJcHJpbnQgJzxocj4nCgkJCXByaW50ICc8aDI+UmVsZWFzZSBhIHByb2plY3Q8L2gyPicK
CQkJcHJpbnQgIjxwPkhlcmUncyB3aGVyZSB5b3UgY2FuIHJlbGVhc2UgYSBmaWxlIHRvIGJlIHRl
c3RlZC4gVGhlIGZvcm1hdCBvZiB0aGlzIHNlY3Rpb24gaGFzIGNoYW5nZWQgYSBiaXQuIEJhc2lj
YWxseSwgeW91IG5vdyBnZXQgYSBsaXN0IG9mIHBlb3BsZSB3aG8gYXJlIGF2YWlsYWJsZSB0byB0
ZXN0IGZpbGVzLiB5b3UgY2FuIGNob29zZSB3aGljaCB0ZXN0ZXJzIHlvdSB3YW50IHRvIHRlc3Qg
eW91ciBmaWxlcywgYnV0IHlvdSA8Yj5jYW5ub3QgY2hvb3NlIG1vcmUgdGhhbiAxMCBwZW9wbGUh
PC9iPi48L3A+IgoJCQlwcmludCAnPHA+SWYgeW91IGFyZSBhIHRlc3RlciwgYW5kIHlvdSB3YW50
IHRvIHRlc3QgYSBmaWxlLCBidXQgbm8gb25lIGV2ZXIgY2hvb3NlcyB5b3UsIHRoZSBiZXN0IHdh
eSB0byBnZXQgaW50byB0aGUgdGVzdGluZyBzY2hlbWUgaXMgdG8gc3VibWl0IGJ1ZyByZXBvcnRz
IHRvIHZhcmlvdXMgZG1vZCBhdXRob3JzLiBNb3N0IG9mIHRoZW0gYXJlIHZlcnkgZ3JhdGVmdWxs
IGZvciB0aGVzZSByZXBvcnRzLCBhbmQgeW91IG1heSBldmVuIGdldCBhIG1lbnRpb24gaW4gdGhl
IGNyZWRpdHMhPC9wPicKCQkJcHJpbnQgJzxocj4nCgkJCWxpbmVzLHJlc3VsdCA9IG15c3FsKCdz
ZWxlY3QgdW5hbWUsIGZpcnN0LCBsYXN0LCBlbWFpbCwgdWlkIGZyb20gdXNlcnMgd2hlcmUgcHJl
c2VuY2U9ImF2YWlsYWJsZSIgYW5kIHRlc3Rlcj4xJykKCQkJcHJpbnQgJzxmb3JtIGFjdGlvbj0i
cm9zdGVyLnB5IiBtZXRob2Q9InBvc3QiPicKCQkJcHJpbnQgJzx0YWJsZT48dHI+PHRkPjxiPlVJ
RDwvYj48L3RkPjx0ZD48Yj5Vc2VyIE5hbWU8L2I+PC90ZD48dGQ+PGI+Rmlyc3QgTmFtZTwvYj48
L3RkPjx0ZD48Yj5MYXN0IE5hbWU8L2I+PC90ZD48dGQ+PGI+RW1haWwgQWRkcmVzczwvYj48L3Rk
PjwvdHI+JwoJCQlmb3IgdXNlciBpbiByZXN1bHQ6CgkJCQlwcmludCAnPHRyPicKCQkJCXByaW50
ICc8dGQ+PGlucHV0IHR5cGU9ImNoZWNrYm94IiBuYW1lPSJ1aWQiIHZhbHVlPSIlcyI+ICVzJyAl
ICh1c2VyWzRdLHVzZXJbNF0pCgkJCQlwcmludCAnPHRkPiVzPC90ZD4nICUgKHVzZXJbMF0pCgkJ
CQlwcmludCAnPHRkPiVzPC90ZD4nICUgKHVzZXJbMV0pCQkJCQoJCQkJcHJpbnQgJzx0ZD4lczwv
dGQ+JyAlICh1c2VyWzJdKQoJCQkJcHJpbnQgJzx0ZD4lczwvdGQ+JyAlICh1c2VyWzNdKQoJCQkJ
cHJpbnQgJzwvdHI+JwoJCQlwcmludCAnPC90YWJsZT4nCgkJCXByaW50ICc8aW5wdXQgdHlwZT0i
aGlkZGVuIiBuYW1lPSJhY3Rpb24iIHZhbHVlPSJhZGRwcm9qZWN0Ij4nCgkJCXByaW50ICc8aW5w
dXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJ1bmFtZSIgdmFsdWU9IiVzIj4nICUgKGRldGFpbHNbMF1b
MV0pCgkJCXByaW50ICc8aW5wdXQgdHlwZT0iaGlkZGVuIiBuYW1lPSJwYXNzIiB2YWx1ZT0iJXMi
PicgJSAoZGV0YWlsc1swXVsyXSkKCQkJcHJpbnQgJzxwPiBZb3UgbmVlZCB0byB3cml0ZSBhIHNo
b3J0IGRlc2NyaXB0aW9uLCB3aGljaCBzaG91bGQgaW5jbHVkZSA8Yj4gd2hlcmUgdG8gZG93bmxv
YWQgeW91ciBmaWxlIGZyb208L2I+LCA8Yj5ob3cgdG8gY29udGFjdCB5b3UsIHRvIHN1Ym1pdCBi
dWcgcmVwb3J0czwvYj4sIGFuZCBhIDxiPmJyaWVmIGRlc2NyaXB0aW9uIG9mIHdoYXQgeW91ciBm
aWxlIGlzPC9iPiAoZWcuLSBpcyBpdCBhIGRtb2Q/IGdyYXBoaWNzIHV0aWxpdHk/IHdhbGt0aHJv
dWdoLCBldGMuIGV0Yy4gZXRjLik8L3A+JwoJCQlwcmludCAnPHRleHRhcmVhIG5hbWU9ImRlc2Ny
aXB0aW9uIiByb3dzPSIxMCIgY29scz0iNjAiPlByb2plY3QgRGVzY3JpcHRpb246PC90ZXh0YXJl
YT48YnI+JwoJCQkKCQkJcHJpbnQgJzxpbnB1dCB0eXBlPSJzdWJtaXQiIHZhbHVlPSJSZWxlYXNl
IFByb2plY3QiPicKCQkJcHJpbnQgJzwvZm9ybT4nCgkJCXByaW50ICc8aHI+JwkJCglkZWYgbmV3
YWNjb3VudChzZWxmLGVycm9yPU5vbmUpOgoJCXNlbGYudGFibGV0b3AoJ0JFVEEgdGVzdGVycyBO
ZXcgQWNjb3VudCBQYWdlJyxlcnJvcikKCQlwcmludCAnPHA+VGhpcyBpcyB3aGVyZSB5b3UgY2Fu
IHNpZ24gdXAgZm9yIGEgbmV3IGFjY291bnQsIGVpdGhlciB0byB0ZXN0IGEgZmlsZSwgb3IgdG8g
cmVsZWFzZSBhIGZpbGUgdG8gYmUgdGVzdGVkLiBZb3UgbXVzdCBmaWxsIGluIGFsbCB0aGUgZmll
bGRzIGJlbG93LCB0aGVuIGNsaWNrIHN1Ym1pdC4gYWZ0ZXIgY29tcGxldGluZyB0aGlzIHByb2Nl
c3MsIHl1IHdpbGwgYmUgYWJsZSB0byBsb2cgaW4gdmlhIHRoZSBtYWluIHBhZ2UuPC9wPicKCQlw
cmludCAnPGZvcm0gYWN0aW9uPSJyb3N0ZXIucHkiIG1ldGhvZD0icG9zdCI+JwoJCXByaW50ICc8
cD5Vc2VyIG5hbWU6IDxpbnB1dCB0eXBlPSJ0ZXh0IiBuYW1lPSJ1bmFtZSI+PC9wPicKCQlwcmlu
dCAnPHA+UGFzc3dvcmQ6IDxpbnB1dCB0eXBlPSJwYXNzd29yZCIgbmFtZT0icGFzc3ciPjwvcD4n
CgkJcHJpbnQgJzxwPkZpcnN0IE5hbWU6IDxpbnB1dCB0eXBlPSJ0ZXh0IiBuYW1lPSJmaXJzdCI+
PC9wPicKCQlwcmludCAnPHA+TGFzdCBOYW1lOiA8aW5wdXQgdHlwZT0idGV4dCIgbmFtZT0ibGFz
dCI+PC9wPicKCQlwcmludCAnPHA+RW1haWwgQWRkcmVzczogPGlucHV0IHR5cGU9InRleHQiIG5h
bWU9ImVtYWlsIj48L3A+JwoJCXByaW50ICc8aW5wdXQgdHlwZT0ic3VibWl0IiB2YWx1ZT0iU3Vi
bWl0IERhdGEiPicKCQlwcmludCAnPGlucHV0IHR5cGU9ImhpZGRlbiIgbmFtZT0iYWN0aW9uIiB2
YWx1ZT0icmVnaXN0ZXJuZXdhY2NvdW50Ij4nCgkJcHJpbnQgJzwvZm9ybT4nCgkJCQoJCQkKCQkK
CQkKCgkKCQpjbGFzcyBwcm9jZXNzY2dpOgoJZGVmIF9faW5pdF9fKHNlbGYpOgoJCXNlbGYuZm9y
bSA9IGNnaS5GaWVsZFN0b3JhZ2UoKQoJCXNlbGYuZm9ybWl0ZW1zID0gc2VsZi5mb3JtLmtleXMo
KQoJCQoJZGVmIGdldHZhbHVlcyhzZWxmLGl0ZW0pOgoJCWlmIHNlbGYuZm9ybS5oYXNfa2V5KGl0
ZW0pOgoJCQlyZXR1cm4gc2VsZi5mb3JtW2l0ZW1dLnZhbHVlCgkJZWxzZToKCQkJcmV0dXJuIE5v
bmUKCWRlZiBjaGVja2xvZyhzZWxmKToKCQlpZiBkZWJ1ZzoKCQkJcHJpbnQgJzxwcmU+SW4gY2hl
Y2tsb2cgc3ViLjwvcHJlPicKCQlpZiAndW5hbWUnIGFuZCAncGFzcycgaW4gc2VsZi5mb3JtLmtl
eXMoKToKCQkJaWYgZGVidWc6CgkJCQlwcmludCAnPHByZT51bmFtZSBhbmQgcGFzcyBrZXlzIGZv
dW5kPC9wcmU+JwoJCQlsaW5lcyxyZXN1bHQgPSBteXNxbCgnc2VsZWN0IHVuYW1lLHBhc3MgZnJv
bSB1c2VycycpCgkJCQoJCQlpZiAoc2VsZi5mb3JtWyd1bmFtZSddLnZhbHVlLHNlbGYuZm9ybVsn
cGFzcyddLnZhbHVlKSBpbiByZXN1bHQ6CgkJCQlyZXR1cm4gMQoJCQllbHNlOgoJCQkJcmV0dXJu
IDAKCWRlZiBjaGFuZ2VzdGF0cyhzZWxmKToKCQlpZiBub3Qgc2VsZi5jaGVja2xvZygpOgoJCQly
ZXR1cm4gMAoJCXVpZCA9IGRldGFpbHNbMF1bMF0KCQl1bmFtZSA9IGRldGFpbHNbMF1bMV0KCQlw
YXNzdyA9IGRldGFpbHNbMF1bMl0KCQlmaXJzdCA9IGRldGFpbHNbMF1bM10KCQlsYXN0ID0gZGV0
YWlsc1swXVs0XQoJCWVtYWlsID0gZGV0YWlsc1swXVs1XQoJCXRlc3RlciA9IGRldGFpbHNbMF1b
Nl0KCQlkZXZlbG9wZXIgPSBkZXRhaWxzWzBdWzddCgkJcHJlc2VuY2UgPSBkZXRhaWxzWzBdWzhd
CgoJCWlmIHNlbGYuZm9ybVsnZmlyc3QnXS52YWx1ZSAhPSBmaXJzdDoKCQkJbXlzcWwoJ3VwZGF0
ZSB1c2VycyBTRVQgZmlyc3Q9IiVzIiB3aGVyZSB1bmFtZT0iJXMiIGFuZCBwYXNzPSIlcyInICUg
KHNlbGYuZm9ybVsnZmlyc3QnXS52YWx1ZSxzZWxmLmZvcm1bJ3VuYW1lJ10udmFsdWUsc2VsZi5m
b3JtWydwYXNzJ10udmFsdWUpKQoKCQlpZiBzZWxmLmZvcm1bJ2xhc3QnXS52YWx1ZSAhPSBsYXN0
OgoJCQlteXNxbCgndXBkYXRlIHVzZXJzIFNFVCBsYXN0PSIlcyIgd2hlcmUgdW5hbWU9IiVzIiBh
bmQgcGFzcz0iJXMiJyAlIChzZWxmLmZvcm1bJ2xhc3QnXS52YWx1ZSxzZWxmLmZvcm1bJ3VuYW1l
J10udmFsdWUsc2VsZi5mb3JtWydwYXNzJ10udmFsdWUpKQoKCQlpZiBzZWxmLmZvcm1bJ2VtYWls
J10udmFsdWUgIT0gZW1haWw6CgkJCW15c3FsKCd1cGRhdGUgdXNlcnMgU0VUIGVtYWlsPSIlcyIg
d2hlcmUgdW5hbWU9IiVzIiBhbmQgcGFzcz0iJXMiJyAlIChzZWxmLmZvcm1bJ2VtYWlsJ10udmFs
dWUsc2VsZi5mb3JtWyd1bmFtZSddLnZhbHVlLHNlbGYuZm9ybVsncGFzcyddLnZhbHVlKSkKCQkK
CQlpZiBzZWxmLmZvcm1bJ3Rlc3RlciddLnZhbHVlICE9IHRlc3RlcjoKCQkJbXlzcWwoJ3VwZGF0
ZSB1c2VycyBTRVQgdGVzdGVyPSVzIHdoZXJlIHVuYW1lPSIlcyIgYW5kIHBhc3M9IiVzIicgJSAo
c2VsZi5mb3JtWyd0ZXN0ZXInXS52YWx1ZSxzZWxmLmZvcm1bJ3VuYW1lJ10udmFsdWUsc2VsZi5m
b3JtWydwYXNzJ10udmFsdWUpKQoKCQlpZiBzZWxmLmZvcm1bJ3ByZXNlbmNlJ10udmFsdWUgIT0g
cHJlc2VuY2U6CgkJCW15c3FsKCd1cGRhdGUgdXNlcnMgU0VUIHByZXNlbmNlPSIlcyIgd2hlcmUg
dW5hbWU9IiVzIiBhbmQgcGFzcz0iJXMiJyAlIChzZWxmLmZvcm1bJ3ByZXNlbmNlJ10udmFsdWUs
c2VsZi5mb3JtWyd1bmFtZSddLnZhbHVlLHNlbGYuZm9ybVsncGFzcyddLnZhbHVlKSkKCQlyZXR1
cm4gMQoJZGVmIGFkZGFjY291bnQoc2VsZik6CgkJdW5hbWUgPSBzZWxmLmZvcm1bJ3VuYW1lJ10u
dmFsdWUKCQlwYXNzdyA9IHNlbGYuZm9ybVsncGFzc3cnXS52YWx1ZQoJCWZpcnN0ID0gc2VsZi5m
b3JtWydmaXJzdCddLnZhbHVlCgkJbGFzdCA9IHNlbGYuZm9ybVsnbGFzdCddLnZhbHVlCgkJZW1h
aWwgPSBzZWxmLmZvcm1bJ2VtYWlsJ10udmFsdWUKCQkKCQlpZiBub3QgKHVuYW1lIGFuZCBwYXNz
dyBhbmQgZmlyc3QgYW5kIGxhc3QgYW5kIGVtYWlsKToKCQkJcmV0dXJuIDAKCQllbHNlOgoJCQkj
d2UgbmVlZCB0byBtYWtlIHN1cmUgdGhhdCBubyBvbmUgZWxzZSBoYXMgdGhlIHNhbWUgdXNlcm5h
bWUgYW5kIHBhc3N3b3JkOgoJCQlsaW5lcyxyZXN1bHQgPSBteXNxbCgnc2VsZWN0IHVuYW1lLHBh
c3MgZnJvbSB1c2VycycpCgkJCWZvciB1c2VyIGluIHJlc3VsdDoKCQkJCWlmIHVzZXJbMF0gPT0g
dW5hbWU6CgkJCQkJcmV0dXJuIDAKCQkJCWlmIHVzZXJbMV0gPT0gcGFzc3c6CgkJCQkJcmV0dXJu
IDAKCQkJI25vdyB3ZSBuZWVkIHRvIGFkZCB0aGVzZSByZXN1bHRzIHRvIHRoZSBkYXRhYmFzZQoJ
CQl0cnk6CgkJCQlteXNxbCgnaW5zZXJ0IGludG8gdXNlcnMgKHVuYW1lLHBhc3MsZmlyc3QsbGFz
dCxlbWFpbCx0ZXN0ZXIpIHZhbHVlcygiJXMiLCIlcyIsIiVzIiwiJXMiLCIlcyIsMSknICUgKHVu
YW1lLHBhc3N3LGZpcnN0LGxhc3QsZW1haWwpKQoJCQlleGNlcHQ6CgkJCQlyZXR1cm4gMAoJCQly
ZXR1cm4gMQoJCQkKCQkKcGFnZSA9IGRpc3BsYXlodG1sKCkKcGFnZS5oZWFkZXJzKCkKcGFnZS50
b3BodG1sKCkKcGFnZS5tZXRhdGFncygpCgoKY2dpID0gcHJvY2Vzc2NnaSgpCgojdGhlIGFjdGlv
biBmb3JtIGl0ZW0gZGVmaW5lcyB3aGF0IGxldmVsIHdlIGFyZSBhdAppZiAnYWN0aW9uJyBub3Qg
aW4gY2dpLmZvcm1pdGVtczoKCSN3ZSBhcmUgYXQgdGhlIGJlZ2lubmluZywgbG9naW4gcGFnZS4K
CXBhZ2UubG9naW5zY3JlZW4oKQplbHNlOgoJdHJ5OgoJCWxpbmVzLGRldGFpbHMgPSBteXNxbCgn
c2VsZWN0ICogZnJvbSB1c2VycyB3aGVyZSB1bmFtZT0iJXMiIGFuZCBwYXNzPSIlcyInICUgKGNn
aS5mb3JtWyd1bmFtZSddLnZhbHVlLGNnaS5mb3JtWydwYXNzJ10udmFsdWUpKQoJZXhjZXB0OgoJ
CXBhc3MKCWlmIGNnaS5mb3JtWydhY3Rpb24nXS52YWx1ZSA9PSAnd2VsY29tZSc6CgkJaWYgY2dp
LmNoZWNrbG9nKCk6CgkJCXBhZ2UuaW50ZXJuYWwoKQoJCWVsc2U6CgkJCXBhZ2UubG9naW5zY3Jl
ZW4oJ1VzZXJuYW1lIG9yIFBhc3N3b3JkIEluY29ycmVjdCEnKQoJCgllbGlmIGNnaS5mb3JtWydh
Y3Rpb24nXS52YWx1ZSA9PSAnY2hhbmdlc3RhdHMnOgoJCWlmIGNnaS5jaGFuZ2VzdGF0cygpOgoJ
CQkjd2UgbmVlZCB0byB1cGRhdGUgZGV0YWlscywgb3RoZXJ3aXNlIHBhZ2UuaW50ZXJuYWwgcmVh
ZHMgdGhlIE9MRCB2YWx1ZXMsIHdoaWNoIGNvbmZ1c2VzIHVzZXJzIDotKQoJCQlsaW5lcyxkZXRh
aWxzID0gbXlzcWwoJ3NlbGVjdCAqIGZyb20gdXNlcnMgd2hlcmUgdW5hbWU9IiVzIiBhbmQgcGFz
cz0iJXMiJyAlIChjZ2kuZm9ybVsndW5hbWUnXS52YWx1ZSxjZ2kuZm9ybVsncGFzcyddLnZhbHVl
KSkKCQkJcGFnZS5pbnRlcm5hbCgpCgkJZWxzZToKCQkJcGFnZS5sb2dpbnNjcmVlbignVXNlcm5h
bWUgb3IgUGFzc3dvcmQgSW5jb3JyZWN0IScpCgllbGlmIGNnaS5mb3JtWydhY3Rpb24nXS52YWx1
ZSA9PSAnbmV3YWNjb3VudCc6CgkJcGFnZS5uZXdhY2NvdW50KCkKCWVsaWYgY2dpLmZvcm1bJ2Fj
dGlvbiddLnZhbHVlID09ICdyZWdpc3Rlcm5ld2FjY291bnQnOgoJCWlmIGNnaS5hZGRhY2NvdW50
KCk6CgkJCXBhZ2UubG9naW5zY3JlZW4oJ0FjY291bnQgQ3JlYXRlZC4geW91IG1heSBub3cgbG9n
aW4gdXNpbmcgdGhlIGZvcm0gYmVsb3cnKQoJCWVsc2U6CgkJCXBhZ2UubmV3YWNjb3VudCgnU29t
ZSBvciBhbGwgZGV0YWlscyBvbWl0dGVkLiBwbGVhc2UgdHJ5IGFnYWluIScpCgllbGlmIGNnaS5m
b3JtWydhY3Rpb24nXS52YWx1ZSA9PSAnYWRkcHJvamVjdCc6CgkJaWYgY2dpLmNoZWNrbG9nKCk6
CgkJCXByaW50IGNnaS5mb3JtaXRlbXMKCQkJcHJpbnQgY2dpLmZvcm1bJ3VpZCddLnZhbHVlCgkJ
CSNob3cgZG8gaSBnZXQgdGhlIHZhbHVlcyBvZiBhIGNoZWNrYm94Pz8KCQoKCgpwYWdlLmVuZGh0
bWwoKQo=

--Multipart_Tue__10_Dec_2002_12:52:03_+1300_088a1528
Content-Type: application/octet-stream;
 name="tmysql.py"
Content-Disposition: attachment;
 filename="tmysql.py"
Content-Transfer-Encoding: base64

IyEvdXNyL2Jpbi9weXRob24KCgppbXBvcnQgTXlTUUxkYgoKSE9TVD0nbG9jYWxob3N0JwpEQiA9
ICdiZXRhdGVzdCcKVVNFUj0ndGhvbWknClBBU1M9J3Rob21hcycKCmRlZiBteXNxbChxdWVyeV9z
dHJpbmcpOgoJY29ubmVjdGlvbiA9IE15U1FMZGIuY29ubmVjdChob3N0PUhPU1QsdXNlcj1VU0VS
LHBhc3N3ZD1QQVNTLGRiPURCKQoJY3Vyc29yID0gY29ubmVjdGlvbi5jdXJzb3IoKQoKCXRyeToK
CQlsaW5lcyA9IGN1cnNvci5leGVjdXRlKHF1ZXJ5X3N0cmluZykKCQlyZXN1bHQgPSBjdXJzb3Iu
ZmV0Y2hhbGwoKQoJZXhjZXB0OgoJCXJldHVybiBOb25lLE5vbmUKCXJldHVybiBsaW5lcyxyZXN1
bHQKCmlmIF9fbmFtZV9fID09ICdfX21haW5fXyc6CglwcmludCAndGVzdGluZyB3aXRoIHRoZSBm
b2xsb3dpbmcgcXVlcnlfc3RyaW5nOicKCXByaW50ICdzZWxlY3QgKiBmcm9tIHVzZXJzOycKCWxp
bmVzLHJlc3VsdCA9IG15c3FsKCdzZWxlY3QgKiBmcm9tIHVzZXJzJykKCXByaW50ICclZCBsaW5l
cywgd2l0aCByZXN1bHM6JyAlIChsaW5lcykKCXByaW50IAoJcHJpbnQgcmVzdWx0CgkJCg==

--Multipart_Tue__10_Dec_2002_12:52:03_+1300_088a1528--


From thomi@thomi.imail.net.nz  Mon Dec  9 18:55:03 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Mon Dec  9 18:55:03 2002
Subject: [Tutor] blog, blog blog blog, BLOG, blog blog blog...
In-Reply-To: <47B6167F8E69D31194BA0008C7918D4205C54FAC@msxcvg02itscge.gecits.ge.com>
References: <47B6167F8E69D31194BA0008C7918D4205C54FAC@msxcvg02itscge.gecits.ge.com>
Message-ID: <20021210125400.15717e49.thomi@thomi.imail.net.nz>

> Oh! It seems, Alfred is going to reinvent the wiki!
> (Why always reinvent only the wheel?) See:

perhaps because it's fun/educational to see how these things are
created?? Also, i much prefer creating my own small apps, so i know
exactly how they work, and I'll usually learn something at the same time
;-)

-- 
The software required Win95 or better, so I installed Linux.
Thomi Richards,
thomi@imail.net.nz


From wolf_binary@hotmail.com  Mon Dec  9 21:09:01 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Mon Dec  9 21:09:01 2002
Subject: [Tutor] Little apps
Message-ID: <F43E6iAlWUa3I3xRsRa0001ca28@hotmail.com>

-Adam,

I made a basic encryption program that's a bit more than 20 lines, but each 
part isn't more than twenty lines.  When you make a program you usually test 
each part out before adding more to it.  Ex:  say you want to prompt for a 
list of numbers and then print them out and then see if you want to do it 
again.  Well you start with the prompt and make sure it works right, then 
move on to the capturing of the data of just one list item.  Once you have 
that done you put this segment of code in a loop that is either dependent on 
the user to know how much data to enter or a preset limet.  The loop just 
needs to terminate some how.  It might be easier to understand what you 
might want to do?  This encryption program took me a while, but that was 
because I didn't plan to well or think things through.  I know some would 
say you should start coding, but code what was always my thought.  Start 
with some kind of menu program, maybe.  Simple exercises in understanding 
concepts like file IO help a lot.

HTH,
Cameron Stoner

>Thursday, December 5, 2002, 7:17:21 AM, you wrote:
>
> >> At 23:16 2002-12-04 -0600, david wrote:
> >>why are global variables bad?
>
> >> Beacause your brain would explode if all variables were global?
>
> >> When we learn programming, we naturally begin by writing small
> >> programs. In small programs, let's say twenty lines of code and
>
>Does anyone want to share some like that?
>
>What did you write in the beginning?
>
>--
>Adam Vardy
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor


_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail



From gp@pooryorick.com  Mon Dec  9 21:21:02 2002
From: gp@pooryorick.com (Poor Yorick)
Date: Mon Dec  9 21:21:02 2002
Subject: [Tutor] communication between class instances
References: <7497DCA1C240C042B28F6657ADFD8E0974DA5E@i2km11-ukbr.domain1.systemhost.net>
Message-ID: <3DF54F7C.4080301@pooryorick.com>

Many thanks to Magnus and Alan for their feedback.  I'm starting to see 
the light about having the gui drive the app, and having few to no 
reverse callbacks.  After reading Magnus' post, I realized that if I 
were to develop an browser-based interface, or even a text-based 
interface, I certainly would have trouble dealing with callbacks to the 
interface from the application.  I've greatly simplified my program 
design with your guidance.

Poor Yorick
gp@pooryorick.com



From gp@pooryorick.com  Mon Dec  9 21:25:09 2002
From: gp@pooryorick.com (Poor Yorick)
Date: Mon Dec  9 21:25:09 2002
Subject: [Tutor] Another __builtins__.__dict__ question
Message-ID: <3DF550A4.7010609@pooryorick.com>

I'm surprised that

__builtins__.__dict__.keys().sort()

returns nothing.

Could someone explain this, please?

Poor Yorick
gp@pooryorick.com




From gp@pooryorick.com  Mon Dec  9 21:32:02 2002
From: gp@pooryorick.com (Poor Yorick)
Date: Mon Dec  9 21:32:02 2002
Subject: [Tutor] os.environ weirdness
Message-ID: <3DF55214.70405@pooryorick.com>

Another phenomenon I haven't made sense of:

 >>> for i in os.environ:
    print i

   
Traceback (most recent call last):
  File "<pyshell#13>", line 1, in ?
    for i in os.environ:
  File "C:\Python22\lib\os.py", line 387, in __getitem__
    return self.data[key.upper()]
AttributeError: 'int' object has no attribute 'upper'

I realize that os.environ is not a builtin dictionary, but some sort of 
subclassed dictionary, but these commands work:

os.environ.keys()
os.environ.items()

doesn't the "in" statement just resolve to one of those functions?

Regards,

Poor Yorick
gp@pooryorick.com



From ramrom@earthling.net  Mon Dec  9 21:38:02 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Mon Dec  9 21:38:02 2002
Subject: [Tutor] Another __builtins__.__dict__ question
In-Reply-To: <3DF550A4.7010609@pooryorick.com>
Message-ID: <5.2.0.9.0.20021209183408.02aadae8@66.28.54.253>

--=====================_39692404==.ALT
Content-Type: text/plain; charset="us-ascii"; format=flowed

At 07:25 PM 12/9/2002 -0700, Poor Yorick wrote:
>__builtins__.__dict__.keys().sort() returns nothing.

Actually it returns None, as you'd see if you
print __builtins__.__dict__.keys().sort()
which is what sort() always returns.

Another good occasion to read the documentation:
"The sort() and reverse() methods modify the list in place for economy of 
space when sorting or reversing a large list. To remind you that they 
operate by side effect, they don't return the sorted or reversed list."

So try:
keylist = __builtins__.__dict__.keys()
keylist.sort()
print leylist

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625

--=====================_39692404==.ALT
Content-Type: text/html; charset="us-ascii"

<html>
<body>
At 07:25 PM 12/9/2002 -0700, Poor Yorick wrote:<br>
<blockquote type=cite class=cite cite>__builtins__.__dict__.keys().sort()
returns nothing.</blockquote><br>
Actually it returns None, as you'd see if you <br>
print __builtins__.__dict__.keys().sort()<br>
which is what sort() always returns.<br><br>
Another good occasion to read the documentation:<br>
&quot;The <tt>sort()</tt> and <tt>reverse()</tt> methods modify the list
in place for economy of space when sorting or reversing a large list. To
remind you that they operate by side effect, they don't return the sorted
or reversed list.&quot;<br><br>
So try:<br>
keylist = __builtins__.__dict__.keys()<br>
keylist.sort()<br>
print leylist<br>
<x-sigsep><p></x-sigsep>
Bob Gailer<br>
<a href="mailto:ramrom@earthling.net" eudora="autourl">mailto:ramrom@earthling.net</a><br>
303 442 2625<br>
</body>
</html>

--=====================_39692404==.ALT--



From op73418@mail.telepac.pt  Mon Dec  9 21:39:12 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Mon Dec  9 21:39:12 2002
Subject: [Tutor] Another __builtins__.__dict__ question
References: <3DF550A4.7010609@pooryorick.com>
Message-ID: <001901c29ff6$21ccb430$b5110dd5@violante>

The method sort() sorts a list *inplace*, returning None. You want

temp = __builtins__.__dict__.keys()
temp.sort()

and now temp references the sorted list.

All the best,
G. Rodrigues

----- Original Message ----- 
From: "Poor Yorick" <gp@pooryorick.com>
To: <tutor@python.org>
Sent: Tuesday, December 10, 2002 2:25 AM
Subject: [Tutor] Another __builtins__.__dict__ question


> I'm surprised that
> 
> __builtins__.__dict__.keys().sort()
> 
> returns nothing.
> 
> Could someone explain this, please?
> 
> Poor Yorick
> gp@pooryorick.com




From dman@dman.ddts.net  Tue Dec 10 00:14:01 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Tue Dec 10 00:14:01 2002
Subject: [Tutor] Re: Using Vi in the interpreter
In-Reply-To: <20021209201020.GF10444@daboyz.org>
References: <20021209201020.GF10444@daboyz.org>
Message-ID: <20021210052901.GA31287@dman.ddts.net>

--x+6KMIRAuhnl3hBn
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Dec 09, 2002 at 12:10:20PM -0800, Michael Barrett wrote:
| Howdy, so I just rebuilt my linux (now FreeBSD) system

linux !=3D *BSD.  They are different kernels, and often different
userland applications.  Both are "UNIX-like", though.

| and completely forgot how to make it so that when I'm in the python
| interpreter it uses vi commands to edit.  Anyone know off the top of
| their heads how to do this?  I'm going nuts without it.  Thanks in
| advance. :)

$ echo 'set editing-mode vi' >> ~/.inputrc

(this assumes you linked your python with libreadline)

-D

--=20
The Consultant's Curse:
    When the customer has beaten upon you long enough, give him
what he asks for, instead of what he needs.  This is very strong
medicine, and is normally only required once.
=20
http://dman.ddts.net/~dman/

--x+6KMIRAuhnl3hBn
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj31e50ACgkQO8l8XBKTpRT1CgCgpjJbH3DGwm4uKvbJqktq4aJv
rWsAnjh0bo6PQGAkhtk9WyZwvJqJTlEi
=k3J3
-----END PGP SIGNATURE-----

--x+6KMIRAuhnl3hBn--


From dman@dman.ddts.net  Tue Dec 10 00:20:02 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Tue Dec 10 00:20:02 2002
Subject: [Tutor] Re: How different is math logic from computer logic?
In-Reply-To: <5.1.0.14.0.20021208224228.02abaff8@www.thinkware.se>
References: <MHHPAJHBHCNDEAAA@mailcity.com> <5.1.0.14.0.20021208224228.02abaff8@www.thinkware.se>
Message-ID: <20021210053506.GB31287@dman.ddts.net>

--neYutvxvOLaeuPCA
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Dec 09, 2002 at 01:03:25AM +0100, Magnus Lycka wrote:

| In the 19th century, british mathematician George Boole introduced
| symbolic logic or Boolean Algebra as we call it today. Basically,
| he made a simple and a complete algebraic system containing only two
| "digits": True and False, and three operations, AND, OR and NOT. If
| we use the following symbols:

Just out of curiosity, did Boole come up with "nand" or did that come
later?

For those unfamiliar with it, the nand operator is functionally
complete.  With just nand you can write any logic expression.  The
combination of and, or and not is also functionally complete.  (it's
more natural too, but require 3 operators instead of 1)

IIRC the nand truth table looks like

      | 0  1
    --|-----
    0 | 1  1
    1 | 1  0


If you're really interested in logic or rule based programming, check
out Prolog.  (I've only heard about it but never used it)

-D

--=20
If we claim we have not sinned, we make Him out to be a liar and His
Word has no place in our lives.
        I John 1:10
=20
http://dman.ddts.net/~dman/

--neYutvxvOLaeuPCA
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj31fQoACgkQO8l8XBKTpRR2SwCfWB0kl8w3PtzW2tgB1n7fOAQA
t5gAnjmfMe5RjrElKAQkpxt9j6D/s9Gu
=JJhX
-----END PGP SIGNATURE-----

--neYutvxvOLaeuPCA--


From gp@pooryorick.com  Tue Dec 10 01:38:05 2002
From: gp@pooryorick.com (Poor Yorick)
Date: Tue Dec 10 01:38:05 2002
Subject: [Tutor] Another __builtins__.__dict__ question
References: <5.2.0.9.0.20021209183408.02aadae8@66.28.54.253>
Message-ID: <3DF58BD6.7010408@pooryorick.com>

--------------080309080907050604070109
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Thank you for the reply.  I'll try to remember next time to rtfm ;)

Poor Yorick
gp@pooryorick.com

Bob Gailer wrote:

> At 07:25 PM 12/9/2002 -0700, Poor Yorick wrote:
>
>> __builtins__.__dict__.keys().sort() returns nothing.
>
>
> Actually it returns None, as you'd see if you
> print __builtins__.__dict__.keys().sort()
> which is what sort() always returns.
>
> Another good occasion to read the documentation:
> "The sort() and reverse() methods modify the list in place for economy 
> of space when sorting or reversing a large list. To remind you that 
> they operate by side effect, they don't return the sorted or reversed 
> list."
>
> So try:
> keylist = __builtins__.__dict__.keys()
> keylist.sort()
> print leylist
>
> Bob Gailer
> mailto:ramrom@earthling.net
> 303 442 2625
>


--------------080309080907050604070109
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<html>
<head>
</head>
<body>
Thank you for the reply. &nbsp;I'll try to remember next time to rtfm ;)<br>
<br>
Poor Yorick<br>
<a class="moz-txt-link-abbreviated" href="mailto:gp@pooryorick.com">gp@pooryorick.com</a><br>
<br>
Bob Gailer wrote:<br>
<blockquote type="cite" cite="mid:5.2.0.9.0.20021209183408.02aadae8@66.28.54.253">
  At 07:25 PM 12/9/2002 -0700, Poor Yorick wrote:<br>
  <blockquote type="cite" class="cite" cite="">__builtins__.__dict__.keys().sort() 
returns nothing.</blockquote>
    <br>
 Actually it returns None, as you'd see if you <br>
 print __builtins__.__dict__.keys().sort()<br>
 which is what sort() always returns.<br>
    <br>
 Another good occasion to read the documentation:<br>
 "The <tt>sort()</tt> and <tt>reverse()</tt> methods modify the list in place
for economy of space when sorting or reversing a large list. To remind you
that they operate by side effect, they don't return the sorted or reversed
list."<br>
    <br>
 So try:<br>
 keylist = __builtins__.__dict__.keys()<br>
 keylist.sort()<br>
 print leylist<br>
    <x-sigsep></x-sigsep>
    <p> Bob Gailer<br>
    <a href="mailto:ramrom@earthling.net" eudora="autourl">mailto:ramrom@earthling.net</a>
    <br>
 303 442 2625<br>
    </p>
    </blockquote>
    <br>
    </body>
    </html>

--------------080309080907050604070109--



From rdm@rcblue.com  Tue Dec 10 02:58:03 2002
From: rdm@rcblue.com (Dick Moores)
Date: Tue Dec 10 02:58:03 2002
Subject: [Tutor] TKinter and IDLE problem
Message-ID: <5.1.0.14.2.20021209233700.037c4b70@rcblue.com>

I've been learning Python with v2.2.2 for Windows (on Win98). I've started 
to try out Tkinter with the Tkinter Intro at
http://www.pythonware.com/library/tkinter/introduction/index.htm

When I run hello1.py
(http://www.pythonware.com/library/tkinter/introduction/hello-tkinter.htm )

using IDLE, it starts fine, showing the GUI with the "Hello, World!" label. 
However, IDLE then becomes unusable, even after closing both the GUI 
and  hello1.py (no more ">>>" appear when hitting Enter).

What am I doing wrong?

Thanks,

Dick Moores
rdm@rcblue.com

========================
# File: hello1.py

from Tkinter import *

root = Tk()

w = Label(root, text="Hello, world!")
w.pack()

root.mainloop()
========================




From glingl@aon.at  Tue Dec 10 04:22:02 2002
From: glingl@aon.at (Gregor Lingl)
Date: Tue Dec 10 04:22:02 2002
Subject: [Tutor] TKinter and IDLE problem
References: <5.1.0.14.2.20021209233700.037c4b70@rcblue.com>
Message-ID: <3DF5B20A.8040502@aon.at>

AFIS, this is a well known problem when using
IDLE with Tkinter. IT has it's origin in the fact,
that IDLE itself is a Tkinter-App, so there is
already an active mainloop there.

Solution: if you use or develop TKinter-programs
with IDLE, comment out (or delete)  the
root.mainloop() statement.

However, if you want to run your app without
IDLE you have to uncomment or insert it again.

A nice idiom, to accomplish this is as follows below:


Dick Moores schrieb:

>
>
> What am I doing wrong?
>
> Thanks,
>
> Dick Moores
> rdm@rcblue.com
>
> ========================
> # File: hello1.py
>
> from Tkinter import *

  usingIDLE = 1   # True

  # code of your app

>
> root = Tk()
>
> w = Label(root, text="Hello, world!")
> w.pack()

  if not usingIDLE:
      root.mainloop()

# you turn mainloop on by setting
# usingIDLE = 0

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






From rdm@rcblue.com  Tue Dec 10 05:17:01 2002
From: rdm@rcblue.com (Dick Moores)
Date: Tue Dec 10 05:17:01 2002
Subject: [Tutor] TKinter and IDLE problem
In-Reply-To: <3DF5B20A.8040502@aon.at>
References: <5.1.0.14.2.20021209233700.037c4b70@rcblue.com>
Message-ID: <5.1.0.14.2.20021210020411.037afec0@rcblue.com>

That works. Thanks!

Dick Moores
rdm@rcblue.com

At 10:21 12/10/2002 +0100, you wrote:
 >
 >AFIS, this is a well known problem when using
 >IDLE with Tkinter. IT has it's origin in the fact,
 >that IDLE itself is a Tkinter-App, so there is
 >already an active mainloop there.
 >
 >Solution: if you use or develop TKinter-programs
 >with IDLE, comment out (or delete)  the
 >root.mainloop() statement.
 >
 >However, if you want to run your app without
 >IDLE you have to uncomment or insert it again.
 >
 >A nice idiom, to accomplish this is as follows below:
 >
 >
 >Dick Moores schrieb:
 >
 >>
 >>
 >> What am I doing wrong?
 >>
 >> Thanks,
 >>
 >> Dick Moores
 >> rdm@rcblue.com
 >>
 >> ========================
 >> # File: hello1.py
 >>
 >> from Tkinter import *
 >
 >  usingIDLE = 1   # True
 >
 >  # code of your app
 >
 >>
 >> root = Tk()
 >>
 >> w = Label(root, text="Hello, world!")
 >> w.pack()
 >
 >  if not usingIDLE:
 >      root.mainloop()
 >
 ># you turn mainloop on by setting
 ># usingIDLE = 0




From alan.gauld@bt.com  Tue Dec 10 05:57:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 10 05:57:01 2002
Subject: [Tutor] cgi module and checkboxes.
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0970225F@i2km11-ukbr.domain1.systemhost.net>

> I'm guessing that the result would be a dictionary, with "uid" as the key,

> 
> I flicked through the documentation, but didn't see anything 
> very useful there, just something about files....

Flick again and look at the "FieldStorage" stuff...

Alan G


From alan.gauld@bt.com  Tue Dec 10 06:07:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 10 06:07:02 2002
Subject: [Tutor] cgi module and checkboxes.
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0974DA5F@i2km11-ukbr.domain1.systemhost.net>

> attached is roster.py, It's unfinished, but you should be able to see
> whats happening :-)

OK, You have discovered FieldStorage.
So what is happening? Without a web server its hard to try the code out...

> the problem lies within the last 10 lines of code

	elif cgi.form['action'].value == 'addproject':
		if cgi.checklog():
			print cgi.formitems
			print cgi.form['uid'].value


This bit presumably. But what does get printed?	Anything? 
Or do you get an error message? If so what does it say?

Alan g



From alan.gauld@bt.com  Tue Dec 10 06:12:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 10 06:12:02 2002
Subject: [Tutor] Another __builtins__.__dict__ question
Message-ID: <7497DCA1C240C042B28F6657ADFD8E09702261@i2km11-ukbr.domain1.systemhost.net>

> __builtins__.__dict__.keys().sort()
> 
> returns nothing.

Unfortunately sort() sorts the list in place but dsoesn't return a 
reference to the sorted list. You have to do something like:

keys = __builtins__.__dict__.keys()
keys.sort()
print keys


HTH,

Alan G.


From alan.gauld@bt.com  Tue Dec 10 06:19:00 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 10 06:19:00 2002
Subject: [Tutor] os.environ weirdness
Message-ID: <7497DCA1C240C042B28F6657ADFD8E09702262@i2km11-ukbr.domain1.systemhost.net>

> Another phenomenon I haven't made sense of:
> 
>  >>> for i in os.environ:
>     print i

Yeah, I can't make sense of the 'in' operation on dictionaries either.... 
is it the key that's in or the value? Wierd....

Much better to be explicit:

for k in os.environ.keys()
   print os.environ[k]

> I realize that os.environ is not a builtin dictionary, but 
> some sort of subclassed dictionary, but these commands work:
> 
> os.environ.keys()
> os.environ.items()

Yep, thats why i prefer to use them.

> doesn't the "in" statement just resolve to one of those functions?

Dunno, like I said the whole concept of 'in' applying to a 
dictionary confuses the heck out of me... ;-)

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld



From glingl@aon.at  Tue Dec 10 07:41:07 2002
From: glingl@aon.at (Gregor Lingl)
Date: Tue Dec 10 07:41:07 2002
Subject: [Tutor] os.environ weirdness
References: <3DF55214.70405@pooryorick.com>
Message-ID: <3DF5E0C7.6060100@aon.at>

Poor Yorick schrieb:

> Another phenomenon I haven't made sense of:
>
> >>> for i in os.environ:
>    print i
>
>   Traceback (most recent call last):
>  File "<pyshell#13>", line 1, in ?
>    for i in os.environ:
>  File "C:\Python22\lib\os.py", line 387, in __getitem__
>    return self.data[key.upper()]
> AttributeError: 'int' object has no attribute 'upper'

For me this works (although it's not a subclassed dict, but
a subclassed IterableUserDict, which also implements __iter__(),
as a look at os.py shows.):

 >>> import os
 >>> for i in os.environ:
    print i,

   
TMP USERNAME COMPUTERNAME LOGONSERVER COMSPEC USERDOMAIN HOME TFLIBDIR 
TCL_LIBRARY COMMONPROGRAMFILES PROCESSOR_IDENTIFIER PROGRAMFILES 
PROCESSOR_REVISION PATHEXT SYSTEMROOT PATH APPDATA TEMP HOMEDRIVE 
SYSTEMDRIVE PROCESSOR_ARCHITECTURE NUMBER_OF_PROCESSORS ALLUSERSPROFILE 
PROCESSOR_LEVEL TK_LIBRARY HOMEPATH OS2LIBPATH USERPROFILE OS WINDIR
 >>>

Your errormessage shows, that there is a key in your os.environ, which 
is an 'int',
whereas it is assumed. that all keys are of type string. so they have a 
method upper.
Did you tinker around with os.eviron?

Regards, Gregor


>
> I realize that os.environ is not a builtin dictionary, but some sort 
> of subclassed dictionary, but these commands work:
>
> os.environ.keys()
> os.environ.items()
>
> doesn't the "in" statement just resolve to one of those functions?
>
> Regards,
>
> Poor Yorick
> gp@pooryorick.com
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>






From glingl@aon.at  Tue Dec 10 07:50:02 2002
From: glingl@aon.at (Gregor Lingl)
Date: Tue Dec 10 07:50:02 2002
Subject: [Tutor] os.environ weirdness
References: <3DF55214.70405@pooryorick.com> <3DF5E0C7.6060100@aon.at>
Message-ID: <3DF5E238.9080903@aon.at>

Gregor Lingl schrieb:

>
> For me this works (although it's not a subclassed dict, but
> a subclassed IterableUserDict, which also implements __iter__(),
> as a look at os.py shows.):

... a look at UserDict.py shows ...
sorry, Gregor






From muldersmaarten@hotmail.com  Tue Dec 10 09:51:02 2002
From: muldersmaarten@hotmail.com (Maarten Mulders)
Date: Tue Dec 10 09:51:02 2002
Subject: [Tutor] (no subject)
Message-ID: <F161VtCBIhZqA4u6hnI00009e23@hotmail.com>

<html><div style='background-color:'><DIV>
<P><BR>Well, this might be the most basic question ever asked, but I'll do...<BR>I'm using Win98. How can I compile Python-code to an executable (*.exe)? Or isn't that possible?<BR>Thanks in advance.<BR></P></DIV></div><br clear=all><hr>Ontvang je Hotmail & Messenger berichten op je mobiele telefoon met Hotmail SMS <a href="http://g.msn.com/8HMHNL/2023">Klik hier</a> </html>


From op73418@mail.telepac.pt  Tue Dec 10 10:53:04 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Tue Dec 10 10:53:04 2002
Subject: [Tutor] (no subject)
References: <F161VtCBIhZqA4u6hnI00009e23@hotmail.com>
Message-ID: <001801c2a064$fd05ba60$771b0dd5@violante>

This is a multi-part message in MIME format.

------=_NextPart_000_0015_01C2A064.FC282BA0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

At present there are no compilers that translate Python source code =
directly into a native executable - and probably there will never be - =
you always need the interpreter around.

There are however tools that can "freeze" an application. Essentially =
they just bundle together your source along with any modules it needs =
and the interpreter into a unique binary executable that can then be =
distributed standalone without requiring the users to have Python =
installed.

With my best regards,
G. Rodrigues
  ----- Original Message -----=20
  From: Maarten Mulders=20
  To: tutor@python.org=20
  Sent: Tuesday, December 10, 2002 2:49 PM
  Subject: [Tutor] (no subject)



  Well, this might be the most basic question ever asked, but I'll do...
  I'm using Win98. How can I compile Python-code to an executable =
(*.exe)? Or isn't that possible?
  Thanks in advance.


------=_NextPart_000_0015_01C2A064.FC282BA0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2716.2200" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>At present there are no compilers that =
translate=20
Python source code directly into a native executable - and probably =
there will=20
never be - you always need the interpreter around.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>There are however tools that can =
"freeze" an=20
application. Essentially they just bundle together your source along =
with any=20
modules it needs and the interpreter into a unique binary executable =
that can=20
then be distributed standalone without requiring the users to have =
Python=20
installed.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>With my best regards,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>G. Rodrigues</FONT></DIV>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Dmuldersmaarten@hotmail.com=20
  href=3D"mailto:muldersmaarten@hotmail.com">Maarten Mulders</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A title=3Dtutor@python.org =

  href=3D"mailto:tutor@python.org">tutor@python.org</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Tuesday, December 10, =
2002 2:49=20
  PM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Tutor] (no =
subject)</DIV>
  <DIV><FONT face=3DArial size=3D2></FONT><BR></DIV>
  <DIV>
  <DIV>
  <P><FONT face=3DArial size=3D2></FONT><BR>Well, this might be the most =
basic=20
  question ever asked, but I'll do...<BR>I'm using Win98. How can I =
compile=20
  Python-code to an executable (*.exe)? Or isn't that =
possible?<BR>Thanks in=20
  advance.</P></DIV></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0015_01C2A064.FC282BA0--



From hall@ouhep1.nhn.ou.edu  Tue Dec 10 12:29:02 2002
From: hall@ouhep1.nhn.ou.edu (Isaac Hall)
Date: Tue Dec 10 12:29:02 2002
Subject: [Tutor] Tkinter wierdness
Message-ID: <Pine.LNX.4.44.0212101125210.27621-100000@ouhep1.nhn.ou.edu>

I was wondering if someone could explain the source of some wierdness I am 
seeing in Tkinter.
I have a program with a main window, and later create other Toplevel 
Windows.  I place a button in the Toplevel window, but then the wierdness 
ensues.  the command for the button is run when the button is created, and 
can never be run again!  clicking the button afterward does nothing.  can 
someone explain why this is happening, because I am stumped.  

Thanks

Ike

-- 



From alan.gauld@bt.com  Tue Dec 10 12:50:03 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 10 12:50:03 2002
Subject: [Tutor] Re: How different is math logic from computer logic?
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0974DA63@i2km11-ukbr.domain1.systemhost.net>

> Just out of curiosity, did Boole come up with "nand" or did that come
> later?

It came later but I don't know from where or when exactly.
ISTR Boole didn't even use 'and', 'or' and 'not' he used other 
more mathematically based names. Certainly he didn't use the 
+ and * symbols that Magnus posted, he used the pure math 
notation found in formal notations like VDM and Z.

OR = v
AND = ^

Which are somewhat like the set notations for intersection 
and union. Negation uses a strange symbol somewhat like:  -|
(think about the top corner of a rectangle) and used as 
a superscript in front of the thing being negated.
(The symbol is on the key to the left of the digit 1 on my 
keypad if that helps...)

> For those unfamiliar with it, the nand operator is functionally
> complete.  

As is its twin nor.

> With just nand you can write any logic expression.  The
> combination of and, or and not is also functionally complete.  (it's
> more natural too, but require 3 operators instead of 1)

This is really only of much significance if you are using 
hardware gates to build a solution though! :-)

> If you're really interested in logic or rule based programming, check
> out Prolog.  (I've only heard about it but never used it)

I have played with Micro Prolog and another variant on our old VAX.
Never built anything that other people used, but its a fun language.

Alan g.


From alan.gauld@bt.com  Tue Dec 10 12:53:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 10 12:53:01 2002
Subject: [Tutor] TKinter and IDLE problem
Message-ID: <7497DCA1C240C042B28F6657ADFD8E09702267@i2km11-ukbr.domain1.systemhost.net>

> I've been learning Python with v2.2.2 for Windows (on Win98). 
> I've started 
> to try out Tkinter with the Tkinter Intro at

> However, IDLE then becomes unusable, even after closing both the GUI 
> and  hello1.py (no more ">>>" appear when hitting Enter).
> 
> What am I doing wrong?

Using IDLE!
Try saving your program into a file and running it from the 
DOS prompt - or double clicking it in explorer).

IDLE is written in Tkinter and its difficult for Tkinter to run 
two programs at the same time, it gets confused. There is a fudge 
to get round this but then your program doesn't run right outside IDLE!

Its easier IMHO to just get into the good habit of saving your Tkinter
code as a file and running it outside IDLE. I discuss this issue in 
passing in the GUI section of my tutorial...

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld


From alan.gauld@bt.com  Tue Dec 10 13:02:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 10 13:02:01 2002
Subject: [Tutor] (no subject)
Message-ID: <7497DCA1C240C042B28F6657ADFD8E09702268@i2km11-ukbr.domain1.systemhost.net>

> asked, but I'll do...<BR>I'm using Win98. How can I compile 
> Python-code to an executable (*.exe)? 

Its possible but IMHO not something you want to do if you 
can avoid it. It basically involved wrapping the python 
interpreter up with all the liraries you need into one big file. 
It won't run any faster and won'ty be much smaller. And it won't 
be much easier to  distribute.

The only advantage, and spurious at that, is that people 
can't see your code!

The big disadvantage is that if you want to distribute 
several python programs you wind up distrinbuting several 
copies of the python interpreter.

Better to do as HP and others do, create an installer that 
checks if Python is already installed (check the registry 
then the filesystem) and if not run the standard Python 
installer followed by dumping your files into a suitable 
place. Finally update the PYTHONPATH in autoexec.bat or the 
sys.path if you prefer.

One copy of python and you can get the benefit of upgrades
later if needed.

If you really must bundle to exe then look at py2exe
(A Google search will find it)

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld


From rickp@telocity.com  Tue Dec 10 13:07:02 2002
From: rickp@telocity.com (Rick Pasotto)
Date: Tue Dec 10 13:07:02 2002
Subject: [Tutor] Tkinter wierdness
In-Reply-To: <Pine.LNX.4.44.0212101125210.27621-100000@ouhep1.nhn.ou.edu>
References: <Pine.LNX.4.44.0212101125210.27621-100000@ouhep1.nhn.ou.edu>
Message-ID: <20021210180525.GC13252@tc.niof.net>

On Tue, Dec 10, 2002 at 11:28:20AM -0600, Isaac Hall wrote:
> I was wondering if someone could explain the source of some wierdness
> I am seeing in Tkinter. I have a program with a main window, and later
> create other Toplevel Windows.  I place a button in the Toplevel
> window, but then the wierdness ensues.  the command for the button is
> run when the button is created, and can never be run again!  clicking
> the button afterward does nothing.  can someone explain why this is
> happening, because I am stumped.  

Without seeing your actual code this is only a guess but does your
button definition include 'command=func()'? If so, drop the parentheses
and your problem will be solved.

-- 
"The financial policy of the welfare state requires that there be no
way for the owners of wealth to protect themselves.  This is the
shabby secret of the welfare statists' tirades against gold.   Deficit
spending is simply a scheme for the 'hidden' confiscation of wealth.
Gold stands in the way of this insidious process.   It stands as a
protector of property rights."
		-- Alan Greenspan
    Rick Pasotto    rickp@telocity.com    http://www.niof.net


From hall@ouhep1.nhn.ou.edu  Tue Dec 10 13:43:03 2002
From: hall@ouhep1.nhn.ou.edu (Isaac Hall)
Date: Tue Dec 10 13:43:03 2002
Subject: [Tutor] Tkinter wierdness
In-Reply-To: <20021210180525.GC13252@tc.niof.net>
Message-ID: <Pine.LNX.4.44.0212101239400.27621-100000@ouhep1.nhn.ou.edu>

On Tue, 10 Dec 2002, Rick Pasotto wrote:

> On Tue, Dec 10, 2002 at 11:28:20AM -0600, Isaac Hall wrote:
> > I was wondering if someone could explain the source of some wierdness
> > I am seeing in Tkinter. I have a program with a main window, and later
> > create other Toplevel Windows.  I place a button in the Toplevel
> > window, but then the wierdness ensues.  the command for the button is
> > run when the button is created, and can never be run again!  clicking
> > the button afterward does nothing.  can someone explain why this is
> > happening, because I am stumped.  
> 
> Without seeing your actual code this is only a guess but does your
> button definition include 'command=func()'? If so, drop the parentheses
> and your problem will be solved.
> 
> 
That was it exactly.  Thank you

Ike

P.S. the inevitable follow-up question:  why must this be done?  if I wish 
to call a function with some arguments, how is this done?  


-- 



From ramrom@earthling.net  Tue Dec 10 14:10:13 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Tue Dec 10 14:10:13 2002
Subject: [Tutor] Re: How different is math logic from computer
 logic?
In-Reply-To: <20021210053506.GB31287@dman.ddts.net>
References: <5.1.0.14.0.20021208224228.02abaff8@www.thinkware.se>
 <MHHPAJHBHCNDEAAA@mailcity.com>
 <5.1.0.14.0.20021208224228.02abaff8@www.thinkware.se>
Message-ID: <5.2.0.9.0.20021210105855.02342550@66.28.54.253>

At 12:35 AM 12/10/2002 -0500, Derrick 'dman' Hudson wrote:
>Just out of curiosity, did Boole come up with "nand" or did that come later?

The earliest implementations of transistor and integrated circuit logic 
gates were based on inverters. An input voltage applied (through a 
resistor) to the base of a bipolar transistor "turned on" the transistor, 
causing its output (collector) voltage to drop towards zero, thus inverting 
the input signal (a NOT gate). Combining several inputs created NOR and 
NAND gates. This was this way strictly for economy of components; a 
beneficial side effect was that any more complex logic could be easily 
built up from these fundamental gates.

My guess is that NAND as a term became popular, if not invented, at that time.

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625



From gp@pooryorick.com  Tue Dec 10 14:16:14 2002
From: gp@pooryorick.com (Poor Yorick)
Date: Tue Dec 10 14:16:14 2002
Subject: [Tutor] os.environ weirdness
References: <3DF55214.70405@pooryorick.com> <3DF5E0C7.6060100@aon.at>
Message-ID: <3DF63D2A.2000605@pooryorick.com>

No, I didn't tinker around with os.environ.  I see this behavior on both 
of my windows 2000 computers.  Can anyone else reproduce this?

Poor Yorick
gp@pooryorick.com

Gregor Lingl wrote:

> Poor Yorick schrieb:
>
>> Another phenomenon I haven't made sense of:
>>
>> >>> for i in os.environ:
>>    print i
>>
>>   Traceback (most recent call last):
>>  File "<pyshell#13>", line 1, in ?
>>    for i in os.environ:
>>  File "C:\Python22\lib\os.py", line 387, in __getitem__
>>    return self.data[key.upper()]
>> AttributeError: 'int' object has no attribute 'upper'
>
>
> For me this works (although it's not a subclassed dict, but
> a subclassed IterableUserDict, which also implements __iter__(),
> as a look at os.py shows.):
>
> >>> import os
> >>> for i in os.environ:
>    print i,
>
>   TMP USERNAME COMPUTERNAME LOGONSERVER COMSPEC USERDOMAIN HOME 
> TFLIBDIR TCL_LIBRARY COMMONPROGRAMFILES PROCESSOR_IDENTIFIER 
> PROGRAMFILES PROCESSOR_REVISION PATHEXT SYSTEMROOT PATH APPDATA TEMP 
> HOMEDRIVE SYSTEMDRIVE PROCESSOR_ARCHITECTURE NUMBER_OF_PROCESSORS 
> ALLUSERSPROFILE PROCESSOR_LEVEL TK_LIBRARY HOMEPATH OS2LIBPATH 
> USERPROFILE OS WINDIR
> >>>
>
> Your errormessage shows, that there is a key in your os.environ, which 
> is an 'int',
> whereas it is assumed. that all keys are of type string. so they have 
> a method upper.
> Did you tinker around with os.eviron?
>
> Regards, Gregor
>
>
>>
>> I realize that os.environ is not a builtin dictionary, but some sort 
>> of subclassed dictionary, but these commands work:
>>
>> os.environ.keys()
>> os.environ.items()
>>
>> doesn't the "in" statement just resolve to one of those functions?
>>
>> Regards,
>>
>> Poor Yorick
>> gp@pooryorick.com
>>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
>
>
>
>
>




From bindas_qwerty@hotmail.com  Tue Dec 10 14:38:00 2002
From: bindas_qwerty@hotmail.com (sachin mehra)
Date: Tue Dec 10 14:38:00 2002
Subject: [Tutor] question on Partition
Message-ID: <F396OZj9mspgEOI7vDc000113fc@hotmail.com>

hi,
I need to use the partition function.How can I use it?Do I have to include 
any module for that?Kidly let me know.
Thanx,



###
>>>paritition("attackatdawn")
[['at', 'tack', 'at', 'dawn'],
['attack', 'at', 'dawn']]

>>>partition("iscreamforicecream")
[['is', 'cream', 'for', 'ice', 'cream'],
['i', 'scream', 'for', 'ice', 'cream']]

>>>partition("uselesspython")
[['use', 'less', 'python'],
['useless', 'python']]

>>>partition("inaholetherelivedahobbit")
[['in', 'a', 'hole', 'the', 're', 'lived', 'a', 'hobbit'],
['in', 'a', 'hole', 'there', 'lived', 'a', 'hobbit']]
###


_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail



From jeff@ccvcorp.com  Tue Dec 10 15:29:03 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Tue Dec 10 15:29:03 2002
Subject: [Tutor] Tkinter wierdness
References: <Pine.LNX.4.44.0212101239400.27621-100000@ouhep1.nhn.ou.edu>
Message-ID: <3DF64E80.6020600@ccvcorp.com>


Isaac Hall wrote:

>P.S. the inevitable follow-up question:  why must this be done?  if I wish 
>to call a function with some arguments, how is this done?  
>

The reason this must be done is based on Python reference semantics. 
 When you construct a button, you're setting the command to be a 
function that you want called when the button is pressed.  This means 
that when you have 'command=xxx', you want xxx to be a *reference* to a 
function.  Tkinter then holds on to that reference and calls it as 
necessary.  In Python, when you use a bare function name, it evaluates 
to a reference to that function, but when you put parens after it, that 
function is immediately called.

To look at this a bit more concretely, say you have a function, 
MyFunc(), which you want to have called when a button is pressed.  If 
you say "command=MyFunc", then a reference to your function is passed 
into Tkinter (and given the name command).  Now, at some later point, 
Tkinter can execute "command()" and it will be identical to Tkinter 
having executed "MyFunc()" at that point.

On the other hand, if you say "command=MyFunc()", then MyFunc() is 
executed *right then*, when your button is created, and the *results* of 
that are assigned to command.  Since most handlers in GUI toolkits are 
supposed to have no return value (they return None), you've essentially 
told Tkinter that the command to execute when the button is pressed, is 
None -- so of course it does nothing.

As far as passing arguments to a command function -- that's a little 
tricky, because Tkinter won't call command() with any arguments, so you 
need to find some way to wedge your data in there without requiring it 
to be a normal parameter.  This technique is called currying, and 
there's *lots* of discussions about it in the comp.lang.python archives. 
 One of the most common methods is to use a lambda to create an 
anonymous function that requires no arguments, whose effect (when 
called) is to call the *real* function with an argument that's specified 
when you create the lambda.  (Personally, I never quite got the hang of 
lambdas and don't particularly like them, so I can't demonstrate the 
proper way to do this -- I can never remember proper lambda syntax.  I'm 
sure others will chime in, though.)

Another way of doing this is to create a nested function, which has much 
the same effect as the lambda, but gives the intermediate function a 
name.  This would look something like this:

    # create a button to call MyFunc with the current value of MyName
    def namecommand():
        return MyFunc(name=MyName)
    self.button = Button(root, command=namecommand, ...)

Another, still more flexible option, is to use a callable class instance 
instead of a regular function for your command.  

class namecommand:
    def __init__(self, name):
        self.name = name
    def __call__(self):
        # do stuff making use of self.name

    # ... when creating the button...
    MyFunc = namecommand(MyName)
    self.button = Button(root, command=MyFunc, ...)

You can pass any number of parameters to the class __init__(), of 
course, and anything you set as an object attribute will be available 
when the object is called.  The only requirement is that __call__() has 
no parameters other than "self", because Tkinter will call it with no 
parameters.  (The "self" will automagically come from Python's object 
reference semantics.)  You can even change the parameters later by 
modifying MyFunc.name, if you wish.

Jeff Shannon
Technician/Programmer
Credit International







From magnus@thinkware.se  Tue Dec 10 17:20:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Dec 10 17:20:02 2002
Subject: [Tutor] os.environ weirdness
In-Reply-To: <3DF63D2A.2000605@pooryorick.com>
References: <3DF55214.70405@pooryorick.com>
 <3DF5E0C7.6060100@aon.at>
Message-ID: <5.1.0.14.0.20021210230244.03421928@www.thinkware.se>

At 12:14 2002-12-10 -0700, Poor Yorick wrote:
>No, I didn't tinker around with os.environ.  I see this behavior on both 
>of my windows 2000 computers.  Can anyone else reproduce this?

Yes, with Python 2.2.1 for Win 2000 and Linux. Looks like a bug to me.
Google is your friend...
http://mail.python.org/pipermail/python-bugs-list/2002-September/013375.html

It seems this was reported and fixed on 2002-09-06.

>Gregor Lingl wrote:
>>For me this works ...

What python version are you running Gregor?

BTW, ActivePython 2.2.2 is out I think...


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Tue Dec 10 17:37:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Dec 10 17:37:02 2002
Subject: [Tutor] Tkinter wierdness
In-Reply-To: <Pine.LNX.4.44.0212101239400.27621-100000@ouhep1.nhn.ou.edu
 >
References: <20021210180525.GC13252@tc.niof.net>
Message-ID: <5.1.0.14.0.20021210232434.03454d20@www.thinkware.se>

At 12:42 2002-12-10 -0600, Isaac Hall wrote:
>P.S. the inevitable follow-up question:  why must this be done?  if I wish
>to call a function with some arguments, how is this done?

Because "command=function" means "function is the command you should
run". "command=function()" means "The result value from function is
the command you should run".

Look here:
 >>> def hw(aString="world"):
...     return "Hello %s" % aString
...
 >>> print hw()
Hello world
 >>> print hw
<function hw at 0x015E9900>
 >>> command = hw
 >>> command
<function hw at 0x015E9900>
 >>> command()
'Hello world'
 >>> command('Moon')
'Hello Moon'
 >>> command = hw()
 >>> command
'Hello world'
 >>> command()
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
TypeError: 'str' object is not callable

See the difference? When you bind a command in Tkinter, you tell
the computer what to run at a later time. You must hand over something
that can run, right?

But look here!
 >>> class hw:
...     def __init__(self, greeting='hello'):
...             self.greeting = greeting
...     def __call__(self, who='world'):
...             return "%s %s" % (self.greeting, who)
...
 >>> command = hw('hi') # Run __init__
 >>> command('moon')    # Run __call__
'hi moon'


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From gp@pooryorick.com  Tue Dec 10 17:52:01 2002
From: gp@pooryorick.com (Poor Yorick)
Date: Tue Dec 10 17:52:01 2002
Subject: [Tutor] TKinter and IDLE problem
References: <7497DCA1C240C042B28F6657ADFD8E09702267@i2km11-ukbr.domain1.systemhost.net>
Message-ID: <3DF67004.3060402@pooryorick.com>

--------------000607000306060806090300
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

I've been doing a lot of Tkinter programming in Idle on Windows 2000, 
and I've found that the easiest way to proceed is to keep a DOS window 
open to the folder where my python source file is, and follow this sequence:

alt+f-s (saves the tkinter program in the idle window)
alt-lefttab-<enter> (switches to the command window)
<up arrow>-<enter> (recalls the previous dos command, something like 
"python myprogram.py"
alt-lefttab<enter> (when the Tkinter program finishes to get back to the 
Idle edit window)

Poor Yorick
gp@pooryorick.om

alan.gauld@bt.com wrote:

>>I've been learning Python with v2.2.2 for Windows (on Win98). 
>>I've started 
>>to try out Tkinter with the Tkinter Intro at
>>
>
>>However, IDLE then becomes unusable, even after closing both the GUI 
>>and  hello1.py (no more ">>>" appear when hitting Enter).
>>
>>What am I doing wrong?
>>
>
>Using IDLE!
>Try saving your program into a file and running it from the 
>DOS prompt - or double clicking it in explorer).
>
>IDLE is written in Tkinter and its difficult for Tkinter to run 
>two programs at the same time, it gets confused. There is a fudge 
>to get round this but then your program doesn't run right outside IDLE!
>
>Its easier IMHO to just get into the good habit of saving your Tkinter
>code as a file and running it outside IDLE. I discuss this issue in 
>passing in the GUI section of my tutorial...
>
>Alan g.
>Author of the 'Learning to Program' web site
>http://www.freenetpages.co.uk/hp/alan.gauld
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>


--------------000607000306060806090300
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<html>
<head>
</head>
<body>
I've been doing a lot of Tkinter programming in Idle on Windows 2000, and
I've found that the easiest way to proceed is to keep a DOS window open to
the folder where my python source file is, and follow this sequence:<br>
<br>
alt+f-s (saves the tkinter program in the idle window)<br>
alt-lefttab-&lt;enter&gt; (switches to the command window)<br>
&lt;up arrow&gt;-&lt;enter&gt; (recalls the previous dos command, something
like "python myprogram.py"<br>
alt-lefttab&lt;enter&gt; (when the Tkinter program finishes to get back to
the Idle edit window)<br>
<br>
Poor Yorick<br>
<a class="moz-txt-link-abbreviated" href="mailto:gp@pooryorick.om">gp@pooryorick.om</a><br>
<br>
<a class="moz-txt-link-abbreviated" href="mailto:alan.gauld@bt.com">alan.gauld@bt.com</a> wrote:<br>
<blockquote type="cite" cite="mid:7497DCA1C240C042B28F6657ADFD8E09702267@i2km11-ukbr.domain1.systemhost.net">
  <blockquote type="cite">
    <pre wrap="">I've been learning Python with v2.2.2 for Windows (on Win98). <br>I've started <br>to try out Tkinter with the Tkinter Intro at<br></pre>
    </blockquote>
    <pre wrap=""><!----><br></pre>
    <blockquote type="cite">
      <pre wrap="">However, IDLE then becomes unusable, even after closing both the GUI <br>and  hello1.py (no more "&gt;&gt;&gt;" appear when hitting Enter).<br><br>What am I doing wrong?<br></pre>
      </blockquote>
      <pre wrap=""><!----><br>Using IDLE!<br>Try saving your program into a file and running it from the <br>DOS prompt - or double clicking it in explorer).<br><br>IDLE is written in Tkinter and its difficult for Tkinter to run <br>two programs at the same time, it gets confused. There is a fudge <br>to get round this but then your program doesn't run right outside IDLE!<br><br>Its easier IMHO to just get into the good habit of saving your Tkinter<br>code as a file and running it outside IDLE. I discuss this issue in <br>passing in the GUI section of my tutorial...<br><br>Alan g.<br>Author of the 'Learning to Program' web site<br><a class="moz-txt-link-freetext" href="http://www.freenetpages.co.uk/hp/alan.gauld">http://www.freenetpages.co.uk/hp/alan.gauld</a><br><br>_______________________________________________<br>Tutor maillist  -  <a class="moz-txt-link-abbreviated" href="mailto:Tutor@python.org">Tutor@python.org</a><br><a class="moz-txt-link-freetext" href="http://mail
.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a><br><br><br></pre>
      </blockquote>
      <br>
      </body>
      </html>

--------------000607000306060806090300--



From magnus@thinkware.se  Tue Dec 10 17:53:25 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Dec 10 17:53:25 2002
Subject: [Tutor] Re: How different is math logic from computer
 logic?
In-Reply-To: <20021210053506.GB31287@dman.ddts.net>
References: <5.1.0.14.0.20021208224228.02abaff8@www.thinkware.se>
 <MHHPAJHBHCNDEAAA@mailcity.com>
 <5.1.0.14.0.20021208224228.02abaff8@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021210234519.03448928@www.thinkware.se>

At 00:35 2002-12-10 -0500, Derrick 'dman' Hudson wrote:
>Just out of curiosity, did Boole come up with "nand" or did that come
>later?

NAND isn't really a logic operator on it's own. "O = I1 NAND I2" is
nothing else but "O = NOT (I1 AND I2)". NAND and NOR are more common
in electronic devices for practical reasons, but that has little to do
with logic or programming. (Unless you have some bizarre drive to only
use multiples of four "and" or "or" statements in your code.) I'll
refrain from discussing electronic design right now...

I'm not sure who came up with what in logic, but if I allow myself to
mention one interesting piece of boolean algebra, it has to be de Morgan's
Theorem. I guess that was discovered by someone called de Morgan...

NOT (A AND B) = (NOT A) OR (NOT B)

or if you prefer

NOT (A OR B) = (NOT A) AND (NOT B)


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Tue Dec 10 17:56:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Dec 10 17:56:02 2002
Subject: [Tutor] TKinter and IDLE problem
In-Reply-To: <3DF5B20A.8040502@aon.at>
References: <5.1.0.14.2.20021209233700.037c4b70@rcblue.com>
Message-ID: <5.1.0.14.0.20021210235651.0344db60@www.thinkware.se>

At 10:21 2002-12-10 +0100, Gregor Lingl wrote:
>AFIS, this is a well known problem when using
>IDLE with Tkinter. IT has it's origin in the fact,
>that IDLE itself is a Tkinter-App, so there is
>already an active mainloop there.
>
>Solution: if you use or develop TKinter-programs
>with IDLE, comment out (or delete)  the
>root.mainloop() statement.

Isn't it more convenient to use IDLE-fork, which runs
programs in a separate process?


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Tue Dec 10 18:15:03 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Dec 10 18:15:03 2002
Subject: [Tutor] TKinter and IDLE problem
In-Reply-To: <3DF67004.3060402@pooryorick.com>
References: <7497DCA1C240C042B28F6657ADFD8E09702267@i2km11-ukbr.domain1.systemhost.net>
Message-ID: <5.1.0.14.0.20021211001209.0344dca8@www.thinkware.se>

At 15:51 2002-12-10 -0700, Poor Yorick wrote:
>I've been doing a lot of Tkinter programming in Idle on Windows 2000, and 
>I've found that the easiest way to proceed is to keep a DOS window open to 
>the folder where my python source file is, and follow this sequence:
>
>alt+f-s (saves the tkinter program in the idle window)
>alt-lefttab-<enter> (switches to the command window)
><up arrow>-<enter> (recalls the previous dos command, something like 
>"python myprogram.py"
>alt-lefttab<enter> (when the Tkinter program finishes to get back to the 
>Idle edit window)

And the great thing is that this works equally well
with wxPython or any other GUI tool kit that won't
play well at all with IDLE.

If you save with Ctrl-S instead, it also works with
PythonWin. (I can hardly imagine working without a
folding editor any longer.)

The problem is that graphical debugging of a GUI program
might be difficult. I just tested Boa Constructor, and
that is the first environment I tested that worked as I
expected for debugging wxPython programs. I don't know
what to use for Tkinter programs though...


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From thomi@thomi.imail.net.nz  Tue Dec 10 18:51:01 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Tue Dec 10 18:51:01 2002
Subject: [Tutor] (no subject)
In-Reply-To: <F161VtCBIhZqA4u6hnI00009e23@hotmail.com>
References: <F161VtCBIhZqA4u6hnI00009e23@hotmail.com>
Message-ID: <20021211124930.00639c5f.thomi@thomi.imail.net.nz>

> Well, this might be the most basic question ever asked, but I'll do...
> I'm using Win98. How can I compile Python-code to an executable
> (*.exe)? Or isn't that possible? Thanks in advance.

search for py2exe on google.

i *think* it is at:

http://sourceforge.net/projects/py2exe

> 
> ------------------------------------------------
> Ontvang je Hotmail & Messenger berichten op je mobiele telefoon met
> Hotmail SMS http://g.msn.com/8HMHNL/2023 Klik hier
> _______________________________________________ Tutor maillist -
> Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

-- 
Thomi Richards
thomi@imail.net.nz
http://ddmodd.sourceforge.net/
Thomi Richards,
thomi@imail.net.nz


From glingl@aon.at  Tue Dec 10 18:54:01 2002
From: glingl@aon.at (Gregor Lingl)
Date: Tue Dec 10 18:54:01 2002
Subject: [Tutor] TKinter and IDLE problem
Message-ID: <3DF67E85.4060708@aon.at>



Magnus Lycka schrieb:

> At 10:21 2002-12-10 +0100, Gregor Lingl wrote:
>
>> AFIS, this is a well known problem when using
>> IDLE with Tkinter. IT has it's origin in the fact,
>> that IDLE itself is a Tkinter-App, so there is
>> already an active mainloop there.
>>
>> Solution: if you use or develop TKinter-programs
>> with IDLE, comment out (or delete)  the
>> root.mainloop() statement.
>
>
> Isn't it more convenient to use IDLE-fork, which runs
> programs in a separate process?
>
>
Several months ago, I also thought this, so I tried out IDLE-fork.
I must confess, now I don't remember very well it's features.

In general I would agree with you and also with poor Yorick.

But when I was preparing some introductory material for kids, I found that
that running programs in a separate process also has disatvantages.
As far as I remember, you cannot investigate (global) variables used
in a program, which e. g. terminated with an error, interactively.  Also
you cannot define functionsprogrammatically and then continue
using them in an interactive session. (Correct me, please, if I'm wrong).

This may not be a disatvantage for programmers with some experience,
who know how to use the debugger or how to insert some tracing statements.
And I know, that there is the danger of producing unexpected results due to
the existence of global variables in the workspace, the programmer isn't
aware of, as well as to overlook programming errors (e. g. to forget
proper intialization of variables), which only reveal themselves when the
program is executed stand alone.

Nevertheless I found it preferable that the kids - or beginners - have 
this tight contact to their programs via the interactive interpreter.  And 
switching the value of a boolean variable isn't really hard work! 
(Moreover: it's very easy to use the IDLE Python comes with, whereas IDLE-fork seems still
to be under development, needs to be downloaded from somewhere, installed properly,
and who knows, how stable it is ....
I remember wild discussions about responsibilities in the development 
team only few months ago at the idledev-mailing list. Nevertheless I think, 
sometimes, not far from now, it will go into the standard-distribution.)

(BTW, one of the most severe inconveniences of IDLE is it's inability to 
produce printed program-listings.)

Regards, Gregor








From Adam Vardy <anvardy@roadrunner.nf.net>  Tue Dec 10 20:53:01 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Tue Dec 10 20:53:01 2002
Subject: [Tutor] Example 1
Message-ID: <3286194150.20021210222238@roadrunner.nf.net>

I can follow the meaning of the following function. Should be simple,
so, want to explain?

def union(*args):
    res = []
    for seq in args:                     # for all args
        for x in seq:                    # for all nodes
            if not x in res:
                res.append(x)            # add new items to result
    return res
  

-- 
Adam Vardy



From Adam Vardy <anvardy@roadrunner.nf.net>  Tue Dec 10 21:31:02 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Tue Dec 10 21:31:02 2002
Subject: [Tutor] command ...
Message-ID: <5988461741.20021210230026@roadrunner.nf.net>

If I type some commands, and some come after ... and at some point it
stops and complains with a syntax error, it seems like it abandons
what I already entered.

I should be able to back up, and cross out the last command, shouldn't I?
If it didn't like it.

-- 
Adam Vardy



From wesc@fuzzyorange.com  Tue Dec 10 21:40:02 2002
From: wesc@fuzzyorange.com (Wesley Chun)
Date: Tue Dec 10 21:40:02 2002
Subject: [Tutor] REM: BayPIGgies mtg Wed 12/11 7:30pm
In-Reply-To: <Pine.LNX.4.31.0212052230370.6903-100000@emperor.deirdre.org>
Message-ID: <Pine.LNX.4.31.0212101807430.17004-100000@emperor.deirdre.org>

hi there,

here is a reminder (with the correct date) for tomorrow night's meeting!
hope to see some of you there... and bring your friends!!  more info and
directions at http://www.baypiggies.net and my original message below.

-wesley

ps. again, UC Santa Cruz is offering 2 Python classes Winter Quarter.
    i'll be instructing the standard Python Programming course, and
    there will be new course for complete newbies.  just go to
    http://www.ucsc-extension.edu, hit the red "Course Search" tab
    and type "Python" into the keyword field to pull up info on both
    courses.  the deadline is Dec 20.  call Sherry at 408-861-3765
    or e-mail her at smirkarimi at ucsc-extension.edu


On Thu, 5 Dec 2002, Wesley Chun wrote:

> BayPIGgies: Silicon Valley-San Francisco Bay Area Python Users Group
>
> When:     December 11, 2002 @ 7:30pm
> Where:    Stanford University, Palo Alto, CA
> Agenda:   Newbies' Nite
> Speaker:  (everyone!)
>
> Due to popular demand, we are having another Newbie Night (e.g. April
> 2002). This is the chance for all Python programmers to bring their
> friends and colleagues who should hear about Python. It is also for
> those who want to or are picking up Python and have questions! We will
> have a good number of Python experts who will try and help you out. Perl
> and Java experts are welcome too, as many Python developers also have
> experience there and can give you an honest comparison.
>
> The format is this: Wesley (or Danny) will give just a short half-hour
> intro presentation on Python to beginners followed by a quick demo, and
> then we will open it up to everyone for Q&A. Mingling and networking
> will bring our meeting to a glorious conclusion. :-)
>
> # NOTE: the next meeting on January 8, 2003 will be not be at the usual
> # place... stay tuned for a location update.
>
> # Call For Talks: We are actively seeking speakers for BayPIGgies! If you
> would like to give a talk at one of our 2003 meetings (any Python related
> topic), contact us to coordinate!
>
> more info including directions:    http://www.baypiggies.net
>
> hope to see some of you next Wednesday!
>
> -wesley
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>
> "Core Python Programming", Prentice Hall PTR, =A9 2001
>     http://starship.python.net/crew/wesc/cpp/
>
> Silicon Valley-San Francisco Bay Area Python Users Group (BayPIGgies)
>     http://deirdre.org/baypiggies
>
> wesley.j.chun :: wesc at deirdre.org
> cyberweb.consulting : henderson, nv : cyberweb at rocketmail.com
> http://www.roadkill.com/~wesc/cyberweb/



From Adam Vardy <anvardy@roadrunner.nf.net>  Tue Dec 10 22:12:01 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Tue Dec 10 22:12:01 2002
Subject: [Tutor] Add to list
Message-ID: <12490934717.20021210234139@roadrunner.nf.net>

How do you add an item to a list?

-- 
Adam Vardy



From dylan.belsey@baesystems.com  Tue Dec 10 22:35:01 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Tue Dec 10 22:35:01 2002
Subject: [Tutor] Add to list
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B98D2B6E@wtntex1.baea.com.au>

	Refer to the IDLE session below:


Python 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> mylist = [1,2,3]
>>> mylist.append(4)
>>> mylist
[1, 2, 3, 4]
>>> 

	The append() method is what you need to perform this.  If you are
interested in looking up to see what methods a particular Python type has
available to it, the documentation or texts on Python are also valuable
resources and can often shed more light on other/further functionality :)
	The following address is a good place to start for Python's built-in
types:
http://www.python.org/doc/current/lib/types.html
		Dylan


From din22@cox.net  Tue Dec 10 23:40:02 2002
From: din22@cox.net (david)
Date: Tue Dec 10 23:40:02 2002
Subject: Fw: [Tutor] my newbie program
Message-ID: <000d01c2a0cf$383ea820$fc550144@pn.at.cox.net>

----- Original Message ----- 
From: david <din22@cox.net>
To: Magnus Lycka <magnus@thinkware.se>
Sent: Tuesday, December 10, 2002 10:38 PM
Subject: Re: [Tutor] my newbie program


> hello everyone and thanks for all the food for thought
> concerning global variables. i am still struggling with all
> this though. i was messing with the code below and i 
> took the underscores out because i didn't know what
> they were for and i didn't like them. then i noticed that
> when my rooms are instanciated? that they all have their
> own map and dont know about the other rooms. then
> i read about private variables in the tutorial and i don't 
> think i get it. also when you raise a KeyError doesn't
> that dump you out of your program? anyway i don't 
> want to get my program working at the expense of 
> understanding it. tia.
> david
> > 
> > class Map:
> >      def __init__(self):
> >          self.__grid={} # Don't assume global startroom
> >      def addRoom(self, room, x, y):
> >          if self.__grid.has_key((x,y)):
> >              raise KeyError, "Location occupied"
> >          self.__grid[(x, y)] = room
> >      def getRoom(self, x, y):
> >          return self.__grid[(x, y)]
> >      def getLocation(self, room):
> >          for coord, aRoom in self.__grid.items():
> >              if room == aRoom:
> >                  return coord
> >          raise KeyError
> > 
> > class Room:
> >      def __init__(self, map, x=0, y=0):
> >          self.__map = map
> >          map.addRoom(self, x, y)
> >      def dig(direction):
> >          ...
> > 
> 
> 



From idiot1@netzero.net  Wed Dec 11 01:03:01 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Wed Dec 11 01:03:01 2002
Subject: [Tutor] myblog
Message-ID: <3DF6D582.4040207@netzero.net>

ok, I cleaned up the script, gangstrip snippet comes to hand again, nice neet 
display, clean, works fine.

	http//www.tinylist.org/myplog.shtml

Myblog form source:
	http://www.tinylist.org/myblogform.txt

myblog script source:
	http://www.tinylist.org/myblog.txt

-- 

end

Respectfully,
              Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                            +--------+

---------------------------------------------
Introducing NetZero Long Distance
1st month Free!
Sign up today at: www.netzerolongdistance.com


From idiot1@netzero.net  Wed Dec 11 01:59:01 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Wed Dec 11 01:59:01 2002
Subject: [Tutor] cgi module and checkboxes.
References: <20021209234348.7d6c8393.thomi@thomi.imail.net.nz>
Message-ID: <3DF6E2A9.1080001@netzero.net>

ok, this is at least partly a html question.

Thomi Richards wrote:
> Hey,
> 
> what happens if you have a check box (say called "uid"), and you submit
> it to a CGI, and get the results of the form using the cgi module? I'm
> trying this, and for some reason, i cannot get it to work. I'm guessing
> that the result would be a dictionary, with "uid" as the key, and a list
> of all the check boxes which were ticked as the value? (or maybe a
> tuple?)
Check boxes have different names. RADIO BUTTONS have different values, same 
name. Unchecked checkboxes do not return a value. with 2+ radio buttons, a 
name returns with a value, but which one is depressed determines WHICH value.
so for checking ticked boxes, look for keys with 'haskey'. if the box is 
checked, the key is present, if not checked, not present. SEVERAL checkboxes 
can be there, all with the same value, but different names.

Am I clarifying, or confusing?



> 
> I flicked through the documentation, but didn't see anything very useful
> there, just something about files....
> 


-- 

end

Respectfully,
              Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                            +--------+

---------------------------------------------
Introducing NetZero Long Distance
1st month Free!
Sign up today at: www.netzerolongdistance.com


From dyoo@hkn.eecs.berkeley.edu  Wed Dec 11 02:21:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed Dec 11 02:21:02 2002
Subject: [Tutor] question on Partition
In-Reply-To: <F396OZj9mspgEOI7vDc000113fc@hotmail.com>
Message-ID: <Pine.LNX.4.44.0212101206450.26118-100000@hkn.eecs.berkeley.edu>


On Wed, 11 Dec 2002, sachin mehra wrote:

> I need to use the partition function.  How can I use it?  Do I have to
> include any module for that?
>
> ###
> >>>paritition("attackatdawn")
> [['at', 'tack', 'at', 'dawn'],
> ['attack', 'at', 'dawn']]
>
> >>>partition("iscreamforicecream")
> [['is', 'cream', 'for', 'ice', 'cream'],
> ['i', 'scream', 'for', 'ice', 'cream']]
>
> >>>partition("uselesspython")
> [['use', 'less', 'python'],
> ['useless', 'python']]
>
> >>>partition("inaholetherelivedahobbit")
> [['in', 'a', 'hole', 'the', 're', 'lived', 'a', 'hobbit'],
> ['in', 'a', 'hole', 'there', 'lived', 'a', 'hobbit']]
> ###

Hi Sachin,

It is not built in; it's something I cooked up a few weeks ago when I was
thinking about your program.  However, it is a part of your homework to
write source code; we cannot directly give you the code to do this task.



This task is not too difficult to do if you approach the partitioning
problem recursively.  If you solve the problem recursively, your solution
should come to around five lines of code.

As a concrete example, given the word "attackatdawn", you can recursively
solve for the partitioning of "tackatdawn", or you can recursively solve
for the partitioning of "atdawn".  Either way, if can attack these smaller
problems, then you can solve for the partitioning of "attackatdawn".



From alan.gauld@bt.com  Wed Dec 11 03:36:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed Dec 11 03:36:01 2002
Subject: [Tutor] Tkinter wierdness
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0970226A@i2km11-ukbr.domain1.systemhost.net>

> ensues.  the command for the button is run when the button is 
> created, and can never be run again!  

I guess you have a bit of code like this somewhere:

button = Button(parent,command=somefunc(),....)

ie you have put parens after the callback methods name.

The result is the fuction runs and its result is stored
as the command, but since the result is probably None, 
the button does nothing...

Alan g.


From carroll@tjc.com  Wed Dec 11 03:43:03 2002
From: carroll@tjc.com (Terry Carroll)
Date: Wed Dec 11 03:43:03 2002
Subject: [Tutor] Wanted: module to parse out a CSV line
Message-ID: <Pine.GSU.4.44.0212110025460.27504-100000@waltz.rahul.net>

I'm writing one of my first Python apps (I've used perl up  until
now) and need to parse out lines of comma-separated values (CSV).  I'm on
a Windows/XP system.

For example, if a line contains this:

A, 232, "Title", "Smith, Adam" "1, 2, 3, 4"

I'd like to parse this into five fields:

 A
 232
 Title
 Smith, Adam
 1, 2, 3, 4

If this were perl, I'd use Text::CSV, from
<http://search.cpan.org/author/ALANCITT/Text-CSV-0.01/CSV.pm>, which works
just great.

I've found some Python CSV support, but nothing that will work for me:

 1. ASV, from <http://tratt.net/laurie/python/asv/>
    Nice, but it reads in an entire file that is assumed to be
    CSV-formatted.  That's not my case, I have a single variable I need
    to parse out (yeah, it comes from a file, but not all lines in the
    file are CSV).

 2. A CSV module from
    <http://www.object-craft.com.au/projects/csv/documentation.html>
    Perfect!  Exactly what I need.  Except the install fails looking for a
    program named cl.exe; I think it's a compiler, which I don't have.

 3. Python-DSV, at <http://python-dsv.sourceforge.net/>
    This looks like some whole separate program, rather than something
    that I can just call in to parse out a single line.  It also looks
    like it goes after a whole file at once.  Hard to tell -- there's no
    docs, unless (I presume) I install it.

This can't be a problem unique to me.  Anyone have an answer?

-- 
Terry Carroll        |
Santa Clara, CA      |   "The parties are advised to chill."
carroll@tjc.com      |       - Mattel, Inc. v. MCA Records, Inc.,
Modell delendus est  |         no. 98-56577 (9th Cir. July 24, 2002)



From alan.gauld@bt.com  Wed Dec 11 03:43:16 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed Dec 11 03:43:16 2002
Subject: [Tutor] Tkinter wierdness
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0970226B@i2km11-ukbr.domain1.systemhost.net>

> P.S. the inevitable follow-up question:  why must this be 
> done?  if I wish  to call a function with some arguments, 
> how is this done?  

You typically use default parameters in a lambda:

def theRealCallback(x,y,z): 
   #do something here

butt = Button(p,command = lambda x=1, y=42, z='foo':
theRealCallback(x,y,z),....)

OR in two lines:

def phonyCallBack(x=1, y= 42 z='foo'): return theRealCallback(x,y,z)
butt = Button(p,command=phonyCallBack,...)

Note that the phoneCallBack must be defined at the point where you 
know the default values(assuming they are variables not literals as 
I've shown)

HTH,

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld


From magnus@thinkware.se  Wed Dec 11 04:08:08 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 11 04:08:08 2002
Subject: [Tutor] Example 1
In-Reply-To: <3286194150.20021210222238@roadrunner.nf.net>
Message-ID: <5.1.0.14.0.20021211093610.02ba5e68@www.thinkware.se>

At 22:22 2002-12-10 -03-30, Adam Vardy wrote:
>I can follow the meaning of the following function. Should be simple,
>so, want to explain?
Sure!

>def union(*args):

I assume you understand the basic "def" statement. The odd thing here
is the * before args. Python has some special features in that regard.

Typically, you do

def f(x,y):
     return x + y

But sometimes you don't know how many arguments to expect.
Then you can use the *-form, like this:

 >>> def f(x,y,*more):
...     print "x=", x, "y=", y, "the rest=", more
...
 >>> f(1,2)
x= 1 y= 2 the rest= ()
 >>> f(1,2,3)
x= 1 y= 2 the rest= (3,)
 >>> f(1,2,3,4,5,6,7)
x= 1 y= 2 the rest= (3, 4, 5, 6, 7)

This means that you can construct more flexible functions in python.
You might feel that it's not needed in Python (in contrast to C for
instance), since you might as well pass a list or a tuple as an argument
to a function, but sometimes this is a more convenient approach.

There is more to learn that we don't need to explain the stuff below, see
http://www.python.org/doc/current/tut/node6.html#SECTION006700000000000000000

>     res = []

This is what we return below. An empty list that will append something
to before we get to the return line. Let's see below:

>     for seq in args:

We loop through our function call arguments, however many they are.

 From the variable name "seq" we can make a guess that the next line
of code validates: Every argument in the function call should be a
sequence, i.e. something we can loop over with a for-loop.

In other words, we expect that the function call looks something like
"union([1,4,6],(5,6,4),[2,3,4])" or perhaps "union('strings','are',
'also','sequences')".

>         for x in seq:

For each sequence, loop over the elements (x) in the sequence.

>             if not x in res:

If the sequence element (x) is not already in the result list...

>                 res.append(x)

...put it there

>     return res

And finally return a list containing only one copy each of
every element that was in any of the sequences

So...
 >>> union([1,4,6],(5,6,4),[2,3,4])
[1, 4, 6, 5, 2, 3]
 >>> x = union('strings','are','also','sequences')
 >>> print "".join(x)
stringaeloquc

OK?


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Wed Dec 11 04:25:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 11 04:25:01 2002
Subject: [Tutor] command ...
In-Reply-To: <5988461741.20021210230026@roadrunner.nf.net>
Message-ID: <5.1.0.14.0.20021211101116.02b98300@www.thinkware.se>

At 23:00 2002-12-10 -03-30, Adam Vardy wrote:
>If I type some commands, and some come after ... and at some point it
>stops and complains with a syntax error, it seems like it abandons
>what I already entered.

I'm not sure what you mean:
 >>> a = "Hello"
 >>> b = "World"
 >>> print a b
Traceback (  File "<interactive input>", line 1
     print a b
             ^
SyntaxError: invalid syntax
 >>> print a, b
Hello World

My variable definitions weren't abandoned.

If you are in a block (def, if, while etc), Python will run
it all at once, and if there is an error, you have to redo
the block, but in most of the environments (IDLE, PythonWin
and character mode interpreters with readline enabled etc)
you can do that with up-arrow etc.

Here's an example from a PythonWin session:

 >>> for name in ['Brian', 'Bicycle repair man', 'Ron Obvious']:
...     greet = 'Hello' # Stupid to have it in the loop, I know
...     print greet name # Missing comma
Traceback (  File "<interactive input>", line 3
     print greet name # Missing comma
                    ^
SyntaxError: invalid syntax
 >>>     print greet, name
Traceback (  File "<interactive input>", line 1
     print greet, name
     ^
SyntaxError: invalid syntax
 >>> # The syntax error here is due to the indentation. We "lost" the for
 >>> # loop, so the code should not be intented at all.
 >>> # I will now press up-arrow until I reach the "print greet name" line, or
 >>> # simply click there with the mouse. Then I press enter to get a copy
 >>> # of my code that I can edit the normal way. It will run when I press 
enter.
 >>> for name in ['Brian', 'Bicycle repair man', 'Ron Obvious']:
...     greet = 'Hello' # Stupid to have it in the loop, I know
...     print greet, name # Now I added a comma
...
Hello Brian
Hello Bicycle repair man
Hello Ron Obvious
 >>>

>I should be able to back up, and cross out the last command, shouldn't I?
>If it didn't like it.

Use the interactive interpreter for small tests, and by
all means as a calculator etc, but if you want to do something
"real": Put it in a file, save it, and run it non-interactively.

When python finds problems, you correct them and rerun your
program file.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Wed Dec 11 05:33:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 11 05:33:01 2002
Subject: [Tutor] Wanted: module to parse out a CSV line
In-Reply-To: <Pine.GSU.4.44.0212110025460.27504-100000@waltz.rahul.net>
Message-ID: <5.1.0.14.0.20021211103301.02bd9da0@www.thinkware.se>

At 00:42 2002-12-11 -0800, Terry Carroll wrote:
>I'm writing one of my first Python apps

Welcome Terry! I hope you will enjoy it!

(Dave, there is something here that looks like a bug in CSV to me.
Care to comment?)

>(I've used perl up  until
>now) and need to parse out lines of comma-separated values (CSV).  I'm on
>a Windows/XP system.

I was just about to suggest that you used one of the three
modules below. It's nice to see that someone has made the
effort to search the net before asking here! :)

I'm afraid you should have tried a bit harder with these modules.
They can all solve your problem (?), but maybe they could be a little
better documented, and one of them could be in the standard library
I think.

>I've found some Python CSV support, but nothing that will work for me:

>  1. ASV, from <http://tratt.net/laurie/python/asv/>
>     Nice, but it reads in an entire file that is assumed to be
>     CSV-formatted.

There is an input_from_file method, but you don't have to use
that. Use input instead.

>  That's not my case, I have a single variable I need
>     to parse out (yeah, it comes from a file, but not all lines in the
>     file are CSV).

 >>> import ASV
 >>> asv = ASV.ASV()
 >>> asv.input('A, 232, "Title", "Smith, Adam", "1, 2, 3, 4"', ASV.CSV())
 >>> print asv
[['A', '232', 'Title', 'Smith, Adam', '1, 2, 3, 4']]

>  2. A CSV module from
>     <http://www.object-craft.com.au/projects/csv/documentation.html>
>     Perfect!  Exactly what I need.  Except the install fails looking for a
>     program named cl.exe; I think it's a compiler, which I don't have.

This module is implemented in C to make it really fast even
for very large files. But look at the download page:
http://www.object-craft.com.au/projects/csv/download.html

If you are using Win32, you can use one of the following binaries:
Win32 Python 2.1 binary: csv.pyd 20K Nov 20 2002
Win32 Python 2.2 binary: csv.pyd 20K Nov 20 2002

 >>> import csv
 >>> csv.parser().parse('A, 232, "Title", "Smith, Adam", "1, 2, 3, 4"')
['A', ' 232', ' "Title"', ' "Smith', ' Adam"', ' "1', ' 2', ' 3', ' 4"']

Not quite...but...

 >>> csv.parser().parse('A,232,"Title","Smith, Adam","1, 2, 3, 4"')
['A', '232', 'Title', 'Smith, Adam', '1, 2, 3, 4']

It seems the space after the comma confuses CSV regarding the use
of double quotes. I've seen a lot of files with whitespace after
the comma, so this is not what I would like. And the parser won't
accept field_sep = ', ', it has to be a single character.

>  3. Python-DSV, at <http://python-dsv.sourceforge.net/>
>     This looks like some whole separate program, rather than something
>     that I can just call in to parse out a single line.  It also looks
>     like it goes after a whole file at once.  Hard to tell -- there's no
>     docs, unless (I presume) I install it.

The documentation is in the form of a documentation string in the source.
It shows you what to do.

Basic use:
     from DSV import DSV
     data = file.read() # file.read() returns a string, so this is what you 
need
     qualifier = DSV.guessTextQualifier(data) # optional
     data = DSV.organizeIntoLines(data, textQualifier = qualifier)
     delimiter = DSV.guessDelimiter(data) # optional
     data = DSV.importDSV(data, delimiter = delimiter, textQualifier = 
qualifier)
     hasHeader = DSV.guessHeaders(data) # optional

You can skip the guessing games, and run the two functions that matters.

 >>> from DSV import DSV
 >>> data = 'A, 232, "Title", "Smith, Adam", "1, 2, 3, 4"'
 >>> data = DSV.organizeIntoLines(data, textQualifier = '"')
 >>> data = DSV.importDSV(data, delimiter = ',', textQualifier = '"')
 >>> print data
[['A', ' 232', 'Title', 'Smith, Adam', '1, 2, 3, 4']]

As you see, like csv, but unlike asv, it won't strip the leading space
from before 232. I'm pretty sure this is intentional. Whether it's a
bug or a feature in your eyes is a different issue...

The reason that the "organizeIntoLines" step (which you can bypass by
putting your string in a list I guess) exists is because programs like
Excel will produce CSV files with line breaks inside "-delimited strings.
So a logical line might span several physical lines.

I think it would be a good thing to have parsers/importers/exporters for
both CSV (and fixed format) in the standard library. We just need some
kind of consensus on how they should behave I guess...


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From thomi@thomi.imail.net.nz  Wed Dec 11 05:58:02 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Wed Dec 11 05:58:02 2002
Subject: [Tutor] cgi module and checkboxes.
In-Reply-To: <3DF6E2A9.1080001@netzero.net>
References: <20021209234348.7d6c8393.thomi@thomi.imail.net.nz>
 <3DF6E2A9.1080001@netzero.net>
Message-ID: <20021211235716.6f3cfc4c.thomi@thomi.imail.net.nz>

> Am I clarifying, or confusing?

ummm.. confusing. although it may be the time here in New Zealand, or
the cider I've just drunk. what python code do i need to use, so i can
print something like "you checked the following boxes:"


-- 
The software required Win95 or better, so I installed Linux.
Thomi Richards,
thomi@imail.net.nz


From lobow@brturbo.com  Wed Dec 11 06:51:01 2002
From: lobow@brturbo.com (Diego Prestes)
Date: Wed Dec 11 06:51:01 2002
Subject: [Tutor] Slow program
Message-ID: <39869403.1039607349546.JavaMail.nobody@webmail2.brturbo.com>

--409492443.1039607349545.JavaMail.nobody.webmail2.brturbo.com
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

    Hello,

   Im trying to make a program that take a text and test whats the two words that apeer more in the text together, but when I do this code it is to slow. I think its because of that create many times the same text (var b), but I dont find any better program. Someone could give a hand?

Diego


def calc(b): 
    dic={}            
    for x in range(len(b)-1):
        if dic.has_key(b[x]+' '+b[x+1]) == 0:
            c = 0
            for y in range(len(b)-1):
                if b[x] == b[y] and b[x+1] == b[y+1]:
                    c=c+1
            dic[b[x]+' '+b[x+1]] = c
    ma=0
    for x in range(len(dic)):
        if dic.values()[x] > ma:
            ma = dic.values()[x]
    for x in range(len(dic)):
        if dic.values()[x] == ma:
            print "%s -> %d" % (dic.keys()[x],dic.values()[x])
--409492443.1039607349545.JavaMail.nobody.webmail2.brturbo.com--



From Adam Vardy <anvardy@roadrunner.nf.net>  Wed Dec 11 07:30:02 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Wed Dec 11 07:30:02 2002
Subject: [Tutor] Example 1
In-Reply-To: <5.1.0.14.0.20021211093610.02ba5e68@www.thinkware.se>
References: <5.1.0.14.0.20021211093610.02ba5e68@www.thinkware.se>
Message-ID: <10721133758.20021211085933@roadrunner.nf.net>

Wednesday, December 11, 2002, 5:40:11 AM, you wrote:

>> But sometimes you don't know how many arguments to expect.
>> Then you can use the *-form, like this:

>> In other words, we expect that the function call looks something like
>> "union([1,4,6],(5,6,4),[2,3,4])" or perhaps "union('strings','are',

Sure then. So how does the program logic know where are the 1 4 6 and
the other numbers? And tell them apart?

-- 
Adam Vardy



From Adam Vardy <anvardy@roadrunner.nf.net>  Wed Dec 11 07:37:02 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Wed Dec 11 07:37:02 2002
Subject: [Tutor] Pythonwin
Message-ID: <8621554784.20021211090634@roadrunner.nf.net>

I paste a few lines in PythonWin. Then click Run, and I got a three
field menu.  Making a guess, I figure it wants me to name the Script
file. So I type a name. And it says File not found!

Ok, so, looking at the menu, I try clicking File Save, perhaps that'll
do. So I browse, or type a name and click Save.  I circle back through
to Run. But, this doesn't seem to work out. I get a feeling the file
wasn't saved.  It's confusing see.

So, suppose the best way to get unconfused is to consult the docs!  I
am trying clicking on the Help menu, one of these options, but this
just loads the whole general Python documentation. Right.

I also try clicking on a little icon question mark button. Help index.
Whoops. That just does the same thing. Even after giving a little
menu of choices. Whatever choice I made, same result.

-- 
Adam Vardy



From op73418@mail.telepac.pt  Wed Dec 11 07:41:02 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Wed Dec 11 07:41:02 2002
Subject: [Tutor] Example 1
References: <5.1.0.14.0.20021211093610.02ba5e68@www.thinkware.se> <10721133758.20021211085933@roadrunner.nf.net>
Message-ID: <007b01c2a113$59164f00$b0180dd5@violante>

----- Original Message -----
From: "Adam Vardy" <anvardy@roadrunner.nf.net>
To: <tutor@python.org>
Sent: Wednesday, December 11, 2002 12:29 PM
Subject: Re: [Tutor] Example 1


>
> Wednesday, December 11, 2002, 5:40:11 AM, you wrote:
>
> >> But sometimes you don't know how many arguments to expect.
> >> Then you can use the *-form, like this:
>
> >> In other words, we expect that the function call looks something like
> >> "union([1,4,6],(5,6,4),[2,3,4])" or perhaps "union('strings','are',
>
> Sure then. So how does the program logic know where are the 1 4 6 and
> the other numbers? And tell them apart?

Consider the following

>>> def testargs(*args):
...  print args
...
>>> testargs(1, 2, 3, 4)
(1, 2, 3, 4)

As you can see, when you include *args in our function definition, the
arguments passed are collected in a tuple. You can now refer to them as
args[0], args[1], etc.

>
> --
> Adam Vardy
>

HTH,
G. Rodrigues



From magnus@thinkware.se  Wed Dec 11 07:41:23 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 11 07:41:23 2002
Subject: [Tutor] my newbie program
In-Reply-To: <000801c2a0cf$1c305840$fc550144@pn.at.cox.net>
References: <5.1.0.14.0.20021126105534.02b1fe70@www.thinkware.se>
 <5.1.0.14.0.20021127121448.035a5a80@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021211114251.02bcece8@www.thinkware.se>

At 22:38 2002-12-10 -0600, david wrote:
>i was messing with the code below and i
>took the underscores out because i didn't know what
>they were for and i didn't like them.

That sounds a bit like those Unix sysadmin horror stories:
"I never used those files in /dev/ and I didn't know what
they were for, so I erased them... ;)

But experimenting, testing and changing things is a good way
to learn. This change DOES make a difference.

Like it or not, underscores are significant in python, and used
for particular reasons.

I.

Leading *and* trailing underscores are used by "magic" names
that have a special meaning for the python interpreter. Never
use them for other things. Example:

 >>> class X:
...     def __init__(self, **kwargs):
...             self.__dict__ = kwargs
...     def __str__(self):
...             return "\n".join(["%s = %s" % (key, getattr(self, key))
...                                     for key in dir(self)])
...
 >>> x = X(a='Hello', b=2, c=3)
 >>> x.d = 99
 >>> print x
__doc__ = None
__init__ = <bound method X.__init__ of <__main__.X instance at 0x022F1818>>
__module__ = __main__
__str__ = <bound method X.__str__ of <__main__.X instance at 0x022F1818>>
a = Hello
b = 2
c = 3
d = 99

If you remove the underscores in __init__, __dict__ or __str__,
things won't work the same at all.

__init__ is the magic name for the method that is invoked when we
instanciate a class. __dict__ is the dictionary that keeps track of
the attributes in an instance object. __str__ is the method that is
called when we use the str() function or print.

II.

Leading (but not trailing) double underscores are used for private
attributes in classes. These are variables that should only be changed
from within the class. The idea is that someone who uses a class should
only be dependent on it's public interface, not on it's implementation,
so that class implementations can be changed if needed, without breaking
the programs that use them. This "data hiding" is not absolute in Python.
The name is "mangled" and you can access it if you really want, but then
you know that you are breaking the rules and have to take the consequences.
This ability to break the rules is helpful in debugging etc, but should
not be used in production code.

 >>> class Person:
...     def __init__(self, fname, lname):
...             self.__fname = fname
...             self.__lname = lname
...     def __str__(self):
...             return "My name is %s %s and you can't change that" % (
...                         self.__fname, self.__lname)
...
 >>> p = Person('Brian', 'Cohen')
 >>> print p
My name is Brian Cohen and you can't change that
 >>> p.__lname
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
AttributeError: Person instance has no attribute '__lname'
 >>> p.__fname = 'Ron'
 >>> print p
My name is Brian Cohen and you can't change that
 >>> dir(p)
['_Person__fname', '_Person__lname', '__doc__', '__fname', '__init__', 
'__module__', '__str__']
 >>> print p.__fname
Ron
 >>> p._Person__lname = 'Parrot'
 >>> print p
My name is Brian Parrot and you can't change that

Well, I could obviously change that, and those kinds of manipulations
are useful in testing and debugging code. Of course, you _can_ abuse it,
but there is no way of defending programs from stupid programmers
anyway.

(Note that "p.__fname = 'Ron'" worked though. But note that that
attribute can't be reached from within the class without fishing
it out of self.__dict__. self.__fname will always find the key
'_Person__fname' in self.__dict__. The "outside __fname" and
"inside __fname" are different variables.)

III.

"from <module> import *" won't import names starting with
underscore.

 >>> print file('test.py').read()
public = 1
_protected = 2
__private = 3
__magic__ = 4
ordinary_ = 5

 >>> dir()
['__builtins__', '__doc__', '__name__']
 >>> from test import *
 >>> dir()
['__builtins__', '__doc__', '__name__', 'ordinary_', 'public']
 >>> # Only "public" and "ordinary_" were imported from test.
 >>> import test
 >>> dir(test)
['__builtins__', '__doc__', '__file__', '__magic__', '__name__',
  '__private', '_protected', 'ordinary_', 'public']

This means that you will never get your variables that start with _
overwritten by names that you import with "from <module> import *".
I still think "from <module> import *" is a bad idea most of the
time anyway...

Note that these leading underscores can be used to stop any kind
of object from being imported with "from <module> import *". It might
be classes, functions or other modules etc.

IV.

Many python programmers (me included) use the convention to denote
protected attributes in classes with one leading underscore. This is
not enforced by the interpreter (no name mangling), but I know that I
should normally never use "x._protected", only "self._protected".

The difference between private and protected attributes in classes
(as defined in C++) is that private attributes can only be accessed
in the class where they were defined. Protected attributes can also
be used in subclasses.

The concept is meaningless unless you understand inheritance. And if
you do, you might be of the opinion that derived classes should use
the public interface...

 >>> class Person:
...     def __init__(self, fname, lname):
...             self._fname = fname
...             self._lname = lname
...
 >>> class Customer(Person):
...     def __init__(self, fname, lname, custNo):
...             Person.__init__(self, fname, lname)
...             self.__custNo = custNo
...     def remind(self, date):
...             return "Dear %s %s. As of %s you should have..." % (
...                         self._fname, self._lname, date)
...
 >>> c = Customer('Bill', 'Gates', 123)
 >>> print c.remind('2002-12-05')
Dear Bill Gates. As of 2002-12-05 you should have...
 >>> c._fname = "William" # Legal Python but not following Magnus' coding 
standards
 >>> print c.remind('2002-12-05')
Dear William Gates. As of 2002-12-05 you should have...

V.

A trailing underscore, is sometimes used when we want to use a variable
name that we can't use because it's a reserved word, or it's used by a
standard type or function that we don't want to hide.

 >>> from, to = '2002-12-10', '2002-12-24'
Traceback (  File "<interactive input>", line 1
     from, to = '2002-12-10', '2002-12-24'
         ^
SyntaxError: invalid syntax
 >>> from_, to = '2002-12-10', '2002-12-24'

 >>> list_ = [1,2,3,4] # No problem
 >>> list('qwe')
['q', 'w', 'e']
 >>> list = [1,2,3,4] # This is not a good idea...
 >>> list('qwe')      # ...since this won't work.
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
TypeError: 'list' object is not callable



-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From Adam Vardy <anvardy@roadrunner.nf.net>  Wed Dec 11 09:34:22 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Wed Dec 11 09:34:22 2002
Subject: [Tutor] Pythonpath
Message-ID: <4428547188.20021211110306@roadrunner.nf.net>

How do I set a Pythonpath?

And does Python have command line options?

-- 
Adam Vardy



From magnus@thinkware.se  Wed Dec 11 09:47:36 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 11 09:47:36 2002
Subject: [Tutor] Pythonwin
In-Reply-To: <8621554784.20021211090634@roadrunner.nf.net>
Message-ID: <5.1.0.14.0.20021211154515.02bbbf48@www.thinkware.se>

At 09:06 2002-12-11 -03-30, Adam Vardy wrote:
>I paste a few lines in PythonWin. Then click Run, and I got a three
>field menu.  Making a guess, I figure it wants me to name the Script
>file. So I type a name. And it says File not found!

You don't need to press "run" to execute things interactively.
You use "run" only to execute python code which is in a file.

Sadly, PythonWin (and most other interactive interpreters) can't
handle pasting more than one line at one time. :( As you see, you
don't get the secondary prompts "...".

IPython and psi handles this correctly. Actually, IPython even
allows you to paste code with >>> or ... in the start of the
lines. (But doesn't work well in Windows IIRC.)

To paste code in PythonWin, open a script window, paste the code
there, save and run with F5.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Wed Dec 11 09:55:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 11 09:55:02 2002
Subject: [Tutor] Pythonpath
In-Reply-To: <4428547188.20021211110306@roadrunner.nf.net>
Message-ID: <5.1.0.14.0.20021211155630.02bf7090@www.thinkware.se>

At 11:03 2002-12-11 -03-30, Adam Vardy wrote:
>How do I set a Pythonpath?

What OS? (Don't say Windows, that's several OS's)
You set is like any environment variable.

>And does Python have command line options?

H:\python>python -h
usage: python [option] ... [-c cmd | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
-c cmd : program passed in as string (terminates option list)
-d     : debug output from parser (also PYTHONDEBUG=x)
-E     : ignore environment variables (such as PYTHONPATH)
-h     : print this help message and exit
-i     : inspect interactively after running script, (also PYTHONINSPECT=x)
          and force prompts, even if stdin does not appear to be a terminal
-O     : optimize generated bytecode (a tad; also PYTHONOPTIMIZE=x)
-OO    : remove doc-strings in addition to the -O optimizations
-Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew
-S     : don't imply 'import site' on initialization
-t     : issue warnings about inconsistent tab usage (-tt: issue errors)
-u     : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)
-v     : verbose (trace import statements) (also PYTHONVERBOSE=x)
-V     : print the Python version number and exit
-W arg : warning control (arg is action:message:category:module:lineno)
-x     : skip first line of source, allowing use of non-Unix forms of #!cmd
file   : program read from script file
-      : program read from stdin (default; interactive mode if a tty)
arg ...: arguments passed to program in sys.argv[1:]
Other environment variables:
PYTHONSTARTUP: file executed on interactive startup (no default)
PYTHONPATH   : ';'-separated list of directories prefixed to the
                default module search path.  The result is sys.path.
PYTHONHOME   : alternate <prefix> directory (or <prefix>;<exec_prefix>).
                The default module search path uses <prefix>\lib.
PYTHONCASEOK : ignore case in 'import' statements (Windows).



-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Wed Dec 11 10:05:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 11 10:05:02 2002
Subject: [Tutor] Wanted: module to parse out a CSV line
In-Reply-To: <m31y4ozpc0.fsf@ferret.object-craft.com.au>
References: <5.1.0.14.0.20021211103301.02bd9da0@www.thinkware.se>
 <5.1.0.14.0.20021211103301.02bd9da0@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021211155744.02be9210@www.thinkware.se>

At 23:56 2002-12-11 +1100, Dave Cole wrote:
>Have you checked what Excel does with that data?

It behaves worse than csv it seems. ;) Why am I not surprised.
I'm happy that you don't need to mimic that exactly!

1       directly
after
comma"
2        "space
after comma"
3         "two
spaces
after
comma"
4               tab after
comma"

It doesn't seem to honour the concept of line breaks in strings on import.
But it removes the " before directly even though it obviously didn't fint
a match. But as soon as there is space after the comma, the " is left as
it is. Even though I explicitly marked , as separator, a tab after the
comman made the text after ,\t end up in column C instead of B!



-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From Adam Vardy <anvardy@roadrunner.nf.net>  Wed Dec 11 10:22:01 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Wed Dec 11 10:22:01 2002
Subject: [Tutor] Pythonpath
In-Reply-To: <5.1.0.14.0.20021211155630.02bf7090@www.thinkware.se>
References: <5.1.0.14.0.20021211155630.02bf7090@www.thinkware.se>
Message-ID: <17531437334.20021211115116@roadrunner.nf.net>

Wednesday, December 11, 2002, 11:27:29 AM, you wrote:

>> At 11:03 2002-12-11 -03-30, Adam Vardy wrote:
>>How do I set a Pythonpath?

>> What OS? (Don't say Windows, that's several OS's)

Windows XP Pro.

>>And does Python have command line options?

H:\python>>python -h

Yeah, I tried 'python /?', but just gave an error.

-- 
Adam Vardy



From Adam Vardy <anvardy@roadrunner.nf.net>  Wed Dec 11 10:27:02 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Wed Dec 11 10:27:02 2002
Subject: [Tutor] Pythonwin
In-Reply-To: <5.1.0.14.0.20021211154515.02bbbf48@www.thinkware.se>
References: <5.1.0.14.0.20021211154515.02bbbf48@www.thinkware.se>
Message-ID: <1331726890.20021211115606@roadrunner.nf.net>

Wednesday, December 11, 2002, 11:19:37 AM, you wrote:

>> To paste code in PythonWin, open a script window, paste the code

How do I do that?

-- 
Adam Vardy



From shendric@arches.uga.edu  Wed Dec 11 10:43:02 2002
From: shendric@arches.uga.edu (shendric@arches.uga.edu)
Date: Wed Dec 11 10:43:02 2002
Subject: [Tutor] (no subject)
Message-ID: <1039621255.smmsdV1.1.2@mail.arches.uga.edu>

Is there a good place to find a basic installer for this type of use, at 
least as a starting point?

Sean

>Better to do as HP and others do, create an installer that 
>checks if Python is already installed (check the registry 
>then the filesystem) and if not run the standard Python 
>installer followed by dumping your files into a suitable 
>place. Finally update the PYTHONPATH in autoexec.bat or the 
>sys.path if you prefer.

>Alan g.
>Author of the 'Learning to Program' web site
>http://www.freenetpages.co.uk/hp/alan.gauld
>




From mongo57a@comcast.net  Wed Dec 11 11:17:02 2002
From: mongo57a@comcast.net (andy surany)
Date: Wed Dec 11 11:17:02 2002
Subject: [Tutor] Wanted: module to parse out a CSV line
Message-ID: <002501c2a130$d6fe7e20$2502a8c0@emily.ewndsr01.nj.comcast.net>

Hello Magnus,

Is there an advantage to using something like asv or csv over opening
the file, reading each line, and using string.split (line_contents,
',')?

Thanks.

-Andy


-----Original Message-----
From: Magnus Lycka <magnus@thinkware.se>
To: Terry Carroll <carroll@tjc.com>; tutor@python.org <tutor@python.org>
Cc: djc@object-craft.com.au <djc@object-craft.com.au>
Date: Wednesday, December 11, 2002 5:33 AM
Subject: Re: [Tutor] Wanted: module to parse out a CSV line


>At 00:42 2002-12-11 -0800, Terry Carroll wrote:
>>I'm writing one of my first Python apps
>
>Welcome Terry! I hope you will enjoy it!
>
>(Dave, there is something here that looks like a bug in CSV to me.
>Care to comment?)
>
>>(I've used perl up  until
>>now) and need to parse out lines of comma-separated values (CSV).  I'm
on
>>a Windows/XP system.
>
>I was just about to suggest that you used one of the three
>modules below. It's nice to see that someone has made the
>effort to search the net before asking here! :)
>
>I'm afraid you should have tried a bit harder with these modules.
>They can all solve your problem (?), but maybe they could be a little
>better documented, and one of them could be in the standard library
>I think.
>
>>I've found some Python CSV support, but nothing that will work for me:
>
>>  1. ASV, from <http://tratt.net/laurie/python/asv/>
>>     Nice, but it reads in an entire file that is assumed to be
>>     CSV-formatted.
>
>There is an input_from_file method, but you don't have to use
>that. Use input instead.
>
>>  That's not my case, I have a single variable I need
>>     to parse out (yeah, it comes from a file, but not all lines in
the
>>     file are CSV).
>
> >>> import ASV
> >>> asv = ASV.ASV()
> >>> asv.input('A, 232, "Title", "Smith, Adam", "1, 2, 3, 4"',
ASV.CSV())
> >>> print asv
>[['A', '232', 'Title', 'Smith, Adam', '1, 2, 3, 4']]
>
>>  2. A CSV module from
>>     <http://www.object-craft.com.au/projects/csv/documentation.html>
>>     Perfect!  Exactly what I need.  Except the install fails looking
for a
>>     program named cl.exe; I think it's a compiler, which I don't
have.
>
>This module is implemented in C to make it really fast even
>for very large files. But look at the download page:
>http://www.object-craft.com.au/projects/csv/download.html
>
>If you are using Win32, you can use one of the following binaries:
>Win32 Python 2.1 binary: csv.pyd 20K Nov 20 2002
>Win32 Python 2.2 binary: csv.pyd 20K Nov 20 2002
>
> >>> import csv
> >>> csv.parser().parse('A, 232, "Title", "Smith, Adam", "1, 2, 3, 4"')
>['A', ' 232', ' "Title"', ' "Smith', ' Adam"', ' "1', ' 2', ' 3', '
4"']
>
>Not quite...but...
>
> >>> csv.parser().parse('A,232,"Title","Smith, Adam","1, 2, 3, 4"')
>['A', '232', 'Title', 'Smith, Adam', '1, 2, 3, 4']
>
>It seems the space after the comma confuses CSV regarding the use
>of double quotes. I've seen a lot of files with whitespace after
>the comma, so this is not what I would like. And the parser won't
>accept field_sep = ', ', it has to be a single character.
>
>>  3. Python-DSV, at <http://python-dsv.sourceforge.net/>
>>     This looks like some whole separate program, rather than
something
>>     that I can just call in to parse out a single line.  It also
looks
>>     like it goes after a whole file at once.  Hard to tell -- there's
no
>>     docs, unless (I presume) I install it.
>
>The documentation is in the form of a documentation string in the
source.
>It shows you what to do.
>
>Basic use:
>     from DSV import DSV
>     data = file.read() # file.read() returns a string, so this is what
you
>need
>     qualifier = DSV.guessTextQualifier(data) # optional
>     data = DSV.organizeIntoLines(data, textQualifier = qualifier)
>     delimiter = DSV.guessDelimiter(data) # optional
>     data = DSV.importDSV(data, delimiter = delimiter, textQualifier =
>qualifier)
>     hasHeader = DSV.guessHeaders(data) # optional
>
>You can skip the guessing games, and run the two functions that
matters.
>
> >>> from DSV import DSV
> >>> data = 'A, 232, "Title", "Smith, Adam", "1, 2, 3, 4"'
> >>> data = DSV.organizeIntoLines(data, textQualifier = '"')
> >>> data = DSV.importDSV(data, delimiter = ',', textQualifier = '"')
> >>> print data
>[['A', ' 232', 'Title', 'Smith, Adam', '1, 2, 3, 4']]
>
>As you see, like csv, but unlike asv, it won't strip the leading space
>from before 232. I'm pretty sure this is intentional. Whether it's a
>bug or a feature in your eyes is a different issue...
>
>The reason that the "organizeIntoLines" step (which you can bypass by
>putting your string in a list I guess) exists is because programs like
>Excel will produce CSV files with line breaks inside "-delimited
strings.
>So a logical line might span several physical lines.
>
>I think it would be a good thing to have parsers/importers/exporters
for
>both CSV (and fixed format) in the standard library. We just need some
>kind of consensus on how they should behave I guess...
>
>
>--
>Magnus Lycka, Thinkware AB
>Alvans vag 99, SE-907 50 UMEA, SWEDEN
>phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
>http://www.thinkware.se/  mailto:magnus@thinkware.se
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor



From carroll@tjc.com  Wed Dec 11 11:40:02 2002
From: carroll@tjc.com (Terry Carroll)
Date: Wed Dec 11 11:40:02 2002
Subject: [Tutor] Wanted: module to parse out a CSV line
In-Reply-To: <002501c2a130$d6fe7e20$2502a8c0@emily.ewndsr01.nj.comcast.net>
Message-ID: <Pine.GSU.4.44.0212110833270.27504-100000@waltz.rahul.net>

On Wed, 11 Dec 2002, andy surany wrote:

> Is there an advantage to using something like asv or csv over opening
> the file, reading each line, and using string.split (line_contents,
> ',')?

The biggest reasons are that you want to handle a fiels that may or may
not be surrounded by quotes, and that may have embedded commas.

For example, consider the string:

  "Programming Python","Lutz, Mark",1-56592-197-6

A good CSV module will parse this into three elements:
  Programming Python
  Lutz, Mark
  1-56592-197-6

A plain old comma-split will parse it into four elements, and leave the
quote marks:

  "Programming Python"
  "Lutz
   Mark"
  1-56592-197-6


-- 
Terry Carroll        |
Santa Clara, CA      |   "The parties are advised to chill."
carroll@tjc.com      |       - Mattel, Inc. v. MCA Records, Inc.,
Modell delendus est  |         no. 98-56577 (9th Cir. July 24, 2002)



From mongo57a@comcast.net  Wed Dec 11 11:57:38 2002
From: mongo57a@comcast.net (andy surany)
Date: Wed Dec 11 11:57:38 2002
Subject: [Tutor] Wanted: module to parse out a CSV line
Message-ID: <004301c2a136$420ab8a0$2502a8c0@emily.ewndsr01.nj.comcast.net>

Thanks Terry. I think I'll re-write my code to use ASV.....

-----Original Message-----
From: Terry Carroll <carroll@tjc.com>
To: andy surany <mongo57a@comcast.net>
Cc: tutor@python.org <tutor@python.org>
Date: Wednesday, December 11, 2002 11:40 AM
Subject: Re: [Tutor] Wanted: module to parse out a CSV line


>On Wed, 11 Dec 2002, andy surany wrote:
>
>> Is there an advantage to using something like asv or csv over opening
>> the file, reading each line, and using string.split (line_contents,
>> ',')?
>
>The biggest reasons are that you want to handle a fiels that may or may
>not be surrounded by quotes, and that may have embedded commas.
>
>For example, consider the string:
>
>  "Programming Python","Lutz, Mark",1-56592-197-6
>
>A good CSV module will parse this into three elements:
>  Programming Python
>  Lutz, Mark
>  1-56592-197-6
>
>A plain old comma-split will parse it into four elements, and leave the
>quote marks:
>
>  "Programming Python"
>  "Lutz
>   Mark"
>  1-56592-197-6
>
>
>--
>Terry Carroll        |
>Santa Clara, CA      |   "The parties are advised to chill."
>carroll@tjc.com      |       - Mattel, Inc. v. MCA Records, Inc.,
>Modell delendus est  |         no. 98-56577 (9th Cir. July 24, 2002)
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor



From carroll@tjc.com  Wed Dec 11 12:14:02 2002
From: carroll@tjc.com (Terry Carroll)
Date: Wed Dec 11 12:14:02 2002
Subject: [Tutor] Wanted: module to parse out a CSV line
In-Reply-To: <5.1.0.14.0.20021211103301.02bd9da0@www.thinkware.se>
Message-ID: <Pine.GSU.4.44.0212110856450.27504-100000@waltz.rahul.net>

On Wed, 11 Dec 2002, Magnus Lycka wrote:

> I was just about to suggest that you used one of the three
> modules below. It's nice to see that someone has made the
> effort to search the net before asking here! :)

Hey, I'm new to Python, so I'm going to be asking a lot more questions
here, and this was my first post -- I figured it's best to start off at
least *looking* a little clueful.  :-)

> >  1. ASV, from <http://tratt.net/laurie/python/asv/>
> >     Nice, but it reads in an entire file that is assumed to be
> >     CSV-formatted.
>
> There is an input_from_file method, but you don't have to use
> that. Use input instead.

Thanks.  The docs are a little sparse, and don't have any hint that that's
possible.  I tried reading through the Python code, but, as I said, I'm
still a newbie to Python, and couldn't really follow it yet.  I'll keep
that in mind.

> >  2. A CSV module from
> >     <http://www.object-craft.com.au/projects/csv/documentation.html>
>
> If you are using Win32, you can use one of the following binaries:
> Win32 Python 2.1 binary: csv.pyd 20K Nov 20 2002
> Win32 Python 2.2 binary: csv.pyd 20K Nov 20 2002

You know, maybe 30 minutes after I posted to the list (and after writing
Dave separately, based on an old message I found where he first gave a
URL, now dead, for the the Windows version, I looked at the download page
and saw it.  I downloaded it, installed it, and it works fine for me.

The hazards of programming too far past bedtime.

> It seems the space after the comma confuses CSV regarding the use
> of double quotes. I've seen a lot of files with whitespace after
> the comma, so this is not what I would like.

Actually, my real project doesn't have the spaces following the commas,
so I'm fine.  My example did not properly mirror my requirement.

For what it's worth (not that I'm implying that Python should emulate
Perl), I tried my bad example with the perl module Text::CSV, and it
choked, returning an error and giving up on the parse.

> I think it would be a good thing to have parsers/importers/exporters for
> both CSV (and fixed format) in the standard library. We just need some
> kind of consensus on how they should behave I guess...

>From what I gathered in my search, there's a long way to go on that
consensus.  :-)

Thanks very much for the help, I appreciate it.

-- 
Terry Carroll        |
Santa Clara, CA      |   "The parties are advised to chill."
carroll@tjc.com      |       - Mattel, Inc. v. MCA Records, Inc.,
Modell delendus est  |         no. 98-56577 (9th Cir. July 24, 2002)



From bindas_qwerty@hotmail.com  Wed Dec 11 12:50:01 2002
From: bindas_qwerty@hotmail.com (sachin mehra)
Date: Wed Dec 11 12:50:01 2002
Subject: [Tutor] question on Partition
Message-ID: <F15yI1iNAp3gRFvXYaI00015ba4@hotmail.com>

So is there any other function which does it? Something like partition as 
you mentioned?
I think there is some functtion in unix which does it ..Would you know ?
Thanx,






>From: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
>To: sachin mehra <bindas_qwerty@hotmail.com>
>CC: tutor@python.org
>Subject: Re: [Tutor] question on Partition
>Date: Tue, 10 Dec 2002 23:20:27 -0800 (PST)
>
>
>
>On Wed, 11 Dec 2002, sachin mehra wrote:
>
> > I need to use the partition function.  How can I use it?  Do I have to
> > include any module for that?
> >
> > ###
> > >>>paritition("attackatdawn")
> > [['at', 'tack', 'at', 'dawn'],
> > ['attack', 'at', 'dawn']]
> >
> > >>>partition("iscreamforicecream")
> > [['is', 'cream', 'for', 'ice', 'cream'],
> > ['i', 'scream', 'for', 'ice', 'cream']]
> >
> > >>>partition("uselesspython")
> > [['use', 'less', 'python'],
> > ['useless', 'python']]
> >
> > >>>partition("inaholetherelivedahobbit")
> > [['in', 'a', 'hole', 'the', 're', 'lived', 'a', 'hobbit'],
> > ['in', 'a', 'hole', 'there', 'lived', 'a', 'hobbit']]
> > ###
>
>Hi Sachin,
>
>It is not built in; it's something I cooked up a few weeks ago when I was
>thinking about your program.  However, it is a part of your homework to
>write source code; we cannot directly give you the code to do this task.
>
>
>
>This task is not too difficult to do if you approach the partitioning
>problem recursively.  If you solve the problem recursively, your solution
>should come to around five lines of code.
>
>As a concrete example, given the word "attackatdawn", you can recursively
>solve for the partitioning of "tackatdawn", or you can recursively solve
>for the partitioning of "atdawn".  Either way, if can attack these smaller
>problems, then you can solve for the partitioning of "attackatdawn".
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor


_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. 
http://join.msn.com/?page=features/virus



From djc@object-craft.com.au  Wed Dec 11 13:20:03 2002
From: djc@object-craft.com.au (Dave Cole)
Date: Wed Dec 11 13:20:03 2002
Subject: [Tutor] Wanted: module to parse out a CSV line
In-Reply-To: <5.1.0.14.0.20021211103301.02bd9da0@www.thinkware.se>
References: <5.1.0.14.0.20021211103301.02bd9da0@www.thinkware.se>
Message-ID: <m31y4ozpc0.fsf@ferret.object-craft.com.au>

> At 00:42 2002-12-11 -0800, Terry Carroll wrote:
> >I'm writing one of my first Python apps
> 
> Welcome Terry! I hope you will enjoy it!
> 
> (Dave, there is something here that looks like a bug in CSV to me.
> Care to comment?)

We consider what Excel exports to be the definitive statement of what
our parser should be handling.  Do you know if Excel ever exports
files with the ', ' separator?

Another question is what does Excel do when you import that data?

> I'm afraid you should have tried a bit harder with these modules.
> They can all solve your problem (?), but maybe they could be a little
> better documented, and one of them could be in the standard library
> I think.

Which one?  :-)

>  >>> import ASV
>  >>> asv = ASV.ASV()
>  >>> asv.input('A, 232, "Title", "Smith, Adam", "1, 2, 3, 4"', ASV.CSV())
>  >>> print asv
> [['A', '232', 'Title', 'Smith, Adam', '1, 2, 3, 4']]

It seems to be doing what you expect.

>  >>> import csv
>  >>> csv.parser().parse('A, 232, "Title", "Smith, Adam", "1, 2, 3, 4"')
> ['A', ' 232', ' "Title"', ' "Smith', ' Adam"', ' "1', ' 2', ' 3', ' 4"']
> 
> Not quite...but...
> 
>  >>> csv.parser().parse('A,232,"Title","Smith, Adam","1, 2, 3, 4"')
> ['A', '232', 'Title', 'Smith, Adam', '1, 2, 3, 4']
> 
> It seems the space after the comma confuses CSV regarding the use
> of double quotes. I've seen a lot of files with whitespace after
> the comma, so this is not what I would like. And the parser won't
> accept field_sep = ', ', it has to be a single character.

Have you checked what Excel does with that data?

> The reason that the "organizeIntoLines" step (which you can bypass by
> putting your string in a list I guess) exists is because programs like
> Excel will produce CSV files with line breaks inside "-delimited strings.
> So a logical line might span several physical lines.

Our CSV parser handles the records split over multiple lines thing.

If it turns out that Excel exports the ', ' separator then we would
absolutely consider our module to have a bug.

If Excel never exports files with ', ', but imports files with the
', ' separator differently to ours then we would seriously consider
changing our module to behave the same way.

>From our point of view we want to be absolutely sure that anything
Excel exports will be correctly parsed by our module.  It slightly
less important to duplicate the way that data is imported by Excel.

q> I think it would be a good thing to have parsers/importers/exporters for
> both CSV (and fixed format) in the standard library. We just need some
> kind of consensus on how they should behave I guess...

I agree.  Agreeing with what those parsers should do is always the
problem...

- Dave

-- 
http://www.object-craft.com.au



From alan.gauld@bt.com  Wed Dec 11 13:28:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed Dec 11 13:28:02 2002
Subject: [Tutor] (no subject)
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0970226F@i2km11-ukbr.domain1.systemhost.net>

> Is there a good place to find a basic installer for this type 
> of use, at least as a starting point?

There are a few freeware ones but I haven't used them.
(ASPack or somesuch comes to mind???)

Both Wise (as used by the Python insyaller) and Installshield
can do it easily but are both commercial. Wise seems to be opensource 
friendly aso they mught have a free version for use on opensource 
projects mebbe. The other thing is to write one yourself which 
for a one-off project isn't too hard, lots of os.system() calls
and a few windows registry calls using winall...

Alan g.


From alan.gauld@bt.com  Wed Dec 11 13:29:08 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed Dec 11 13:29:08 2002
Subject: [Tutor] Wanted: module to parse out a CSV line
Message-ID: <7497DCA1C240C042B28F6657ADFD8E09702270@i2km11-ukbr.domain1.systemhost.net>

> Is there an advantage to using something like asv or csv over opening
> the file, reading each line, and using string.split (line_contents,
> ',')?

Yeah, string.split can't handle nested commas in strings or currency etc...
The dedicated csv modules should do it correctly(both encoding and decoding)

Alan g


From dyoo@hkn.eecs.berkeley.edu  Wed Dec 11 13:47:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed Dec 11 13:47:01 2002
Subject: [Tutor] Slow program
In-Reply-To: <39869403.1039607349546.JavaMail.nobody@webmail2.brturbo.com>
Message-ID: <Pine.LNX.4.44.0212111021110.24671-100000@hkn.eecs.berkeley.edu>


On Wed, 11 Dec 2002, Diego Prestes wrote:

>    Im trying to make a program that take a text and test whats the two
> words that apeer more in the text together, but when I do this code it
> is to slow. I think its because of that create many times the same text
> (var b), but I dont find any better program. Someone could give a hand?

Hi Diego,

Ok, let's take a look.  Hey, wait, is this a colocations-detecting
program?  We're getting a heck of a lot of NLP-related questions these
days...  *grin*


> def calc(b):
>     dic={}
>     for x in range(len(b)-1):
>         if dic.has_key(b[x]+' '+b[x+1]) == 0:
>             c = 0
>             for y in range(len(b)-1):
>                 if b[x] == b[y] and b[x+1] == b[y+1]:
>                     c=c+1
>             dic[b[x]+' '+b[x+1]] = c
>     ma=0
>     for x in range(len(dic)):
>         if dic.values()[x] > ma:
>             ma = dic.values()[x]
>     for x in range(len(dic)):
>         if dic.values()[x] == ma:
>             print "%s -> %d" % (dic.keys()[x],dic.values()[x])



This function appears to be working in two steps.  The first step
accumulates a count of 2-word phrases that it sees, so let's concentrate
on that part first:

>     dic={}
>     for x in range(len(b)-1):
>         if dic.has_key(b[x]+' '+b[x+1]) == 0:
>             c = 0
>             for y in range(len(b)-1):
>                 if b[x] == b[y] and b[x+1] == b[y+1]:
>                     c=c+1
>             dic[b[x]+' '+b[x+1]] = c

This code is doing way too much work: it's using a nested loop, and doing
too much computation by tracing through the list multiple times.


It's possible to do a count of the word pairs by scanning through the list
once, comparing adjacent pairs of words.  Imagine a finger tracing across
the page: that's a linear scan, and linear-scanning approaches are pretty
efficient.


The approach I'm thinking of is a generalization of the word-counting
histogram program, but uses pairs of words rather than single words.
Think about it for a while, and if you're still stuck, look below after
the spoiler space.



One other change we made is avoiding the kludge of appending words
together using some kind of sentinel character, like a space, that we used
in the original code:

    dic[b[x]+' '+b[x+1]] = c

In some languages, like Perl, programmers often do things like this to
keep key pairs in a dictionary (hashtable).  But it's a kludge because, if
we're not careful, we can easily break this if our sentinel character is
not unique:

###
w1, w2 = "a b", "c"
w3, w4 = "a", "b c"
dict[w1 + " " + w2] = dict.get(w1 + " " + w2, 0) + 1
dict[w3 + " " + w4] = dict.get(w3 + " " + w4, 0) + 1
###

Python allows the keys of our dictionary to contain real tuples, so we can
do this:

    dict[b[x], b[x+1]] = c

without resorting to string glue.


Anyway, hope this helps!


*** spoiler space ahead ***
*** spoiler space ahead ***
*** spoiler space ahead ***
*** spoiler space ahead ***
*** spoiler space ahead ***
*** spoiler space ahead ***
*** spoiler space ahead ***
*** spoiler space ahead ***
*** spoiler space ahead ***
*** spoiler space ahead ***
*** spoiler space ahead ***
*** spoiler space ahead ***
*** spoiler space ahead ***
*** spoiler space ahead ***
*** spoiler space ahead ***
*** spoiler space ahead ***
*** spoiler space ahead ***
*** spoiler space ahead ***
*** spoiler space ahead ***
*** spoiler space ahead ***


Here's one way to do that code in a linear scan:

###
    dic = {}
    for i in range(len(b)-1):
        pair = b[x], b[x+1]
        dict[pair] = dict.get(pair, 0) + 1

        ## By this time, all of the colocations from 0 to i+1 have been
        ## counted in our dictionary.
###

So our dictionary continues to have a partial count of all the colocations
as it marches through the list.  By the end of this code, you should have
the same results --- a count of all the word pairs --- in the 'dic'
dictionary.



From magnus@thinkware.se  Wed Dec 11 13:57:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 11 13:57:01 2002
Subject: [Tutor] Pythonwin
In-Reply-To: <1331726890.20021211115606@roadrunner.nf.net>
References: <5.1.0.14.0.20021211154515.02bbbf48@www.thinkware.se>
 <5.1.0.14.0.20021211154515.02bbbf48@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021211195840.02be2fe8@www.thinkware.se>

At 11:56 2002-12-11 -03-30, Adam Vardy wrote:
>How do I do that?

File -> New perhaps?


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Wed Dec 11 14:20:06 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 11 14:20:06 2002
Subject: [Tutor] Pythonpath
In-Reply-To: <17531437334.20021211115116@roadrunner.nf.net>
References: <5.1.0.14.0.20021211155630.02bf7090@www.thinkware.se>
 <5.1.0.14.0.20021211155630.02bf7090@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021211195351.02bde128@www.thinkware.se>

At 11:51 2002-12-11 -03-30, Adam Vardy wrote:
>Wednesday, December 11, 2002, 11:27:29 AM, you wrote:
>
> >> At 11:03 2002-12-11 -03-30, Adam Vardy wrote:
> >>How do I set a Pythonpath?
>
> >> What OS? (Don't say Windows, that's several OS's)
>
>Windows XP Pro.

Hm...I'll have to look at my wife's computer.

Control Panel => System => Advanced [Tab] => Environment
Variables [Button near bottom]
(if I'm back-translating names correctly from Swedish.)

The setting will only affect processes started after you
have applied that change.

> >>And does Python have command line options?
>
>H:\python>>python -h
>
>Yeah, I tried 'python /?', but just gave an error.

Well, in most operating systems where Python works, /?
means "all files in the root directory with a file name
that is one character long".

Fortunately, Python follows standards, not DOS absurdities.
It works on almost every OS under the sun as you might know.
(Is Python still available on more platforms than Java?)

The really stupid design decision in DOS wasn't to use
"/" for command switches though, but to use the character
that C etc used for escape sequences "\". I guess the reason
they did that was because "/" was used for the switches, but
surely they could have found a way to use ":" as separator
(which is what some other OS's that don't use / do).

Microsoft is trying to back out of this now, and allow /
as well as \ as directory separator in paths, but they
have these absurd situations where you have to use / in
some situations \ on others and \\ in some. There are
even situations where you might need to use both \ and / in
different parts of the same path to make things work. :(
This is a non-problem in all non-Microsoft OS's as far as
I know. It belongs to the same mistakes as 8.3 filenames
and file allocation tables.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From jeff@ccvcorp.com  Wed Dec 11 14:44:31 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Wed Dec 11 14:44:31 2002
Subject: [Tutor] (no subject)
References: <7497DCA1C240C042B28F6657ADFD8E0970226F@i2km11-ukbr.domain1.systemhost.net>
Message-ID: <3DF795A0.1070506@ccvcorp.com>


alan.gauld@bt.com wrote:

>>Is there a good place to find a basic installer for this type 
>>of use, at least as a starting point?
>>    
>>
>
>There are a few freeware ones but I haven't used them.
>(ASPack or somesuch comes to mind???)
>  
>

I know that wxPython (among other projects) uses Inno Setup, which is 
free.  There's also some freeware extensions available to expand the 
pre- and post-setup scripting capabilities.  I haven't examined this too 
closely myself, though.

Jeff Shannon
Technician/Programmer
Credit International




From magnus@thinkware.se  Wed Dec 11 15:37:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 11 15:37:01 2002
Subject: [Tutor] Wanted: module to parse out a CSV line
In-Reply-To: <Pine.GSU.4.44.0212110856450.27504-100000@waltz.rahul.net>
References: <5.1.0.14.0.20021211103301.02bd9da0@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021211213000.02c11688@www.thinkware.se>

At 09:13 2002-12-11 -0800, Terry Carroll wrote:
>Thanks.  The docs are a little sparse, and don't have any hint that that's
>possible.  I tried reading through the Python code, but, as I said, I'm
>still a newbie to Python, and couldn't really follow it yet.  I'll keep
>that in mind.

Ok. At least ASV.py seems reather simple to read (although
I wish the author didn't use quite that much whitespace.)

what about

 >>> import ASV
 >>> help(ASV)

?


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Wed Dec 11 15:40:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 11 15:40:02 2002
Subject: [Tutor] Slow program
In-Reply-To: <Pine.LNX.4.44.0212111021110.24671-100000@hkn.eecs.berkeley
 .edu>
References: <39869403.1039607349546.JavaMail.nobody@webmail2.brturbo.com>
Message-ID: <5.1.0.14.0.20021211203613.02beebb0@www.thinkware.se>

At 10:46 2002-12-11 -0800, Danny Yoo wrote:
>Here's one way to do that code in a linear scan: ...

There were a few typos here, but I compared this with the
original program, and it makes quite a difference. If you use
the function below which is based on Danny's code and the
original function, you can profile them with the code below.

In this case it's obvious that you will benefit from going
from a loop inside a loop, to one single loop, but as program
get longer, it usually gets very difficult to spot manually
where our bottle-necks are.

There is no reason to think about any measurements if the app
is already fast enough, but if there are performance problems,
it's very often really helpful to use the profiler.

So, getting used to using the profiler is a good thing. In addition
to this trivial usage, we can make a program run save data in a
statistics file, that we analyze with the pstats module.

The disadvantage with the profiler is that it slow down the code
a lot. There is a new profiler written in C called hotshot. It's
included in Python (try "import hotshot") and it's much faster,
but it's not quite ready, and it's not documented. See
http://web.pydoc.org/2.2/hotshot.html and
starship.python.net/crew/fdrake/talks/ IPC10-HotShot-2002-Feb-06.ppt


def calc2(b):
     dic = {}
     for x in range(len(b)-1):
         pair = b[x], b[x+1]
         dic[pair] = dic.get(pair, 0) + 1
     ma=0
     for x in range(len(dic)):
         if dic.values()[x] > ma:
             ma = dic.values()[x]
     for x in range(len(dic)):
         if dic.values()[x] == ma:
             print "%s -> %d" % (" ".join(dic.keys()[x]),dic.values()[x])

b = "some suitably big string..."

import profile
print "original"
profile.run('calc(b)')
print "Danny Yoo"
profile.run('calc2(b)')



-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From dyoo@hkn.eecs.berkeley.edu  Wed Dec 11 15:47:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed Dec 11 15:47:01 2002
Subject: [Tutor] question on Partition       [off-topic rant/flame]
In-Reply-To: <F15yI1iNAp3gRFvXYaI00015ba4@hotmail.com>
Message-ID: <Pine.LNX.4.44.0212111212120.28470-100000@hkn.eecs.berkeley.edu>


On Wed, 11 Dec 2002, sachin mehra wrote:

> So is there any other function which does it? Something like partition
> as you mentioned? I think there is some function in unix which does it
> ..Would you know ? Thanx,


Dear Sachin,

I can't think of a Unix utility that will do it directly; this is
something that's so specialized, so artificial, that you will probably
need to cook the function up in the language of your choice.


Forgive me for being cruel and blunt about this, but your question is not
difficult.  This kind of homework question is supposed to be covered by an
introductory CS course, and you can solve it using standard recursive
techniques.

If you weren't doing this for a class, I really wouldn't have any
reservations giving advice to a fellow student.  But you are doing this
for a class project, in what sounds like an advanced CS class, and your
responses are hinting that you haven't tried writing this function using
your own efforts.


I cannot write this program for you.



From shendric@arches.uga.edu  Wed Dec 11 16:43:03 2002
From: shendric@arches.uga.edu (shendric@arches.uga.edu)
Date: Wed Dec 11 16:43:03 2002
Subject: [Tutor] Linux installation
Message-ID: <1039642864.smmsdV1.1.2@mail.arches.uga.edu>

Hi all,

I just installed Python 2.2.2 on a Linux machine with a 2.4.18-14 
kernel, and after doing the "configure" "make" dance, I tried to open 
IDLE, but I received a message saying that my system might not be 
configured for Tk.  Has anyone who has installed Python on Linux had 
problems with installing it?

Sean




From magnus@thinkware.se  Wed Dec 11 17:48:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 11 17:48:02 2002
Subject: [Tutor] Linux installation
In-Reply-To: <1039642864.smmsdV1.1.2@mail.arches.uga.edu>
Message-ID: <5.1.0.14.0.20021211234809.02c1d4d0@www.thinkware.se>

At 16:41 2002-12-11 -0500, shendric@arches.uga.edu wrote:
>I just installed Python 2.2.2 on a Linux machine with a 2.4.18-14
>kernel, and after doing the "configure" "make" dance, I tried to open
>IDLE, but I received a message saying that my system might not be
>configured for Tk.  Has anyone who has installed Python on Linux had
>problems with installing it?

Python's standard GUI, Tkinter, needs Tcl/Tk to be installed. Is it?
I'm using Mandrake 9 and their standard RPMs, so I don't have any
problems.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From Adam Vardy <anvardy@roadrunner.nf.net>  Wed Dec 11 17:51:01 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Wed Dec 11 17:51:01 2002
Subject: [Tutor] Training
Message-ID: <6560389886.20021206115219@roadrunner.nf.net>

Have an opinion on this program?
"The Complete Python Training Course"

Is it effective? Friendly?
  

-- 
Adam Vardy



From Adam Vardy <anvardy@roadrunner.nf.net>  Wed Dec 11 17:51:14 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Wed Dec 11 17:51:14 2002
Subject: [Tutor] Example 2
Message-ID: <4020991974.20021211085711@roadrunner.nf.net>

Some ideas in Python are hard to follow. Is there a way to help
configure your mind around it? Example:
>>>
>>> sch=[ (echo,'Spam!'), (echo,'Ham!') ]
>>> for (func,arg) in sch:
...   apply(func, (arg,))
...
Spam!
Ham!
>>>

-- 
Adam Vardy



From Adam Vardy <anvardy@roadrunner.nf.net>  Wed Dec 11 17:53:01 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Wed Dec 11 17:53:01 2002
Subject: [Tutor] Pythonwin
In-Reply-To: <5.1.0.14.0.20021211195840.02be2fe8@www.thinkware.se>
References: <5.1.0.14.0.20021211154515.02bbbf48@www.thinkware.se>
 <5.1.0.14.0.20021211154515.02bbbf48@www.thinkware.se>
 <5.1.0.14.0.20021211195840.02be2fe8@www.thinkware.se>
Message-ID: <5358500839.20021211192220@roadrunner.nf.net>

Wednesday, December 11, 2002, 3:29:02 PM, you wrote:

>> At 11:56 2002-12-11 -03-30, Adam Vardy wrote:
>>How do I do that?

File ->> New perhaps?

I am trying to run this. Goes to the same menu. And bottom of screen
just says Exception raised.  Program still seems good to me. I thought
it would give more detailed explanation.

I haven't actually reached the chapter on exceptions.

I could locate a Help section on PythonWin.  It starts off though
about Modules and Objects. not apropos. The only documentation there
was a like a page or two. I thought you'd get explanations for all the
File...Tools menu system.


-+-+-+-+-+-+-+-+-+-+-+

L=[1,2,4,8,16,32,64]
X=5

found = i = 0
while i< len(L):
  if 2 ** X==L(i): break
  else:
    i=i+1

##if found:
  print 'at index',i
else:
  print X, 'not found'


-- 
Adam Vardy



From rob@uselesspython.com  Wed Dec 11 18:12:15 2002
From: rob@uselesspython.com (Rob Andrews)
Date: Wed Dec 11 18:12:15 2002
Subject: [Tutor] Training
In-Reply-To: <6560389886.20021206115219@roadrunner.nf.net>
Message-ID: <MPEOIFCOPCIHEDCLBLPBAEBGCNAA.rob@uselesspython.com>

It depends on your needs, budget, and learning style, really.

If this is what I think it is, The book _Python How to Program_ covers
essentially all the same material, only you don't get it on CD. A lot of
handy information is conveyed in both, although nothing is beyond criticism.
The book alone is $80 (USD) on amazon.com, but "The Complete Python Training
Course" is currently listed as a few dollars less. Normally I would assume
this is not the case.

If you'd like a book that will introduce necessary basics of a lot of useful
programming tasks, and will present a decent introduction to Python, it
should do the job nicely. It's not beyond criticism, as none are, but it
does take the time to explain a things in what is generally plain language.
Try to see if you can get a used copy and save a few bucks, though.

Rob

> -----Original Message-----
>
> Have an opinion on this program?
> "The Complete Python Training Course"
>
> Is it effective? Friendly?
>




From magnus@thinkware.se  Wed Dec 11 18:17:07 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 11 18:17:07 2002
Subject: [Tutor] Pythonwin
In-Reply-To: <5358500839.20021211192220@roadrunner.nf.net>
References: <5.1.0.14.0.20021211195840.02be2fe8@www.thinkware.se>
 <5.1.0.14.0.20021211154515.02bbbf48@www.thinkware.se>
 <5.1.0.14.0.20021211154515.02bbbf48@www.thinkware.se>
 <5.1.0.14.0.20021211195840.02be2fe8@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021211235827.02bda918@www.thinkware.se>

At 19:22 2002-12-11 -03-30, Adam Vardy wrote:
>I am trying to run this. Goes to the same menu.

What same menu?
1 Click File -> New.
2 Select "Python script"
3 Paste code
4 Ctrl-S to save (give filename first time)
5 F5 to run (Hm... that's not clearly indicated I guess. But it's
              the run key in all Windows IDE's I ever used.)
6 Switch to Interactive Window
7 Read an interpret traceback
8 Switch back and fix code
9 Go to 4

I'm not sure if you installed ActivePython or Mark's win32all.

In the ActivePython help, look at:
ActivePython User's Guide
   What's included in ActivePython

       PythonWin Development Environment

         Keyboard Bindings

           F5 Run

Remember that "real programmer" don't use the mouse unless
they really have to... Typing at the keyboard is much, much
faster.

>And bottom of screen
>just says Exception raised.  Program still seems good to me. I thought
>it would give more detailed explanation.

It does... Switch over to the interactive window, and you
will see the traceback.

>I haven't actually reached the chapter on exceptions.

All runtime error messages come as exeptions. Reading
tracebacks is fairly clear. I don't think you need to
grok exceptions.

>I could locate a Help section on PythonWin.  It starts off though
>about Modules and Objects. not apropos. The only documentation there
>was a like a page or two. I thought you'd get explanations for all the
>File...Tools menu system.

I guess Mark Hammond though it was self explanatory. ;)

I think you will get used to it fairly quickly.

>L=[1,2,4,8,16,32,64]
>X=5
>
>found = i = 0
>while i< len(L):
>   if 2 ** X==L(i): break

This is where is chokes first. I think you mean L[i]

>   else:
>     i=i+1
>
>##if found:
>   print 'at index',i

When the if-statement is commented out like that,
the next line will cause a syntax error due to the
indetation. You can't suddenly have indented code
without if, while, for, def etc.

>else:
>   print X, 'not found'


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From kalle@lysator.liu.se  Wed Dec 11 18:40:02 2002
From: kalle@lysator.liu.se (Kalle Svensson)
Date: Wed Dec 11 18:40:02 2002
Subject: [Tutor] Linux installation
In-Reply-To: <1039642864.smmsdV1.1.2@mail.arches.uga.edu>
References: <1039642864.smmsdV1.1.2@mail.arches.uga.edu>
Message-ID: <20021211233910.GH31121@i92.ryd.student.liu.se>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[shendric@arches.uga.edu]
> I just installed Python 2.2.2 on a Linux machine with a 2.4.18-14 
> kernel, and after doing the "configure" "make" dance, I tried to open 
> IDLE, but I received a message saying that my system might not be 
> configured for Tk.  Has anyone who has installed Python on Linux had 
> problems with installing it?

When you compile Python, you will need Tk header files and libraries
to get Tkinter support.  On Debian, you can do
apt-get install tk8.3-dev
to get them.  Other distributions probably have similar packages.

Peace,
  Kalle
- -- 
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>

iD8DBQE998yZdNeA1787sd0RAuqZAJ4hk6ZgL3h1wapUr3Ihu16vWHtuaQCffnrc
oozQ4Cnq8ZVoLhmVb3uEOxc=
=74Bj
-----END PGP SIGNATURE-----


From aicolburn@yahoo.com  Wed Dec 11 18:55:01 2002
From: aicolburn@yahoo.com (Alan Colburn)
Date: Wed Dec 11 18:55:01 2002
Subject: [Tutor] Sorting Instance Attributes
Message-ID: <20021211235413.56094.qmail@web20507.mail.yahoo.com>

Hi all--

I wrote a program awhile ago to help me keep track of
attendance in my courses. Now, as an exercise, I've
decided to rewrite the program OOP-style. Among other
things, each student will be an object. The Student
class constructor begins with this code:

class Student:
     def __init__(self, firstName, lastName):
          self.firstName=firstName
          self.lastName=lastName

Adding a student into the course amounts to creating a
new instance of the Student class. Now, onto my
questions:

1. If I'd like to record most student information
within individual Student class instances, what would
be the recommended type (is that the right word?) to
use for storing the collection of Student objects?
List? Dictionary? I'll save the information via
cpickle or shelve.

2. [Here's the one that I'm stumped on...] How do I
sort objects via a single object attribute. In the
example above, suppose I'd like to create a class
list, sorted alphabetically via lastName? 

As always, thanks for your help! -- Al Colburn

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com


From grimmtooth@softhome.net  Wed Dec 11 18:57:01 2002
From: grimmtooth@softhome.net (Jeff Grimmett)
Date: Wed Dec 11 18:57:01 2002
Subject: [Tutor] (no subject)
In-Reply-To: <3DF795A0.1070506@ccvcorp.com>
Message-ID: <MBEOLOBBHMCCJMEHEFHAOEOHCDAA.grimmtooth@softhome.net>

FWIW, I've used Inno Setup and it has proven to be excellent software. I'm
sure the pro packages have more goodies, but for straightforward installs,
this one's great.

> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> Jeff Shannon
> Sent: Wednesday, December 11, 2002 2:45 PM
> To: tutor@python.org
> Subject: Re: [Tutor] (no subject)
>
>
>
>
> alan.gauld@bt.com wrote:
>
> >>Is there a good place to find a basic installer for this type
> >>of use, at least as a starting point?
> >>
> >>
> >
> >There are a few freeware ones but I haven't used them.
> >(ASPack or somesuch comes to mind???)
> >
> >
>
> I know that wxPython (among other projects) uses Inno Setup, which is
> free.  There's also some freeware extensions available to expand the
> pre- and post-setup scripting capabilities.  I haven't examined this too
> closely myself, though.
>
> Jeff Shannon
> Technician/Programmer
> Credit International
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From op73418@mail.telepac.pt  Wed Dec 11 19:15:02 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Wed Dec 11 19:15:02 2002
Subject: [Tutor] Sorting Instance Attributes
References: <20021211235413.56094.qmail@web20507.mail.yahoo.com>
Message-ID: <002501c2a174$46fa9220$b0180dd5@violante>

----- Original Message -----
From: "Alan Colburn" <aicolburn@yahoo.com>
To: <tutor@python.org>
Sent: Wednesday, December 11, 2002 11:54 PM
Subject: [Tutor] Sorting Instance Attributes


> Hi all--
>
> I wrote a program awhile ago to help me keep track of
> attendance in my courses. Now, as an exercise, I've
> decided to rewrite the program OOP-style. Among other
> things, each student will be an object. The Student
> class constructor begins with this code:
>
> class Student:
>      def __init__(self, firstName, lastName):
>           self.firstName=firstName
>           self.lastName=lastName
>
> Adding a student into the course amounts to creating a
> new instance of the Student class. Now, onto my
> questions:
>
> 1. If I'd like to record most student information
> within individual Student class instances, what would
> be the recommended type (is that the right word?) to
> use for storing the collection of Student objects?
> List? Dictionary? I'll save the information via
> cpickle or shelve.

There is really no answer to this, depends on what you want to do with the
"collection of Student objects." Think about how you want to manage this
collection, what you want to do it. Is a list enough? Or probably it is
better to roll out your own "collection" class?

>
> 2. [Here's the one that I'm stumped on...] How do I
> sort objects via a single object attribute. In the
> example above, suppose I'd like to create a class
> list, sorted alphabetically via lastName?

Here Python's magic methods are useful. Consider the following

class Student(object):

    #Methods snipped.

    def __lt__(self, other):
        return self.lastname < other.lastname

I have added here one magic method - magic methods are signalled by being
surrounded by double underscores - that tells Python that this class
understands what is "less than". The method code is really simple: Since you
want alphabetical order we can just delegate to the order of builtin string
objects (There are probably some caveats with uppercase letters but let us
forget that for a moment). For more details on magic methods consult the
manuals.

Now, if you have a list, l say, of student objects, you can just call

l.sort()

and it will automatically sort the list by calling the __lt__ method.

Pretty cool stuff, I say.

>
> As always, thanks for your help! -- Al Colburn
>

With my best regards,
G. Rodrigues



From alan.gauld@bt.com  Wed Dec 11 19:44:23 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed Dec 11 19:44:23 2002
Subject: [Tutor] Pythonpath
Message-ID: <7497DCA1C240C042B28F6657ADFD8E09702273@i2km11-ukbr.domain1.systemhost.net>

> The really stupid design decision in DOS wasn't to use
> "/" for command switches though, but to use the character
> that C etc used for escape sequences "\". I guess the reason
> they did that was because "/" was used for the switches, 

ISTR CP/M used '/' for switches and DOS was originally a cheap 
emulator of CP/M for Intel 8088 (hence the presence of the 
ERA command)

> I know. It belongs to the same mistakes as 8.3 filenames
> and file allocation tables.

Yep, they come from CP/M too. Back when a floppy was 8 inches 
square, really was floppy and stored 180Kb and hard disks only 
existed for mainframes and Midis(anyone still talk about midis? :-)

Alan g.


From emil@lysator.liu.se  Wed Dec 11 21:04:02 2002
From: emil@lysator.liu.se (Emil Styrke)
Date: Wed Dec 11 21:04:02 2002
Subject: [Tutor] Example 2
In-Reply-To: <4020991974.20021211085711@roadrunner.nf.net>
References: <4020991974.20021211085711@roadrunner.nf.net>
Message-ID: <87isy0kn8e.fsf@i110.ryd.student.liu.se>

Adam Vardy <anvardy@roadrunner.nf.net> writes:

> Some ideas in Python are hard to follow. Is there a way to help
> configure your mind around it? Example:

Just keep on programming, and ask questions!

(In the following, I will assume that a function 'echo' exists, which
prints its argument to the screen)

> >>>
> >>> sch=[ (echo,'Spam!'), (echo,'Ham!') ]
> >>> for (func,arg) in sch:

This line is a short form for:

>>> for elem in sch:
>>>     (func, arg) = elem

The last line here, in turn, uses a concept called tuple
unpacking. It's equivalent to:

>>> func = elem[0]
>>> arg = elem[1]


> ...   apply(func, (arg,))

The apply function is a concept borrowed from functional programming
(e.g. Lisp).  It takes as arguments a function reference and a
sequence of arguments, and then it calls the function reference with
the argument sequence as arguments.

So, inside the loop, we have the variable func, which will contain the
first element of each tuple in the list sch, and another variable arg,
which will contain the second element of each tuple in the list.
Then, for each of these pairs, we call apply.  For example, the first
iteration of the loop will evaluate into

>>> apply(echo, ('Spam!',))

which will then call the function echo with the argument 'Spam!':

>>> echo('Spam!')

Hope that clears things up a little, for this particular case at
least!

        /Emil

> ...
> Spam!
> Ham!
> >>>
> 
> -- 
> Adam Vardy
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From SWidney@ci.las-vegas.nv.us  Wed Dec 11 21:11:02 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Wed Dec 11 21:11:02 2002
Subject: [Tutor] Pythonwin
Message-ID: <0E5508EBA1620743B409A2B8365DE16FDC828E@SOVEREIGN>

> -+-+-+-+-+-+-+-+-+-+-+
> 
> L=[1,2,4,8,16,32,64]
> X=5
> 
> found = i = 0
> while i< len(L):
>   if 2 ** X==L(i): break
>   else:
>     i=i+1
> 
> ##if found:
>   print 'at index',i
> else:
>   print X, 'not found'
> 
> 
> -- 

Aren't you glad that the batteries are included! From eleven lines to three:

>>> L, X = [1,2,4,8,16,32,64], 5
>>> if L.index(2**X): print "found at", L.index(2**X)
... else: print X, "not found"
... 
 found at 5
>>> 


Scott


From glingl@aon.at  Wed Dec 11 21:23:01 2002
From: glingl@aon.at (Gregor Lingl)
Date: Wed Dec 11 21:23:01 2002
Subject: [Tutor] Example 2
References: <4020991974.20021211085711@roadrunner.nf.net> <87isy0kn8e.fsf@i110.ryd.student.liu.se>
Message-ID: <3DF7F2FF.3040904@aon.at>

Emil Styrke schrieb:

>>...   apply(func, (arg,))
>>    
>>
>
>The apply function is a concept borrowed from functional programming
>(e.g. Lisp).  
>
>  
>
>>>>apply(echo, ('Spam!',))
>>>>        
>>>>
>
>which will then call the function echo with the argument 'Spam!':
>  
>

In Python 2.2 you (at least in many cases) can avoid to use apply in 
favour of the following
simpler syntax:

 >>> def echo(cry):
    print '***'+cry+'***'

   
 >>> sch = [(echo,'Spam!'), (echo, 'Ham!')]
 >>> for (func, arg) in sch:
    print func, arg
    func(arg)

   
<function echo at 0x0093EBB0> Spam!
***Spam!***
<function echo at 0x0093EBB0> Ham!
***Ham!***
 >>>

Less hard to follow?
Regards, Gregor


>  
>
>>>>echo('Spam!')
>>>>        
>>>>
>
>Hope that clears things up a little, for this particular case at
>least!
>
>        /Emil
>
>  
>
>>...
>>Spam!
>>Ham!
>>    
>>
>>-- 
>>Adam Vardy
>>
>>
>>_______________________________________________
>>Tutor maillist  -  Tutor@python.org
>>http://mail.python.org/mailman/listinfo/tutor
>>    
>>
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>  
>






From glingl@aon.at  Wed Dec 11 21:32:03 2002
From: glingl@aon.at (Gregor Lingl)
Date: Wed Dec 11 21:32:03 2002
Subject: [Tutor] Pythonwin
References: <0E5508EBA1620743B409A2B8365DE16FDC828E@SOVEREIGN>
Message-ID: <3DF7F517.5090604@aon.at>

Scott Widney schrieb:

>Aren't you glad that the batteries are included! From eleven lines to three:
>
>  
>
>>>>L, X = [1,2,4,8,16,32,64], 5
>>>>if L.index(2**X): print "found at", L.index(2**X)
>>>>        
>>>>
>... else: print X, "not found"
>... 
> found at 5
>  
>
A little too short cut:

 >>> L, X = [1,2,4,8,16,32,64], 0
 >>> if L.index(2**X): print "found at", L.index(2**X)
else: print X, "not found"

0 not found

whereas
 >>> 2**0
1

and what, when
 >>> L, X = [1,2,4,8,16,32,64], 7
?
Regards, Gregor




>
>Scott
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>  
>






From Don Arnold" <darnold02@sprynet.com  Wed Dec 11 22:43:02 2002
From: Don Arnold" <darnold02@sprynet.com (Don Arnold)
Date: Wed Dec 11 22:43:02 2002
Subject: [Tutor] Sorting Instance Attributes
References: <20021211235413.56094.qmail@web20507.mail.yahoo.com> <002501c2a174$46fa9220$b0180dd5@violante>
Message-ID: <01da01c2a190$5c338cc0$1813ba3f@defaultcomp>

> > Hi all--
> >
> > I wrote a program awhile ago to help me keep track of
> > attendance in my courses. Now, as an exercise, I've
> > decided to rewrite the program OOP-style. Among other
> > things, each student will be an object. The Student
> > class constructor begins with this code:
> >
> > class Student:
> >      def __init__(self, firstName, lastName):
> >           self.firstName=firstName
> >           self.lastName=lastName
> >
> > Adding a student into the course amounts to creating a
> > new instance of the Student class. Now, onto my
> > questions:
> >
> > 1. If I'd like to record most student information
> > within individual Student class instances, what would
> > be the recommended type (is that the right word?) to
> > use for storing the collection of Student objects?
> > List? Dictionary? I'll save the information via
> > cpickle or shelve.
>
> There is really no answer to this, depends on what you want to do with the
> "collection of Student objects." Think about how you want to manage this
> collection, what you want to do it. Is a list enough? Or probably it is
> better to roll out your own "collection" class?
>
> >
> > 2. [Here's the one that I'm stumped on...] How do I
> > sort objects via a single object attribute. In the
> > example above, suppose I'd like to create a class
> > list, sorted alphabetically via lastName?
>
> Here Python's magic methods are useful. Consider the following
>
> class Student(object):
>
>     #Methods snipped.
>
>     def __lt__(self, other):
>         return self.lastname < other.lastname
>
> I have added here one magic method - magic methods are signalled by being
> surrounded by double underscores - that tells Python that this class
> understands what is "less than". The method code is really simple: Since
you
> want alphabetical order we can just delegate to the order of builtin
string
> objects (There are probably some caveats with uppercase letters but let us
> forget that for a moment). For more details on magic methods consult the
> manuals.
>
> Now, if you have a list, l say, of student objects, you can just call
>
> l.sort()
>
> and it will automatically sort the list by calling the __lt__ method.
>
> Pretty cool stuff, I say.
>
> >
> > As always, thanks for your help! -- Al Colburn
> >
>
> With my best regards,
> G. Rodrigues
>

This got me to thinking (which can be dangerous at times): what if you don't
always want to sort by the same attribute? I played around a little, and
here's what I came up with:

def setStudentKey(key):
    """builds the comparison function on the fly"""
    c = 'def studentCompare(l,r):\n\treturn cmp(str(l.%s),str(r.%s))\n' \
        % (key, key)
    exec(c,__builtins__.__dict__)

class Student:
    def __init__(self,id,firstName,lastName,grade):
        self.id = id
        self.firstName = firstName
        self.lastName = lastName
        self.grade = grade

if __name__ == '__main__':
    theClass = []
    Mary = Student(1,'Mary','Smith', 93)
    Bob = Student(2,'Bob','Jones', 97)
    John = Student(3,'John','Albert', 70)

    theClass.append(Bob)
    theClass.append(John)
    theClass.append(Mary)

    for currKey in ('id','firstName','lastName','grade'):
        setStudentKey(currKey)
        theClass.sort(studentCompare)
        print 'class sorted by "%s":' % currKey
        for x in theClass:
            print '\t%s, %s, %s, %s' % (x.id,x.firstName,x.lastName,x.grade)
        print "\n"

When ran, this outputs:

class sorted by "id":
 1, Mary, Smith, 93
 2, Bob, Jones, 97
 3, John, Albert, 70


class sorted by "firstName":
 2, Bob, Jones, 97
 3, John, Albert, 70
 1, Mary, Smith, 93


class sorted by "lastName":
 3, John, Albert, 70
 2, Bob, Jones, 97
 1, Mary, Smith, 93


class sorted by "grade":
 3, John, Albert, 70
 1, Mary, Smith, 93
 2, Bob, Jones, 97

I realize that it's not perfect, but I was still kind of proud of myself. Of
course, I then realized that I was probably re-inventing the wheel, so I
whipped out my copy of 'The Python Cookbook'. Sure enough, recipe 2.6
('Sorting a List of Objects by an Attribute of the Objects') had quite
elegantly beaten me to the punch. Oh, well!

Don



From thomi@thomi.imail.net.nz  Thu Dec 12 00:57:02 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Thu Dec 12 00:57:02 2002
Subject: [Tutor] problems with my first pygame game
Message-ID: <20021212185628.5b748f05.thomi@thomi.imail.net.nz>

This is a multi-part message in MIME format.

--Multipart_Thu__12_Dec_2002_18:56:28_+1300_08260ed0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit


Hi,

I thought I'd start to learn how to us pygame, and i made myself a small
program modelled around the chimp program. It's meant to be a bit like a
clay shooting range, you have a cross hair cursor, and you have to click
on the clay pigeons which come flying across the screen. everything
works, apart from the line of code which tests to see if the pigeon is
off the screen, and if it is, reset it. could i please ask someone to
take a look at the attached python file? the game won't run, because i
haven't attached the two bitmap files, but i hope someone can tell me
what I'm doing wrong :-)

thanks!

-- 
The software required Win95 or better, so I installed Linux.
Thomi Richards,
thomi@imail.net.nz


--Multipart_Thu__12_Dec_2002_18:56:28_+1300_08260ed0
Content-Type: application/octet-stream;
 name="main.py"
Content-Disposition: attachment;
 filename="main.py"
Content-Transfer-Encoding: base64

IyEvdXNyL2Jpbi9weXRob24KCicnJ1Rob21pJ3MgcmlmbGUgcmFuZ2UgcHJvZ3JhbS4KClRoaXMg
aXMgbXkgZmlyc3QgcHJvZ3JhbSwgc28gaWYgdGhlIGNvZGluZyBpcyByZWFsbHkgYmFkLCBvciB0
aGUgZ3JhcGhpY3Mgc3VjaywKdGhleSBhcmUgYm91bmQgdG8gaW1wcm92ZSBpbiBteSBzZWNvbmQg
YW5kIHRoaXJkIGFuZCBmb3VydGggZ2FtZXMuCgpjb21tZW50cy9mZWVkYmFjayBhcmUgbW9zdCB3
ZWxjb21lLiBlbWFpbCBpcyBiZXN0OgoKdGhvbWlAaW1haWwubmV0Lm56JycnCgojd2UgbmVlZCBz
eXMgYW5kIG9zCmltcG9ydCBzeXMsb3MKaW1wb3J0IHJhbmRvbQoKaW1wb3J0IHB5Z2FtZQpmcm9t
IHB5Z2FtZS5sb2NhbHMgaW1wb3J0ICoKCmlmIG5vdCBweWdhbWUuZm9udDoKCXByaW50ICdXYXJu
aW5nOiBGb250cyBEaXNhYmxlZCcKaWYgbm90IHB5Z2FtZS5taXhlcjoKCXByaW50ICdXYXJuaW5n
OiBTb3VuZCBkaXNhYmxlZCcKCgpkZWYgbG9hZF9pbWFnZShuYW1lLCBjb2xvcmtleT1Ob25lKToK
CWZ1bGxuYW1lID0gb3MucGF0aC5qb2luKCdkYXRhJyxuYW1lKQoJdHJ5OgoJCWltYWdlID0gcHln
YW1lLmltYWdlLmxvYWQoZnVsbG5hbWUpCglleGNlcHQgcHlnYW1lLmVycm9yLCBtZXNzYWdlOgoJ
CXByaW50ICdDYW5ub3QgbG9hZCBpbWFnZTonLGZ1bGxuYW1lCgkJcmFpc2UgU3lzdGVtRXhpdCwg
bWVzc2FnZQoJaW1hZ2UgPSBpbWFnZS5jb252ZXJ0KCkKCWlmIGNvbG9ya2V5IGlzIG5vdCBOb25l
OgoJCWlmIGNvbG9ya2V5IGlzIC0xOgoJCQljb2xvcmtleSA9IGltYWdlLmdldF9hdCgoMCwwKSkK
CQlpbWFnZS5zZXRfY29sb3JrZXkoY29sb3JrZXksIFJMRUFDQ0VMKQoJcmV0dXJuIGltYWdlLCBp
bWFnZS5nZXRfcmVjdCgpCgpjbGFzcyBHdW4ocHlnYW1lLnNwcml0ZS5TcHJpdGUpOgoJZGVmIF9f
aW5pdF9fKHNlbGYpOgoJCXB5Z2FtZS5zcHJpdGUuU3ByaXRlLl9faW5pdF9fKHNlbGYpCgkJc2Vs
Zi5pbWFnZSwgc2VsZi5yZWN0ID0gbG9hZF9pbWFnZSgnZ3VuLmJtcCcsIC0xKQoJZGVmIHVwZGF0
ZShzZWxmKToKCQlwb3MgPSBweWdhbWUubW91c2UuZ2V0X3BvcygpCgkJc2VsZi5yZWN0Lm1pZHRv
cCA9IHBvcwoJZGVmIGZpcmUoc2VsZix0YXJnZXQpOgoJCWhpdGJveCA9IHNlbGYucmVjdC5pbmZs
YXRlKC01LC01KQoJCXJldHVybiBoaXRib3guY29sbGlkZXJlY3QodGFyZ2V0LnJlY3QpCgoKY2xh
c3MgUGlnZW9uKHB5Z2FtZS5zcHJpdGUuU3ByaXRlKToKCWRlZiBfX2luaXRfXyhzZWxmKToKCQkj
aW5pdCByb3V0aW5lCgkJcHlnYW1lLnNwcml0ZS5TcHJpdGUuX19pbml0X18oc2VsZikKCQlzZWxm
LmltYWdlLCBzZWxmLnJlY3QgPSBsb2FkX2ltYWdlKCdwaWdlb24uYm1wJywtMSkKCQlzY3JlZW4g
PSBweWdhbWUuZGlzcGxheS5nZXRfc3VyZmFjZSgpCgkJc2VsZi5hcmVhID0gc2NyZWVuLmdldF9y
ZWN0KCkKCQlzZWxmLnJlY3QudG9wcmlnaHQgPSBzZWxmLmFyZWEudG9wcmlnaHQgI2NoYW5nZSB0
aGlzIGxhdGVyIG9uIQoJCXNlbGYubW92ZSA9IC05CSNhbmQgdGhpcyA6LSkKCQlzZWxmLl9uZXdz
bG9wZSgpCgkJCglkZWYgdXBkYXRlKHNlbGYpOgoJCW5ld3BvcyA9IHNlbGYucmVjdC5tb3ZlKChz
ZWxmLm1vdmUsc2VsZi5zbG9wZSkpCgkJaWYgbm90IHNlbGYuYXJlYS5jb250YWlucyhuZXdwb3Mp
OgoJCQkjcGlnZW9uIGhhcyBkaWVkLCBzdGFydCBhZ2FpbjoKCQkJc2VsZi5yZWN0LnRvcHJpZ2h0
ID0gc2VsZi5hcmVhLnRvcHJpZ2h0CgoJCXNlbGYucmVjdCA9IG5ld3BvcwoKCWRlZiBoaXQoc2Vs
Zik6CgkJIndlIGhhdmUgYmVlbiBoaXQsIHdlIG5lZWQgdG8ga2lsbCB0aGlzIHBpZ2Vvbiwgb3Ig
YXQgbGVhc3Qgc3RhcnQgaXQgYWdpbiA6LSkiCgkJc2VsZi5yZWN0LnRvcHJpZ2h0ID0gc2VsZi5h
cmVhLnRvcHJpZ2h0CgkJc2VsZi5fbmV3c2xvcGUoKQoJZGVmIF9uZXdzbG9wZShzZWxmKToKCQlz
ZWxmLnNsb3BlID0gaW50KHJhbmRvbS5yYW5kb20oKSAqIDIwKQoJCQpkZWYgbWFpbigpOgoJcHln
YW1lLmluaXQoKQoJc2NyZWVuID0gcHlnYW1lLmRpc3BsYXkuc2V0X21vZGUoKDgwMCw2MDApKQoJ
cHlnYW1lLmRpc3BsYXkuc2V0X2NhcHRpb24oJ1Rob21pcyBSaWZsZSBSYW5nZSEnKQoJcHlnYW1l
Lm1vdXNlLnNldF92aXNpYmxlKDApCgkKCWJhY2tncm91bmQgPSBweWdhbWUuU3VyZmFjZShzY3Jl
ZW4uZ2V0X3NpemUoKSkKCWJhY2tncm91bmQgPSBiYWNrZ3JvdW5kLmNvbnZlcnQoKQoJYmFja2dy
b3VuZC5maWxsKCgyNTUsMjU1LDI1NSkpCgkKCWlmIHB5Z2FtZS5mb250OgoJCWZvbnQgPSBweWdh
bWUuZm9udC5Gb250KE5vbmUsIDM2KQoJCXRleHQgPSBmb250LnJlbmRlcigiSGl0IHRoZSBjbGF5
IFBpZ2VvbnMsIHRvIGdldCBwb2ludHMhIiwgMSwgKDEwLDEwLDEwKSkKCQl0ZXh0cG9zID0gdGV4
dC5nZXRfcmVjdCgpCgkJdGV4dHBvcy5jZW50ZXJ4ID0gYmFja2dyb3VuZC5nZXRfcmVjdCgpLmNl
bnRlcngKCQliYWNrZ3JvdW5kLmJsaXQodGV4dCwgdGV4dHBvcykKCQoJc2NyZWVuLmJsaXQoYmFj
a2dyb3VuZCwgKDAsMCkpCglweWdhbWUuZGlzcGxheS5mbGlwKCkKCQoJI2dvISEKCQoJZ3VuID0g
R3VuKCkKCXBpZ2VvbiA9IFBpZ2VvbigpCglhbGxzcHJpdGVzID0gcHlnYW1lLnNwcml0ZS5SZW5k
ZXJQbGFpbigoZ3VuLHBpZ2VvbikpCgljbG9jayA9IHB5Z2FtZS50aW1lLkNsb2NrKCkKCQoJd2hp
bGUgMToKCQljbG9jay50aWNrKDYwKQoJCWZvciBldmVudCBpbiBweWdhbWUuZXZlbnQuZ2V0KCk6
CgkJCWlmIGV2ZW50LnR5cGUgaXMgUVVJVDoKCQkJCXJldHVybgoJCQllbGlmIGV2ZW50LnR5cGUg
aXMgS0VZRE9XTiBhbmQgZXZlbnQua2V5IGlzIEtfRVNDQVBFOgoJCQkJcmV0dXJuCgkJCWVsaWYg
ZXZlbnQudHlwZSBpcyBNT1VTRUJVVFRPTkRPV046CgkJCQlpZiBndW4uZmlyZShwaWdlb24pOgoJ
CQkJCXBpZ2Vvbi5oaXQoKQoJCQkJZWxzZToKCQkJCQlwYXNzCSN3ZSBtaXNzZWQKCQlhbGxzcHJp
dGVzLnVwZGF0ZSgpCgkJc2NyZWVuLmJsaXQoYmFja2dyb3VuZCwgKDAsMCkpCgkJYWxsc3ByaXRl
cy5kcmF3KHNjcmVlbikKCQlweWdhbWUuZGlzcGxheS5mbGlwKCkKCmlmIF9fbmFtZV9fID09ICdf
X21haW5fXyc6CgltYWluKCkKCiNnYW1lIG92ZXIKCQkJCQoJCQkKCgkJCgkJCgo=

--Multipart_Thu__12_Dec_2002_18:56:28_+1300_08260ed0--


From magnus@thinkware.se  Thu Dec 12 02:58:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu Dec 12 02:58:01 2002
Subject: [Tutor] Pythonwin
In-Reply-To: <0E5508EBA1620743B409A2B8365DE16FDC828E@SOVEREIGN>
Message-ID: <5.1.0.14.0.20021212085224.02c23b90@www.thinkware.se>

At 18:10 2002-12-11 -0800, Scott Widney wrote:
> >>> L, X = [1,2,4,8,16,32,64], 5

I don't think this improves readability over
L = [1,2,4,8,16,32,64]
X = 5

> >>> if L.index(2**X): print "found at", L.index(2**X)
>... else: print X, "not found"
>...
>  found at 5
> >>>

This is not correct, is it? Try replacing the X value
with 0 or 7 and see what happens. It not a big change
that has to be made though.

 >>> if (2**X) in L: print "found at", L.index(2**X)
... else: print X, "not found"

Try putting it in a for loop:

 >>> L = [1,2,4,8,16,32,64]
 >>> for X in range(-1,8):
...     if (2**X) in L: print "found at", L.index(2**X)
...     else: print X, "not found"


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From rdm@rcblue.com  Thu Dec 12 03:12:02 2002
From: rdm@rcblue.com (Dick Moores)
Date: Thu Dec 12 03:12:02 2002
Subject: [Tutor] TKinter and IDLE problem
Message-ID: <5.1.0.14.2.20021212001111.03a66ec0@rcblue.com>

 >Try saving your program into a file and running it from the
 >DOS prompt - or double clicking it in explorer).

Double clicking it in explorer works fine, but I can't get it to run from a 
DOS window prompt. I have several Tkinker GUI scripts in a 
C:\Python22\Tkinter directory, and have CD-ed to this directory in DOS. dir 
shows the list of scripts, but when I try to run, for example, 
C:\Python22\Tkinter\helloTkinter.py, I get "Bad command or file name". What 
to do? I'd like to follow Poor Yorick's tip, "I've been doing a lot of 
Tkinter programming in Idle on Windows 2000, and I've found that the 
easiest way to proceed is to keep a DOS window open to the folder where my 
python source file is ..."

BTW if it matters, I'm using Win98.

Thanks,

Dick Moores
rdm@rcblue.com




From alan.gauld@bt.com  Thu Dec 12 04:03:32 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu Dec 12 04:03:32 2002
Subject: [Tutor] TKinter and IDLE problem
Message-ID: <7497DCA1C240C042B28F6657ADFD8E09702274@i2km11-ukbr.domain1.systemhost.net>

> shows the list of scripts, but when I try to run, for example, 
> C:\Python22\Tkinter\helloTkinter.py, I get "Bad command or 
> file name". 

You need to type 

C:\PATH> python myscript.py

> Tkinter programming in Idle on Windows 2000, and I've found that the 
> easiest way to proceed is to keep a DOS window open

Thats exactly what I do to - that way I know that when it runs it 
is doing so exactly as an end user will see it.

Alan g


From magnus@thinkware.se  Thu Dec 12 04:12:05 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu Dec 12 04:12:05 2002
Subject: [Tutor] TKinter and IDLE problem
In-Reply-To: <5.1.0.14.2.20021212001111.03a66ec0@rcblue.com>
Message-ID: <5.1.0.14.0.20021212094421.02c24de8@www.thinkware.se>

At 00:11 2002-12-12 -0800, Dick Moores wrote:
>Double clicking it in explorer works fine, but I can't get it to run from 
>a DOS window prompt. I have several Tkinker GUI scripts in a 
>C:\Python22\Tkinter directory, and have CD-ed to this directory in DOS. 
>dir shows the list of scripts, but when I try to run, for example, 
>C:\Python22\Tkinter\helloTkinter.py, I get "Bad command or file name". 
>What to do?

python C:\Python22\Tkinter\helloTkinter.py

If that also causes "Bad command or file name", add the path
to python.exe to your PATH variable in C:\AUTOEXEC.BAT. Something
like "SET PATH=%PATH%;C:\PYTHON22". You can do that in the
command line as well, but you need to change AUTOEXEC.BAT
and reboot to get it to stick.

>I'd like to follow Poor Yorick's tip, "I've been doing a lot of Tkinter 
>programming in Idle on Windows 2000, and I've found that the easiest way 
>to proceed is to keep a DOS window open to the folder where my python 
>source file is ..."
>
>BTW if it matters, I'm using Win98.

I think it does matter. The NT/Win2k/XP command shell cmd.exe is
much better than the bad old DOS command.com. (I don't think it
was even developed by Microsoft origianlly, but bought from some
manufacturer of DOS/Windows emulators. This makes sense, since
NT and friends needs to emulate DOS as well...)

C:\Python22\Tkinter\helloTkinter.py
Will work in BT/W2k, but
C:\Python22\Tkinter\helloTkinter.py some command line parameters
won't work as expected. sys.argv won't find the parameters. You
need to prepend "python" there as well. :(

Don't know about XP.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Thu Dec 12 04:28:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu Dec 12 04:28:01 2002
Subject: [Tutor] Wanted: module to parse out a CSV line
In-Reply-To: <5.1.0.14.0.20021211155744.02be9210@www.thinkware.se>
References: <m31y4ozpc0.fsf@ferret.object-craft.com.au>
 <5.1.0.14.0.20021211103301.02bd9da0@www.thinkware.se>
 <5.1.0.14.0.20021211103301.02bd9da0@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021212101929.02c6a178@www.thinkware.se>

At 16:06 2002-12-11 +0100, Dave Cole wrote:
>Even though I explicitly marked , as separator, a tab after the
>comma made the text after ,\t end up in column C instead of B!

This might have been my mistake. I probably checked the 'comma'
check box, but forgot to uncheck the tab check box.

On the other hand, I still don't manage to get it to read strings
with embedded line breaks. Also, I don't manage to get it to
export CSV files with embedded line breaks. How is that done?


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From lumbricus@gmx.net  Thu Dec 12 04:33:01 2002
From: lumbricus@gmx.net (lumbricus@gmx.net)
Date: Thu Dec 12 04:33:01 2002
Subject: [Tutor] os.environ weirdness
References: <3DF63D2A.2000605@pooryorick.com>
Message-ID: <10837.1039685534@www31.gmx.net>

Hi!

> No, I didn't tinker around with os.environ.

Me neither.

> I see this behavior on both 
> of my windows 2000 computers.  Can anyone else reproduce this?

Yes:

>>> sys.platform
'osf1V4'
>>> for i in os.environ: print i
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/disk/29/dvass/Soft/tools/Python-2.2.1/Lib/UserDict.py", line 14, in
__getitem__
    def __getitem__(self, key): return self.data[key]
KeyError: 0
>>> 
 
> Poor Yorick
> gp@pooryorick.com

HTH, J"o!

-- 
sigfault

+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!



From thomi@thomi.imail.net.nz  Thu Dec 12 06:27:00 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Thu Dec 12 06:27:00 2002
Subject: [Tutor] cgi module and checkboxes.
In-Reply-To: <20021211235716.6f3cfc4c.thomi@thomi.imail.net.nz>
References: <20021209234348.7d6c8393.thomi@thomi.imail.net.nz>
 <3DF6E2A9.1080001@netzero.net>
 <20021211235716.6f3cfc4c.thomi@thomi.imail.net.nz>
Message-ID: <20021213002537.75b309af.thomi@thomi.imail.net.nz>

> > Am I clarifying, or confusing?

unfortunately, i still cannot get my head around it. surely the uid vale
in the FieldStorage thingy what should be something like the following:

print form['uid'].value
['1','4','6']

which would mean that the user clicked on the 1st, 4th and 6th check
boxes? (remember that the value parameter on the check boxes is set to
user ID numbers, which are a unique number within the system).

> 
> ummm.. confusing. although it may be the time here in New Zealand, or
> the cider I've just drunk. what python code do i need to use, so i can
> print something like "you checked the following boxes:"
> 
> 
> -- 
> The software required Win95 or better, so I installed Linux.
> Thomi Richards,
> thomi@imail.net.nz
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


-- 
 "Avoid the Gates of Hell.  Use Linux"

Thomi Richards,
thomi@imail.net.nz


From magnus@thinkware.se  Thu Dec 12 08:36:59 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu Dec 12 08:36:59 2002
Subject: [Tutor] Wanted: module to parse out a CSV line
In-Reply-To: <m38yyv8ota.fsf@ferret.object-craft.com.au>
References: <5.1.0.14.0.20021212101929.02c6a178@www.thinkware.se>
 <m31y4ozpc0.fsf@ferret.object-craft.com.au>
 <5.1.0.14.0.20021211103301.02bd9da0@www.thinkware.se>
 <5.1.0.14.0.20021211103301.02bd9da0@www.thinkware.se>
 <5.1.0.14.0.20021212101929.02c6a178@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021212142954.02bf08b8@www.thinkware.se>

At 22:22 2002-12-12 +1100, Dave Cole wrote:
>Magnus> On the other hand, I still don't manage to get it to read
>Magnus> strings with embedded line breaks. Also, I don't manage to get
>Magnus> it to export CSV files with embedded line breaks. How is that
>Magnus> done?
>
>The module assumes that you are reading your input one line at a time
>and passing the lines to the parser as you read them.

Sorry Dave, I was unclear. I meant with Excel.

As far as I understand, you say that you need the broken line handling
to be Excel complient. Right?

I have not been able to make Excel import broken lines into a cell.

<WARNING>ASCII art below</WARNING>

2,"Hello
there"

Will become

+------+------+
|2     |Hello |
+------+------+
|there |      |
+------+------+

in excel, not

+------+------+
|2     |Hello |
|      |there |
+------+------+

as I guessed it would, considering that csv does that with reference to Excel.

Also, if I enable wordwrap in cells,

+------+------+
|2     |Hello |
|      |there |
+------+------+

will still be exported as

2,Hello there

not

2,"Hello
there"

So I wonder, how do you manage to get something like

2,"Hello
there"

out of Excel? I've been unable to paste a line feed into a cell.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From Adam Vardy <anvardy@roadrunner.nf.net>  Thu Dec 12 09:10:01 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Thu Dec 12 09:10:01 2002
Subject: [Tutor] Take file and dice
Message-ID: <14113508626.20021212103908@roadrunner.nf.net>

Could I find a program like this? Will search down through a text
file. Each time a line is found that starts like here, take the
filename, create it, and save the following text to it, up until a
line starts with some non alphabetic symbol. And then continue looking
for this part again, for a new file. So, you end up with a bunch of
new files in some path.

# file filename

Also, take the text file, and remove all lines that start like

...
>>>

and save the result.

-- 
Adam Vardy



From magnus@thinkware.se  Thu Dec 12 09:25:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu Dec 12 09:25:02 2002
Subject: [Tutor] cgi module and checkboxes.
In-Reply-To: <20021213002537.75b309af.thomi@thomi.imail.net.nz>
References: <20021211235716.6f3cfc4c.thomi@thomi.imail.net.nz>
 <20021209234348.7d6c8393.thomi@thomi.imail.net.nz>
 <3DF6E2A9.1080001@netzero.net>
 <20021211235716.6f3cfc4c.thomi@thomi.imail.net.nz>
Message-ID: <5.1.0.14.0.20021212145537.02c7db10@www.thinkware.se>

At 00:25 2002-12-13 +1300, Thomi Richards wrote:
>unfortunately, i still cannot get my head around it. surely the uid vale
>in the FieldStorage thingy what should be something like the following:
>
>print form['uid'].value
>['1','4','6']
>
>which would mean that the user clicked on the 1st, 4th and 6th check
>boxes? (remember that the value parameter on the check boxes is set to
>user ID numbers, which are a unique number within the system).

Why guess when you have both the possibility to experiment and
good docs? Have you tried something obvious like???

#!/usr/bin/python -u
print "Content-type: text/html"
print
print "<pre>"
import cgi
form = cgi.FieldStorage()
print form
print "</pre>"

That should give you some hint about what is happening.

Then you could read

http://www.python.org/doc/current/lib/node298.html

Note getlist() !!!

Perhaps "print form.getlist('uid')" is what you want?

And by all means: Use cgitb!
http://www.python.org/doc/current/lib/module-cgitb.html

So, you might end up with something like

#!/usr/bin/python -u
import cgi, cgitb
cgitb.enable()
form = cgi.FieldStorage()
print "Content-type: text/html"
print
print "<pre>"
print form.getlist('uid')
print "</pre>"


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From shendric@arches.uga.edu  Thu Dec 12 09:40:02 2002
From: shendric@arches.uga.edu (shendric@arches.uga.edu)
Date: Thu Dec 12 09:40:02 2002
Subject: [Tutor] Linux installation
Message-ID: <1039703836.smmsdV1.1.2@mail.arches.uga.edu>

Ah,

I had thought that Tcl/Tk was part of the Python distribution.  Thanks.

Sean

---------Included Message----------
>Date: Wed, 11 Dec 2002 23:50:46 +0100
>From: "Magnus Lycka" <magnus@thinkware.se>
>To: <shendric@arches.uga.edu>, "Python Tutor" <tutor@python.org>
>Subject: Re: [Tutor] Linux installation
>
>At 16:41 2002-12-11 -0500, shendric@arches.uga.edu wrote:
>>I just installed Python 2.2.2 on a Linux machine with a 2.4.18-14
>>kernel, and after doing the "configure" "make" dance, I tried to open
>>IDLE, but I received a message saying that my system might not be
>>configured for Tk.  Has anyone who has installed Python on Linux had
>>problems with installing it?
>
>Python's standard GUI, Tkinter, needs Tcl/Tk to be installed. Is it?
>I'm using Mandrake 9 and their standard RPMs, so I don't have any
>problems.
>
>
>-- 
>Magnus Lycka, Thinkware AB
>Alvans vag 99, SE-907 50 UMEA, SWEDEN
>phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
>http://www.thinkware.se/  mailto:magnus@thinkware.se
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
---------End of Included Message----------




From lumbricus@gmx.net  Thu Dec 12 09:48:01 2002
From: lumbricus@gmx.net (lumbricus@gmx.net)
Date: Thu Dec 12 09:48:01 2002
Subject: [Tutor] Linux installation
References: <1039703836.smmsdV1.1.2@mail.arches.uga.edu>
Message-ID: <19845.1039704424@www31.gmx.net>

Hi!

> Ah,
> 
> I had thought that Tcl/Tk was part of the Python distribution.  Thanks.

No. Tcl is a scripting language on its own (tool commands language IIRC).
Tk is a "toolkit" for it.
f.e.:
"http://www.tcl.tk/"

HTH, J"o!

-- 
sigfault

-- 
sigfault

+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!



From S.Huijgen@Student.TUDelft.NL  Thu Dec 12 10:09:02 2002
From: S.Huijgen@Student.TUDelft.NL (Stephan Huijgen)
Date: Thu Dec 12 10:09:02 2002
Subject: [Tutor] PyMat installation
References: <1039703836.smmsdV1.1.2@mail.arches.uga.edu> <19845.1039704424@www31.gmx.net>
Message-ID: <00db01c2a1f0$90fd2f50$6501a8c0@superyethzer>

Where do i have to install PyMat, when i have downloaded it? in the
Python2.0 dir? or in a subdirectory?

Stephan



From op73418@mail.telepac.pt  Thu Dec 12 10:16:00 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Thu Dec 12 10:16:00 2002
Subject: [Tutor] Take file and dice
References: <14113508626.20021212103908@roadrunner.nf.net>
Message-ID: <001c01c2a1f2$3f3942b0$631b0dd5@violante>

----- Original Message -----
From: "Adam Vardy" <anvardy@roadrunner.nf.net>
To: <tutor@python.org>
Sent: Thursday, December 12, 2002 2:09 PM
Subject: [Tutor] Take file and dice


> Could I find a program like this?

Probably not, but let's run down through your spec and see *what we need* to
accomplish the task.

>Will search down through a text
> file.

You need to know how to open (text) files.

>Each time a line is found that starts like here,

You need to scan the file line by line.
(A) You need to check if a line starts with a given sequence of chars.

>take the
> filename, create it,

If a line starts with the given sequence of characters:
(somehow) grab a filename from the line

>and save the following text to it, up until a
> line starts with some non alphabetic symbol.

for each line following and "until it starts with some non alphabetic
symbol":
save line which means: open a new file for writing with the filename we
grabbed and write line to file.


>And then continue looking
> for this part again, for a new file.

Go back to (A) and do it all again.


>So, you end up with a bunch of
> new files in some path.
>
> # file filename
>
> Also, take the text file, and remove all lines that start like
>
> ...
> >>>

if line starts with ">>>":
delete it.

>
> and save the result.
>

Rewrite what we have to our original file.

> --
> Adam Vardy

This should give you a (simple) prototype. Now get to work! ;-)

All the best,
G. Rodrigues



From shendric@arches.uga.edu  Thu Dec 12 11:00:02 2002
From: shendric@arches.uga.edu (shendric@arches.uga.edu)
Date: Thu Dec 12 11:00:02 2002
Subject: [Tutor] Checking the registry (was: (no subject))
Message-ID: <1039708634.smmsdV1.1.2@mail.arches.uga.edu>

I've rtfm'ed and I can't seem to locate winall.  Could you direct me to 
docs on that?  I'm not sure how to check the registry for currently 
installed versions of Python.

Sean

---------Included Message----------
>Date: Wed, 11 Dec 2002 18:26:46 -0000
>From: <alan.gauld@bt.com>
>To: <shendric@arches.uga.edu>, <tutor@python.org>
>Subject: RE: [Tutor] (no subject)
>
>> Is there a good place to find a basic installer for this type 
>> of use, at least as a starting point?
>
>There are a few freeware ones but I haven't used them.
>(ASPack or somesuch comes to mind???)
>
>Both Wise (as used by the Python insyaller) and Installshield
>can do it easily but are both commercial. Wise seems to be opensource 
>friendly aso they mught have a free version for use on opensource 
>projects mebbe. The other thing is to write one yourself which 
>for a one-off project isn't too hard, lots of os.system() calls
>and a few windows registry calls using winall...
>
>Alan g.
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
---------End of Included Message----------




From dyoo@hkn.eecs.berkeley.edu  Thu Dec 12 13:17:08 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu Dec 12 13:17:08 2002
Subject: [Tutor] Sorting Instance Attributes
In-Reply-To: <01da01c2a190$5c338cc0$1813ba3f@defaultcomp>
Message-ID: <Pine.LNX.4.44.0212121009110.26167-100000@hkn.eecs.berkeley.edu>

> This got me to thinking (which can be dangerous at times): what if you
> don't always want to sort by the same attribute? I played around a
> little, and here's what I came up with:
>
> def setStudentKey(key):
>     """builds the comparison function on the fly"""
>     c = 'def studentCompare(l,r):\n\treturn cmp(str(l.%s),str(r.%s))\n' \
>         % (key, key)
>     exec(c,__builtins__.__dict__)
>
> class Student:
>     def __init__(self,id,firstName,lastName,grade):
>         self.id = id
>         self.firstName = firstName
>         self.lastName = lastName
>         self.grade = grade
>
> if __name__ == '__main__':
>     theClass = []
>     Mary = Student(1,'Mary','Smith', 93)
>     Bob = Student(2,'Bob','Jones', 97)
>     John = Student(3,'John','Albert', 70)
>
>     theClass.append(Bob)
>     theClass.append(John)
>     theClass.append(Mary)
>
>     for currKey in ('id','firstName','lastName','grade'):
>         setStudentKey(currKey)
>         theClass.sort(studentCompare)
>         print 'class sorted by "%s":' % currKey
>         for x in theClass:
>             print '\t%s, %s, %s, %s' % (x.id,x.firstName,x.lastName,x.grade)
>         print "\n"



This is pretty nice!


If we want to avoid using eval, we can still do something similar with
this:

###
def makeStudentComparer(attribute_name):
    def comparison_function(a, b):
        return cmp(getattr(a, attribute_name),
                   getattr(b, attribute_name))
    return comparison_function
###

This function is unusual because it doesn't return a string or a number:
it actually returns a new comparison function that's custom-fitted to
compare what we want.  If we want to mutter in intimidating technical
terms, we'd say makeStudentComparer returns a "closure".  It's actually
not that scary: it's just a function that's dynamically generated, and
that knows about that 'attribute_name' that we originally passed in.


With this, we won't have a single global 'studentCompare()' function, but
we still have much of the power of your original code:


###
     for currKey in ('id','firstName','lastName','grade'):
         theClass.sort(makeStudentComparer(currKey))
         print 'class sorted by "%s":' % currKey
         for x in theClass:
             print '\t%s, %s, %s, %s' % (x.id,x.firstName,x.lastName,x.grade)
         print "\n"
###



Good luck!



From op73418@mail.telepac.pt  Thu Dec 12 13:50:14 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Thu Dec 12 13:50:14 2002
Subject: [Tutor] Checking the registry (was: (no subject))
References: <1039708634.smmsdV1.1.2@mail.arches.uga.edu>
Message-ID: <002801c2a210$1c0289a0$631b0dd5@violante>

----- Original Message -----
From: <shendric@arches.uga.edu>
To: "Python Tutor" <tutor@python.org>
Sent: Thursday, December 12, 2002 3:57 PM
Subject: RE: [Tutor] Checking the registry (was: (no subject))


> I've rtfm'ed and I can't seem to locate winall.  Could you direct me to
> docs on that?  I'm not sure how to check the registry for currently
> installed versions of Python.
>
> Sean
>

winall is not in the standard distribution. It is a package done by M.
Hammond essential for any serious Windows programming. You can get it by
installing ActiveState's Python distro. You can also get it separately but I
don't have the site address by me to give you so you will have to dig for
it - maybe someone here in the list has it?

All the best,
G. Rodrigues



From Adam Vardy <anvardy@roadrunner.nf.net>  Thu Dec 12 14:59:02 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Thu Dec 12 14:59:02 2002
Subject: [Tutor] Pythonpath
In-Reply-To: <5.1.0.14.0.20021211195351.02bde128@www.thinkware.se>
References: <5.1.0.14.0.20021211155630.02bf7090@www.thinkware.se>
 <5.1.0.14.0.20021211155630.02bf7090@www.thinkware.se>
 <5.1.0.14.0.20021211195351.02bde128@www.thinkware.se>
Message-ID: <81134461946.20021212162821@roadrunner.nf.net>

Would someone know how to set this in Windows? There also must be some
special syntax I need to follow.

And for the command-line, again I don't know the syntax it requires to
specify this, its help only mentions presence of such a path.

It would be handier if the Python installation would add it itself,
with a path to a new empty directory.

-- 
Adam Vardy



From SWidney@ci.las-vegas.nv.us  Thu Dec 12 15:07:02 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Thu Dec 12 15:07:02 2002
Subject: [Tutor] Checking the registry (was: (no subject))
Message-ID: <0E5508EBA1620743B409A2B8365DE16FDC8294@SOVEREIGN>

> > I've rtfm'ed and I can't seem to locate winall.  Could you 
> > direct me to docs on that?  I'm not sure how to check the
> > registry for currently installed versions of Python.
> >
> > Sean
> >
> 
> winall is not in the standard distribution. It is a package done
> by M. Hammond essential for any serious Windows programming. You 
> can get it by installing ActiveState's Python distro. You can 
> also get it separately but I don't have the site address by me 
> to give you so you will have to dig for it - maybe someone here 
> in the list has it?

http://starship.python.net/crew/skippy/win32/Downloads.html



From dyoo@hkn.eecs.berkeley.edu  Thu Dec 12 15:29:05 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu Dec 12 15:29:05 2002
Subject: [Tutor] Another example of closures: a function that intercepts exceptions
Message-ID: <Pine.LNX.4.44.0212121126090.26167-100000@hkn.eecs.berkeley.edu>

[The following post is slightly advanced, and written in a badly rushed
fashion; I'm still at work at the moment, but thought this was a cute
example to show folks.]



Hi everyone,

During yesterday's Baypiggies Python meeting, someone brought up a
question about closures: why would anyone want to use something so
academic and weird?



Here's one concrete example where they might come in handy:


######
def wrapErrorsToDefaultValue(function, default_value=None):
    """
    wrapErrorsToDefaultValue(function, default_value=None)
        -> wrapped function

    This adds a small exception handling wrapper around a given
    function.  This wrapped function should behave similarly to the
    input, but if an exception occurs, the wrapper intercepts and
    returns the default_value instead.
    """
    def new_function(*args, **kwargs):
        try:
            return function(*args, **kwargs)
        except:
            return default_value
    return new_function
######



wrapErrorsToDefaultValue() is a function that is pretty cute: it takes in
a function, and returns a new function that's a mimic of the inputted
function... Except it acts as a safety net if the function dies:


###
>>> def divide(a, b):
...     return a / b
...
>>> divide(3, 0)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 2, in divide
ZeroDivisionError: integer division or modulo by zero
>>>
>>> wrapped_divide = wrapErrorsToDefaultValue(divide, "This is bad!")
>>> wrapped_divide(42, 2)
21
>>> wrapped_divide(42, 0)
'This is bad!'
###


The wrapped_divide() function doesn't raise an error like the first
divide()  function: rather, it returns the default value that we pass in.




A more realistic example where something like this might be useful is XML
DOM parsing: I'm finding myself diving through some XML data, but not
knowing if a certain element exists or not in the marked-up data file.
In the XML files that I'm reading, there are a list of "gene models", each
of which possibly contain a "CDS" or "PROTEIN" sequence element.  (For
people who are interested, the DTD of the data format I'm parsing is:

    ftp://ftp.tigr.org/pub/data/a_thaliana/ath1/BACS/CHR1/tigrxml.dtd
)

I'm using the pulldom module:

    http://www.python.org/doc/lib/module-xml.dom.pulldom.html

to parse these files, just because the biological sequences involved can
get quite large.  Anyway, back to my example!  Here's a bit of code that
I'm using to pull the text contents of a CDS_SEQUENCE element nested in a
MODEL element:


###
def get_cds_sequence(dom_node):
    """Tries to return the coding region sequence of a model gene."""
    if not dom_node.getElementsByTagName('MODEL'):
        return None
    first_model = dom_node.getElementsByTagName('MODEL')[0]
    if not first_model.getElementsByTagName('CDS_SEQUENCE'):
        return None
    return first_model.getElementsByTagName('CDS_SEQUENCE')[0]\
            .firstChild.data
###


I'm doing all these checks because if I'm not careful, I'll get an
IndexError.  But the code feels like it's just tiptoeing around a
minefield.



There is a good solution though: I can use exception handling to make this
code less awkward:

###
def get_cds_sequence(dom_node):
    """Tries to return the coding region sequence of a model gene."""
    try:
        first_model = dom_node.getElementsByTagName('MODEL')[0]
        return first_model.getElementsByTagName('CDS_SEQUENCE')[0]\
                .firstChild.data
    except IndexError:
        return None
###


But it's still a slight hassle having to wrap everything in try/except
blocks.  I'll be doing this for about ten of my functions, and I don't
want to wrap each function with it's own little try/except.



The code becomes even nicer, though, when I take advantage of that
wrapErrorsToDefaultValue() function:

###
def _get_cds_sequence(dom_node):
    """Tries to return the coding region sequence of a model gene."""
    first_model = dom_node.getElementsByTagName('MODEL')[0]
    return first_model.getElementsByTagName('CDS_SEQUENCE')[0]\
            .firstChild.data

def _get_protein_sequence(dom_node):
    """Tries to return the protein sequence of a model gene."""
    first_model = dom_node.getElementsByTagName('MODEL')[0]
    return first_model.getElementsByTagName('PROTEIN_SEQUENCE')[0]\
            .firstChild.data

for func, name in [ (_get_cds_sequence, 'getCdsSequence'),
                    (_get_protein_sequence, 'getProteinSequence')] :
    globals()[name] = wrapErrorsToDefaultValue(func)
###


(The only problem here is that wrapErrorsToDefaultValue() is too strong of
a safety net: it should really be weakened so that it only responses to
that specific IndexError, rather than everything.)




And we can take closures even further: the code of get_cds_sequence() and
get_protein_sequence() is almost identical, so we can tease the common
elements out:

###
def make_model_seq_function(sequence_type):
    """Makes a new function for extracting the MODEL/[sequence_type]
    of a model gene."""
    def new_function(dom_node):
        "Extracts the %s sequence of a model gene" % sequence_type
        first_model = dom_node.getElementsByTagName('MODEL')[0]
        return first_model.getElementsByTagName(sequence_type)[0]\
                .firstChild.data
    return wrapErrorsToDefaultValue(new_function)

for seq_type, name in [ ('CDS_SEQUENCE', 'getCdsSequence'),
                        ('PROTEIN_SEQUENCE', 'getProteinSequence')]:
    globals()[name] = make_model_seq_function(seq_type)
###



Anyway, I hope that made some sort of sense.  Back to work for me...
*grin*



From magnus@thinkware.se  Thu Dec 12 15:38:10 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu Dec 12 15:38:10 2002
Subject: [Tutor] Pythonpath
In-Reply-To: <81134461946.20021212162821@roadrunner.nf.net>
References: <5.1.0.14.0.20021211195351.02bde128@www.thinkware.se>
 <5.1.0.14.0.20021211155630.02bf7090@www.thinkware.se>
 <5.1.0.14.0.20021211155630.02bf7090@www.thinkware.se>
 <5.1.0.14.0.20021211195351.02bde128@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021212213836.02c3fec8@www.thinkware.se>

At 16:28 2002-12-12 -03-30, Adam Vardy wrote:
>It would be handier if the Python installation would add it itself,
>with a path to a new empty directory.

It seems you don't understand what PYTHONPATH is.
Typically you don't need it at all. The python
installation will certainly not need it. Its purpose
is to locate python modules or packages that are
located in non-standard positions.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From shendric@arches.uga.edu  Thu Dec 12 16:05:03 2002
From: shendric@arches.uga.edu (shendric@arches.uga.edu)
Date: Thu Dec 12 16:05:03 2002
Subject: [Tutor] Checking the registry (was: (no subject))
Message-ID: <1039726920.smmsdV1.1.2@mail.arches.uga.edu>

Great!  Thanks!

Sean

---------Included Message----------
>Date: Thu, 12 Dec 2002 12:05:49 -0800
>From: "Scott Widney" <SWidney@ci.las-vegas.nv.us>
>To: "Python Tutor" <tutor@python.org>
>Subject: RE: [Tutor] Checking the registry (was: (no subject))
>
>> > I've rtfm'ed and I can't seem to locate winall.  Could you 
>> > direct me to docs on that?  I'm not sure how to check the
>> > registry for currently installed versions of Python.
>> >
>> > Sean
>> >
>> 
>> winall is not in the standard distribution. It is a package done
>> by M. Hammond essential for any serious Windows programming. You 
>> can get it by installing ActiveState's Python distro. You can 
>> also get it separately but I don't have the site address by me 
>> to give you so you will have to dig for it - maybe someone here 
>> in the list has it?
>
>http://starship.python.net/crew/skippy/win32/Downloads.html
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
---------End of Included Message----------




From magnus@thinkware.se  Thu Dec 12 17:40:03 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu Dec 12 17:40:03 2002
Subject: [Tutor] Sorting Instance Attributes
In-Reply-To: <01da01c2a190$5c338cc0$1813ba3f@defaultcomp>
References: <20021211235413.56094.qmail@web20507.mail.yahoo.com>
 <002501c2a174$46fa9220$b0180dd5@violante>
Message-ID: <5.1.0.14.0.20021212214051.02c7d9b8@www.thinkware.se>

At 21:40 2002-12-11 -0600, Don Arnold wrote:
>This got me to thinking (which can be dangerous at times): what if you don't
>always want to sort by the same attribute? I played around a little, and
>here's what I came up with:
>
>def setStudentKey(key):
>     """builds the comparison function on the fly"""
>     c = 'def studentCompare(l,r):\n\treturn cmp(str(l.%s),str(r.%s))\n' \
>         % (key, key)
>     exec(c,__builtins__.__dict__)

Another approach would be to do something like this:

 >>> class Student:
...    compare = 'lname'
...    def __init__(self, fname, lname):
...        self.fname = fname
...        self.lname = lname
...    def __str__(self):
...        return "%s %s" % (self.fname, self.lname)
...    def setStudentKey(self, attribute):
...        if attribute not in self.__dict__.keys():
...            return AttributeError
...        Student.compare = attribute
...    def __cmp__(self, other):
...        return cmp(getattr(self, Student.compare),
...                    getattr(other, Student.compare))
...
 >>> a = Student('Allan', 'Zak')
 >>> b = Student('Barney', 'Yak')
 >>> c = Student('Caesar', 'Xak')
 >>> l = [a,b,c]
 >>> l.sort()
 >>> map(str, l)
['Caesar Xak', 'Barney Yak', 'Allan Zak']
 >>> b.setStudentKey('fname')
 >>> l.sort()
 >>> map(str, l)
['Allan Zak', 'Barney Yak', 'Caesar Xak']
 >>> a.setStudentKey('lname')
 >>> l.sort()
 >>> map(str, l)
['Caesar Xak', 'Barney Yak', 'Allan Zak']
 >>>


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From aicolburn@yahoo.com  Thu Dec 12 18:11:02 2002
From: aicolburn@yahoo.com (Alan Colburn)
Date: Thu Dec 12 18:11:02 2002
Subject: [Tutor] Re: Sorting Instance Attributes
Message-ID: <20021212231041.30917.qmail@web20514.mail.yahoo.com>

My thanks to you all for responding to my post
yesterday. I really appreciate you taking the time to
do so.

I have to admit that your solutions are a bit beyond
my abilities right now. Maybe if I ask a question or
two at a time I'll understand. 

Let's start with the cmp function/method. I understand
that the function returns -1 if the first item is less
than the second, 0 if they're equal, and 1 if the
first item is greater than the second. The part I
don't know about relates to using the function/method
with a list of items; I only understand using it to
compare two items.

So, if it's not too much trouble, let's start there...
Thanks! -- Al

p.s. I have no idea whether this is something for the
whole list or just for me; if you think it's not
something the whole list would be interested, perhaps
you would still respond to me directly. 

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com


From wilson@visi.com  Thu Dec 12 18:26:01 2002
From: wilson@visi.com (Tim Wilson)
Date: Thu Dec 12 18:26:01 2002
Subject: [Tutor] Optimizing a simple radioactive decay simulation
Message-ID: <200212121722.56528.wilson@visi.com>

Hi everyone,

My students and I did a fun little simulation of C-14 decay today using=20
pennies to represent the atoms. We flipped the coins repeatedly until all=
=20
the pennies had "decayed" (by turning up heads) and used the results to=20
make a graph of the decay curve.

I thought it would be fun to replicate the demo on the computer so I coul=
d=20
expand the simulation to many more pennies. My first approach, which I wi=
ll=20
include below, was to create Coin and DecaySim classes that contain the=20
needed methods. This worked perfectly, but was quite slow. Since I'm=20
interested in using simulations to teach science, I wonder if anyone has=20
suggestions for optimizing this code. I realize that there is probably a=20
much simpler approach, but I found this one appealing because of the 1:1=20
mapping between it and the real-life penny simulation.

-Tim

--snip--
"""
decay.py by Tim Wilson <wilson@visi.com>

This program simulates radioactive decay using coins.

"""

import random

class DecaySim:
    """Radioactive decay simulator class.
   =20
    Class uses 'coins' to simulate decayed and undecayed atoms.
   =20
    """
   =20
    def __init__(self, numcoins):
        """Create decay simulator instance."""       =20
        self.contents =3D []
        for i in range(numcoins):
            self.contents.append(Coin(1))
   =20
    def __len__(self):
        """Return number of coins left in simulator."""
        return len(self.contents)
      =20
    def removeTails(self):
        """Remove all coins from the simulator that are 'tails'."""
        self.contents =3D [coin for coin in self.contents if coin.value =3D=
=3D 1]
       =20
    def decay(self):
        """Flip each coin in the simulator and see which ones decay."""
        for coin in self.contents:
            coin.flip()

class Coin:
    """Coin class for use in radioactive decay simulation."""
   =20
    def __init__(self, value):
        """Create a coin instance. 1 =3D heads, 2 =3D tails"""       =20
        self.value =3D value
       =20
    def flip(self):
        """Flip the coin."""
        self.value =3D random.randint(0, 1)

def main():
    """Run the decay simulator."""
    numcoins =3D raw_input("How many coins? ")
    ds =3D DecaySim(int(numcoins))
    halflives =3D 0
    while len(ds) > 0:
        print "Undecayed (heads): %s" % len(ds)
        ds.decay()
        halflives +=3D 1
        ds.removeTails()
    print "\n%s half-lives required." % halflives
   =20
if __name__ =3D=3D '__main__':
    main()

--snip--

Here's the output on my 1-GHz Athlon with 512 MB RAM.

wilsont@galileo:~/Documents> time python decay.py
How many coins? 1000000
Undecayed (heads): 1000000
Undecayed (heads): 500350
Undecayed (heads): 250901
Undecayed (heads): 125447
Undecayed (heads): 62783
Undecayed (heads): 31182
Undecayed (heads): 15479
Undecayed (heads): 7796
Undecayed (heads): 3972
Undecayed (heads): 2001
Undecayed (heads): 1016
Undecayed (heads): 515
Undecayed (heads): 287
Undecayed (heads): 138
Undecayed (heads): 76
Undecayed (heads): 33
Undecayed (heads): 18
Undecayed (heads): 12
Undecayed (heads): 6
Undecayed (heads): 6
Undecayed (heads): 2

21 half-lives required.

real    12m6.267s
user    8m26.820s
sys     0m1.190s

--=20
Tim Wilson
Twin Cities, Minnesota, USA
Science teacher, Linux fan, Zope developer, Grad. student, Daddy
mailto:wilson@visi.com | http://qwerk.org/ | public key: 0x8C0F8813



From thomi@thomi.imail.net.nz  Thu Dec 12 18:57:01 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Thu Dec 12 18:57:01 2002
Subject: [Tutor] cgi module and checkboxes.
In-Reply-To: <5.1.0.14.0.20021212145537.02c7db10@www.thinkware.se>
References: <20021211235716.6f3cfc4c.thomi@thomi.imail.net.nz>
 <20021209234348.7d6c8393.thomi@thomi.imail.net.nz>
 <3DF6E2A9.1080001@netzero.net>
 <20021211235716.6f3cfc4c.thomi@thomi.imail.net.nz>
 <5.1.0.14.0.20021212145537.02c7db10@www.thinkware.se>
Message-ID: <20021213125503.5fdbbc46.thomi@thomi.imail.net.nz>

> Note getlist() !!!

thanks :-)

-- 
Thomi Richards
thomi@imail.net.nz
http://ddmodd.sourceforge.net/
Thomi Richards,
thomi@imail.net.nz


From dylan.belsey@baesystems.com  Thu Dec 12 19:25:34 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Thu Dec 12 19:25:34 2002
Subject: [Tutor] Embedded Python on different versions of Windows.
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B98D2B72@wtntex1.baea.com.au>

Using Python 2.1.1

Hi List,
	I am still working on embedding Python within C++ and have almost
reached wits end with a particular issue.  At the moment I initialise the
Python Interpreter within a C++ class (ScriptInterface) using the standard
Py_Initialise().  The class has a method called Update_10Hz, which is called
by an EventServer (CORBA) every 100 ms.  Within this method I use standard
commands such as PyRun_SimpleString() and PyRun_SimpleFile() to run a python
script file.
	I have profiling code within the Update_10Hz() method to measure the
time it takes to run a cycle.  The problem that I am encountering is that on
a Windows NT box I get good consistent timing results (eg 20 ms for a
particular script).  When I move the exact same code onto a Windows 2K box
with dual processors, I get sporadic fluctuations in the time it takes to
execute the method, sometimes blowing out to values in the order of seconds.
	By profiling the internals of the method we find that sometimes, the
greatest amount of time is taken by the PyRun_SimpleFile() command but I am
not sure whether this is a function of the command having to do the greatest
amount of working within the method as it has to call the script file and
then execute it and therefore Python is being scheduled (??) out, or whether
it is something else on the system.
	We have also tried setting priorities of various threads,
particularly elevating the thread that executes the Update_10Hz() and many
other strategies, such as streaming the script file into a buffer before it
is executed, but to no avail.
	After all this explanation, my question is whether anyone has seen
this similar behaviour between different flavours of Windows, where embedded
Python runs differently, and if so what is causing it.  Alternatively, if
anyone has any ideas as to possible causes or fixes or any discussion on the
topic, that would be greatly appreciated.
	By the way, the script makes calls back into the C++ code by way of
a module I have created using SWIG.  We have tested these module calls as
possible sources of error and have confirmed that they are not.
	
	Thanks for your time,
		Dylan


From dyoo@hkn.eecs.berkeley.edu  Thu Dec 12 19:30:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu Dec 12 19:30:02 2002
Subject: [Tutor] Re: Sorting Instance Attributes
In-Reply-To: <20021212231041.30917.qmail@web20514.mail.yahoo.com>
Message-ID: <Pine.LNX.4.44.0212121607310.26167-100000@hkn.eecs.berkeley.edu>


On Thu, 12 Dec 2002, Alan Colburn wrote:

> Let's start with the cmp function/method. I understand that the function
> returns -1 if the first item is less than the second, 0 if they're
> equal, and 1 if the first item is greater than the second.

Yes.



> The part I don't know about relates to using the function/method with a
> list of items; I only understand using it to compare two items.

I'm interpreting this question as: "Once I have this comparison function,
what good is it when I'm sorting a list of items?"  Stop me if I'm
completely missing your question.  *grin*


Python's sort() method uses the comparison function repeatedly between
pairs of elements in a list.  If a pair of elements are misordered --- in
descending order --- then Python swaps those two elements so that they're
now ascending.  We can almost imagine that the disorder of the list
gradually drops to zero as Python does repeated swaps and comparisons on
the list.



It's hard to believe that doing repeated swaps actually accomplishes
anything, so it's pretty neat that this actually works.  But we don't need
to just believe it in theory: we can actually see this comparison in
action!  Let's hijack the comparison function so that it prints out the
state of a list of numbers as a list gradually gets sorted.

###
>>> numbers = [random.randrange(100) for i in range(10)]
>>> numbers
[55, 82, 79, 74, 57, 58, 74, 58, 78, 62]
>>> def mycmp(a, b):
...     global numbers
...     print "my numbers list is", numbers
...     print "I'm comparing", a, "and", b
...     return cmp(a, b)
...
>>> numbers.sort(mycmp)
my numbers list is [55, 82, 79, 74, 57, 58, 74, 58, 78, 62]
I'm comparing 82 and 55
my numbers list is [55, 82, 79, 74, 57, 58, 74, 58, 78, 62]
I'm comparing 79 and 82
my numbers list is [55, 82, 79, 74, 57, 58, 74, 58, 78, 62]
I'm comparing 79 and 82
my numbers list is [55, 82, 79, 74, 57, 58, 74, 58, 78, 62]
I'm comparing 79 and 55
my numbers list is [55, 79, 82, 74, 57, 58, 74, 58, 78, 62]
I'm comparing 74 and 79
my numbers list is [55, 79, 82, 74, 57, 58, 74, 58, 78, 62]
I'm comparing 74 and 55
my numbers list is [55, 74, 79, 82, 57, 58, 74, 58, 78, 62]
I'm comparing 57 and 79
my numbers list is [55, 74, 79, 82, 57, 58, 74, 58, 78, 62]
I'm comparing 57 and 74
my numbers list is [55, 74, 79, 82, 57, 58, 74, 58, 78, 62]
I'm comparing 57 and 55
my numbers list is [55, 57, 74, 79, 82, 58, 74, 58, 78, 62]
I'm comparing 58 and 74
my numbers list is [55, 57, 74, 79, 82, 58, 74, 58, 78, 62]
I'm comparing 58 and 57
my numbers list is [55, 57, 58, 74, 79, 82, 74, 58, 78, 62]
I'm comparing 74 and 74
my numbers list is [55, 57, 58, 74, 79, 82, 74, 58, 78, 62]
I'm comparing 74 and 82
my numbers list is [55, 57, 58, 74, 79, 82, 74, 58, 78, 62]
I'm comparing 74 and 79
my numbers list is [55, 57, 58, 74, 74, 79, 82, 58, 78, 62]
I'm comparing 58 and 74
my numbers list is [55, 57, 58, 74, 74, 79, 82, 58, 78, 62]
I'm comparing 58 and 57
my numbers list is [55, 57, 58, 74, 74, 79, 82, 58, 78, 62]
I'm comparing 58 and 58
my numbers list is [55, 57, 58, 58, 74, 74, 79, 82, 78, 62]
I'm comparing 78 and 74
my numbers list is [55, 57, 58, 58, 74, 74, 79, 82, 78, 62]
I'm comparing 78 and 79
my numbers list is [55, 57, 58, 58, 74, 74, 79, 82, 78, 62]
I'm comparing 78 and 74
my numbers list is [55, 57, 58, 58, 74, 74, 78, 79, 82, 62]
I'm comparing 62 and 74
my numbers list is [55, 57, 58, 58, 74, 74, 78, 79, 82, 62]
I'm comparing 62 and 58
my numbers list is [55, 57, 58, 58, 74, 74, 78, 79, 82, 62]
I'm comparing 62 and 58
>>> numbers
[55, 57, 58, 58, 62, 74, 74, 78, 79, 82]
###


The action is very gradual on this list, but we do see that the list
gradually becomes more and more sorted until the sort() stops.  All the
while, Python's doing cmp()'s on pairs of elements, and making some
decisions based on the comparisons.


I hope this helps!



From fredm@smartypantsco.com  Thu Dec 12 19:45:02 2002
From: fredm@smartypantsco.com (Alfred Milgrom)
Date: Thu Dec 12 19:45:02 2002
Subject: [Tutor] Optimizing a simple radioactive decay simulation
In-Reply-To: <200212121722.56528.wilson@visi.com>
Message-ID: <5.1.0.14.0.20021213113110.00aac450@192.168.1.1>

Hi Tim:

The most time-consuming part of your program appears to be the calls to the 
random routine. 2 million calls to random.randint(0,1) (which is what you 
need with an initial population of 1 million) takes about 5 minutes on my 
computer.

The rest of the time is due to your use of classes.
Here is a much simpler program which accomplishes similar result to yours 
without the use of classes. It still uses the random.randint routine, but 
it's about 1/3 faster than yours:

def main2():
     """Run the decay simulator."""
    numcoins = int(raw_input("How many coins? "))
    halflives = 0
     while numcoins > 0:
         print "Undecayed (heads): %s" % numcoins
         ds = [1 for coin in range(numcoins) if random.randint(0,1)]
         halflives += 1
         numcoins = len(ds)
     print "\n%s half-lives required." % halflives

if __name__ == '__main__':
     main2()

I'm sure that there is an even faster solution out there.

HTH, Best regards,
Alfred Milgrom

At 05:22 PM 12/12/02 -0600, Tim Wilson wrote:
>Hi everyone,
>
>My students and I did a fun little simulation of C-14 decay today using
>pennies to represent the atoms. We flipped the coins repeatedly until all
>the pennies had "decayed" (by turning up heads) and used the results to
>make a graph of the decay curve.
>
>I thought it would be fun to replicate the demo on the computer so I could
>expand the simulation to many more pennies. My first approach, which I will
>include below, was to create Coin and DecaySim classes that contain the
>needed methods. This worked perfectly, but was quite slow.
>-Tim
>
>
>Here's the output on my 1-GHz Athlon with 512 MB RAM.
>
>wilsont@galileo:~/Documents> time python decay.py
>How many coins? 1000000
>...
>21 half-lives required.
>
>real    12m6.267s
>user    8m26.820s
>sys     0m1.190s
>
>--
>Tim Wilson



From andrewm@object-craft.com.au  Thu Dec 12 19:50:06 2002
From: andrewm@object-craft.com.au (Andrew McNamara)
Date: Thu Dec 12 19:50:06 2002
Subject: [Tutor] Wanted: module to parse out a CSV line
In-Reply-To: Message from Dave Cole <djc@object-craft.com.au>
 of "13 Dec 2002 10:03:48 +1100." <m3adjac017.fsf@ferret.object-craft.com.au>
References: <5.1.0.14.0.20021212101929.02c6a178@www.thinkware.se> <m31y4ozpc0.fsf@ferret.object-craft.com.au> <5.1.0.14.0.20021211103301.02bd9da0@www.thinkware.se> <5.1.0.14.0.20021211103301.02bd9da0@www.thinkware.se> <5.1.0.14.0.20021212101929.02c6a178@www.thinkware.se> <5.1.0.14.0.20021212142954.02bf08b8@www.thinkware.se>  <m3adjac017.fsf@ferret.object-craft.com.au>
Message-ID: <20021213004938.E42E23C510@coffee.object-craft.com.au>

>Magnus> Sorry Dave, I was unclear. I meant with Excel.
>
>Magnus> As far as I understand, you say that you need the broken line
>Magnus> handling to be Excel complient. Right?
>
>Magnus> I have not been able to make Excel import broken lines into a
>Magnus> cell.
>
>I am fairly sure that I have seen cells with newlines in Excel.  I
>have definitely seen them in Access.
>
>Andrew, do you have Excel handy?

Yep. Excel's behaviour is a little bizare - I first tried importing a
file with a CRLF pair in the field - this worked, but left an unprintable
character in the field (a square).

So I started wondering how you actually created a field with a newline in
it from within Excel, because hitting ENTER moves you to the next field.
Some experimentation found the ALT-ENTER combination, which inserts a
newline within the current field.

Looking at the file exported after entering this, I found that fields
with embedded newlines contain only a LF, not CR (and are quoted, as
you would expect).

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/


From Don Arnold" <darnold02@sprynet.com  Thu Dec 12 20:17:02 2002
From: Don Arnold" <darnold02@sprynet.com (Don Arnold)
Date: Thu Dec 12 20:17:02 2002
Subject: [Tutor] Re: Sorting Instance Attributes
References: <20021212231041.30917.qmail@web20514.mail.yahoo.com>
Message-ID: <009901c2a245$387637f0$1813ba3f@defaultcomp>

----- Original Message -----
From: "Alan Colburn" <aicolburn@yahoo.com>
To: <tutor@python.org>
Sent: Thursday, December 12, 2002 5:10 PM
Subject: [Tutor] Re: Sorting Instance Attributes


> My thanks to you all for responding to my post
> yesterday. I really appreciate you taking the time to
> do so.
>

You're welcome.

> I have to admit that your solutions are a bit beyond
> my abilities right now. Maybe if I ask a question or
> two at a time I'll understand.
>

Sounds reasonable...

> Let's start with the cmp function/method. I understand
> that the function returns -1 if the first item is less
> than the second, 0 if they're equal, and 1 if the
> first item is greater than the second. The part I
> don't know about relates to using the function/method
> with a list of items; I only understand using it to
> compare two items.
>

Well, cmp( ) itself only knows how to compare two items, so you're not doing
too badly. The thing is that you can define the comparison function that a
list's sort( ) method uses for its comparisons to get customized sorting
behavior. The easiest way (IMO) to do this is to supply your comparison
function as an argument to the sort( ) call:

import random

def myCmp(lhs,rhs):
    ''' customized sort routine: odd #'s are greater than even #'s'''
    lhsOdd = lhs % 2
    rhsOdd = rhs % 2
    if lhsOdd == rhsOdd:
        # both are odd or both even. compare them using the default cmp( )
        return cmp(lhs, rhs)
    else:
        if lhsOdd:
            # lhs was the odd one, so it's greater
            return 1
        else:
            # rhs was the odd one, so lhs is less than it
            return -1

mylist = []
# generate a list of 10 random numbers
for i in range(10):
    mylist.append(random.randrange(100))
print mylist

-> [88, 60, 77, 23, 65, 79, 53, 88, 59, 58]

## now sort the list using our comparison function
mylist.sort(myCmp)

print mylist

-> [58, 60, 88, 88, 23, 53, 59, 65, 77, 79]


Another way to customize sort( ) is to override the magical __cmp__( )
method of the class being sorted, which is what cmp( ) calls when it compare
two objects:


import random

class myInt:
    def __init__(self,value):
        self.value = value

    def __repr__(self):
        return "%s" % self.value

    def __cmp__(lhs,rhs):
        # myInts sort from high to low. just reverse the sign of the result
of
        # comparing their values
        return - cmp(lhs.value,rhs.value)

mylist = []
for i in range(10):
    mylist.append(myInt(random.randrange(100)))
print mylist

-> [29, 56, 91, 77, 22, 22, 6, 14, 76, 97]

## now sort the list of myInts. since they know how to compare themselves to
each
## other, no comparison function is supplied to sort().
mylist.sort()

print mylist

-> [97, 91, 77, 76, 56, 29, 22, 22, 14, 6]

HTH,

Don



From dyoo@hkn.eecs.berkeley.edu  Thu Dec 12 20:28:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu Dec 12 20:28:01 2002
Subject: [Tutor] Optimizing a simple radioactive decay simulation
In-Reply-To: <200212121722.56528.wilson@visi.com>
Message-ID: <Pine.LNX.4.44.0212121638470.26167-100000@hkn.eecs.berkeley.edu>


On Thu, 12 Dec 2002, Tim Wilson wrote:

> This worked perfectly, but was quite slow.
>
> Since I'm interested in using simulations to teach science, I wonder if
> anyone has suggestions for optimizing this code.

Hi Tim,


Profiling time!  *grin*

    http://www.python.org/doc/lib/profile.html


The profiler is pretty sophisticated, but for the moment, let's use it's
simple "profile.run()" function directly on the main() function.



Here's what happens on my system:

###
>>> import decay
>>> import profile
>>> profile.run("decay.main()")
How many coins? 50000
Undecayed (heads): 50000
Undecayed (heads): 24948
Undecayed (heads): 12440
Undecayed (heads): 6276
Undecayed (heads): 3209
Undecayed (heads): 1605
Undecayed (heads): 769
Undecayed (heads): 374
Undecayed (heads): 191
Undecayed (heads): 97
Undecayed (heads): 47
Undecayed (heads): 20
Undecayed (heads): 10
Undecayed (heads): 4
Undecayed (heads): 2
Undecayed (heads): 2
Undecayed (heads): 2
Undecayed (heads): 1
Undecayed (heads): 1
Undecayed (heads): 1
Undecayed (heads): 1

21 half-lives required.
         450089 function calls in 13.060 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000   13.060   13.060 <string>:1(?)
        1    1.490    1.490    1.820    1.820 decay.py:10(__init__)
       43    0.000    0.000    0.000    0.000 decay.py:16(__len__)
       21    0.380    0.018    0.380    0.018 decay.py:20(removeTails)
       21    1.080    0.051   10.860    0.517 decay.py:24(decay)
    50000    0.330    0.000    0.330    0.000 decay.py:32(__init__)
   100000    2.300    0.000    9.780    0.000 decay.py:36(flip)
        1    0.000    0.000   13.060   13.060 decay.py:40(main)
        1    0.000    0.000   13.060   13.060 profile:0(decay.main())
        0    0.000             0.000          profile:0(profiler)
   100000    1.750    0.000    1.750    0.000 random.py:153(random)
   100000    3.530    0.000    5.280    0.000 random.py:277(randrange)
   100000    2.200    0.000    7.480    0.000 random.py:316(randint)
###


It looks the system spends a significant amount of time doing random
number generation in the flip() method.  That's what we expect: it's doing
a flippin' lot of of flipping.  *grin*

One optimization that specifically applies to Python is to pull specific
functions out of modules so that they appear to be local.  Python can more
quickly access local variables in a function.

Whenever a name is used in a program, Python needs to search in the
following approximate order:

    1.  Local
    2.  Class
    3.  Module

(Nested scopes complicates this somewhat, but not by much.)


At the moment, 'random.randint' is being found at the module level, so
we can speed up random number generation somewhat by pulling the randint
function as a local variable:


######
class Coin:
    """Coin class for use in radioactive decay simulation."""

    def __init__(self, value):
        """Create a coin instance. 1 = heads, 2 = tails"""
        self.value = value


    def flip(self, randint=random.randint):
                                         ## randint is default
                                         ## parameter for speed
                                         ## optimization reasons
        """Flip the coin."""
        self.value = randint(0, 1)
######


[Time out!  The comment of the Coin class is wrong: self.value is between
0 and 1, not 1 and 2, so something has to give: either the code is wrong,
or the comment is wrong.  I'm betting on the comment.]



Let's see if that helps any:

###
...
17 half-lives required.
         449977 function calls in 12.470 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000   12.460   12.460 <string>:1(?)
        1    1.340    1.340    1.740    1.740 decay.py:10(__init__)
       35    0.000    0.000    0.000    0.000 decay.py:16(__len__)
       17    0.360    0.021    0.360    0.021 decay.py:20(removeTails)
       17    1.430    0.084   10.360    0.609 decay.py:24(decay)
    50000    0.400    0.000    0.400    0.000 decay.py:32(__init__)
    99976    1.790    0.000    8.930    0.000 decay.py:36(flip)
        1    0.000    0.000   12.460   12.460 decay.py:43(main)
        1    0.010    0.010   12.470   12.470 profile:0(decay.main())
        0    0.000             0.000          profile:0(profiler)
    99976    1.700    0.000    1.700    0.000 random.py:153(random)
    99976    3.020    0.000    4.720    0.000 random.py:277(randrange)
    99976    2.420    0.000    7.140    0.000 random.py:316(randint)
###


It shaved a little bit off the runtime, but not too much.  Still, that's a
start.  We know now that we should concentrate our efforts on minimizing
the cost of flip(): it's called the most often, and takes up the majority
of time.


We should notice, also, that randrange() is showing up in our profiling
report.  What gives?  That's because randint(), underneath the surface, is
using randrange()!  Let's avoid the middle man, and directly use
randrange:

###
## in the Coin class definition:
    def flip(self, randrange=random.randrange):
                                         ## randrange is default
                                         ## parameter for speed
                                         ## optimization reasons
        """Flip the coin."""
        self.value = randrange(2)
###



Does that help?

###
16 half-lives required.
         350051 function calls in 11.010 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000   11.010   11.010 <string>:1(?)
        1    1.270    1.270    1.640    1.640 decay.py:10(__init__)
       33    0.000    0.000    0.000    0.000 decay.py:16(__len__)
       16    0.370    0.023    0.370    0.023 decay.py:20(removeTails)
       16    1.430    0.089    8.990    0.562 decay.py:24(decay)
    50000    0.370    0.000    0.370    0.000 decay.py:32(__init__)
    99994    2.590    0.000    7.560    0.000 decay.py:36(flip)
        1    0.010    0.010   11.010   11.010 decay.py:43(main)
        1    0.000    0.000   11.010   11.010 profile:0(decay.main())
        0    0.000             0.000          profile:0(profiler)
    99994    1.840    0.000    1.840    0.000 random.py:153(random)
    99994    3.130    0.000    4.970    0.000 random.py:277(randrange)
###


A little better.  And so on: we'll have to do little tweaks, compare
performance using profile, and tweak again.

I'll stop for now; Let's let someone else suggest a good way of speeding
flip() up.




Oh, by the way, since this experiment uses random numbers, we're not
getting exactly the same results, run after run.  This is not a good
thing: we want to make experiments repeatable, and not merely "almost"
repeatable.


But we can fix this, since we're actually using "pseudorandom" numbers.
Unlike the lottery, we can bias things so that we get the exact same
pseudorandom numbers, run after run, by twiddling random.seed() before
every program run:

###
>>> help(random.seed)

Help on method seed in module random:

seed(self, a=None) method of random.Random instance
    Initialize internal state from hashable object.

    None or no argument seeds from current time.

    If a is not None or an int or long, hash(a) is used instead.

    If a is an int or long, a is used directly.  Distinct values between
    0 and 27814431486575L inclusive are guaranteed to yield distinct
    internal states (this guarantee is specific to the default
    Wichmann-Hill generator).
###


So when we do profiling, let's call:

###
>>> random.seed("profiling")
###

just before every profile run, to make sure we get the same results.



Let's continue attacking this problem till we get tired.  *grin* Good luck
to you!



From dyoo@hkn.eecs.berkeley.edu  Thu Dec 12 21:37:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu Dec 12 21:37:02 2002
Subject: [Tutor] Embedded Python on different versions of Windows.
In-Reply-To: <86C3892A0C52D411AF5000A0C9EAA3B98D2B72@wtntex1.baea.com.au>
Message-ID: <Pine.LNX.4.44.0212121828530.11040-100000@hkn.eecs.berkeley.edu>


On Fri, 13 Dec 2002, BELSEY, Dylan wrote:

> 	I am still working on embedding Python within C++ and have almost
> reached wits end with a particular issue.  At the moment I initialise
> the Python Interpreter within a C++ class (ScriptInterface) using the
> standard Py_Initialise().  The class has a method called Update_10Hz,
> which is called by an EventServer (CORBA) every 100 ms.  Within this
> method I use standard commands such as PyRun_SimpleString() and
> PyRun_SimpleFile() to run a python script file.

Hi Dylan,

Yikes.

You may want to ask your question on the main comp.lang.python newsgroup
for this question.  Platform-dependent issues suck because they're often
very difficult to debug, and aren't encountered by many of us here.

The problem you're seeing sounds like some weird interaction that happens
in Win2k and not in WinNT.  This sounds serious, and you might not get
good answers from us here.  There are experts on comp.lang.python that
should have some suggestions for you, so I'd try there.


I wish the best for you!



From rdm@rcblue.com  Thu Dec 12 22:16:25 2002
From: rdm@rcblue.com (Dick Moores)
Date: Thu Dec 12 22:16:25 2002
Subject: [Tutor] TKinter and IDLE problem
In-Reply-To: <5.1.0.14.0.20021212094421.02c24de8@www.thinkware.se>
References: <5.1.0.14.2.20021212001111.03a66ec0@rcblue.com>
Message-ID: <5.1.0.14.2.20021212185902.035a2bb0@rcblue.com>

In a DOS window, neither

      python C:\Python22\Tkinter\helloTkinter.py

nor

      C:\PATH> python myscript.py
(where I assume "C:\python22\Tkinter> python helloTkinter.py" is what is meant)

work.

So as suggested I edited autoexec.bat, which now reads:

"""
SET MSINPUT=C:\MSINPUT

@SET CLASSPATH=C:\PROGRA~1\PHOTOD~1.0\ADOBEC~1
DOSKEY
SET Path=%Path%;"C:\Program Files\Executive Software\DiskeeperLite\"
SET Path=%Path%;"C:\PYTHON22\"
"""

After rebooting, the GUIs in the Tkinter folder still won't execute (though 
they do when clicked on in Explorer). Sorry, but I think I need precise 
instructions here, rather than "something like".

What's wrong, other than I'm DOS dumb?

Again, Win98.

Thanks,

Dick Moores
rdm@rcblue.com

  




From ramrom@earthling.net  Thu Dec 12 23:30:01 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Thu Dec 12 23:30:01 2002
Subject: [Tutor] Optimizing a simple radioactive decay simulation
In-Reply-To: <200212121722.56528.wilson@visi.com>
Message-ID: <5.2.0.9.0.20021212212505.02140a00@66.28.54.253>

import random, time
start = time.time()
numcoins = int(raw_input("How many coins? "))
halflives = 0
while numcoins >= 1:
   for i in range(numcoins):
     numcoins -= random.randint(0,1)
   print "Undecayed (heads): %s" % numcoins
   halflives += 1
print "\n%s half-lives required." % halflives
print '%d seconds' % (time.time() - start)

for 1000000 coins on an almost identical machine:
Undecayed (heads): 500026
Undecayed (heads): 250149
Undecayed (heads): 125008
Undecayed (heads): 62168
Undecayed (heads): 31002
Undecayed (heads): 15513
Undecayed (heads): 7678
Undecayed (heads): 3883
Undecayed (heads): 1918
Undecayed (heads): 944
Undecayed (heads): 484
Undecayed (heads): 245
Undecayed (heads): 120
Undecayed (heads): 64
Undecayed (heads): 38
Undecayed (heads): 18
Undecayed (heads): 9
Undecayed (heads): 6
Undecayed (heads): 4
Undecayed (heads): 4
Undecayed (heads): 1
Undecayed (heads): 1
Undecayed (heads): 0
23 half-lives required.
35 seconds

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625



From fredm@smartypantsco.com  Fri Dec 13 01:09:01 2002
From: fredm@smartypantsco.com (Alfred Milgrom)
Date: Fri Dec 13 01:09:01 2002
Subject: [Tutor] How do you simulate a CGI script locally?
In-Reply-To: <5.1.0.14.0.20021213113110.00aac450@192.168.1.1>
References: <200212121722.56528.wilson@visi.com>
Message-ID: <5.1.0.14.0.20021213170335.00aafa70@192.168.1.1>

I guess this is a pretty stupid question, but I haven't been able to find 
the answer anywhere.

I want to develop a CGI script, and I'd like to test it locally (I mean on 
my own computer, running Windows), rather than uploading the file to the 
server, testing it, revising it, and so on.

My question is: how do I make my Python program behave like a CGI script, 
where print statements end up shown in the browser window. If I point my 
browser at my CGI test file, it runs, but the output goes to the DOS box 
instead.

Any help would be appreciated.
Thanks,
Alfred Milgrom



From shalehperry@attbi.com  Fri Dec 13 02:21:02 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Fri Dec 13 02:21:02 2002
Subject: [Tutor] How do you simulate a CGI script locally?
In-Reply-To: <5.1.0.14.0.20021213170335.00aafa70@192.168.1.1>
References: <200212121722.56528.wilson@visi.com> <5.1.0.14.0.20021213170335.00aafa70@192.168.1.1>
Message-ID: <200212122319.43961.shalehperry@attbi.com>

On Thursday 12 December 2002 23:08, Alfred Milgrom wrote:
> I guess this is a pretty stupid question, but I haven't been able to fi=
nd
> the answer anywhere.
>
> I want to develop a CGI script, and I'd like to test it locally (I mean=
 on
> my own computer, running Windows), rather than uploading the file to th=
e
> server, testing it, revising it, and so on.
>
> My question is: how do I make my Python program behave like a CGI scrip=
t,
> where print statements end up shown in the browser window. If I point m=
y
> browser at my CGI test file, it runs, but the output goes to the DOS bo=
x
> instead.
>

a) install a web server on your local machine

b) in the end a cgi is simply a program which gets some input and prints =
some=20
output.  You can test these programs from the command line, especially ea=
sy=20
if you install the cygwin tools.


From carroll@tjc.com  Fri Dec 13 04:18:02 2002
From: carroll@tjc.com (Terry Carroll)
Date: Fri Dec 13 04:18:02 2002
Subject: [Tutor] Grokking immutability
Message-ID: <Pine.GSU.4.44.0212130026130.25459-100000@waltz.rahul.net>

Beginner here.  I don't really get immutability.  Can someone explain its
practical effect in small words?

For example, I understand tuples are immutable, lists aren't.  So I can do
this:

  l1 = ["x", "y"]
  l1.append("z")
  print "l1: ", l1, type(l1)

 l1:  ['x', 'y', 'z'] <type 'list'>

But I can't do this:

  t3 = ("x", "y")
  t3.append("z")
  print "t3: ", t3

 AttributeError: 'tuple' object has no attribute 'append'

Okay, but I can do this:

  t1 = ("x", "y")
  t1 = ("x", "y", "z")
  print "t1: ", t1, type(t1)

 t1:  ('x', 'y', 'z') <type 'tuple'>

Now, I understand that, technically, there is no variable t1 being
modified; that a new tuple with "x", "y", and "z" is being created, and
the name "t1" is now associated with that new tuple, and the old one can
be garbage-collected.  But as a practical matter, it amounts to the same
thing, no?

I can even do this:

  t2 = ("x", "y")
  print "t2: ", t2, type(t2)
  l_temp = list(t2)
  l_temp.append("z")
  t2 = tuple(l_temp)
  print "t2: ", t2, type(t2)

 t2:  ('x', 'y') <type 'tuple'>
 t2:  ('x', 'y', 'z') <type 'tuple'>

Not practical, I understand: if I want to modify t2, I should have made it
a list to start with, rather than a tuple.

But this demonstrates to me that immutability is something deeper than
something like a "read-only" attribute for a variable.  I'm trying to
understand what.

Specifically, why bother to add the concept of immutability to the
language?  Or, on a more specific level, why is there a tuple type in the
language, when the list can pretty much do everything a tuple can?

Oh, and while you're at it, what's the Meaning of Life?

-- 
Terry Carroll        |
Santa Clara, CA      |   "The parties are advised to chill."
carroll@tjc.com      |       - Mattel, Inc. v. MCA Records, Inc.,
Modell delendus est  |         no. 98-56577 (9th Cir. July 24, 2002)



From dyoo@hkn.eecs.berkeley.edu  Fri Dec 13 05:32:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri Dec 13 05:32:02 2002
Subject: [Tutor] Grokking immutability
In-Reply-To: <Pine.GSU.4.44.0212130026130.25459-100000@waltz.rahul.net>
Message-ID: <Pine.LNX.4.44.0212130137130.22136-100000@hkn.eecs.berkeley.edu>


On Fri, 13 Dec 2002, Terry Carroll wrote:

> Beginner here.  I don't really get immutability.  Can someone explain
> its practical effect in small words?

Immutability affects many of the primitive data types that we know about.
For example, all the numbers in Python are immutable: if I have a number
42, and you also have that same number number 42, there's nothing I can
do, be it multiplying, or incrementing, or dividing, or bitshifting:
nothing affects your 42.

###
x = 42
y = x
x = x * 2          ## ... no effect on y
x += 1             ## ... still no effect...
###

This may seem obvious for numbers, but this idea of an immutable thing
also extends to strings in Python.  And Python's string immutability isn't
so obvious for people who've programmed in traditional languages like C:

###
x = "forty two"
y = x
x[2] = 'o'        ## ... won't work in Python, but would conceptually work
                  ## in the C language
###

So, the more common data things that we work in the language --- numbers
and strings --- are both immutable: if two variable name refer to the same
thing, if we start fiddling with one variable name, nothing appears to
reflect in the other variable.



> For example, I understand tuples are immutable, lists aren't.

Tuples are immutable in the sense that once we build up the container, we
can't do anything to affect it's physical form.

###
>>> x = ('this', 'is', 42)
>>> x[0] = 'that'
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: object doesn't support item assignment
###

In this sense, they're behaving just like strings and numbers: we just
don't have any operations that we can do to bend them!



But there's a simplification involved whenever we say a tuple is
immutable: it's only truly immutable, through and through, if the values
that are contained in it are themselves immutable.


If we stick a list in a tuple, for example, we've still got a shallow
sense of immutability,

###
>>> x = ('this', 'is', 'a', 'tuple', 'with', 'a', ['list'])
>>> x[0] = 'that'
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: object doesn't support item assignment
###

but the inner parts can still definitely change: the list that's inside
has contaminated the purity of that tuple's immutability!

###
>>> x[-1].insert(0, 'happy')
>>> x[-1][1] = 42
>>> x
('this', 'is', 'a', 'tuple', 'with', 'a', ['happy', 42])
###

So when we say tuples are "immutable", there's usually the caveat that
everything that's in the tuple is being assumed to be immutable as well.
Just something to make things more confusing... *grin*



> Okay, but I can do this:
>
>   t1 = ("x", "y")
>   t1 = ("x", "y", "z")
>   print "t1: ", t1, type(t1)
>
>  t1:  ('x', 'y', 'z') <type 'tuple'>
>
> Now, I understand that, technically, there is no variable t1 being
> modified; that a new tuple with "x", "y", and "z" is being created, and
> the name "t1" is now associated with that new tuple, and the old one can
> be garbage-collected.  But as a practical matter, it amounts to the same
> thing, no?


It might help to think of t1 as a honking big arrow pointed to some boxy
looking thing:

t1  ---------------> +-------------+
                     |  "x" |  "y" |
                     |      |      |
                     +-------------+

(This is a simplification: the 'x' and 'y' actually should be living
outside the boxes, but we'll ignore that for the moment...  *grin*)


What immutability is saying is that that box is made of concrete, and that
the values that are in there are physically glued in place: nothing we can
do to the tuple will let us plug in "w" anywhere in there, or make the box
larger.

The reason immutability matters is that it's very possible to make two
arrows to a single tuple:

###
t1 = ("x", "y")
t2 = t1
###

t1  ---------------> +-------------+
                     |  "x" |  "y" |
t2  ---------------> |      |      |
                     +-------------+

And what an immutable thing guarantess is that we can have absolute
certainly that if we pass t1 to some function, nothing can be done to make
t2 look different.  As long as t2 points to the same box, we're pretty
sure it stays as ("x", "y") throughout our program.


But immutability is a separate issue from being able to rebind t1 to a new
name:


t1  -------+         +-------------+
           |         |  "x" |  "y" |  <----------- t2
           |         |      |      |
           |         +-------------+
           |
           |         +-------------+-----+
           +------>  |  "x" |  "y" |  "z"|
                     |      |      |     |
                     +-------------+-----+


Immutability is more about the permanence of the structures that we play
with: it has nothing to do with us being able to toss them in the garbage
can.  Immutable structures are awesomely indestructible, but they're not
glued to our hands.



> Specifically, why bother to add the concept of immutability to the
> language?  Or, on a more specific level, why is there a tuple type in
> the language, when the list can pretty much do everything a tuple can?

One big reason is because immutability as a mathematical concept makes
sense for numbers, and can be extended to strings.  My concept of Pi can't
be redefined by any legislature.  My guess is that the designers of Python
wanted to bring immutability to a very simple container structure for
symmetry's sake.  And math is fraught with tuples!  A set of coordinates
on the x-y plane:

###
>>> x = 42
>>> y = 24
>>> p = x,y
>>> p2 = p
>>> p
(42, 24)
>>> p2
(42, 24)
###

is just as mathy an object as a number.  Python's core designer's a
mathematician, so that's probably also a contributing factor to having a
separate tuple type.


But a major one is that tuples can be used as dictionary keys:

###
>>> sparse_matrix = {}
>>> for i in range(5):
...     sparse_matrix[i,i] = 1
...
>>> sparse_matrix
{(1, 1): 1, (3, 3): 1, (0, 0): 1, (4, 4): 1, (2, 2): 1}
###

Dictionaries don't work well unless the keys are guaranteed not to melt or
or break or bend or shatter.  A doorknob lock is useless if the key's made
of butter.

###
>>> key = 42
>>> deep_thought = { key : "answer to life" }
###

We want to make sure we can get at the values in our dictionaries, no
matter how we construct the key:

###
>>> key = int("4") * 10 + int("2")
>>> deep_thought[key]
'answer to life'
###

42 is 42, no matter how we get there.  Same way with tuples:

###
>>> deep_thought[4,2] = 'another answer'
>>> import math
>>> math.pi, math.e
(3.1415926535897931, 2.7182818284590451)
>>> key = (int(str(math.pi)[3]), int(str(math.e)[0]))
>>> deep_thought[key]
'another answer'
###


> Oh, and while you're at it, what's the Meaning of Life?

*grin*



Best of wishes to you!



From magnus@thinkware.se  Fri Dec 13 09:37:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri Dec 13 09:37:02 2002
Subject: [Tutor] TKinter and IDLE problem
In-Reply-To: <5.1.0.14.2.20021212185902.035a2bb0@rcblue.com>
References: <5.1.0.14.0.20021212094421.02c24de8@www.thinkware.se>
 <5.1.0.14.2.20021212001111.03a66ec0@rcblue.com>
Message-ID: <5.1.0.14.0.20021213153156.02bca7e0@www.thinkware.se>

At 19:15 2002-12-12 -0800, Dick Moores wrote:
>In a DOS window, neither
>
>      python C:\Python22\Tkinter\helloTkinter.py
>
>nor
>
>      C:\PATH> python myscript.py
>(where I assume "C:\python22\Tkinter> python helloTkinter.py" is what is 
>meant)

1)
What happens if you just type "python" at the prompt?
If that works, it's the script that can't be found.
If it doesn't work, python can't be found. See below.
(On Windows you exit python with Ctrl-Z.)

2)
Will "c:\python22\python.exe" start python? If not, where
is your "python.exe"?

3)
If 2) worked, type "path" at the prompt. Does the path look
like you expected? If not, consult a windows expert.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Fri Dec 13 10:28:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri Dec 13 10:28:01 2002
Subject: [Tutor] How do you simulate a CGI script locally?
In-Reply-To: <200212122319.43961.shalehperry@attbi.com>
References: <5.1.0.14.0.20021213170335.00aafa70@192.168.1.1>
 <200212121722.56528.wilson@visi.com>
 <5.1.0.14.0.20021213170335.00aafa70@192.168.1.1>
Message-ID: <5.1.0.14.0.20021213154115.02bca928@www.thinkware.se>

>On Thursday 12 December 2002 23:08, Alfred Milgrom wrote:
> > I guess this is a pretty stupid question

No, it's not.

> > I want to develop a CGI script, and I'd like to test it locally (I mean on
> > my own computer, running Windows), rather than uploading the file to the
> > server, testing it, revising it, and so on.
> >
> > My question is: how do I make my Python program behave like a CGI script,
> > where print statements end up shown in the browser window. If I point my
> > browser at my CGI test file, it runs, but the output goes to the DOS box
> > instead.
At 23:19 2002-12-12 -0800, Sean 'Shaleh' Perry wrote:
>a) install a web server on your local machine

If you don't have a web server, you can use this little one:
#############
# mywebserver.py
import BaseHTTPServer, SimpleHTTPServer, CGIHTTPServer

class myRequestHandler(CGIHTTPServer.CGIHTTPRequestHandler):
     def is_executable(self, path):
         return self.is_python(path)

if __name__ == '__main__':
     SimpleHTTPServer.test(myRequestHandler, BaseHTTPServer.HTTPServer)
#############

Put "mywebserver.py" in a directory of your liking.

Put your python CGI script (e.g. script.py) in a subdirectory
called cgi-bin. (Script name must end .py etc, or you have to
modify "is_ececutable" above.

Run "mywebserver.py"

Point your browser to "http://localhost:8000/cgi-bin/script.py

Enjoy!

>b) in the end a cgi is simply a program which gets some input and prints some
>output.  You can test these programs from the command line, especially easy
>if you install the cygwin tools.

Agreed.

But even without cygwin, it's not so diffictult to run

python script.py > test.html

And then you can look at the HTML with your browser.

Again, I'd like to push for using "cgitb". It's very helpful.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From rdm@rcblue.com  Fri Dec 13 10:36:00 2002
From: rdm@rcblue.com (Dick Moores)
Date: Fri Dec 13 10:36:00 2002
Subject: [Tutor] TKinter and IDLE problem
In-Reply-To: <5.1.0.14.0.20021213153156.02bca7e0@www.thinkware.se>
References: <5.1.0.14.2.20021212185902.035a2bb0@rcblue.com>
 <5.1.0.14.0.20021212094421.02c24de8@www.thinkware.se>
 <5.1.0.14.2.20021212001111.03a66ec0@rcblue.com>
Message-ID: <5.1.0.14.2.20021213071255.02bb62f0@rcblue.com>

At 15:39 12/13/2002 +0100, you wrote:
 >
 >At 19:15 2002-12-12 -0800, Dick Moores wrote:
 >>In a DOS window, neither
 >>
 >>      python C:\Python22\Tkinter\helloTkinter.py
 >>
 >>nor
 >>
 >>      C:\PATH> python myscript.py
 >>(where I assume "C:\python22\Tkinter> python helloTkinter.py" is what is
 >>meant)

Things started to work when I commented out

 >1)
 >What happens if you just type "python" at the prompt?
 >If that works, it's the script that can't be found.
 >If it doesn't work, python can't be found. See below.
 >(On Windows you exit python with Ctrl-Z.)

Python starts, and it seems much like IDLE.

 >2)
 >Will "c:\python22\python.exe" start python? If not, where
 >is your "python.exe"?

Python starts.

 >3)
 >If 2) worked, type "path" at the prompt. Does the path look
 >like you expected? If not, consult a windows expert.

Things started to work when I commented out that extra path to 
defragmenter, etc. Now typing path gets me only
PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\PYTHON22
However, when I close a GUI program (by clicking on the "X" in the upper 
right corner), the DOS cursor just continues to blink bleakly at me. It 
won't move. And the title bar of the DOS window says PYTHON. I can usually 
close the window only by closing "oldwinap" in the Windows task list.

Thanks for your continuing help.

Dick Moores
rdm@rcblue.com






From max_ig@yahoo.com  Fri Dec 13 11:02:01 2002
From: max_ig@yahoo.com (MIG)
Date: Fri Dec 13 11:02:01 2002
Subject: [Tutor] Editors/form builders for GUI and productivity
Message-ID: <20021213160052.29082.qmail@web11305.mail.yahoo.com>

I've been coding with python for about 8 month with very interesting
results. Most of my works have GUI, wich I develop with Tkinter and
PMW.
In the beginnig the learning curve was impressive and let me speed up
my coding day-after-day.

However, nowadys I feel I'm in a plateau with no advances in 
productivity, so I'm interested to hear (or read) about gui form
buiders, python editors and others tools that may help.

Thank you,


Max

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com


From carroll@tjc.com  Fri Dec 13 11:38:02 2002
From: carroll@tjc.com (Terry Carroll)
Date: Fri Dec 13 11:38:02 2002
Subject: [Tutor] Grokking immutability
In-Reply-To: <Pine.LNX.4.44.0212130137130.22136-100000@hkn.eecs.berkeley.edu>
Message-ID: <Pine.GSU.4.44.0212130836380.25459-100000@waltz.rahul.net>

On Fri, 13 Dec 2002, Danny Yoo wrote:

> Immutability affects many of the primitive data types that we know about.

[snip long and very helpful explanation]

Thanks, Danny!  That was very helpful.



-- 
Terry Carroll        |
Santa Clara, CA      |   "The parties are advised to chill."
carroll@tjc.com      |       - Mattel, Inc. v. MCA Records, Inc.,
Modell delendus est  |         no. 98-56577 (9th Cir. July 24, 2002)



From janos.juhasz@VELUX.com  Fri Dec 13 11:39:06 2002
From: janos.juhasz@VELUX.com (janos.juhasz@VELUX.com)
Date: Fri Dec 13 11:39:06 2002
Subject: [Tutor] Open *.chm from pythonwin
Message-ID: <OFC1C9E25E.F0C09166-ONC1256C8E.005A6020@LocalDomain>

Dear All,

can someone explain me, how '*.chm' files, like 'C:
\Python22\Doc\ActivePython.chm'
can be openned from command promt, VIM, or simple from pythonwin at a
topic?

It means that, i cant set the argument of hh.exe well, :(

Best regards,
-----------------------
Juh=E1sz J=E1nos
IT department

VELUX Magyarorsz=E1g
Fert=F5di =C9p=EDt=F5komponens Kft.
Fert=F5d Malom k=F6z 1.
Phone: +36 99 537 939
Fax: +36 99 537 921
E-Mail: janos.juhasz@VELUX.com
=




From carroll@tjc.com  Fri Dec 13 11:56:24 2002
From: carroll@tjc.com (Terry Carroll)
Date: Fri Dec 13 11:56:24 2002
Subject: [Tutor] What does "sort" without parens do?
Message-ID: <Pine.GSU.4.44.0212130837400.25459-100000@waltz.rahul.net>

I made an error in a program, and Python's handling of it befuddles me.
I had a list named "file_list"  that was full of instances of a class,
each instance describing a file on a set of CDROMs (I'm indexing my MP3
collection).

To sort the list: I mistyped:

  file_list.sort

Okay, that's wrong.  I should have used:

  file_list.sort()

I did that, and everything worked fine.

Now, I'm not surprised that the version without parens didn't work -- it's
not supposed to.  But I'm intrigued that it didn't give a syntax error or
exception, or, as far as I can tell, have any effect at all.  How did
Python interpret that line?

-- 
Terry Carroll        |
Santa Clara, CA      |   "The parties are advised to chill."
carroll@tjc.com      |       - Mattel, Inc. v. MCA Records, Inc.,
Modell delendus est  |         no. 98-56577 (9th Cir. July 24, 2002)



From op73418@mail.telepac.pt  Fri Dec 13 12:09:02 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Fri Dec 13 12:09:02 2002
Subject: [Tutor] What does "sort" without parens do?
References: <Pine.GSU.4.44.0212130837400.25459-100000@waltz.rahul.net>
Message-ID: <003301c2a2cb$2f8c4d60$a9160dd5@violante>

----- Original Message -----
From: "Terry Carroll" <carroll@tjc.com>
To: <tutor@python.org>
Sent: Friday, December 13, 2002 4:55 PM
Subject: [Tutor] What does "sort" without parens do?


>
> I made an error in a program, and Python's handling of it befuddles me.
> I had a list named "file_list"  that was full of instances of a class,
> each instance describing a file on a set of CDROMs (I'm indexing my MP3
> collection).
>
> To sort the list: I mistyped:
>
>   file_list.sort
>
> Okay, that's wrong.  I should have used:
>
>   file_list.sort()
>
> I did that, and everything worked fine.
>
> Now, I'm not surprised that the version without parens didn't work -- it's
> not supposed to.  But I'm intrigued that it didn't give a syntax error or
> exception, or, as far as I can tell, have any effect at all.  How did
> Python interpret that line?

In Python *everything* is an object - In particular functions, methods, etc
are objects with the same status and privelieges than others (like lists).
When Python sees something like

file_list.sort

It just looks for the attribute sort in the object (a list in this case)
file_list. Since it can't find it there, it goes to the class of file_list
and finds a sort attribute there. It then returns what it found with some
wrapping to make it a bound method - I'm being a little bit sloppy, but it
doen't matter. You could for example do

sorting_file_list = file_list.sort

Now sorting_file_list  is what is called a callable - it behaves much like a
function. The great difference is that it is a bound method - it "knows"
what object it applies (the list file_list in this case). At the syntactic
level you "call" it by sorting_file_list() - notice the parenthesis? It is
*exactly the same* as if you had done file_list.sort() directly.

>
> --
> Terry Carroll

HTH,
G. Rodrigues




From carroll@tjc.com  Fri Dec 13 12:27:03 2002
From: carroll@tjc.com (Terry Carroll)
Date: Fri Dec 13 12:27:03 2002
Subject: [Tutor] What does "sort" without parens do?
In-Reply-To: <003301c2a2cb$2f8c4d60$a9160dd5@violante>
Message-ID: <Pine.GSU.4.44.0212130920410.27342-100000@waltz.rahul.net>

On Fri, 13 Dec 2002, [iso-8859-1] Gon=E7alo Rodrigues wrote:

> When Python sees something like
>
> file_list.sort
>
> It just looks for the attribute sort in the object (a list in this case)
> file_list. Since it can't find it there, it goes to the class of file_lis=
t
> and finds a sort attribute there. It then returns what it found with some
> wrapping to make it a bound method - I'm being a little bit sloppy, but i=
t
> doen't matter.

Thanks for that explanation.

I'm still confused with what it does with this when it's sitting alone on
a line, rather than being callably used.

But now at least I know my question a little better, so now let me try
another one, now clarified.  I tried a tiny program:

 x =3D "abc"
 x

What does Python doing when it encounters line 2, a variable all by
itself?

--=20
Terry Carroll        |
Santa Clara, CA      |   "The parties are advised to chill."
carroll@tjc.com      |       - Mattel, Inc. v. MCA Records, Inc.,
Modell delendus est  |         no. 98-56577 (9th Cir. July 24, 2002)



From charlie@begeistert.org  Fri Dec 13 12:54:02 2002
From: charlie@begeistert.org (Charlie Clark)
Date: Fri Dec 13 12:54:02 2002
Subject: [Tutor] Re: .sort() vs .sort
In-Reply-To: <20021213170005.25254.44959.Mailman@mail.python.org>
References: <20021213170005.25254.44959.Mailman@mail.python.org>
Message-ID: <20021213185557.4472.6@.1039771112.fake>

>   file_list.sort
>   file_list.sort()
> 
> I did that, and everything worked fine.
> 
> Now, I'm not surprised that the version without parens didn't work -- 
> it's not supposed to.  But I'm intrigued that it didn't give a syntax 
> error or exception, or, as far as I can tell, have any effect at all.  
> How did Python interpret that line?

Let's see if I can beat Danny or Magnus to this. The answer is really easy 
but it's something that bites me a lot, too.

.sort  - is an attribute
.sort() - is a method

ie. they are different beasts. file_list.sort asks the object whether it 
has an attribute .sort or provideCompare the following two examples
>>> class list:
...     def __init__(self):
...             self.sort = 4
...
>>> a = list()
>>> a.sort
4        
>>> class list:
...     def sort(self):
...             print "list has been sorted"
...
>>> a = list()
>>> a.sort
<method list.sort of list instance at 0x80028a04>
>>> a.sort()
list has been sorted

Note - it is perfectly possible to overwrite Python's built-ins so be 
warned. I did this deliberately to make the point.

I think OO-people are really happy with this. But it can be confusing for 
the rest of us.

Charlie


From SWidney@ci.las-vegas.nv.us  Fri Dec 13 14:30:02 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Fri Dec 13 14:30:02 2002
Subject: [Tutor] Grokking immutability
Message-ID: <0E5508EBA1620743B409A2B8365DE16FDC8298@SOVEREIGN>

> Oh, and while you're at it, what's the Meaning of Life?

42


From aicolburn@yahoo.com  Fri Dec 13 14:50:02 2002
From: aicolburn@yahoo.com (Alan Colburn)
Date: Fri Dec 13 14:50:02 2002
Subject: [Tutor] Re: Sorting Instance Attributes, cont'd.
Message-ID: <20021213194923.10107.qmail@web20505.mail.yahoo.com>

OK, I think I've got the relationship between cmp and
sort. Thank you :-)

I thought it was interesting to see the function in
action, as Danny set it up. Sometimes it seems like
the function didn't "do" what it was supposed to do,
but grinding away comparison after comparison it did
eventually give us a nice sorted list. And, since
we're working at computer speeds, I guess "eventually"
translates to nanoseconds :-)

Moving on, then ... The simplest solution to my
question looked like this:

class Student(object):
    #Methods snipped.
    def __lt__(self, other):
        return self.lastname < other.lastname

Tell me if I understand this next part correctly ...
methods that begin with a double underscore are are
"silent" and "private" to the class and its instances.
In this case, we are overloading a method that's built
into the class/instance, i.e., that's why you mean by
"magic methods." Is that right?

Further, "lt" is essentially an abbreviation for "less
than," and that method will be run when we call
__cmp__ ... which happens when we call sort() :-)

So, when I try to sort() the objects (which are in a
list), the overloaded __lt__ method is invoked and
returns 1 when one lastname is before the other
lastname, and that 1 is in turn used by the __cmp__
method.

I'm still a little confused, but am I on the right track?

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com


From jeff@ccvcorp.com  Fri Dec 13 15:16:58 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Fri Dec 13 15:16:58 2002
Subject: [Tutor] Re: .sort() vs .sort
References: <20021213170005.25254.44959.Mailman@mail.python.org> <20021213185557.4472.6@.1039771112.fake>
Message-ID: <3DFA3FF0.2080709@ccvcorp.com>

Charlie Clark wrote:

>>  file_list.sort
>>  file_list.sort()
>>
>>I did that, and everything worked fine.
>>
>>Now, I'm not surprised that the version without parens didn't work -- 
>>it's not supposed to.  But I'm intrigued that it didn't give a syntax 
>>error or exception, or, as far as I can tell, have any effect at all.  
>>How did Python interpret that line?
>>    
>>
>
>Let's see if I can beat Danny or Magnus to this. The answer is really easy 
>but it's something that bites me a lot, too.
>
>.sort  - is an attribute
>.sort() - is a method
>
>ie. they are different beasts. file_list.sort asks the object whether it 
>has an attribute .sort or provideCompare the following two examples
>

Actually, that's not really true.  file_list.sort *is* an attribute... 
but it's also a method.  The difference is that without the parens, it 
resolves to an object reference (the object being a method object). 
 *With* the parens, it resolves the object reference and then calls that 
reference as a function.  Methods are just an attribute that happens to 
be a function (and has a little extra magic to pass the 'self' reference 
in).

As for what Python does when it sees 'file_list.sort' by itself on a 
line, or even 'x' by itself... well, it does exactly what you've told it 
to do -- nothing. ;)  It resolves the reference, and then looks to see 
if there's any operations to be done on the object it's found.  It 
doesn't see any operations there, so it quietly drops the reference into 
the garbage collector.  There *is* a special case, though -- when 
running Python in interactive mode (typing directly into an interpreter 
window, or in IDLE's or PythonWin's interactive window), the interactive 
interpreter won't just drop the reference.  It figures that you'd 
probably like to see *something* happen, and the most sensible thing to 
do with an object that's not operated on is to just display it.  So, if 
you do this in the interactive interpreter, you will get a response of 
'42' or of  '<method list.sort of list instance at 0x80028a04>' or whatever.

Jeff Shannon
Technician/Programmer
Credit International








From ramrom@earthling.net  Fri Dec 13 16:38:19 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Fri Dec 13 16:38:19 2002
Subject: [Tutor] How do you simulate a CGI script locally?
In-Reply-To: <5.1.0.14.0.20021213154115.02bca928@www.thinkware.se>
References: <200212122319.43961.shalehperry@attbi.com>
 <5.1.0.14.0.20021213170335.00aafa70@192.168.1.1>
 <200212121722.56528.wilson@visi.com>
 <5.1.0.14.0.20021213170335.00aafa70@192.168.1.1>
Message-ID: <5.2.0.9.0.20021213135909.03cca508@66.28.54.253>

At 04:30 PM 12/13/2002 +0100, Magnus Lycka wrote:
>If you don't have a web server, you can use this little one:
>#############
># mywebserver.py
>import BaseHTTPServer, SimpleHTTPServer, CGIHTTPServer
>
>class myRequestHandler(CGIHTTPServer.CGIHTTPRequestHandler):
>     def is_executable(self, path):
>         return self.is_python(path)
>
>if __name__ == '__main__':
>     SimpleHTTPServer.test(myRequestHandler, BaseHTTPServer.HTTPServer)
>#############
>
>Put "mywebserver.py" in a directory of your liking.
>
>Put your python CGI script (e.g. script.py) in a subdirectory
>called cgi-bin. (Script name must end .py etc, or you have to
>modify "is_ececutable" above.
>
>Run "mywebserver.py"
>
>Point your browser to "http://localhost:8000/cgi-bin/script.py

That's really cool. So easy!

But then I substituted my static IP address for localhost (example 
http://222.111.333.44:8000/cgi-bin/script.py). If the web server is running 
the browser hangs saying "loading". If the web server is not running the 
browser immediately reports that the connection was refused. What do I need 
to fix here?


Bob Gailer
mailto:ramrom@earthling.net
303 442 2625



From ramrom@earthling.net  Fri Dec 13 16:40:09 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Fri Dec 13 16:40:09 2002
Subject: [Tutor] BlackAdder
In-Reply-To: <E18Mwyq-0003FB-00@borgia.local>
References: <Message from Evelyn Mitchell <efm@tummy.com>
 <20021213194108.GA23974@tummy.com>
Message-ID: <5.2.0.9.0.20021213143808.03cb2008@66.28.54.253>

Anyone have any experience with BlackAdder and/or QT? Can recommend? Can 
disparage?

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625



From magnus@thinkware.se  Fri Dec 13 16:46:06 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri Dec 13 16:46:06 2002
Subject: [Tutor] Editors/form builders for GUI and productivity
In-Reply-To: <20021213160052.29082.qmail@web11305.mail.yahoo.com>
Message-ID: <5.1.0.14.0.20021213173832.02bee990@www.thinkware.se>

At 08:00 2002-12-13 -0800, MIG wrote:
>However, nowadys I feel I'm in a plateau with no advances in
>productivity, so I'm interested to hear (or read) about gui form
>buiders, python editors and others tools that may help.

In my opinion, GUI builders and other tools are of more
help at an initial level, and are something that you step
away from more and more as you develop.

How strong are your skills in Object-Oriented Programming
(and thinking)? How much are you able to resuse code?

Obviously, the amount of reuse will depend how similar
the applications you develop are, but I feel that in different
areas I tend to create code that I can reuse.

If you see that you repeatedly do the same thing over again,
there is room for some kind of reuse. You might want to make
a function that holds code that you tend to repeat, and import
and use that function, or if it's things that are similar but
varies a bit, you will make a class that you derive to specialize.

Maybe building menues should be as simple as writing something
like this:

self.menu = bulidmenu(
     'File' , ( ('New', self.file_new),
                ('Open', self.file_open),
                ...
                ('Quit', self.OnClose) ),
     'Edit', ...

Perhaps you often have a buttonbar and can find a similar kind of
shortcut like that.

By placing things like that in a library that you repeatedly use,
I think you can avdvance your productivity another step.



-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From dman@dman.ddts.net  Fri Dec 13 17:05:26 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Fri Dec 13 17:05:26 2002
Subject: [Tutor] Re: Editors/form builders for GUI and productivity
In-Reply-To: <20021213160052.29082.qmail@web11305.mail.yahoo.com>
References: <20021213160052.29082.qmail@web11305.mail.yahoo.com>
Message-ID: <20021213222034.GA13045@dman.ddts.net>

--TB36FDmn/VVEgNH/
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Dec 13, 2002 at 08:00:52AM -0800, MIG wrote:
[snip]
| I'm interested to hear (or read) about gui form buiders, python
| editors and others tools that may help.

Glade
    for GTK+, see also the 'libglade' library and the python bindings

wxDesigner
    for wxWindows (and the python bindings)

I really like the design of the glade/libglade combination.  With
libglade you don't actually generate any code, but instead load the
=2Eglade project file at runtime.  It greatly reduces the amount of
coding you have to do, and it allows for easy relayout of the GUI
without recoding everything.

HTH,
-D

--=20
Trust in the Lord with all your heart and lean not on your own
understanding; in all your ways acknowledge Him, and He will make your
paths straight.
        Proverbs 3:5-6
=20
http://dman.ddts.net/~dman/

--TB36FDmn/VVEgNH/
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj36XTIACgkQO8l8XBKTpRT8GgCfWwsiCxF6cuswU4q99L2xPLXn
ASwAni6Eukz8OWvYZHlUiz664VJTT5yI
=Aggz
-----END PGP SIGNATURE-----

--TB36FDmn/VVEgNH/--


From magnus@thinkware.se  Fri Dec 13 17:55:29 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri Dec 13 17:55:29 2002
Subject: [Tutor] Grokking immutability
In-Reply-To: <0E5508EBA1620743B409A2B8365DE16FDC8298@SOVEREIGN>
Message-ID: <5.1.0.14.0.20021213232059.02ba3e58@www.thinkware.se>

At 11:28 2002-12-13 -0800, Scott Widney wrote:
> > Oh, and while you're at it, what's the Meaning of Life?
>
>42

No it's not! 42 is the Ultimate Answer, as given by Deep
Thought. It's the answer to life, the universe and everything.
Completely different thing when you think about it.

The Meaning of Life is something entirely different...

"Now, here's the meaning of life. Thank you, Brigitte.

M-hmm. Well, it's nothing very special. Uh, try and be
nice to people, avoid eating fat, read a good book every
now and then, get some walking in, and try and live
together in peace and harmony with people of all creeds
and nations, and, finally, here are some completely
gratuitous pictures of penises to annoy the censors and
to hopefully spark some sort of controversy, which, it
seems, is the only way, these days, to get the jaded,
video-sated public off their fucking arses and back in the
sodding cinema. Family entertainment bollocks. What they
want is filth: people doing things to each other with
chainsaws during tupperware parties, babysitters being
stabbed with knitting needles by gay presidential candidates,
vigilante groups strangling chickens, armed bands of theatre
critics exterminating mutant goats-- Where's the fun in
pictures? Oh, well, there we are. Here's the theme music.
Goodnight."

http://bau2.uibk.ac.at/sg/python/Scripts/MeaningOfLife/mol.htm


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From SWidney@ci.las-vegas.nv.us  Fri Dec 13 18:35:02 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Fri Dec 13 18:35:02 2002
Subject: [Tutor] BlackAdder
Message-ID: <0E5508EBA1620743B409A2B8365DE16FDC829D@SOVEREIGN>

> Anyone have any experience with BlackAdder and/or QT? Can 
> recommend? Can disparage?

Boudewijn Rempt undoubtedly has experience with it. I doubt that he would
disparage; he wrote a book about it that's also online. Couldn't hurt to ask
him...

You can get his e-mail address and a link to his book from his website:
http://www.valdyas.org


Scott


From magnus@thinkware.se  Fri Dec 13 18:37:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri Dec 13 18:37:02 2002
Subject: [Tutor] How do you simulate a CGI script locally?
In-Reply-To: <5.2.0.9.0.20021213135909.03cca508@66.28.54.253>
References: <5.1.0.14.0.20021213154115.02bca928@www.thinkware.se>
 <200212122319.43961.shalehperry@attbi.com>
 <5.1.0.14.0.20021213170335.00aafa70@192.168.1.1>
 <200212121722.56528.wilson@visi.com>
 <5.1.0.14.0.20021213170335.00aafa70@192.168.1.1>
Message-ID: <5.1.0.14.0.20021213235736.02ba3d10@www.thinkware.se>

At 14:37 2002-12-13 -0700, Bob Gailer wrote:
>>But then I substituted my static IP address for localhost (example 
>>http://222.111.333.44:8000/cgi-bin/script.py). If the web server is 
>>running the browser hangs saying "loading". If the web server is not 
>>running the browser immediately reports that the connection was refused. 
>>What do I need to fix here?

I hope you don't have an IP address with 333 in it. ;)

Does it work properly to ping this address? Telnet to
it?

C:\> telnet 222.111.333.44 8000
should give a blank screen. Type "GET /" followe by [ENTER]
in the dark (it won't be echoed). After a little while
you should see HTML code followed by "connection to host
broken".

It all works for me. But I think IE (or is it windows?)
is sometimes very grumpy with these local names. Whatever
happens, I doubt it has anything to do with any python
code.

I can use either of

http://nida:8000/
http://192.168.XX.XX:8000/
http://localhost:8000/

locally, or

http://nida:8000/
http://192.168.XX.XX:8000/

remotely on Windows 2000.

Be very careful to allways prepend the URL with "http:"
when entering local addresses in MS IE. Just "nida:8000" or
"192.168.XX.XX:8000" will get transmogrified to the full
version (beginning with "http://") if I type it in on another
machine, but not if it happens to be the address of the
machine I'm typing it in to. Another reason to switch to a
real operating system? Oh well, in a few years we can run
MS Linux and get the best of both worlds...or will we? Or
will the version of Windows after XP simply be based on
BSD? (Who cares. An OS should be Unix, just as a car should
have the accelerator to the right, the break in the middle
and the clutch to the left. (A clutch is a device used in
non-American cars to make switching gears into a dexterious
feat instead of something the car handles by itself. That's
the way we like it. ;) )


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From mcp.bov@insightbb.com  Fri Dec 13 20:08:01 2002
From: mcp.bov@insightbb.com (Mike P)
Date: Fri Dec 13 20:08:01 2002
Subject: [Tutor] Idle
Message-ID: <000b01c2a30c$dd50a4a0$1de4dc0c@ct192133a>

Newbie here. Is the following normal for Idle?

Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> .15
0.14999999999999999
>>> 1.15
1.1499999999999999
>>> 11.15
11.15
>>> 111.15
111.15000000000001
>>>

Mike P


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.427 / Virus Database: 240 - Release Date: 12/6/2002


From dyoo@hkn.eecs.berkeley.edu  Fri Dec 13 20:29:03 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri Dec 13 20:29:03 2002
Subject: [Tutor] Re: Sorting Instance Attributes, cont'd.  [underscores,
 munged names, special functions, PencilNumber]
In-Reply-To: <20021213194923.10107.qmail@web20505.mail.yahoo.com>
Message-ID: <Pine.LNX.4.44.0212131706280.23113-100000@hkn.eecs.berkeley.edu>


On Fri, 13 Dec 2002, Alan Colburn wrote:

> OK, I think I've got the relationship between cmp and sort. Thank you
> :-)
>
> I thought it was interesting to see the function in action, as Danny set
> it up. Sometimes it seems like the function didn't "do" what it was
> supposed to do, but grinding away comparison after comparison it did
> eventually give us a nice sorted list. And, since we're working at
> computer speeds, I guess "eventually" translates to nanoseconds :-)

If you're ever interested in sorting techniques, we'd be happy to give
some sort of informal tutorial about them... *grin*



> Moving on, then ... The simplest solution to my question looked like
> this:
>
> class Student(object):
>     #Methods snipped.
>     def __lt__(self, other):
>         return self.lastname < other.lastname
>
> Tell me if I understand this next part correctly ... methods that begin
> with a double underscore are are "silent" and "private" to the class and
> its instances.

Yes.  This is purely a Python-specific thing: double-underscored names are
intercepted by Python's system, and munged up so that it becomes more
difficult to access them outside of the class.

###
>>> class ThingWithMungedAttribute:
...     __name = "Alan"
...
>>> ThingWithMungedAttribute.__name
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: class ThingWithMungedAttribute has no attribute '__name'
###



We can still see these munged attributes though:

###
>>> dir(ThingWithMungedAttribute)
['_ThingWithMungedAttribute__name', '__doc__', '__module__']
>>> ThingWithMungedAttribute._ThingWithMungedAttribute__name
'Alan'
###

but this underscore munging makes it hard to type accidently (or even
intentionally!).  So for all practical purposes, we treat it as a private
attribute.




However, that's only the case where there's a double underscore on only
the left side of the name.  When there's double underscores on BOTH sides,
that's a "special method" that ties into Python's object system; there's
no name munging involved for special methods.  Your second comment touches
on these special methods:

> In this case, we are overloading a method that's built into the
> class/instance, i.e., that's why you mean by "magic methods." Is that
> right?

There's a good list of all the magic methods that Python our hooks into:

    http://python.org/doc/current/ref/specialnames.html

If we browse through it, we'll see some pretty neat stuff: we can make our
objects look like a numeric type if we define the rest of the comparison
and arithmetic operations in:

    http://python.org/doc/current/ref/customization.html

###
>>> class PencilNumber:
...     def __init__(self, n):
...         self.n = n
...     def __add__(self, other):
...         return PencilNumber(self.n + other.n)
...     def __repr__(self):
...         n = self.n
...         chars = []
...         while n >= 5:
...             chars.append('/')
...             n = n - 5
...         chars.append('|' * n)
...         return ''.join(chars)
...
>>> p1 = PencilNumber(4)
>>> p1
||||
>>> p1 + PencilNumber(1)
/
>>> for i in range(20):
...     print i, PencilNumber(i)
...
0
1 |
2 ||
3 |||
4 ||||
5 /
6 /|
7 /||
8 /|||
9 /||||
10 //
11 //|
12 //||
13 //|||
14 //||||
15 ///
16 ///|
17 ///||
18 ///|||
19 ///||||
###

I dunno, I found the last example oddly mesmerizing to look at.  *grin*
But we can see that by defining __add__(), we're able to add two
PencilNumbers together by using the traditional syntax "x + y", rather
than "x.add(y)".





> Further, "lt" is essentially an abbreviation for "less than," and that
> method will be run when we call __cmp__ ... which happens when we call
> sort() :-)

Yes.  __lt__() also gets called when we do the '<' operator between two
instances.  That's what's "magical": even though we're saying 'a < b',
Python will retranslate that as 'a.__lt__(b)'.  In other languages, this
is known as "operator overloading".




> So, when I try to sort() the objects (which are in a list), the
> overloaded __lt__ method is invoked and returns 1 when one lastname is
> before the other lastname, and that 1 is in turn used by the __cmp__
> method.
>
> I'm still a little confused, but am I on the right track?

Yes, that's exactly right.  I don't think you're really that confused.
*grin*



Good luck!



From dyoo@hkn.eecs.berkeley.edu  Fri Dec 13 20:33:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri Dec 13 20:33:02 2002
Subject: [Tutor] Idle
In-Reply-To: <000b01c2a30c$dd50a4a0$1de4dc0c@ct192133a>
Message-ID: <Pine.LNX.4.44.0212131729050.23113-100000@hkn.eecs.berkeley.edu>


On Fri, 13 Dec 2002, Mike P wrote:

> Newbie here. Is the following normal for Idle?
>
> Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
> Type "copyright", "credits" or "license" for more information.
> IDLE 0.8 -- press F1 for help
> >>> .15
> 0.14999999999999999
> >>> 1.15
> 1.1499999999999999
> >>> 11.15
> 11.15
> >>> 111.15
> 111.15000000000001
> >>>

Hi Mike,

Yes, it's normal: Python's just being truthful when it's showing that it
doesn't represent real numbers.  Computers often use an approximation for
real numbers called "floating point" for practical reasons.

If we're interested, we can look at:

    http://www.python.org/doc/tut/node14.html

which covers these "floating point" numbers in more detail.


If we do want Python to print the number out so that it's more digestible
to our eyes, we can str() "string" it:

###
>>> x = 111.15
>>> x
111.15000000000001
>>> str(x)
'111.15'
###

which is probably more what we expect to see.


Good luck to you!



From magnus@thinkware.se  Fri Dec 13 20:35:13 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri Dec 13 20:35:13 2002
Subject: [Tutor] Idle
In-Reply-To: <000b01c2a30c$dd50a4a0$1de4dc0c@ct192133a>
Message-ID: <5.1.0.14.0.20021214022617.02c5a590@www.thinkware.se>

At 20:05 2002-12-13 -0500, Mike P wrote:
>Newbie here. Is the following normal for Idle?

It's not IDLE, it's binary representation of floating
point numbers presented as decimal numbers...

See http://www.python.org/doc/current/tut/node14.html

>Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
>Type "copyright", "credits" or "license" for more information.
>IDLE 0.8 -- press F1 for help
> >>> .15
>0.14999999999999999

If you type "print .15" instead, python won't show
all available decimals, and these rounding errors
won't show.

But this just means that 0.15 can't be represented exactly
in binary, any more than 2/3 can be represented exactly in
decimal. What is worse is the kind of rounding problems this
might lead to:

 >>> 0.2
0.20000000000000001
 >>> 0.2 + 0.2 - 0.2 -0.2
0.0
 >>> 0.2 + 0.2 + 0.2 - 0.2 - 0.2 -0.2
5.5511151231257827e-017

Always beware of floating point numbers... Never compare
on equality without a fuzz-factor for instance. If x and
y are float: Never do "if x = y:" or "if x - y == 0:".
Do something like "if abs(x-y) < 1e-10:" instead.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From op73418@mail.telepac.pt  Fri Dec 13 21:20:02 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Fri Dec 13 21:20:02 2002
Subject: [Tutor] Re: Sorting Instance Attributes, cont'd.
References: <20021213194923.10107.qmail@web20505.mail.yahoo.com>
Message-ID: <001801c2a318$116ffe10$a9160dd5@violante>

----- Original Message -----
From: "Alan Colburn" <aicolburn@yahoo.com>
To: "PythonTutor" <tutor@python.org>
Sent: Friday, December 13, 2002 7:49 PM
Subject: [Tutor] Re: Sorting Instance Attributes, cont'd.


> OK, I think I've got the relationship between cmp and
> sort. Thank you :-)
>
> I thought it was interesting to see the function in
> action, as Danny set it up. Sometimes it seems like
> the function didn't "do" what it was supposed to do,
> but grinding away comparison after comparison it did
> eventually give us a nice sorted list. And, since
> we're working at computer speeds, I guess "eventually"
> translates to nanoseconds :-)
>
> Moving on, then ... The simplest solution to my
> question looked like this:
>
> class Student(object):
>     #Methods snipped.
>     def __lt__(self, other):
>         return self.lastname < other.lastname
>
> Tell me if I understand this next part correctly ...
> methods that begin with a double underscore are are
> "silent" and "private" to the class and its instances.

What do you mean by "silent" and "private"? I think I know what you mean but
it's better if you're more explicit.

> In this case, we are overloading a method that's built
> into the class/instance, i.e., that's why you mean by
> "magic methods." Is that right?

Overloading? You mean overriding? Overriding is when you redefine a method
fom a base class in some derived class, and in this case, no, you are not
overriding anything. The class object (your base class) does not define
__lt__. These methods are called magic for two reasons at least: They are
surrounded by __ on both sides which is the unimportant reason, and for the
important reason, when you employ special syntax (e.g. < get's "translated"
into a call for __lt__) or in some special conditions (e.g. methods like
__del__ and __getattr__).

>
> Further, "lt" is essentially an abbreviation for "less
> than," and that method will be run when we call

Right. When a class defines an __lt__ method it is essentially telling the
world (its clients) that is instances are comparable by __lt__.

> __cmp__ ... which happens when we call sort() :-)

__cmp__ is the "old" version for making instances comparable. Back in the
old days there was only __cmp__ but in Python 2.0 rich comparisons (__lt__,
__gt__, etc.) were introduced. __cmp__ is still around with us, also because
of backwards compatibility, but the prefered way is to use __lt__, etc. And
don't worry, the sort method is smart enough to know what to use.

>
> So, when I try to sort() the objects (which are in a
> list), the overloaded __lt__ method is invoked and
> returns 1 when one lastname is before the other
> lastname, and that 1 is in turn used by the __cmp__
> method.

The rule sort uses is simpler. First it looks for __lt__, etc., if it does
not have them then it goes after __cmp__. It only uses one of them of
course. Of course you can define both, and have them call each other but
that's your problem not sort's.

>
> I'm still a little confused, but am I on the right track?
>

I'm not sure if I have been clear, but if I wasn't just holler. Also, other
people here more experienced than I (at both in Python and in explaining
Python) may jump in and help.

All the best,
G. Rodrigues



From j.pollack@m.cc.utah.edu  Fri Dec 13 23:04:01 2002
From: j.pollack@m.cc.utah.edu (Joshua Pollack)
Date: Fri Dec 13 23:04:01 2002
Subject: [Tutor] migration simulation
Message-ID: <3DFAAD59.6000808@m.cc.utah.edu>

This is a multi-part message in MIME format.

--Boundary_(ID_iur2IoBeA0oaJNJIFtY31Q)
Content-type: text/plain; charset=us-ascii; format=flowed
Content-transfer-encoding: 7BIT

I


Hi all,

There's been some talk of simulation stuff using python lately, and I 
thought I'd pose a question I had.  I'm super new to python and 
programming general
so this isn't particularly noteworthy but...

I've a migration simulation that's part of a bigger drift and selection 
model.  In the migration section, I define a population as being made of
subpopulations and then pop out migrants from the subpops at a given 
probability.  The migrants then get re-inserted into subpops randomly.
It's all very simple except I'm having a problem with back migration. 
 Migrants will sometimes migrate back to their original population. 
 Does anyone know of a
a way to tag each migrant so that I can make sure they don't 
back-migrate?  See attached code.

Thanks so much!!

Joshua Pollack

P.S. -f this gets sent twice, please ignore message #2.  Thanks again.






--Boundary_(ID_iur2IoBeA0oaJNJIFtY31Q)
Content-type: text/plain; name=migrate.py
Content-transfer-encoding: 7BIT
Content-disposition: inline; filename=migrate.py

## Migration Simulation
import random

## Create subpopulations
sf=[0]*5+[1]*5
la=[2]*5+[3]*5
biloxi=[4]*5+[5]*5
migrants=[]

## Join subpops into single pop
all=[sf,la,biloxi]
print "pre-migrate:", all

## Pull out migrants at a probability of 5%
for i in all:
    for j in i:
        if random.random()<=.05:
            migrants.append(i.pop(j))

## Drop migrants back into random subpopulations    
for i in migrants:
    random.choice(all).append(i)
print "post-migrate:", all




--Boundary_(ID_iur2IoBeA0oaJNJIFtY31Q)--


From idiot1@netzero.net  Sat Dec 14 01:42:01 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Sat Dec 14 01:42:01 2002
Subject: [Tutor] automating list deletion
Message-ID: <3DFAD312.5090408@netzero.net>

OK, I got it to work with the cgi script and the aliases file.

1. Seperated out the aliases for lists into another file, 'aliases.tinylist'.

2. edited sendmail.cf so it referrs to an additional file, 
/etc/mail/aliases.tinylist, and it works fine. newaliases works with the new 
file just fine.

3. ok, panick time, take your asprin and calming meditation exercises serious. 
I assigned ownership of ~/mail dir( that is, '/etc/mail') to 'nobody', the 
apache identity. Group membership remained the same ('wheel'). I insured all 
the aliases files are readable by group and world, but only writable by owner. 
A test run shows the script can now write to the dir and read and write to the 
files there.

I am still getting an error, but it is a different error. Files are being 
deleted fine, but somehow I still have soem sort of a permissions error going 
on here. Anyone relly cunning on such matters drop me a line off list and we 
can swap confusion modes.



-- 

end

Respectfully,
              Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                            +--------+

---------------------------------------------
Introducing NetZero Long Distance
1st month Free!
Sign up today at: www.netzerolongdistance.com


From idiot1@netzero.net  Sat Dec 14 02:02:02 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Sat Dec 14 02:02:02 2002
Subject: [Tutor] Deletion of email lists via web script-the saga continues...
Message-ID: <3DFAD7CB.9090409@netzero.net>

OK, it is giving me this error:

Traceback (innermost last):
   File "/www/www.tinylist.org/cgi-bin/TLlistkill2.py", line 187, in ?
     if mylist not in aliasline:	# if this is NOT the alias to remove,
TypeError: string member test needs char left operand.

This may relate to the structure of the aliases file. here are the first 
several lines of it:


ns# list aliases.tinylist
Listing of file aliases.tinylist in directory:/etc/mail

# this is the tinylist aliases file. only list aliases go in here.
# aliases pointing at listmaster or to capture bounces go in the regular
# aliases file. Make sure this file is owned by 'nobody:wheel'.
#
# tinylist.org domain lists:
tinylist-devlopers:"|/www/www.tinylist.org/cgi-bin/TLpost.py tinylist-devlopers"
tinylist-users:"|/www/www.tinylist.org/cgi-bin/TLpost.py tinylist-users"
testlist3:"|/www/www.tinylist.org/cgi-bin/TLpost.py testlist3"
secret:"|/www/www.tinylist.org/cgi-bin/TLpost.py secret"
biglist:"|/www/www.tinylist.org/cgi-bin/TLpost.py biglist"


The web script posted this oputput- and aborted at the error:

WORKING...


List found, proceeding...

PASSWORD AND EMAIL MATCH UP. INITIATING DESTRUCTION SEQUENCE...

['./lists/testlist3.info', './lists/testlist3.owner']

./lists/testlist3.info
./lists/testlist3.owner
# this is the tinylist aliases file. only list aliases go in here.

That last line is the first line of the aliases file. Hmmm...


-- 

end

Respectfully,
              Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                            +--------+

---------------------------------------------
Introducing NetZero Long Distance
1st month Free!
Sign up today at: www.netzerolongdistance.com


From dyoo@hkn.eecs.berkeley.edu  Sat Dec 14 04:13:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat Dec 14 04:13:01 2002
Subject: [Tutor] PyMat installation
In-Reply-To: <00db01c2a1f0$90fd2f50$6501a8c0@superyethzer>
Message-ID: <Pine.LNX.4.44.0212121230070.26167-100000@hkn.eecs.berkeley.edu>


On Thu, 12 Dec 2002, Stephan Huijgen wrote:

> Where do i have to install PyMat, when i have downloaded it? in the
> Python2.0 dir? or in a subdirectory?

I'm guessing that you mean the 3rd party PyMat module here:

    http://claymore.engineer.gvsu.edu/~steriana/Python/pymat.html

Your question is somewhat specialized: you may want to ask on the main
comp.lang.python newsgroup to see if anyone has experience with PyMat; I'm
not sure if any of us here have worked with it yet.  Perhaps someone can
take some time to nicely package this module using the distutils, so that
it's easier for you to install?

By the way, what kind of platform are you running?



From magnus@thinkware.se  Sat Dec 14 07:59:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat Dec 14 07:59:01 2002
Subject: [Tutor] migration simulation
In-Reply-To: <3DFAAD59.6000808@m.cc.utah.edu>
Message-ID: <5.1.0.14.0.20021214130817.02ba45b8@www.thinkware.se>

At 20:02 2002-12-13 -0800, Joshua Pollack wrote:
>## Create subpopulations
>sf=[0]*5+[1]*5
>la=[2]*5+[3]*5
>biloxi=[4]*5+[5]*5

It's a bit strange that you use integers to represent individuals.
And later you confuse things a bit because of that it seems.

Why did you make that choise. What does the numbers represent?

>migrants=[]
>
>## Join subpops into single pop
>all=[sf,la,biloxi]
>print "pre-migrate:", all
>
>## Pull out migrants at a probability of 5%
>for i in all:
>     for j in i:
>         if random.random()<=.05:
>             migrants.append(i.pop(j))

Here you make several mistakes I think.

First of all, you don't use descriptive variable names,
and that is always bad. You should realize that i and j
are ususally used for index-values, but Python for loops
operate over elements in sequences. Let's rename i and j.

While we're at it, let's make the magic number explicit.
It's much, much better to place descriptions in names that
the programs use than in comments that the program ignores.

migrationRate = 0.05
for population in all:
     for person in population:
         if random.random()<=migrationRate:
             migrants.append(population.pop(person))

Now we see another mistake clearly. The list.pop() method
takes an integer that indicates the index of the element to
pop from the list. But that's not what we feed it. The number
we feed it indicates a person, not a position in the list,
right? This confusion would never have happened with another
type than integer to represent individuals.

migrationRate = 0.05
for population in all:
     for person in population:
         if random.random()<=migrationRate:
             migrants.append(population.pop(
                               population.index(person)))

Now you will pick out the integer you were working with
in the for loop, not the one located at the position that
the number of the current person indicated. (If you don't
see what I mean, pop up migrationRate to 0.95 and change
"biloxi=[4]*5+[5]*5" to "biloxi=[4]*5+[9]*5" as see what
happens with your old code.

We still have a problem though, your original problem. We
just mixed individuals of all populations in one big list,
and they don't have any passports.

One solution would be to have one list of migrants for each
population they come from (a list of lists, like "all"), and
to make sure that you don't put them back in the population
with the same index in all as the one of the list.

A second solution could be not to store them in any inter-
mediate storage at all, but to immediately pick out a new
population among all but the one they came from (I guess
you have to pick out a random population in a loop until
you find one that's not the same as original population
(which you should know at this point in time).

A third solution would be to make the persons a bit more
full features than just integers. But maybe it's a bit to
early in your learning to introduce classes and object-
oriented programming? (The code below doesn't do quite the
same as your code, but it might give some hints on a
different approach...

import random
migrateRate = 0.05

class Populations:
     def __init__(self):
         self.persons = []

     def add(self, person):
         self.persons.append(person)

     def write(self):
         self.persons.sort()
         thisPop = None
         popCnt = 0
         for person in self.persons:
             if person.population != thisPop:
                 if popCnt:
                     print popCnt
                 popCnt = 0
                 thisPop = person.population
                 print thisPop,
             print '.',
             popCnt += 1
         print popCnt

class Person:

     def __init__(self, population):
         self.population = population

     def migrate(self, population):
         self.population = population

     def __cmp__(self, other):
         return cmp(self.population, other.population)

popList = Populations()

popNames = ('sf', 'la', 'biloxi')
popSizes = (10, 10, 10)

for popName, popSize in zip(popNames, popSizes):
     for i in range(popSize):
         popList.add(Person(popName))
popList.write()

for person in popList.persons:
     if random.random() < migrateRate:
         while 1:
             newPop = random.choice(popNames)
             if newPop != person.population:
                 break # Found a good new population
         person.migrate(newPop)
popList.write()




-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From din22@cox.net  Sat Dec 14 10:10:02 2002
From: din22@cox.net (david)
Date: Sat Dec 14 10:10:02 2002
Subject: [Tutor] my newbie program
References: <5.1.0.14.0.20021126105534.02b1fe70@www.thinkware.se><5.1.0.14.0.20021127121448.035a5a80@www.thinkware.se> <5.1.0.14.0.20021211114251.02bcece8@www.thinkware.se>
Message-ID: <000401c2a382$abbc1020$fc550144@pn.at.cox.net>

hello everyone and thanks for all your help and patience so far.
i finally understood about getting my rooms to share a map
object. now its a world object because there is a python function
called map. y'all probably knew that. anyway i am working on
my dig method and i am thinking my exits are all messed up.
i will be wanting to add doors both locked and unlocked next.
so if anyone can help with a better room exit. or any comments
at all. 

import string
import sys

class World:
    def __init__(self):
        self.grid={}
    def addRoom(self,room,x,y):
        if self.grid.has_key((x,y)):
            raise KeyError,"location occupied"
        self.grid[(x,y)]=room
    
class Room:
    world = World()
    def __init__(self,x,y):
        self.desc="a nondescript room"
        self.exits=[]
        self.world.addRoom(self,x,y)
        self.coords=(x,y)
    def dig(self,dir):
        pass

class Parser:
    pass

class Actor:
    def __init__(self,location):
        self.location=location
    def DoCommand(self,cmd):
        if cmd == 'look':
            print self.location.desc
        elif cmd == 'exit':
            sys.exit()
        else:
            print 'unknown command'

class Player(Actor):
    def act(self):
        cmd = string.lower(raw_input('>'))
        self.DoCommand(cmd)
        
startroom=Room(0,0)
newroom=Room(0,1)
me=Player(startroom)

while 1:
    me.act()




From ramrom@earthling.net  Sat Dec 14 12:09:01 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Sat Dec 14 12:09:01 2002
Subject: [Tutor] How do you simulate a CGI script locally?
In-Reply-To: <5.1.0.14.0.20021213235736.02ba3d10@www.thinkware.se>
References: <5.2.0.9.0.20021213135909.03cca508@66.28.54.253>
 <5.1.0.14.0.20021213154115.02bca928@www.thinkware.se>
 <200212122319.43961.shalehperry@attbi.com>
 <5.1.0.14.0.20021213170335.00aafa70@192.168.1.1>
 <200212121722.56528.wilson@visi.com>
 <5.1.0.14.0.20021213170335.00aafa70@192.168.1.1>
Message-ID: <5.2.0.9.0.20021214094315.019c9d78@66.28.54.253>

At 12:39 AM 12/14/2002 +0100, Magnus Lycka wrote:
>I hope you don't have an IP address with 333 in it. ;)

Yeah, just typing a fake address.

Now when I try it I get a response; it takes some time, though.

Monitoring the server window and using telnet, it takes about 12 seconds 
for the server to see the request and another 12 to get the response back 
in the telnet window.

Tracert shows one hop.

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625



From kyle@sent.com  Sat Dec 14 18:17:03 2002
From: kyle@sent.com (Kyle Babich)
Date: Sat Dec 14 18:17:03 2002
Subject: [Tutor] Simple Question
Message-ID: <000501c2a3c6$e8b93860$69608aac@chuck>

How do I create a file?
I was always under the impression that if I attempted to open a file that
didn't exist then the file would be created automatically.  Now that I need
something like that it doesn't happen.  I have 2.2.2 running on XP Home.

Thank you,
Kyle Babich



From magnus@thinkware.se  Sat Dec 14 19:07:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat Dec 14 19:07:01 2002
Subject: [Tutor] Simple Question
In-Reply-To: <000501c2a3c6$e8b93860$69608aac@chuck>
Message-ID: <5.1.0.14.0.20021215010431.02af9f28@www.thinkware.se>

At 18:16 2002-12-14 -0500, Kyle Babich wrote:
>How do I create a file?
>I was always under the impression that if I attempted to open a file that
>didn't exist then the file would be created automatically.  Now that I need
>something like that it doesn't happen.  I have 2.2.2 running on XP Home.

By default, you open files just to read them.
You can't read from a new file...

f = file('newfile.txt', 'w')
f.write('some text\n')
f.close()

See http://www.python.org/doc/current/lib/built-in-funcs.html



-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Sat Dec 14 19:12:25 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat Dec 14 19:12:25 2002
Subject: [Tutor] How do you simulate a CGI script locally?
In-Reply-To: <5.2.0.9.0.20021214094315.019c9d78@66.28.54.253>
References: <5.1.0.14.0.20021213235736.02ba3d10@www.thinkware.se>
 <5.2.0.9.0.20021213135909.03cca508@66.28.54.253>
 <5.1.0.14.0.20021213154115.02bca928@www.thinkware.se>
 <200212122319.43961.shalehperry@attbi.com>
 <5.1.0.14.0.20021213170335.00aafa70@192.168.1.1>
 <200212121722.56528.wilson@visi.com>
 <5.1.0.14.0.20021213170335.00aafa70@192.168.1.1>
Message-ID: <5.1.0.14.0.20021215010917.02b03188@www.thinkware.se>

At 10:07 2002-12-14 -0700, Bob Gailer wrote:
>Monitoring the server window and using telnet, it takes about 12 seconds 
>for the server to see the request and another 12 to get the response back 
>in the telnet window.

:( For me, running Win2k on a 700MHz Duron it takes about 1 second
to get the blank screen with telnet, and when I type "GET /[enter][enter]"
I get an immediate response from my web server program which is derived
from the Python web server classes.

>Tracert shows one hop.

Sounds like a local address...

I'm not sure what is happening, if it tries to connect to some network
server to check things up before doing anything on the network, or what.
I'm pretty sure the delay don't have anything to do with Python if it's
not the execution of the script itself that is so slow.

What happens if you just run the script on its own? (You might need to
set up some environment variables to simulate the environment of the
web server.)


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From michael@trollope.org  Sat Dec 14 20:25:01 2002
From: michael@trollope.org (Michael Powe)
Date: Sat Dec 14 20:25:01 2002
Subject: [Tutor] How do you simulate a CGI script locally?
In-Reply-To: <5.1.0.14.0.20021213170335.00aafa70@192.168.1.1>; from fredm@smartypantsco.com on Fri, Dec 13, 2002 at 05:08:22PM +1000
References: <200212121722.56528.wilson@visi.com> <5.1.0.14.0.20021213113110.00aac450@192.168.1.1> <5.1.0.14.0.20021213170335.00aafa70@192.168.1.1>
Message-ID: <20021214172426.A28343@titan.spiretech.com>

you might try this:

http://www.embl-heidelberg.de/~chenna/pythonpages/cgimadeeasy.html

perl's cgi.pm will create a cgi environment when a script using it is
run from the command line, just for this reason.  perhaps, you should
suggest that the python cgi module include similar functionality.

however, the above appears to be a module designed to do the same thing.

mp


On Fri, Dec 13, 2002 at 05:08:22PM +1000, Alfred Milgrom wrote:
> I guess this is a pretty stupid question, but I haven't been able to find 
> the answer anywhere.
> 
> I want to develop a CGI script, and I'd like to test it locally (I mean on 
> my own computer, running Windows), rather than uploading the file to the 
> server, testing it, revising it, and so on.
> 
> My question is: how do I make my Python program behave like a CGI script, 
> where print statements end up shown in the browser window. If I point my 
> browser at my CGI test file, it runs, but the output goes to the DOS box 
> instead.
> 
> Any help would be appreciated.
> Thanks,
> Alfred Milgrom
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


From magnus@thinkware.se  Sat Dec 14 20:39:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat Dec 14 20:39:01 2002
Subject: Fwd: Re: [Tutor] migration simulation
Message-ID: <5.1.0.14.0.20021215011531.02b5a4b8@www.thinkware.se>

>From: jpollack@socrates.Berkeley.EDU
>To: Magnus Lycka <magnus@thinkware.se>
>Subject: Re: [Tutor] migration simulation

Hi Joshua, I suggest that we stay on the tutor list.

>Magnus:
>
>Thanks so much for the clear and lucid commentary.  I am indeed very new
>to python and, as you could tell, programming in general.  I'm doing my
>Phd in genetics, though, and it requires some powerful tools to deal with
>genomic information.  So I decided to try to learn a programming language
>and python was what it ended up being.

A wise choise I think. Have you had a look at:
http://www.thinkware.se/cgi-bin/thinki.cgi/PythonInScience ?

What you need might be written already... :)

>In answer to your earlier questions, I chose numbers to represent people
>because, when this is all done, each individual will be binary in nature,
>either they have a certain genetic marker, or didn't.  (I changed to 1-5
>in the practice simulation just so I could keep track easier...)
>So, at somepoint, there will be a bunch of subpopulations all filled with
>0's and 1's.  What I'm interested in is the stochasticity of migration and
>genetic drift and how quickly the overall levels of a gene or lack thereof
>change over time.  Is there a better method, do you think?

If the persons are instances of a class, you can give them attributes
that exactly match your needs. Due to Pythons dynamic nature, you can
make a very simple class:

class Person:
     pass

p1 = Person()
p1.population = 'sf'
p1.marker = 1

print p1.poulation
sf
print p1.marker
1

But be aware that if you do

l = [p1, p1, p1, p1]

you will have a four element list with THE SAME person four
times, not four identical persons. I.e.

l[2].population = 'la'

for p in l:
     print p.population
la
la
la
la

You don't need to be more OO than that. The rest of the
program can look more or less as it does today.

You would probably benefit from a slightly more advanced
class though.

class Person:
     def __init__(self, population, marker):
         self.population = population
         self.marker = marker
     def migrate(self, population):
         self.population = population
     def __str__(self):
         return str(self.marker)

p1 = Person('sf', 5)
print p1
5
print p1.population
sf
p1.migrate('la')
print p1.population
la

>Lastly, I'd thought about immediately migrating individuals, but I think
>the intermediary storage is a better idea.  Isn't it the case that, with
>immediate migration, an individual would stand a chance of migrating
>twice?  (i.e.- lands in a list in a subsequen forloop).

You are absolutely correct, but that's easy to avoid. Loop
over a copy of the original population instead of looping
over the dynamic list. But that requires that you copy all
groups before the first possible migration.

The simplest way to copy a list l is to write

copy_of_l = l[:]

This means that you make a slice from the first to the last element.

all = [sf, la, biloxi]
all_copy = [x[:] for x in all] # <= So called list comprehension
for pop_copy in all_copy:
     ...

Also, you still have the option to to have one list per
population. One list for people migrating from 'la', one for
people migrating from 'sf' and so on. When you pick people
from these lists, you can make sure you don't put them back
where they came from.

And you have the OO solution...

>That I don't
>want.  Eventually, the code will be part of a bigger for loop that will
>represent generational migration.
>
>All that said, I've been interested in classes and read a couple of things
>describing them, but I can't seem to get my head around OOP very well.  Do
>you have any suggestions?  Thanks for all your help.

I had been programming for many years before I approached OOP,
and it took quite a while before I understood what it was about.
Although, in those days, I had neither Python nor Tutor... ;)

Could you follow the code I wrote before?

Does anyone else have suggestions for good OOP introductions?

I guess OO isn't really such a big thing.

You store code and data that are related to each other together
in a class.

In this case you have Persons with certain characteristics, certain
attributes, such as what population the belong to, and what certain
genetic marker they have. They also have certain behaviour, such as
the ability to migrate and the ability to prosent themselves. These
data and capabilities of Persons should be collected in a Person
class.

You also have Populations which should have the ability to present
a summary of what they contain and to list the persons that belong
to each population and so on. It's really an open question here
whether to have a class describing one Population that you instanciate
one of per population, or a class that keep track of all populations
that you only instanciate one of. I choose the latter in my previous
mail.

Python has the 'class' construct to keep track of these kinds of
things. A class defines the things that are common for all instances
of a class.

For instance, let's imagine that you have a class Greeter that is
able to greet people in what ever way you like.

 >>> class Greeter:
...     def __init__(self, greeting='Hello'):
...             self.greeting = greeting
...     def to(self, person):
...             print self.greeting, person
...
 >>> hello = Greeter()
 >>> hello.to('John')
Hello John
 >>> hi = Greeter('Hi')
 >>> hi.to('Graham')
Hi Graham
 >>> hello.to('Terry')
Hello Terry
 >>> hi.to('Eric')
Hi Eric

An instance will be created when you call the class as if it
was a function. This call will return an instance object. All
functions in a class, called methods, take the instance object
(a new in the case of __init__ and the one that makes the
invokation for the methods) as its first parameter (typically
called self), and then whatever other parameters you say.
Constructs like "self.x = 5" in the methods means that you
attach an attribute to the instance object that will stay
there even after the method has finished (in contrast to
local variables in the method/function that will disappear
when the function they werw created in ends).

In other words...

 >>> class Greeter:
Let's define a class called "Greeter"
...     def __init__(self, greeting='Hello'):
When we call a class, it's .__init__() method is invoked
to control what happens on instance creation. __init()
takes a parameter that we call "greeting" on it's creation.
If "greeting" is not provided, use default value 'Hello'.

...             self.greeting = greeting
Then attach given or default value of "greeting" to the
instance attribute .greeting.

...     def to(self, person):
Then add a method called to, that takes a parameter "person"

...             print self.greeting, person
which prints the instance attribute .greeting followed by
the value of the variable person.

...
 >>> hello = Greeter()
Create an instance with the default .greeting 'Hello'.
Let's refer to it with a variable called hello.

Pseudocode explaining what "hello = Greeter()" means
could look like this.

hello = <new instance of class Greeter>
Greeter.__init__(hello)

 >>> hello.to('John')
Short-cut for "Greeter.to(hello, 'John')" or more
generally "hello's class.to(hello, 'John')". I.e.
call hello's .to()-method with parameter 'John'
 >>> hi = Greeter('Hi')
Create another Greeter instance with .greeting
attribute set to 'Hi'.

 >>> hi.to('Graham')
This will then give a different greeting when we call it's
.to() method. "Hi Graham".

 >>> hello.to('Terry')
The first variable, hello, still has the greeting 'Hello'!
There attributes are tied to instances, not shared in the
class.

There is much more to classes that this, but this is the
foundation. With this kind of constructs, you can create
"intelligent" data types. Thus you can make smart object
that can carry whatever attributes/values you like, and
also has built-in behaviour, so that it knows how to
behave.

For now, I guess it's the attributes that will be useful
for you, but organizing code in classes will make larger
programs more easy to write and maintain as you organize
things that have to do with each other in a more logical
(and local) way.

Some OO Heuristics:

A class should capture one and only one key abstraction.

Keep related data and behaviour in one place.

Users of a class must depend on its public interface, but
a class should not depend on it's users.

Distribute system intelligence horizontally as uniformly
as possible.


/Magnus

Just tasted Laphroaig 30 y.o, Laphroaig 10 y.o. cast strength
and Bowmore 30 y.o. :)


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From tony@tcapp.com  Sun Dec 15 03:37:03 2002
From: tony@tcapp.com (Tony Cappellini)
Date: Sun Dec 15 03:37:03 2002
Subject: [Tutor] Need help setting up IDE for PythonW32
Message-ID: <5.1.0.14.0.20021215004255.00b10b18@wheresmymailserver.com>

I'm using PythonW32 on a Win200 machine.

I can't seem to get the IDE to recognize the script directory, which is 
already in my path, AND specified in the PYTHON path variable.

I just want to be able to load my scripts from the directory where the 
scripts are, without having to CD or specify the entire path each time I 
start a new session.

Danny- you tried helping me at the last Baypiggies meeting, but that 
doesn't seem to work.

What am I doing wrong ?

Tony



From aztech1200@yahoo.com  Sun Dec 15 07:01:01 2002
From: aztech1200@yahoo.com (Aztech Guy)
Date: Sun Dec 15 07:01:01 2002
Subject: [Tutor] Better (free) IDEs than IDLE for Linux ?
Message-ID: <20021215120021.88655.qmail@web9802.mail.yahoo.com>

--0-1469873621-1039953621=:88216
Content-Type: text/plain; charset=us-ascii


Hi,

Which other (free) IDE's / enhanced Py interpreters do you like better the standard Python interpreter and IDLE - for Linux ? I am using PythonWin on Windows, is good enough for me at present. I just downloaded IPython for Linux and will be trying it out soon, will post my impressions. But wondered about experience of others. I do know about some of the available ones, from the one or two reviews that are there on the Python and other sites. But would like to hear opionions of people who have already tried out some, before downloading any of them. Both non-GUI enhanced interpreters - of which I think IPython is one - and proper GUI IDE's are of interest.

I'll summarize.

TIA.

Az.

 

 



---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now
--0-1469873621-1039953621=:88216
Content-Type: text/html; charset=us-ascii

<P>Hi,</P>
<P>Which other (free) IDE's / enhanced Py interpreters do you like better&nbsp;the standard Python interpreter and IDLE -&nbsp;for Linux ? I am using PythonWin on Windows, is good enough for me at present. I just downloaded IPython for Linux and will be trying it out soon, will post my impressions. But wondered about experience of others. I do know about some of the available ones, from the one or two reviews that are there on the Python and other sites. But would like to hear opionions of people who have already tried out some, before downloading any of them. Both non-GUI enhanced interpreters - of which I think IPython is one - and proper GUI IDE's are of interest.</P>
<P>I'll summarize.</P>
<P>TIA.</P>
<P>Az.</P>
<P>&nbsp;</P>
<P>&nbsp;</P><p><br><hr size=1>Do you Yahoo!?<br>
<a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Yahoo! Mail Plus</a> - Powerful. Affordable. <a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Sign up now</a>
--0-1469873621-1039953621=:88216--


From magnus@thinkware.se  Sun Dec 15 08:09:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sun Dec 15 08:09:01 2002
Subject: [Tutor] Better (free) IDEs than IDLE for Linux ?
In-Reply-To: <20021215120021.88655.qmail@web9802.mail.yahoo.com>
Message-ID: <5.1.0.14.0.20021215135459.02b78a38@www.thinkware.se>

At 04:00 2002-12-15 -0800, Aztech Guy wrote:
>Which other (free) IDE's / enhanced Py interpreters do you like better the 
>standard Python interpreter and IDLE - for Linux ? I am using PythonWin on 
>Windows, is good enough for me at present. I just downloaded IPython for 
>Linux and will be trying it out soon, will post my impressions. But 
>wondered about experience of others. I do know about some of the available 
>ones, from the one or two reviews that are there on the Python and other 
>sites. But would like to hear opionions of people who have already tried 
>out some, before downloading any of them. Both non-GUI enhanced 
>interpreters - of which I think IPython is one - and proper GUI IDE's are 
>of interest.

I've tested IPython (0.2.14pre46) on Win32 recently, and it
doesn't seem to work as well there as I think it does in
Linux. Color doesn't work, neither does autocompletion etc.

A minimalistic IDE, more intended to non-programmers who want
to use python as an advanced calculator is Jean-Michel Fauth's
psi.

I recently tried Boa Constructor, and if you use wxPython for
GUI building, I think this is something to look closer at. I've
mainly tried the debugging features, and they are impressive.
I've never seen anything work well for debugging wxPython GUI
code in a GUI before. It's not as good as PythonWin for pure
editing in my opinion, and I haven't tried the GUI building
features, but I think this will be a serious contender to the
commercial products such as Wing and wxDesigner in time...

I think Boa works as well with Linux as with Windows.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From aztech1200@yahoo.com  Sun Dec 15 09:26:01 2002
From: aztech1200@yahoo.com (Aztech Guy)
Date: Sun Dec 15 09:26:01 2002
Subject: [Tutor] Better (free) IDEs than IDLE for Linux ?
In-Reply-To: <5.1.0.14.0.20021215135459.02b78a38@www.thinkware.se>
Message-ID: <20021215142547.66424.qmail@web9804.mail.yahoo.com>

--0-350225864-1039962347=:66242
Content-Type: text/plain; charset=us-ascii


Thanks. I'll check out Boa. Actually, I haven't started with Python GUI programming. So far only CUI. But am planning to do it soon. I was going to go with PyQt, based on a little experience with Qt (with C++, using the example programs - also the Qt docs seem very good)) and based on some articles by Boudewijn Rempt and Cameron Laird, who recommend it. (Not really done an in-depth analysis before making this decision, because I don't have a lot of GUI development experience anyway - just done a little in VB and Delphi. Mostly worked on UNIX/DOS/WIndows CUI apps.) Do you use wxPython ? What's your opinion about it vs. PyQt ? 
BTW, I liked your series of replies to Poor Yorick about separation of GUI logic from business logic - it helped me to understand this area a little better.
Az.
 Magnus Lycka <magnus@thinkware.se> wrote:At 04:00 2002-12-15 -0800, Aztech Guy wrote:
>Which other (free) IDE's / enhanced Py interpreters do you like better the 

I've tested IPython (0.2.14pre46) on Win32 recently, and it

A minimalistic IDE, more intended to non-programmers who want
to use python as an advanced calculator is Jean-Michel Fauth's
psi.

I recently tried Boa Constructor, and if you use wxPython for
GUI building, I think this is something to look closer at. I've
mainly tried the debugging features, and they are impressive.
I've never seen anything work well for debugging wxPython GUI
code in a GUI before. It's not as good as PythonWin for pure
editing in my opinion, and I haven't tried the GUI building
features, but I think this will be a serious contender to the
commercial products such as Wing and wxDesigner in time...

I think Boa works as well with Linux as with Windows.


-- 
Magnus Lycka, Thinkware AB



---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now
--0-350225864-1039962347=:66242
Content-Type: text/html; charset=us-ascii

<P>Thanks. I'll check out Boa. Actually, I haven't started with Python GUI programming. So far only CUI. But am planning to do it soon. I was going to go with PyQt, based on a little experience with Qt (with C++, using the example programs - also the Qt docs seem very good)) and based on some articles by Boudewijn Rempt and Cameron Laird, who recommend it. (Not really done an in-depth analysis before making this decision, because I don't have a lot of GUI development experience anyway - just done a little in VB and Delphi. Mostly worked on UNIX/DOS/WIndows CUI apps.) Do you use wxPython ? What's your opinion about it vs. PyQt ? 
<P>BTW, I&nbsp;liked your series of replies to Poor Yorick about separation of GUI logic from business logic - it helped me to understand&nbsp;this&nbsp;area&nbsp;a little better.
<P>Az.
<P>&nbsp;<B><I>Magnus Lycka &lt;magnus@thinkware.se&gt;</I></B> wrote:
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">At 04:00 2002-12-15 -0800, Aztech Guy wrote:<BR>&gt;Which other (free) IDE's / enhanced Py interpreters do you like better the <BR><BR>I've tested IPython (0.2.14pre46) on Win32 recently, and it<BR><BR>A minimalistic IDE, more intended to non-programmers who want<BR>to use python as an advanced calculator is Jean-Michel Fauth's<BR>psi.<BR><BR>I recently tried Boa Constructor, and if you use wxPython for<BR>GUI building, I think this is something to look closer at. I've<BR>mainly tried the debugging features, and they are impressive.<BR>I've never seen anything work well for debugging wxPython GUI<BR>code in a GUI before. It's not as good as PythonWin for pure<BR>editing in my opinion, and I haven't tried the GUI building<BR>features, but I think this will be a serious contender to the<BR>commercial products such as Wing and wxDesigner in time...<BR><BR>I think Boa works as well with Linux as with Windows.<BR><BR><BR>-- <BR>Magnus Lycka, Thinkware AB<BR></BLOCKQUOTE><p><br><hr size=1>Do you Yahoo!?<br>
<a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Yahoo! Mail Plus</a> - Powerful. Affordable. <a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Sign up now</a>
--0-350225864-1039962347=:66242--


From Adam Vardy <anvardy@roadrunner.nf.net>  Sun Dec 15 10:09:01 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Sun Dec 15 10:09:01 2002
Subject: [Tutor] Training
In-Reply-To: <MPEOIFCOPCIHEDCLBLPBAEBGCNAA.rob@uselesspython.com>
References: <MPEOIFCOPCIHEDCLBLPBAEBGCNAA.rob@uselesspython.com>
Message-ID: <8087510162.20021215113840@roadrunner.nf.net>

Wednesday, December 11, 2002, 7:42:07 PM, you wrote:

>> It depends on your needs, budget, and learning style, really.

>> If this is what I think it is, The book _Python How to Program_ covers
>> essentially all the same material, only you don't get it on CD. A lot of
>> handy information is conveyed in both, although nothing is beyond criticism.
>> The book alone is $80 (USD) on amazon.com, but "The Complete Python Training
>> Course" is currently listed as a few dollars less. Normally I would assume
>> this is not the case.

Is this accurate?

----------------------------------------------------------------------

You'll start
with basic programs and syntax, then learn CGI programming,
object-oriented techniques, GUIs, exception handling, regular
expressions, XML programming, DB-API database integration, networking,
security -- even wireless application development. With this unique
combination of live code, audio commentary, and in-depth printed and
online explanations, you'll master Python development faster than you
ever thought possible! PYTHON MULTIMEDIA CYBER CLASSROOMore than 22
hours of expert audio instruction walks you through 281 complete,
ready-to-run programs -- 14,930 lines of live code you can load, run,
and adapt! Test your knowledge with 615 interactive self-review
questions and 370 programming exercises! Get fast, in-depth answers


-- 
Adam Vardy



From Adam Vardy <anvardy@roadrunner.nf.net>  Sun Dec 15 10:17:01 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Sun Dec 15 10:17:01 2002
Subject: [Tutor] Take file and dice
In-Reply-To: <001c01c2a1f2$3f3942b0$631b0dd5@violante>
References: <14113508626.20021212103908@roadrunner.nf.net>
 <001c01c2a1f2$3f3942b0$631b0dd5@violante>
Message-ID: <6787987529.20021215114637@roadrunner.nf.net>

Thursday, December 12, 2002, 11:52:13 AM, you wrote:


>> ----- Original Message -----
>> From: "Adam Vardy" <anvardy@roadrunner.nf.net>
>> To: <tutor@python.org>
>> Sent: Thursday, December 12, 2002 2:09 PM
>> Subject: [Tutor] Take file and dice


>> Could I find a program like this?

>> Probably not, but let's run down through your spec and see *what we need* to
>> accomplish the task.

Well, I had the feeling that there would be a kind of standard file
format which includes a lot of sections, all designed to be able to
write out to individual files from a single longer text file. And
maybe what I had here was pretty similar.

What do you think you would call it if you looked for it?

-- 
Adam Vardy



From rob@uselesspython.com  Sun Dec 15 11:14:02 2002
From: rob@uselesspython.com (Rob Andrews)
Date: Sun Dec 15 11:14:02 2002
Subject: [Tutor] Training
In-Reply-To: <8087510162.20021215113840@roadrunner.nf.net>
Message-ID: <MPEOIFCOPCIHEDCLBLPBCEFJCNAA.rob@uselesspython.com>

They do introduce each of these areas in the book, and I thought they did a
fairly decent job of it.

-Rob

> Is this accurate?
>
> ----------------------------------------------------------------------
>
> You'll start
> with basic programs and syntax, then learn CGI programming,
> object-oriented techniques, GUIs, exception handling, regular
> expressions, XML programming, DB-API database integration, networking,
> security -- even wireless application development. With this unique
> combination of live code, audio commentary, and in-depth printed and
> online explanations, you'll master Python development faster than you
> ever thought possible! PYTHON MULTIMEDIA CYBER CLASSROOMore than 22
> hours of expert audio instruction walks you through 281 complete,
> ready-to-run programs -- 14,930 lines of live code you can load, run,
> and adapt! Test your knowledge with 615 interactive self-review
> questions and 370 programming exercises! Get fast, in-depth answers
>




From dyoo@hkn.eecs.berkeley.edu  Sun Dec 15 14:42:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun Dec 15 14:42:01 2002
Subject: [Tutor] Unravelling tricky map/filtering code [wordnet.py:Word.__init__.extractVerbFrames()]
Message-ID: <Pine.LNX.4.44.0212151042060.17411-100000@hkn.eecs.berkeley.edu>

Hi everyone,


For fun, I started browsing through the bug reports in PyWordnet:

    http://sourceforge.net/tracker/?atid=390151&group_id=27422&func=browse

just to see if there was anything interesting in there.  Something caught
my eye:

http://sourceforge.net/tracker/index.php?func=detail&aid=448189&group_id=27422&atid=390151



This looked fairly understandable; the bug that they're mentioning
involves the fact that int() doesn't do automatic base conversion unless
we give an explicit base:

###
>>> int("0e")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: invalid literal for int(): 0e
>>> int("0e", 16)
14
###

so the corrected code explicitely sets 16 as the base for converting
certain numbers, so that the hexidecimal numbers are treated properly.


However, the error report also mentioned one ugly expression that reminded
me too much of a Lisp expression gone wild.  I'm paste it here so that we
can see what slightly obfuscated Python code might look like:

###
def extractVerbFrames(index, vfTuples):
    return tuple(map(lambda t:string.atoi(t[1]),
                     filter(lambda t,i=index:
                                string.atoi(t[2], 16) in (0, i),
                            vfTuples)))
###

Perhaps I'm being too harsh.  *grin* In the original code, this was all
laid out on a single line, so it looked much worse before I indented this.


I do think the code can be improved for readability, and thought it might
be interesting to bring it up on Tutor, and see if we can massage this
into something that's fairly easy to read.


The original code is meant to be compatible with older versions of Python
1.52. The above uses the functional builtins map() and filter() in
combination, as well as the deprecated string.atoi().  Unlike us, the
authors of PyWordnet don't have the freedom to use the latest wiz-bang
features in Python.


If we had the luxury of doing this using those wiz-bang features in
Python, extractVerbFrames() might look like this:

###
def extractVerbFrames(index, vfTuples):
    return tuple([int(t[1]) for t in vfTuples
                  if int(t[2], 16) in (0, index)])
###

There are a few things that we've done here: we've substituted
string.atoi() --- the old string-to-integer function --- with the simpler
int() function.

Also, we've subsituted the combination map/filter with a list
comprehension.  List comprehensions are specifically designed to handle
this map/filter situation, so if the authors had the freedom to use it,
this would probably be a good way to go.



But if we had to stick with compatibility, we can still break down that
nested map/filter into separate statements, by giving names to each
original subexpression.

###
def extractVerbFrames(index, vfTuples):
    filtered_tuples = filter(lambda t, i=index:
                                 string.atoi(t[2], 16) in (0,i),
                             vfTuples)
    frames = map(lambda t: string.atoi(t[1]), filtered_tuples)
    return tuple(frames)
###

so that there's less nesting involved.  Part of me is wavering on this,
since it's merely a asthetic judgement call: I just felt that the
readability of that code was suffering because it was trying to do
everything in one single statement; I'd rather have it take up a few more
lines vertically.

That part about 'i=index' still remains because older versions of Python
did not have nested scopes: without nested-scopes, those lambdas wouldn't
be able to refer to the 'index' parameter.  Old code had to fake nested
scopes by binding those variables to default parameters --- it was an ugly
kludge, but it worked.



For someone who doesn't know about lambdas or map or filter, this might
still look a little intimidating.  We can avoid the functionals altogether
and use a for loop:

###
def extractVerbFrames(index, vfTuples):
    vFrames = []
    for t in vfTuples:
        if string.atoi(t[2], 16) in (0, i):
            vFrames.append(string.atoi[t[1]])
    return tuple(vFrames)
###

and although this isn't "functional" in flavor, I'd actually prefer this
over the map/filter for this particular case, partially because the
complexity of those two lambda expressions was a bit high.



I hope this helps!



From magnus@thinkware.se  Sun Dec 15 16:57:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sun Dec 15 16:57:02 2002
Subject: [Tutor] Better (free) IDEs than IDLE for Linux ?
In-Reply-To: <20021215142547.66424.qmail@web9804.mail.yahoo.com>
References: <5.1.0.14.0.20021215135459.02b78a38@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021215225200.02b7a7d0@www.thinkware.se>

At 06:25 2002-12-15 -0800, Aztech Guy wrote:

>Do you use wxPython ?

Yes.

>What's your opinion about it vs. PyQt ?

Never used Qt.

I'm not entirely happy with the licence status for Qt on
Windows. It's fairly costly for commercial development.

wxPython is very feature rich. Just download it and run
the demo. (I'm not sure it's included in the RPM if you
run Linux, but it's in the source package and in the
Windows installer.)

It also has weaknesses. It's a C++ library wrapped with
SWIG, and sometimes the C++isms shine though a bit.

It also seems that the C++ toolkit (wxWindows) swings a bit
back and forth between versions in features and quality.

There are some problems related to i18n, particularly non-US
keyboards and grids.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From kyle@sent.com  Sun Dec 15 18:03:29 2002
From: kyle@sent.com (Kyle Babich)
Date: Sun Dec 15 18:03:29 2002
Subject: [Tutor] checking and deleting oldest
Message-ID: <003101c2a48e$14489e90$d20591ac@chuck>

I'm trying to count the number of folders in a specific file and if that
number is above a certain amount then the oldest file is deleted.  The first
part is easy but how would I check the dates and delete the oldest file?

Thank you again,
Kyle




From dyoo@hkn.eecs.berkeley.edu  Sun Dec 15 18:28:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun Dec 15 18:28:02 2002
Subject: [Tutor] checking and deleting oldest
In-Reply-To: <003101c2a48e$14489e90$d20591ac@chuck>
Message-ID: <Pine.LNX.4.44.0212151511490.23426-100000@hkn.eecs.berkeley.edu>


On Sun, 15 Dec 2002, Kyle Babich wrote:

> I'm trying to count the number of folders in a specific file and if that
> number is above a certain amount then the oldest file is deleted.

Hi Kyle,


I think you meant to say this instead:

"""I'm trying to count the number of files in a specific folder and if
that number is above a certain amount then the oldest file is deleted."""



> The first part is easy but how would I check the dates and delete the
> oldest file?

One approach could be to take a list of those files, and then sort them by
date.  Once we have a sorted list of files, it's fairly easy to pick out
either the newest or oldest file, since they'll be at the edges of our
list.


People on Tutor talked a little about sorting a week ago; you might find
this thread useful:

    http://mail.python.org/pipermail/tutor/2002-December/019252.html
    http://mail.python.org/pipermail/tutor/2002-December/019219.html

as well as the Sorting HOWTO:

    http://www.amk.ca/python/howto/sorting/sorting.html

The big trick is to write a comparison function that tells sort() how
to order files by date.  But for that, there's a function in
os.path()  called "getmtime()", which tells us when a file was last
modified.

    http://www.python.org/doc/lib/module-os.path.html


Try working it out; if you run into problems, please feel free to ask more
questions.  Good luck to you!



From thomi@thomi.imail.net.nz  Sun Dec 15 20:46:01 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Sun Dec 15 20:46:01 2002
Subject: [Tutor] getting pixel colors from a bitmap image - speed
Message-ID: <20021215220027.13a06b7f.thomi@thomi.imail.net.nz>

Hey:

I am trying to get the colour of a pixel in a bitmap image. i know i
could use the PIL, like so:

import Image
im = Image.open('input.bmp')
print 'pixel colour is:', im.getpixel((23,45))

But the program i have in mind needs to do this many times a second, and
i thought maybe there is a faster way to do this, esp. as the PIL warns
about the speed of using this method.

Does any one know if there is a similar call either in the PIL or in
another library, which is faster?

-- 
Lord, what fools these mortals be!
 -- midsummer nights dream.
Thomi Richards,
thomi@imail.net.nz


From idiot1@netzero.net  Mon Dec 16 00:05:09 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Mon Dec 16 00:05:09 2002
Subject: [Tutor] Re: permissions trouble -solved.
References: <3DFC2831.7060108@netzero.net> <28717.1039965222@euclid.cs.niu.edu>
Message-ID: <3DFD5F70.8060905@netzero.net>

ok, I got it.

The file referred to is in the lists dir.
/www/www.tinylist.org/cgi-bin/lists/aliases.tinylist
lists dir is chmod 755, owner nobody, and the files in there are chmod 644, 
owner nobody.

in /etc/mail we create a SOFT link.
ln -s /www/www.tinylist.org/cgi-bin/lists/aliases.tinylist aliases.tinylist
We have sendmail.cf point at ./etc/mail/aliass.tinylist':

ln -s /www/www.tinylist.org/cgi-bin/lists/aliases.tinylist aliases.tinylist

I was root when I created the link. This makes the sendmail and operating 
system happy. It reads the file just fine, but creates the db right here in 
/etc/mail, where it can write as much as it pleases.

I licked it. Thank you one and all for all the good advice.


Neil W Rickert wrote:
> Kirk Bailey <idiot1@netzero.net> wrote:
> 
> 
>>ok, I have an alias in /etc/mail, called aliases.tinylist; this is able to be 
>>read by sendmail since I edited the sendmail.cf file, and it will compile it 
>>without error.  the /mail dir is owned by root, and is chmod 755.
> 
> 
>>the file aliases.tinylist is owned by nobody currently, although in certain 
>>tests it was owned by an unpriviliged user called grumpy, and it worked.
> 
> 
> That's a security risk.  The ability to add aliases should be tightly
> restricted.
> 
> 
>>I could issue a echo statement from the command prompt as grumpy, appending to 
>>the file, and it worked, regardless of what the current directory was.
> 
> 
>>But when I tried to do it as grumpy running a SCRIPT (in python) it refused 
>>permission to write to the file. odd, grumpy could do it from the command 
>>prompt...
> 
> 
> I don't know why you think this is a sendmail problem.  From your
> description, it would seem to be a python problem.
> 
>  -NWR
> 
> 


-- 

end

Respectfully,
              Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                            +--------+

---------------------------------------------
Introducing NetZero Long Distance
1st month Free!
Sign up today at: www.netzerolongdistance.com


From idiot1@netzero.net  Mon Dec 16 00:51:02 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Mon Dec 16 00:51:02 2002
Subject: [Tutor] script error question
Message-ID: <3DFD6A44.9060602@netzero.net>

Folks, I get this error when examining a string for the presence of a smaller 
string:

Traceback (innermost last):
   File "/www/www.tinylist.org/cgi-bin/TLlistkill2.py", line 187, in ?
     if mylist not in aliasline:	# if this is NOT the alias to remove,
TypeError: string member test needs char left operand

Here is the block of code it is  happening inside of:

           while 1:                                # create a loop
                 aliasline=string.strip(f1.readline())   #
                 if aliasline=="":
                 	break         # break the loop!
                 print aliasline+'<br>'
                 if mylist not in aliasline: #
                  	f2.write(aliasline+"\n")#
                 f1.close()                            #
                 f2.close()                            #190
                 os.remove('./lists/aliases.tinylist') # delete oldfile
                 os.rename('./lists/aliases.new','/etc/mail/aliases.tinylist') 	
		# And rename the new aliases file
                 os.system('newaliases')                 # issue 'newaliases'
                 print '<P><center><B>DONE.</b></center>'   #
                         print '<br>Hope you wanted it that way.</center><br>'
                         print footer                            #
                         sys.exit(0)                             # now exit.


Anyone intrested, feel free totell me more about this, I thought I had it right.
-- 

end

Respectfully,
              Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                            +--------+

---------------------------------------------
Introducing NetZero Long Distance
1st month Free!
Sign up today at: www.netzerolongdistance.com


From dyoo@hkn.eecs.berkeley.edu  Mon Dec 16 01:06:00 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon Dec 16 01:06:00 2002
Subject: [Tutor] script error question   [checking for substrings]
In-Reply-To: <3DFD6A44.9060602@netzero.net>
Message-ID: <Pine.LNX.4.44.0212152153380.2905-100000@hkn.eecs.berkeley.edu>


On Mon, 16 Dec 2002, Kirk Bailey wrote:

> Folks, I get this error when examining a string for the presence of a smaller
> string:
>
> Traceback (innermost last):
>    File "/www/www.tinylist.org/cgi-bin/TLlistkill2.py", line 187, in ?
>      if mylist not in aliasline:	# if this is NOT the alias to remove,
> TypeError: string member test needs char left operand

Hi Kirk,


I think you're misusing 'in'.  It scans well as an English sentence, but
it isn't doing what you think it's doing in Python:

###
>>> def vowel(character):
...     return character in 'aeiou'
...
>>> vowel('a')
1
>>> vowel('z')
0
>>>
>>> 'hello' in 'hello world'
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: 'in <string>' requires character as left operand
###


'in' is meant to see if some element is within a collection.  It's
commonly used when we're checking for an element in a list, but it also
works on strings.  But when we're doing 'in' in a string, we're checking
to see if a single character is 'in' a string, and that's has a different
meaning from seeing if a word lies within --- is a "substring" --- of the
larger string.


Instead of 'in', you'll probably want to use the 'find()' method, which
tells us exactly the position where the smaller string starts to occurs.
And if the smaller "substring" isn't part of the larger string, the find()
method will return -1:

###
>>> 'hello world'.find('world')
6
>>> 'hello world'.find('hello')
0
>>> 'hello world'.find('goodbye')
-1
###



Given this, we can write a quicky wrapper to make it easier to check for
substrings:

###
>>> def isSubstring(smaller, larger):
...     return larger.find(smaller) != -1
...
>>> isSubstring('hello', 'hello world')
1
>>> isSubstring('goodbye', 'hello world')
0
###


Hope this helps!



From gp@pooryorick.com  Mon Dec 16 10:10:06 2002
From: gp@pooryorick.com (Poor Yorick)
Date: Mon Dec 16 10:10:06 2002
Subject: [Tutor] What does "sort" without parens do?
References: <Pine.GSU.4.44.0212130837400.25459-100000@waltz.rahul.net> <003301c2a2cb$2f8c4d60$a9160dd5@violante>
Message-ID: <3DFDECC9.5090802@pooryorick.com>

--------------080705090202090402000608
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

G. Rodrigues' answer to this question seems to say that sort is still 
being called even without the parenthesis.  I don't think this is the 
case.  When Python sees a function without the ensuing parenthesis, it 
looks up the function in the appropriate namespaces, and if it finds the 
function, continues through the program without calling the function. 
 Therefore, a command like:

file_list.sort

does nothing at all.

 >>> list1 = [9, 7, 3, 5, 2, 8, 1]
 >>> list1.sort
<built-in method sort of list object at 0x00915790>
 >>> list1
[9, 7, 3, 5, 2, 8, 1]
 >>>

Poor Yorick
gp@pooryorick.com

Gonçalo Rodrigues wrote:

>----- Original Message -----
>From: "Terry Carroll" <carroll@tjc.com>
>To: <tutor@python.org>
>Sent: Friday, December 13, 2002 4:55 PM
>Subject: [Tutor] What does "sort" without parens do?
>
>
>>I made an error in a program, and Python's handling of it befuddles me.
>>I had a list named "file_list"  that was full of instances of a class,
>>each instance describing a file on a set of CDROMs (I'm indexing my MP3
>>collection).
>>
>>To sort the list: I mistyped:
>>
>>  file_list.sort
>>
>>Okay, that's wrong.  I should have used:
>>
>>  file_list.sort()
>>
>>I did that, and everything worked fine.
>>
>>Now, I'm not surprised that the version without parens didn't work -- it's
>>not supposed to.  But I'm intrigued that it didn't give a syntax error or
>>exception, or, as far as I can tell, have any effect at all.  How did
>>Python interpret that line?
>>
>
>In Python *everything* is an object - In particular functions, methods, etc
>are objects with the same status and privelieges than others (like lists).
>When Python sees something like
>
>file_list.sort
>
>It just looks for the attribute sort in the object (a list in this case)
>file_list. Since it can't find it there, it goes to the class of file_list
>and finds a sort attribute there. It then returns what it found with some
>wrapping to make it a bound method - I'm being a little bit sloppy, but it
>doen't matter. You could for example do
>
>sorting_file_list = file_list.sort
>
>Now sorting_file_list  is what is called a callable - it behaves much like a
>function. The great difference is that it is a bound method - it "knows"
>what object it applies (the list file_list in this case). At the syntactic
>level you "call" it by sorting_file_list() - notice the parenthesis? It is
>*exactly the same* as if you had done file_list.sort() directly.
>
>>--
>>Terry Carroll
>>
>
>HTH,
>G. Rodrigues
>
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>


--------------080705090202090402000608
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<html>
<head>
</head>
<body>
G. Rodrigues' answer to this question seems to say that sort is still being
called even without the parenthesis. &nbsp;I don't think this is the case. &nbsp;When
Python sees a function without the ensuing parenthesis, it looks up the function
in the appropriate namespaces, and if it finds the function, continues through
the program without calling the function. &nbsp;Therefore, a command like:<br>
<br>
file_list.sort<br>
<br>
does nothing at all.<br>
<br>
&gt;&gt;&gt; list1 = [9, 7, 3, 5, 2, 8, 1]<br>
&gt;&gt;&gt; list1.sort<br>
&lt;built-in method sort of list object at 0x00915790&gt;<br>
&gt;&gt;&gt; list1<br>
[9, 7, 3, 5, 2, 8, 1]<br>
&gt;&gt;&gt; <br>
<br>
Poor Yorick<br>
<a class="moz-txt-link-abbreviated" href="mailto:gp@pooryorick.com">gp@pooryorick.com</a><br>
<br>
Gon&ccedil;alo Rodrigues wrote:<br>
<blockquote type="cite" cite="mid:003301c2a2cb$2f8c4d60$a9160dd5@violante">
  <pre wrap="">----- Original Message -----<br>From: "Terry Carroll" <a class="moz-txt-link-rfc2396E" href="mailto:carroll@tjc.com">&lt;carroll@tjc.com&gt;</a><br>To: <a class="moz-txt-link-rfc2396E" href="mailto:tutor@python.org">&lt;tutor@python.org&gt;</a><br>Sent: Friday, December 13, 2002 4:55 PM<br>Subject: [Tutor] What does "sort" without parens do?<br><br><br></pre>
  <blockquote type="cite">
    <pre wrap="">I made an error in a program, and Python's handling of it befuddles me.<br>I had a list named "file_list"  that was full of instances of a class,<br>each instance describing a file on a set of CDROMs (I'm indexing my MP3<br>collection).<br><br>To sort the list: I mistyped:<br><br>  file_list.sort<br><br>Okay, that's wrong.  I should have used:<br><br>  file_list.sort()<br><br>I did that, and everything worked fine.<br><br>Now, I'm not surprised that the version without parens didn't work -- it's<br>not supposed to.  But I'm intrigued that it didn't give a syntax error or<br>exception, or, as far as I can tell, have any effect at all.  How did<br>Python interpret that line?<br></pre>
    </blockquote>
    <pre wrap=""><!----><br>In Python *everything* is an object - In particular functions, methods, etc<br>are objects with the same status and privelieges than others (like lists).<br>When Python sees something like<br><br>file_list.sort<br><br>It just looks for the attribute sort in the object (a list in this case)<br>file_list. Since it can't find it there, it goes to the class of file_list<br>and finds a sort attribute there. It then returns what it found with some<br>wrapping to make it a bound method - I'm being a little bit sloppy, but it<br>doen't matter. You could for example do<br><br>sorting_file_list = file_list.sort<br><br>Now sorting_file_list  is what is called a callable - it behaves much like a<br>function. The great difference is that it is a bound method - it "knows"<br>what object it applies (the list file_list in this case). At the syntactic<br>level you "call" it by sorting_file_list() - notice the parenthesis? It is<br>*exactly the same* as if you had 
done file_list.sort() directly.<br><br></pre>
    <blockquote type="cite">
      <pre wrap="">--<br>Terry Carroll<br></pre>
      </blockquote>
      <pre wrap=""><!----><br>HTH,<br>G. Rodrigues<br><br><br><br>_______________________________________________<br>Tutor maillist  -  <a class="moz-txt-link-abbreviated" href="mailto:Tutor@python.org">Tutor@python.org</a><br><a class="moz-txt-link-freetext" href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a><br><br><br></pre>
      </blockquote>
      <br>
      </body>
      </html>

--------------080705090202090402000608--



From aztech1200@yahoo.com  Mon Dec 16 10:11:03 2002
From: aztech1200@yahoo.com (Aztech Guy)
Date: Mon Dec 16 10:11:03 2002
Subject: [Tutor] Better (free) IDEs than IDLE for Linux ?
In-Reply-To: <5.1.0.14.0.20021215225200.02b7a7d0@www.thinkware.se>
Message-ID: <20021216151045.48018.qmail@web9802.mail.yahoo.com>

--0-466385106-1040051445=:47839
Content-Type: text/plain; charset=us-ascii


 
 Magnus Lycka <magnus@thinkware.se> wrote:
At 06:25 2002-12-15 -0800, Aztech Guy wrote:

>Do you use wxPython ?

Yes.

>What's your opinion about it vs. PyQt ?

Never used Qt.

I'm not entirely happy with the licence status for Qt on
Windows. It's fairly costly for commercial development.


[Az] Yes, that's true. 


wxPython is very feature rich. Just download it and run
the demo. (I'm not sure it's included in the RPM if you
run Linux, but it's in the source package and in the
Windows installer.)

It also has weaknesses. It's a C++ library wrapped with
SWIG, and sometimes the C++isms shine though a bit.


[Az] Yes, this was one reason I was somewhat averse to trying out wxPython - 

after seeing some of the example C++ code of wxWindows, it looked like it had a fair amount of similarity to VC++/MFC code - which I somehow never liked the look of, and hence never tried to learn it .. that message-map syntax, id's for GUI widgets, and so on....

But I guess I unconsciously assumed that the wxPython code would also be similar to the VC/MFC style - I ought to check it out, if its really like that or different.

 Anyway, thanks for the info.

I guess the best way is to spend some time trying out one or two of the toolkits and then take a decision based on my needs and preferences.

 


It also seems that the C++ toolkit (wxWindows) swings a bit
back and forth between versions in features and quality.

There are some problems related to i18n, particularly non-US
keyboards and grids.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/ mailto:magnus@thinkware.se




---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now
--0-466385106-1040051445=:47839
Content-Type: text/html; charset=us-ascii

<P>&nbsp;
<P>&nbsp;<B><I>Magnus Lycka &lt;magnus@thinkware.se&gt;</I></B> wrote:
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">
<P>At 06:25 2002-12-15 -0800, Aztech Guy wrote:<BR><BR>&gt;Do you use wxPython ?<BR><BR>Yes.<BR><BR>&gt;What's your opinion about it vs. PyQt ?<BR><BR>Never used Qt.<BR><BR>I'm not entirely happy with the licence status for Qt on<BR>Windows. It's fairly costly for commercial development.<BR></P>
<P>[Az] Yes, that's true. </P>
<P><BR>wxPython is very feature rich. Just download it and run<BR>the demo. (I'm not sure it's included in the RPM if you<BR>run Linux, but it's in the source package and in the<BR>Windows installer.)<BR><BR>It also has weaknesses. It's a C++ library wrapped with<BR>SWIG, and sometimes the C++isms shine though a bit.<BR></P>
<P>[Az] Yes, this was one reason I was somewhat averse to trying out wxPython - </P>
<P>after seeing some of the example C++ code of wxWindows,&nbsp;it looked like it had a fair amount of similarity to VC++/MFC code - which I somehow never liked the look of, and hence never tried to learn it&nbsp;.. that message-map syntax, id's for GUI&nbsp;widgets, and so on....</P>
<P>But I guess I unconsciously assumed that the wxPython code would also be similar to the VC/MFC style - I ought to check it out, if its really like that or different.</P>
<P>&nbsp;Anyway, thanks for the info.</P>
<P>I guess the best way is to spend some time trying out one or two of the toolkits and then take a decision based on my needs and preferences.</P>
<P>&nbsp;</P>
<P><BR>It also seems that the C++ toolkit (wxWindows) swings a bit<BR>back and forth between versions in features and quality.<BR><BR>There are some problems related to i18n, particularly non-US<BR>keyboards and grids.<BR><BR><BR>-- <BR>Magnus Lycka, Thinkware AB<BR>Alvans vag 99, SE-907 50 UMEA, SWEDEN<BR>phone: int+46 70 582 80 65, fax: int+46 70 612 80 65<BR>http://www.thinkware.se/ mailto:magnus@thinkware.se<BR></P></BLOCKQUOTE><p><br><hr size=1>Do you Yahoo!?<br>
<a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Yahoo! Mail Plus</a> - Powerful. Affordable. <a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Sign up now</a>
--0-466385106-1040051445=:47839--


From alan.gauld@bt.com  Mon Dec 16 12:15:03 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon Dec 16 12:15:03 2002
Subject: [Tutor] Better (free) IDEs than IDLE for Linux ?
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0974DA65@i2km11-ukbr.domain1.systemhost.net>

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C2A526.8D29B6CC
Content-Type: text/plain;
	charset="iso-8859-1"

>  Which other (free) IDE's / enhanced Py interpreters do you like better
the  
>  standard Python interpreter and IDLE - for Linux ?  
 
The best development environment for Linux(or any Unix) is Linux itself.
Linux is a complete and fully integrated development environment, it 
just doesn't look like a Windows IDE thats all.
 
Using vim and the :! command and a couple of xterm sessions may not 
look like an IDE but the fact that they all talk to one another and 
use a common language - text - means it is. And once you get used 
to it its more effective than any Visual Basic type IDE can ever 
hope to be.
 
If you want more pampering use emacs(with python mode on) and get
a whole bunch of other goodies too, including integration with RCS/CVS
and grep etc.
 
>  I am using PythonWin on Windows, is good enough for me at present.  
 
If you like the pythonwin editor you can get Scite for Linux 
- its the same editor but without the debugger etc.
 
> Both non-GUI enhanced interpreters - of which I think IPython is one - and

>  proper GUI IDE's are of interest. 
 
What exactly do you expect to gain using one of these "proper" 
IDEs over a multi window setup in native Linux?
Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld
<http://www.freenetpages.co.uk/hp/alan.gauld>  


------_=_NextPart_001_01C2A526.8D29B6CC
Content-Type: text/html;
	charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>&gt; &nbsp;</FONT></SPAN>Which other (free) IDE's / enhanced Py 
interpreters do you like better&nbsp;the&nbsp;<SPAN 
class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>&gt; </FONT>&nbsp;</SPAN>standard Python interpreter and IDLE -&nbsp;for 
Linux ?&nbsp;<SPAN class=010161217-16122002><FONT face="Courier New" 
color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002></SPAN>&nbsp;</DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>The best development environment for Linux(or any Unix) is Linux 
itself.</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>Linux is a complete and fully integrated development environment, it 
</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>just doesn't look like a Windows IDE thats all.</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>Using vim and the :! command and a couple of xterm sessions may not 
</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>look like an IDE but the fact that they all talk to one another and 
</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>use a common language - text - means it is. And once you get used 
</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>to it its more effective than any Visual Basic type IDE can ever 
</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>hope to be.</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>If you want more pampering use emacs(with python mode on) and 
get</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>a whole bunch of other goodies too, including integration with 
RCS/CVS</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>and grep etc.</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=010161217-16122002>&gt; &nbsp;</SPAN>I am using PythonWin on 
Windows, is good enough for me at present.&nbsp;<SPAN 
class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>If you like the pythonwin editor you can get Scite for Linux 
</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>- its the same editor but without the debugger etc.</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=010161217-16122002></SPAN><FONT face="Courier New"><FONT 
color=#0000ff><FONT size=2>&gt;<SPAN 
class=010161217-16122002>&nbsp;</SPAN></FONT></FONT></FONT>Both non-GUI enhanced 
interpreters - of which I think IPython is one - and&nbsp;<SPAN 
class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>&gt; </FONT>&nbsp;</SPAN>proper GUI IDE's are of interest.<SPAN 
class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002></SPAN>&nbsp;</DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>What exactly do you expect to gain using one of these "proper" 
</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>IDEs over a multi window setup in native Linux?</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff 
size=2>
<P><FONT size=2>Alan g.<BR>Author of the 'Learning to Program' web site<BR><A 
target=_blank 
href="http://www.freenetpages.co.uk/hp/alan.gauld">http://www.freenetpages.co.uk/hp/alan.gauld</A></FONT> 
</P></FONT></SPAN></DIV></BODY></HTML>

------_=_NextPart_001_01C2A526.8D29B6CC--


From alan.gauld@bt.com  Mon Dec 16 12:38:30 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon Dec 16 12:38:30 2002
Subject: [Tutor] script error question   [checking for substrings]
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0974DA66@i2km11-ukbr.domain1.systemhost.net>

> >>> 'hello' in 'hello world'
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: 'in <string>' requires character as left operand
> ###
> 
> Instead of 'in', you'll probably want to use the 'find()' 
> method, which tells us exactly the position where the 
> smaller string starts to occurs.

An alternative is to split the string:

>>> "hello" in "hello world".split()
1
>>>

which is, I think, easier to read than the equivalent
(and possibly faster!) find() version:

>>> print "hello world".find("hello") != -1)
1
>>>

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld


From hall@ouhep1.nhn.ou.edu  Mon Dec 16 14:04:11 2002
From: hall@ouhep1.nhn.ou.edu (Isaac Hall)
Date: Mon Dec 16 14:04:11 2002
Subject: [Tutor] question about python in Emacs
Message-ID: <Pine.LNX.4.44.0212161257040.6004-100000@ouhep1.nhn.ou.edu>

Hi all, 
I have a question about python mode in xemacs that I was wondering if 
anyone can answer.  Is there a way to highlight a block of text and then 
indent the whole block, instead of indenting one line at a time.  I do not 
know much about writing emacs modes or reading them, so I really cant tell 
for myself.  I was hoiping there was, because it would be very nice when 
you decide that an if statement or some other flow control should go 
around a big block of code.  Anyway, I know its a stupid question and 
doesnt really have to do with python (except that it is in the python mode
of emacs).  Feel free to comment on how lazy I am in any responses...I 
dont mind  :)

Ike

-- 



From op73418@mail.telepac.pt  Mon Dec 16 15:12:14 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Mon Dec 16 15:12:14 2002
Subject: [Tutor] What does "sort" without parens do?
References: <Pine.GSU.4.44.0212130837400.25459-100000@waltz.rahul.net> <003301c2a2cb$2f8c4d60$a9160dd5@violante> <3DFDECC9.5090802@pooryorick.com>
Message-ID: <001b01c2a540$3911e800$72150dd5@violante>

This is a multi-part message in MIME format.

------=_NextPart_000_0018_01C2A540.38E5A7E0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hmm, what I meant with my reply was exactly what you said "When Python =
sees a function without the ensuing parenthesis, it looks up the =
function in the appropriate namespaces, and if it finds the function, =
continues through the program without calling the function." My =
appologies if my poor english was unable to render the intended meaning.

With my best regards,
G. Rodrigues

P.S: And as I am in an asking-appologies mood I might as well apologize =
for top-posting. Outlook is giving me a bad time. Must ditch it...

  ----- Original Message -----=20
  From: Poor Yorick=20
  To: Gon=E7alo Rodrigues=20
  Cc: Terry Carroll ; tutor@python.org=20
  Sent: Monday, December 16, 2002 3:10 PM
  Subject: Re: [Tutor] What does "sort" without parens do?


  G. Rodrigues' answer to this question seems to say that sort is still =
being called even without the parenthesis.  I don't think this is the =
case.  When Python sees a function without the ensuing parenthesis, it =
looks up the function in the appropriate namespaces, and if it finds the =
function, continues through the program without calling the function.  =
Therefore, a command like:

  file_list.sort

  does nothing at all.

  >>> list1 =3D [9, 7, 3, 5, 2, 8, 1]
  >>> list1.sort
  <built-in method sort of list object at 0x00915790>
  >>> list1
  [9, 7, 3, 5, 2, 8, 1]
  >>>=20

  Poor Yorick
  gp@pooryorick.com

  Gon=E7alo Rodrigues wrote:

----- Original Message -----From: "Terry Carroll" <carroll@tjc.com>To: =
<tutor@python.org>Sent: Friday, December 13, 2002 4:55 PMSubject: =
[Tutor] What does "sort" without parens do?
I made an error in a program, and Python's handling of it befuddles me.I =
had a list named "file_list"  that was full of instances of a class,each =
instance describing a file on a set of CDROMs (I'm indexing my =
MP3collection).To sort the list: I mistyped:  file_list.sortOkay, that's =
wrong.  I should have used:  file_list.sort()I did that, and everything =
worked fine.Now, I'm not surprised that the version without parens =
didn't work -- it'snot supposed to.  But I'm intrigued that it didn't =
give a syntax error orexception, or, as far as I can tell, have any =
effect at all.  How didPython interpret that line?
In Python *everything* is an object - In particular functions, methods, =
etcare objects with the same status and privelieges than others (like =
lists).When Python sees something likefile_list.sortIt just looks for =
the attribute sort in the object (a list in this case)file_list. Since =
it can't find it there, it goes to the class of file_listand finds a =
sort attribute there. It then returns what it found with somewrapping to =
make it a bound method - I'm being a little bit sloppy, but itdoen't =
matter. You could for example dosorting_file_list =3D file_list.sortNow =
sorting_file_list  is what is called a callable - it behaves much like =
afunction. The great difference is that it is a bound method - it =
"knows"what object it applies (the list file_list in this case). At the =
syntacticlevel you "call" it by sorting_file_list() - notice the =
parenthesis? It is*exactly the same* as if you had=20
done file_list.sort() directly.
--Terry Carroll
HTH,G. Rodrigues_______________________________________________Tutor =
maillist  -  =
Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor



------=_NextPart_000_0018_01C2A540.38E5A7E0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2716.2200" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hmm, what I meant with my reply was =
exactly what=20
you said "<FONT face=3D"Times New Roman" size=3D3>When Python sees a =
function=20
without the ensuing parenthesis, it looks up the function in the =
appropriate=20
namespaces, and if it finds the function, continues through the program =
without=20
calling the function.</FONT>" My appologies if my poor english was =
unable to=20
render the intended meaning.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>With my best regards,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>G. Rodrigues</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>P.S: And as I am in an =
asking-appologies mood I=20
might as well apologize for top-posting. Outlook is giving me a bad =
time. Must=20
ditch it...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Dgp@pooryorick.com href=3D"mailto:gp@pooryorick.com">Poor =
Yorick</A>=20
  </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3Dop73418@mail.telepac.pt=20
  href=3D"mailto:op73418@mail.telepac.pt">Gon=E7alo Rodrigues</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Cc:</B> <A title=3Dcarroll@tjc.com=20
  href=3D"mailto:carroll@tjc.com">Terry Carroll</A> ; <A =
title=3Dtutor@python.org=20
  href=3D"mailto:tutor@python.org">tutor@python.org</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Monday, December 16, 2002 =
3:10=20
  PM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Re: [Tutor] What does =
"sort"=20
  without parens do?</DIV>
  <DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial=20
  size=3D2></FONT><BR></DIV>G. Rodrigues' answer to this question seems =
to say=20
  that sort is still being called even without the parenthesis. &nbsp;I =
don't=20
  think this is the case. &nbsp;When Python sees a function without the =
ensuing=20
  parenthesis, it looks up the function in the appropriate namespaces, =
and if it=20
  finds the function, continues through the program without calling the=20
  function. &nbsp;Therefore, a command =
like:<BR><BR>file_list.sort<BR><BR>does=20
  nothing at all.<BR><BR>&gt;&gt;&gt; list1 =3D [9, 7, 3, 5, 2, 8,=20
  1]<BR>&gt;&gt;&gt; list1.sort<BR>&lt;built-in method sort of list =
object at=20
  0x00915790&gt;<BR>&gt;&gt;&gt; list1<BR>[9, 7, 3, 5, 2, 8, =
1]<BR>&gt;&gt;&gt;=20
  <BR><BR>Poor Yorick<BR><A class=3Dmoz-txt-link-abbreviated=20
  =
href=3D"mailto:gp@pooryorick.com">gp@pooryorick.com</A><BR><BR>Gon=E7alo =
Rodrigues=20
  wrote:<BR>
  <BLOCKQUOTE cite=3Dmid:003301c2a2cb$2f8c4d60$a9160dd5@violante =
type=3D"cite"><PRE wrap=3D"">----- Original Message -----<BR>From: =
"Terry Carroll" <A class=3Dmoz-txt-link-rfc2396E =
href=3D"mailto:carroll@tjc.com">&lt;carroll@tjc.com&gt;</A><BR>To: <A =
class=3Dmoz-txt-link-rfc2396E =
href=3D"mailto:tutor@python.org">&lt;tutor@python.org&gt;</A><BR>Sent: =
Friday, December 13, 2002 4:55 PM<BR>Subject: [Tutor] What does "sort" =
without parens do?<BR><BR><BR></PRE>
    <BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">I made an error in a =
program, and Python's handling of it befuddles me.<BR>I had a list named =
"file_list"  that was full of instances of a class,<BR>each instance =
describing a file on a set of CDROMs (I'm indexing my =
MP3<BR>collection).<BR><BR>To sort the list: I mistyped:<BR><BR>  =
file_list.sort<BR><BR>Okay, that's wrong.  I should have used:<BR><BR>  =
file_list.sort()<BR><BR>I did that, and everything worked =
fine.<BR><BR>Now, I'm not surprised that the version without parens =
didn't work -- it's<BR>not supposed to.  But I'm intrigued that it =
didn't give a syntax error or<BR>exception, or, as far as I can tell, =
have any effect at all.  How did<BR>Python interpret that =
line?<BR></PRE></BLOCKQUOTE><PRE wrap=3D""><!----><BR>In Python =
*everything* is an object - In particular functions, methods, etc<BR>are =
objects with the same status and privelieges than others (like =
lists).<BR>When Python sees something =
like<BR><BR>file_list.sort<BR><BR>It just looks for the attribute sort =
in the object (a list in this case)<BR>file_list. Since it can't find it =
there, it goes to the class of file_list<BR>and finds a sort attribute =
there. It then returns what it found with some<BR>wrapping to make it a =
bound method - I'm being a little bit sloppy, but it<BR>doen't matter. =
You could for example do<BR><BR>sorting_file_list =3D =
file_list.sort<BR><BR>Now sorting_file_list  is what is called a =
callable - it behaves much like a<BR>function. The great difference is =
that it is a bound method - it "knows"<BR>what object it applies (the =
list file_list in this case). At the syntactic<BR>level you "call" it by =
sorting_file_list() - notice the parenthesis? It is<BR>*exactly the =
same* as if you had=20
done file_list.sort() directly.<BR><BR></PRE>
    <BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">--<BR>Terry =
Carroll<BR></PRE></BLOCKQUOTE><PRE wrap=3D""><!----><BR>HTH,<BR>G. =
Rodrigues<BR><BR><BR><BR>_______________________________________________<=
BR>Tutor maillist  -  <A class=3Dmoz-txt-link-abbreviated =
href=3D"mailto:Tutor@python.org">Tutor@python.org</A><BR><A =
class=3Dmoz-txt-link-freetext =
href=3D"http://mail.python.org/mailman/listinfo/tutor">http://mail.python=
.org/mailman/listinfo/tutor</A><BR><BR><BR></PRE></BLOCKQUOTE><BR></BLOCK=
QUOTE></BODY></HTML>

------=_NextPart_000_0018_01C2A540.38E5A7E0--



From sxa@fluent.com  Mon Dec 16 16:50:02 2002
From: sxa@fluent.com (Sebastien Auclair)
Date: Mon Dec 16 16:50:02 2002
Subject: [Tutor] Using python *.py files like DLL...
Message-ID: <004701c2a54d$083808b0$8ae4e9c0@sxapc>

This is a multi-part message in MIME format.

------=_NextPart_000_0044_01C2A523.1F5D1EB0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi  !

We need to find a correct strategy for loading PYTHON modules as defined =
in *.py files. (From a C++ program)

We are porting a C++ software from Linux to Win2000. Our software can =
load modules implemented in either DLL (.so on Linux) or
PYTHON files. (*.py).

The way the doc is made, it is very hard to findout how to do that. It =
is even harder to find how to do it so that it doesn't crash !

The problem is that we just discovered that our strategy for loading =
python files doesn't work under Win2000.
We were using this call sequence :
///////////////
    FILE* fd =3D fopen(fname,"r"); // fname... for instance =
"moduleABC.py"
    struct _node* nd =3D PyParser_SimpleParseFile( fd, fname, =
Py_file_input );
    PyObject* code =3D (PyObject*)PyNode_Compile( nd, fname );
    PyObject* module =3D PyImport_ExecCodeModule( =
const_cast<char*>(name),
code );
    Py_INCREF( module );
///////////////

This is the equivalent of "LoadLibrary" for dll cases.

This code works fine under Linux but there's maybe a bug with the WIN32 =
version of PYTHON.
PyParser_SimpleParseFile causes a :
    "Unhandled exception in TOTO.exe (NTDLL.DLL): 0xC0000005: ACCESS =
VIOLATION."

In all cases, we need an alternative !!! How can we create PyObject from =
PYTHON source contained in a regular *.py file ?

We would at least need to find a way to debug Python C/API. Just =
printing the PyErr_Print call is one hell of a chalange ! (In fact, we =
haven't found a way to do that on WIN2000).

SETUP:
    WIN2000
    PYTHON 2.2.2
    VC++ 6.0
    debug and release versions produces the same result.

Thanks in advance !
________________________________
Seb.

=20

------=_NextPart_000_0044_01C2A523.1F5D1EB0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3315.2870" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2>Hi&nbsp; !<BR><BR>We need to find a =
correct=20
strategy for loading PYTHON modules as defined in *.py files. (From a =
C++=20
program)<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><FONT face=3DArial size=3D2>We are =
porting a C++=20
software from Linux to Win2000. Our software can load modules =
implemented in=20
either DLL (.so on Linux) or<BR>PYTHON files. =
(*.py).</FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><BR>The way the doc is made, it is very =
hard to=20
findout how to do that. It is even&nbsp;harder to find how to do it so =
that it=20
doesn't crash !</FONT></DIV>
<DIV><FONT face=3DArial size=3D2><BR>The problem is that we just =
discovered that our=20
strategy for loading python files doesn't work under Win2000.<BR>We were =
using=20
this call sequence :<BR>///////////////<BR>&nbsp;&nbsp;&nbsp; FILE* fd =
=3D=20
fopen(fname,"r"); // fname... for instance =
"moduleABC.py"<BR>&nbsp;&nbsp;&nbsp;=20
struct _node* nd =3D PyParser_SimpleParseFile( fd, fname, Py_file_input=20
);<BR>&nbsp;&nbsp;&nbsp; PyObject* code =3D (PyObject*)PyNode_Compile( =
nd, fname=20
);<BR>&nbsp;&nbsp;&nbsp; PyObject* module =3D PyImport_ExecCodeModule(=20
const_cast&lt;char*&gt;(name),<BR>code );<BR>&nbsp;&nbsp;&nbsp; =
Py_INCREF(=20
module );<BR>///////////////</FONT></DIV>
<DIV><FONT face=3DArial size=3D2><BR>This is the equivalent of =
"LoadLibrary" for dll=20
cases.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2><BR>This code works fine under Linux =
but there's=20
maybe a bug with the WIN32 version of =
PYTHON.<BR>PyParser_SimpleParseFile causes=20
a :<BR>&nbsp;&nbsp;&nbsp; "Unhandled exception in TOTO.exe (NTDLL.DLL):=20
0xC0000005: ACCESS VIOLATION."<BR><FONT face=3DArial size=3D2><BR>In all =
cases, we=20
need an alternative !!! How can we create PyObject from PYTHON source =
contained=20
in a regular *.py file ?<BR></FONT><BR>We would at least need to find a =
way to=20
debug Python C/API. Just printing the PyErr_Print call is one hell of a =
chalange=20
! (In fact, we haven't found a way to do that on =
WIN2000).<BR></FONT><FONT=20
face=3DArial size=3D2><FONT face=3DArial size=3D2></FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><FONT face=3DArial=20
size=3D2>SETUP:<BR>&nbsp;&nbsp;&nbsp; WIN2000<BR>&nbsp;&nbsp;&nbsp; =
PYTHON=20
2.2.2<BR>&nbsp;&nbsp;&nbsp; VC++ 6.0<BR>&nbsp;&nbsp;&nbsp; debug and =
release=20
versions produces the same result.</FONT></DIV>
<DIV>
<DIV></FONT><FONT face=3DArial size=3D2><BR>Thanks in advance=20
!<BR>________________________________<BR>Seb.<BR></DIV></DIV></FONT>
<DIV><FONT face=3DArial =
size=3D2></FONT>&nbsp;</DIV></FONT></DIV></BODY></HTML>

------=_NextPart_000_0044_01C2A523.1F5D1EB0--



From mongo57a@comcast.net  Mon Dec 16 17:27:01 2002
From: mongo57a@comcast.net (andy surany)
Date: Mon Dec 16 17:27:01 2002
Subject: [Tutor] file operations and formatting
Message-ID: <006501c2a552$8b398860$2502a8c0@emily.ewndsr01.nj.comcast.net>

Hello list!

This should be an easy question.... but I haven't found any good
examples in my search.

a=99.99 # a float
b='hello world'
file=open('junk.txt','w')

What I want is to write a and b to junk.txt with a space in between (I'm
using file.write).

I tried using a format to write, but that didn't work - mostly because I
think that I don't understand formatting as well as I should. So does
anyone have a good reference/tutorial for formatting?

TIA.

-Andy



From SWidney@ci.las-vegas.nv.us  Mon Dec 16 18:41:06 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Mon Dec 16 18:41:06 2002
Subject: [Tutor] file operations and formatting
Message-ID: <0E5508EBA1620743B409A2B8365DE16FDC82A7@SOVEREIGN>

> a=99.99 # a float
> b='hello world'
> file=open('junk.txt','w')
> 
> What I want is to write a and b to junk.txt with a space in 
> between (I'm using file.write).

### Here's the short answer
>>> a = 99.99
>>> b = 'hello world'
>>> fd = file('junk.txt', 'w')
>>> fd.write("%f %s" % a, b)

> I tried using a format to write, but that didn't work - 
> mostly because I think that I don't understand formatting
> as well as I should. So does anyone have a good
> reference/tutorial for formatting?

You'll find the options and descriptions to use in formatting statements in
the Python Library Reference, section 2.2.6.2 String Formatting Operations.
Here's a shortcut:

http://www.python.org/doc/current/lib/typesseq-strings.html#l2h-148


Enjoy!
Scott


From op73418@mail.telepac.pt  Mon Dec 16 18:48:02 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Mon Dec 16 18:48:02 2002
Subject: [Tutor] file operations and formatting
References: <0E5508EBA1620743B409A2B8365DE16FDC82A7@SOVEREIGN>
Message-ID: <000701c2a55e$57e13100$72150dd5@violante>

----- Original Message -----
From: "Scott Widney" <SWidney@ci.las-vegas.nv.us>
To: "'andy surany'" <mongo57a@comcast.net>; <tutor@python.org>
Sent: Monday, December 16, 2002 11:38 PM
Subject: RE: [Tutor] file operations and formatting


> > a=99.99 # a float
> > b='hello world'
> > file=open('junk.txt','w')
> >
> > What I want is to write a and b to junk.txt with a space in
> > between (I'm using file.write).
>
> ### Here's the short answer
> >>> a = 99.99
> >>> b = 'hello world'
> >>> fd = file('junk.txt', 'w')
> >>> fd.write("%f %s" % a, b)
>

You will get an error here since % has lower precedence than , so that
Python parses this as ("%f %s" % a), b. It should be

fd.write("%f %s" % (a, b))

> > I tried using a format to write, but that didn't work -
> > mostly because I think that I don't understand formatting
> > as well as I should. So does anyone have a good
> > reference/tutorial for formatting?
>
> You'll find the options and descriptions to use in formatting statements
in
> the Python Library Reference, section 2.2.6.2 String Formatting
Operations.
> Here's a shortcut:
>
> http://www.python.org/doc/current/lib/typesseq-strings.html#l2h-148
>
>
> Enjoy!
> Scott
>

All the best,
G. Rodrigues



From mongo57a@comcast.net  Mon Dec 16 18:59:02 2002
From: mongo57a@comcast.net (andy surany)
Date: Mon Dec 16 18:59:02 2002
Subject: [Tutor] file operations and formatting
Message-ID: <007401c2a55f$16c54b60$2502a8c0@emily.ewndsr01.nj.comcast.net>

Thanks! I'll give it a try.

I knew that I was close.... I had tried '%4.2f %s' % (file.write (a,b=
))

Regards,

Andy

-----Original Message-----
=46rom: Gon=E7alo Rodrigues <op73418@mail.telepac.pt>
To: tutor@python.org <tutor@python.org>
Date: Monday, December 16, 2002 6:48 PM
Subject: Re: [Tutor] file operations and formatting


>
>----- Original Message -----
>From: "Scott Widney" <SWidney@ci.las-vegas.nv.us>
>To: "'andy surany'" <mongo57a@comcast.net>; <tutor@python.org>
>Sent: Monday, December 16, 2002 11:38 PM
>Subject: RE: [Tutor] file operations and formatting
>
>
>> > a=3D99.99 # a float
>> > b=3D'hello world'
>> > file=3Dopen('junk.txt','w')
>> >
>> > What I want is to write a and b to junk.txt with a space in
>> > between (I'm using file.write).
>>
>> ### Here's the short answer
>> >>> a =3D 99.99
>> >>> b =3D 'hello world'
>> >>> fd =3D file('junk.txt', 'w')
>> >>> fd.write("%f %s" % a, b)
>>
>
>You will get an error here since % has lower precedence than , so th=
at
>Python parses this as ("%f %s" % a), b. It should be
>
>fd.write("%f %s" % (a, b))
>
>> > I tried using a format to write, but that didn't work -
>> > mostly because I think that I don't understand formatting
>> > as well as I should. So does anyone have a good
>> > reference/tutorial for formatting?
>>
>> You'll find the options and descriptions to use in formatting
statements
>in
>> the Python Library Reference, section 2.2.6.2 String Formatting
>Operations.
>> Here's a shortcut:
>>
>> http://www.python.org/doc/current/lib/typesseq-strings.html#l2h-14=
8
>>
>>
>> Enjoy!
>> Scott
>>
>
>All the best,
>G. Rodrigues
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor




From Don Arnold" <darnold02@sprynet.com  Mon Dec 16 19:14:01 2002
From: Don Arnold" <darnold02@sprynet.com (Don Arnold)
Date: Mon Dec 16 19:14:01 2002
Subject: [Tutor] script error question   [checking for substrings]
References: <7497DCA1C240C042B28F6657ADFD8E0974DA66@i2km11-ukbr.domain1.systemhost.net>
Message-ID: <064401c2a560$fe554600$1813ba3f@defaultcomp>

----- Original Message -----
From: <alan.gauld@bt.com>
To: <dyoo@hkn.eecs.berkeley.edu>; <idiot1@netzero.net>
Cc: <tutor@python.org>
Sent: Monday, December 16, 2002 11:37 AM
Subject: RE: [Tutor] script error question [checking for substrings]


> > >>> 'hello' in 'hello world'
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in ?
> > TypeError: 'in <string>' requires character as left operand
> > ###
> >
> > Instead of 'in', you'll probably want to use the 'find()'
> > method, which tells us exactly the position where the
> > smaller string starts to occurs.
>
> An alternative is to split the string:
>
> >>> "hello" in "hello world".split()
> 1
> >>>
>
> which is, I think, easier to read than the equivalent
> (and possibly faster!) find() version:
>
> >>> print "hello world".find("hello") != -1)
> 1

But your split() alternative fails miserably if the substring you're looking
for contains spaces:

>>> "hello world".find("o w")
4
>>> "o w" in "hello world".split()
0

Just something to beware of.

Don






From reavey@nep.net  Mon Dec 16 20:59:01 2002
From: reavey@nep.net (reavey)
Date: Mon Dec 16 20:59:01 2002
Subject: [Tutor] checking for substrings
Message-ID: <3DFE8425.1050004@nep.net>

--------------080306020703070007060506
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Sirs:

I'm confused?
 >>>"the rain in spain falls mainly on the plain"
 >>> "falls " in "the rain in spain falls mainly on the plain"
1
         #"in" looks like a yes or no test.#
 >>>a = "the rain in spain falls mainly on  the plain"
 >>> "falls" in a.split()
1
 >>>print a.find("falls")
18
 >>>a.find("falls")
18
 >>>b = "the rain in spain falls mainly on the plain in june"
Is there a way to use find to "see" the second "in" in the above example?
A reverse find?
TIA
Re-v  ?



--------------080306020703070007060506
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title></title>
</head>
<body>
Sirs:<br>
<br>
I'm confused?<br>
&gt;&gt;&gt;"the rain in spain falls mainly on the plain"<br>
&gt;&gt;&gt; "falls " in "the rain in spain falls mainly on the plain"<br>
1<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#"in" looks like a yes or no test.#<br>
&gt;&gt;&gt;a = "the rain in spain falls mainly on &nbsp;the plain"<br>
&gt;&gt;&gt; "falls" in a.split()<br>
1<br>
&gt;&gt;&gt;print a.find("falls")<br>
18<br>
&gt;&gt;&gt;a.find("falls")<br>
18<br>
&gt;&gt;&gt;b = "the rain in spain falls mainly on the plain in june"<br>
Is there a way to use find to "see" the second "in" in the above example?<br>
A reverse find?<br>
TIA<br>
Re-v &nbsp;<i>&#47803;</i><br>
<br>
<br>
</body>
</html>

--------------080306020703070007060506--



From Don Arnold" <darnold02@sprynet.com  Mon Dec 16 21:40:35 2002
From: Don Arnold" <darnold02@sprynet.com (Don Arnold)
Date: Mon Dec 16 21:40:35 2002
Subject: [Tutor] checking for substrings
References: <3DFE8425.1050004@nep.net>
Message-ID: <065f01c2a575$7603ea80$1813ba3f@defaultcomp>

----- Original Message -----
From: reavey
To: tutor@python.org ; reavey ; idiot1@netzero.net ; alan.gauld@bt.com
Sent: Monday, December 16, 2002 7:55 PM
Subject: [Tutor] checking for substrings


Sirs:

I'm confused?
>>>"the rain in spain falls mainly on the plain"
>>> "falls " in "the rain in spain falls mainly on the plain"
1
         #"in" looks like a yes or no test.#


Well, I'm confused too, because I get:

>>> 'falls' in 'the rain in spain falls mainly on the plain'
Traceback (most recent call last):
  File "<pyshell#21>", line 1, in ?
    'falls' in 'the rain in spain falls mainly on the plain'
TypeError: 'in <string>' requires character as left operand

This is under 2.2.1 on WinXP. What version of Python are you running?


>>>a = "the rain in spain falls mainly on  the plain"
>>> "falls" in a.split()
1
>>>print a.find("falls")
18
>>>a.find("falls")
18
>>>b = "the rain in spain falls mainly on the plain in june"
Is there a way to use find to "see" the second "in" in the above example?


Yes. find() can actually take three arguments: the string your searching
for, the starting offset for your search (defaults to zero), and the ending
offset (defaults to the length of the string you're searching). So you can
supply find()'s starting offset and increment it in a loop until you run out
of matches:

>>> startPosition = 0
>>> mystring = 'the rain in spain falls mainly on the plain'
>>> while 1:
            startPosition = mystring.find('in',startPosition)
            if startPosition == -1:
              break
           else:
              print 'found at:', startPosition
              startPosition += 1

found at: 6
found at: 9
found at: 15
found at: 26
found at: 41


A reverse find?


That's what rfind() is for:

>>> 'the rain in spain falls mainly in the plain'.rfind('in')
41


TIA
Re-v


HTH,

Don



From JettaRock01@aol.com  Tue Dec 17 00:17:04 2002
From: JettaRock01@aol.com (JettaRock01@aol.com)
Date: Tue Dec 17 00:17:04 2002
Subject: [Tutor] unscribe me please
Message-ID: <128.1de310d1.2b300cbc@aol.com>

--part1_128.1de310d1.2b300cbc_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

In a message dated 12/16/2002 6:50:17 PM Eastern Standard Time, 
tutor-request@python.org writes:

> http://mail.python.org/mailman/listinfo/tutor


--part1_128.1de310d1.2b300cbc_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

<HTML><FONT FACE=arial,helvetica><BODY BGCOLOR="#3dffff"><FONT  SIZE=2 FAMILY="SANSSERIF" FACE="Arial" LANG="0">In a message dated 12/16/2002 6:50:17 PM Eastern Standard Time, tutor-request@python.org writes:<BR>
<BR>
<BLOCKQUOTE TYPE=CITE style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">http://mail.python.org/mailman/listinfo/tutor</BLOCKQUOTE><BR>
<BR>
</FONT></HTML>
--part1_128.1de310d1.2b300cbc_boundary--


From dman@dman.ddts.net  Tue Dec 17 00:36:34 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Tue Dec 17 00:36:34 2002
Subject: [Tutor] Re: Better (free) IDEs than IDLE for Linux ?
In-Reply-To: <7497DCA1C240C042B28F6657ADFD8E0974DA65@i2km11-ukbr.domain1.systemhost.net>
References: <7497DCA1C240C042B28F6657ADFD8E0974DA65@i2km11-ukbr.domain1.systemhost.net>
Message-ID: <20021217055209.GA24768@dman.ddts.net>

--FCuugMFkClbJLl1L
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Dec 16, 2002 at 05:14:11PM -0000, alan.gauld@bt.com wrote:
| >  Which other (free) IDE's / enhanced Py interpreters do you like
| >  better the  standard Python interpreter and IDLE - for Linux ? =20
| =20
| The best development environment for Linux(or any Unix) is Linux itself.
| Linux is a complete and fully integrated development environment, it=20
| just doesn't look like a Windows IDE thats all.
| =20
| Using vim and the :! command and a couple of xterm sessions may not=20
| look like an IDE but the fact that they all talk to one another and=20
| use a common language - text - means it is. And once you get used=20
| to it its more effective than any Visual Basic type IDE can ever=20
| hope to be.

I agree.  Alan has just described my IDE right here.  As part of the
toolset, check out the 'ctags' program and the support vim (and emacs)
has for it.  It allows you to jump to various locations (eg class or
function definitions) in the source.  It is _extremely_ valueable when
working on large source trees.  In addition, these tools all work for
Java, C, C++, and other languages as well.  You don't need to learn a
brand new environment if you need to work with other programming languages.

-D

--=20
Running Windows is kinda like playing blackjack:
User stays on success, reboots on failure
=20
http://dman.ddts.net/~dman/

--FCuugMFkClbJLl1L
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj3+u4kACgkQO8l8XBKTpRRJngCfRPfNEov9UAtKJQGM55qt7qC2
2i4AnjRMj8W6173z+70+P0RGWos2hX9u
=hgVO
-----END PGP SIGNATURE-----

--FCuugMFkClbJLl1L--


From idiot1@netzero.net  Tue Dec 17 01:02:02 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Tue Dec 17 01:02:02 2002
Subject: [Tutor] making proigress
Message-ID: <3DFEBDCF.6080408@netzero.net>

OK, I added some code.
f1 = open('./lists/aliases.tinylist','r')       #180 open the aliases fi$
f2 = open('./lists/aliases.new','w')    # and a temp file
	while 1:                                # create a loop
         	aliasline=string.strip(f1.readline())   #
                 print aliasline,'\n<br>'        ###TESTCODE###
                 if aliasline=="":
                 	break                   # break the loop!
                 if aliasline.find(listname+':/"')==-1:  # if this is NOT 
                                    			f2.write(aliasline+"\n")#
                 f1.close()                              # close the files
                 f2.close()                              #190


and I got this error:
Traceback (innermost last):
   File "/www/www.tinylist.org/cgi-bin/TLlistkill2.py", line 187, in ?
     if aliasline.find(listname+':/"')==-1:	# if this is NOT
AttributeError: 'string' object has no attribute 'find'

Advice? this is python 1.5.2, is this important?
-- 

end

Respectfully,
              Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                            +--------+

---------------------------------------------
Introducing NetZero Long Distance
1st month Free!
Sign up today at: www.netzerolongdistance.com


From mongo57a@comcast.net  Tue Dec 17 01:36:33 2002
From: mongo57a@comcast.net (andy surany)
Date: Tue Dec 17 01:36:33 2002
Subject: [Tutor] making proigress
Message-ID: <000901c2a596$6c99ee60$2502a8c0@emily.ewndsr01.nj.comcast.net>

Hi Kirk,

I just tried the logic in question (aliasline.find(listname+':/"')==-1)
and the expression works fine (python 2.2.1). Note that I simply tried
it in python command line using a string variable versus reading a line
in the file.

Being not much more than a newbie myself, you might try the same thing.
Go to your command line and execute the basic logic. Won't take you more
than a minute to write - and you can determine whether this is a 1.5.2
problem or not.

Here is the logic I used:

import string
listname='ok'
a='jjj ok:/" lll'
a.find(listname+':/"') # You get an answer of 4 here
a='jjj kkk'
a.find(listname+':/"') # You get an answer of -1 here
a=''
a.find(listname+':/"') # You get an answer of -1 here

HTH.

Regards,

Andy
-----Original Message-----
From: Kirk Bailey <idiot1@netzero.net>
To: tutor@python.org <tutor@python.org>
Date: Tuesday, December 17, 2002 1:02 AM
Subject: [Tutor] making proigress


>OK, I added some code.
>f1 = open('./lists/aliases.tinylist','r')       #180 open the aliases
fi$
>f2 = open('./lists/aliases.new','w')    # and a temp file
> while 1:                                # create a loop
>         aliasline=string.strip(f1.readline())   #
>                 print aliasline,'\n<br>'        ###TESTCODE###
>                 if aliasline=="":
>                 break                   # break the loop!
>                 if aliasline.find(listname+':/"')==-1:  # if this is
NOT
>                                    f2.write(aliasline+"\n")#
>                 f1.close()                              # close the
files
>                 f2.close()                              #190
>
>
>and I got this error:
>Traceback (innermost last):
>   File "/www/www.tinylist.org/cgi-bin/TLlistkill2.py", line 187, in ?
>     if aliasline.find(listname+':/"')==-1: # if this is NOT
>AttributeError: 'string' object has no attribute 'find'
>
>Advice? this is python 1.5.2, is this important?
>--
>
>end
>
>Respectfully,
>              Kirk D Bailey
>
>
>+---------------------"Thou Art Free." -Eris-----------------------+
>| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
>| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
>| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
>+------------------Thinking| NORMAL |Thinking----------------------+
>                            +--------+
>
>---------------------------------------------
>Introducing NetZero Long Distance
>1st month Free!
>Sign up today at: www.netzerolongdistance.com
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor



From magnus@thinkware.se  Tue Dec 17 06:10:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Dec 17 06:10:02 2002
Subject: [Tutor] file operations and formatting
In-Reply-To: <007401c2a55f$16c54b60$2502a8c0@emily.ewndsr01.nj.comcast.n
 et>
Message-ID: <5.1.0.14.0.20021217105143.02ca0788@www.thinkware.se>

At 18:58 2002-12-16 -0500, andy surany wrote:
>I knew that I was close.... I had tried '%4.2f %s' % (file.write (a,b))

Try to do things one step at a time when you don't
understand what you are doing, never several things
at once. First create the string with the look you
like and put it in a local variable. Then you print
it so that you know what you did. When it comes out
looking right on the console as you print it, it might
be time to consider adding code to write it to a file.

I think you realize that you should create the string
before you write it to the file, right? So if you do
one thing per line of code, you will reduce the risk of
inadvertantly doing things in wrong order.

Also, make sure that you get a habit of using meaningful
variable names, otherwise your programs will be confusing.
You don't feel that right now, but others will, and you
will too what you get back to them after a year or so...
Unless you make an effort to always write meaningful names,
you will use names like a and b even when it really matters
(at least if you are human like the rest of us... ;)

Then we could have had something like:

report = open('junk.txt','w')
value = 99.9
unit = 'kg'
measurement = "%.2f %s" % (value, unit)
#print measurement
report.write(measurement)

If you didn't understand how to create a string with
the formatting syntax, you could do

measurement = str(value) + ' ' + unit

for the time being, and fix that later.

So, try never to do more than one thing per line of code
unless you really know what you are doing!


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Tue Dec 17 06:23:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Dec 17 06:23:01 2002
Subject: [Tutor] making proigress
In-Reply-To: <3DFEBDCF.6080408@netzero.net>
Message-ID: <5.1.0.14.0.20021217121551.02d121e0@www.thinkware.se>

At 01:01 2002-12-17 -0500, Kirk Bailey wrote:
>Advice? this is python 1.5.2, is this important?

Yes, it makes all the difference.

Do you really HAVE to work with that old version?

String methods came in 1.6 or 2.0, don't remember
which, and it makes little difference because you
should never use 1.6.x, it's buggy.

Basically, for 1.5.2 or prior, change all

"a string".some_method(a, b, c)

to

import string
...
string.some_method("a string", a, b, c)

Obviously, you use the old style a few lines above, in:
                 aliasline=string.strip(f1.readline())   #
That's kocher in 1.5.2, but in modern python it would be
written as
                 aliasline=f1.readline().strip()

To be 1.5.2 complient, you must be consistent with this and
do:
                if string.find(aliasline, listname+':/"')==-1:  # if this is
instead of
                if aliasline.find(listname+':/"')==-1:  # if this is

BTW, you seem to have indentation problems with your code,
mixing tabs and spaces. I suggest that you always run your
programs with "python -tt" to root out such evil.



-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From alan.gauld@bt.com  Tue Dec 17 07:16:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 17 07:16:01 2002
Subject: [Tutor] Better (free) IDEs than IDLE for Linux ?
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0974DA67@i2km11-ukbr.domain1.systemhost.net>

>  >>The best development environment for Linux(or any Unix) is 
> Linux itself.
> He's requesting a PYTHON IDE.

That's right and unix is an integrated development environment.
For any language, and much more powerful than many so called 
IDEs - like IDLE!

>  >>What exactly do you expect to gain using one of these "proper"
>  >>IDEs over a multi window setup in native Linux?
> 
> an interactive python development environment, 

Which is what unix is.

> VIM and emacs are editors (mostly) not interpreters for a specific 
> language, even though than can shell out and execute commands.

Both vim and emacs have support for specific languages.
But they are one of the tools unix provides. Unix provides 
many more - over 400 - all fully integrated. For example 
if I'm working on a multi file project I can(in either 
vim or emacs) run a grep and step through each found line
in each file in the project - try that in IDLE!
I can also run the code in my current buffer from within 
the editor and have the output captured into an editor buffer.
I can run the debugger and monitor the input, output and 
debug commands simultaneously - try that in IDLE! Similarly 
with the profiler. I can also monitor system usage, network 
stats, call trees, etc etc and version control the code. 
IDLE can't do any of these things either! Why use a partial 
toolset when you have the full set available?

> Under Windows many people use IDLE. It's an Python, IDE, not 
> an editor. Surely you understand the difference ?

Absolutely, under Windows I use IDLE and Pythonwin.
But under unix I use multiple xterms because its a more 
powerful IDE than any of the packaged IDEs. After all that 
was one of the main reasons unix became popular - it is the 
best, bar none, software development environment.

I ask again, what does a packaged IDE offer than a unix 
environment doesn't?

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld


From alan.gauld@bt.com  Tue Dec 17 07:20:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 17 07:20:02 2002
Subject: [Tutor] script error question   [checking for substrings]
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0974DA68@i2km11-ukbr.domain1.systemhost.net>

> > An alternative is to split the string:
> >
> > >>> "hello" in "hello world".split()
> > 1
> 
> But your split() alternative fails miserably if the substring 
> you're looking for contains spaces:
> 
> >>> "hello world".find("o w")
> 4
> >>> "o w" in "hello world".split()
> 0
> 
> Just something to beware of.

Absolutely, it is only a slightly more readable form that 
looks more like the "if X in S". I don't expect anyone 
to try 

if "x o" in "ghfgfhg hjg jhvhnbmvbv hjb "

For that, and any other general search, find() is undoubtedly best.

Alan G.


From alan.gauld@bt.com  Tue Dec 17 07:24:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 17 07:24:02 2002
Subject: [Tutor] script error question   [checking for substrings]
Message-ID: <7497DCA1C240C042B28F6657ADFD8E09702290@i2km11-ukbr.domain1.systemhost.net>

> But your split() alternative fails miserably if the substring 
> you're looking for contains spaces:
> 
> >>> "hello world".find("o w")
> 4
> >>> "o w" in "hello world".split()
> 0

I meant to add to my last message that the find() solution is 
not without problems too. If you want to find a "word" rather 
than a partial word the splity() method works better:

>>> "Hell" in "Hello from Hell".split()
1
>>> "Hello from Hell".find("Hell") != -1
1
>>> "Hell" in "Hello from Heaven".split()
0
>>> "Hello from Heaven".find("Hell") != -1
1

Of course for this type of search a regular expression is 
probably better still!

Alan g.


From alan.gauld@bt.com  Tue Dec 17 07:34:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 17 07:34:01 2002
Subject: [Tutor] question about python in Emacs
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0974DA69@i2km11-ukbr.domain1.systemhost.net>

> anyone can answer.  Is there a way to highlight a block of 
> text and then indent the whole block, 

Yes, its standard emacs functionality not python mode per se.

The command is indent-region

Select the region in the normal manner either by mouse otr 
using the keyboard, then type M-x indent-region

Or use the keyboard shortcut, which I can't recall but you 
can find, as usual by typing M-x describe-function indent-region

NB I'm using a different emavcs so the names may be slightly 
different, but apropos should find it quickly...

> know much about writing emacs modes or reading them, 

You shouldn't need to.

Alan G.


From magnus@thinkware.se  Tue Dec 17 08:17:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Dec 17 08:17:01 2002
Subject: [Tutor] script error question   [checking for substrings]
In-Reply-To: <7497DCA1C240C042B28F6657ADFD8E0974DA68@i2km11-ukbr.domain1
 .systemhost.net>
Message-ID: <5.1.0.14.0.20021217141230.02c95be0@www.thinkware.se>

At 12:15 2002-12-17 +0000, alan.gauld@bt.com wrote:
>For that, and any other general search, find() is undoubtedly best.

Another convenient solution if you don't need to know location is re.findall().

 >>> import re
 >>> text = "I am a long string and I continue for quite a while, blah blah 
blah..."
 >>> subString = "on"
 >>> re.findall(subString, text)
['on', 'on']

Then you also get wildcard abilities.

 >>> subString = r"\b\w\w\w\b" # Look for three letter words.
 >>> re.findall(subString, text)
['and', 'for']

 >>> subString = r"\ba.*?\b" # Words that start with 'a'
 >>> re.findall(subString, text)
['am', 'a', 'and', 'a']




-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From Jmllr891@cs.com  Tue Dec 17 09:45:02 2002
From: Jmllr891@cs.com (Jmllr891@cs.com)
Date: Tue Dec 17 09:45:02 2002
Subject: [Tutor] A slighty off topic question/rant for the experienced.
Message-ID: <16.29ea3cdb.2b3091ed@cs.com>

--part1_16.29ea3cdb.2b3091ed_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

I'm feeling quite overwhelmed about programming.

I first got into programming with Python because of Eric Raymond's "How to 
Become a Hacker FAQ". At the time I was looking to become one of the Matrixy, 
super-duper green scrolling code breakers that the intelligence agencies were 
always after or something. Now I know what a true hacker is and that's the 
path I'm taking.

But anyway, once I started programming and web design it was pretty cool. You 
know, I was one of the only people in my small-town prep area my age that 
could really do useful stuff with computers (or so I thought). But now that I 
am actively reading and learning about computers and technology, I feel so 
overwhelmed.

Just last week I was thinking: "Yep, I've got Python down and I know that 
it's a solid language that a lot of people use. Once I get through college, I 
might be able to get a job knowing Python alone.", but I hadn't planned on 
stopping there. I'm also learning Java and C in my spare time.

But now, I get to thinking about how many different technologies there are 
and how huge the technology industry is. I thought I was on my way to 
becoming a master after I had HTML, CSS, JavaScript, and Python down. But 
every day I am being bombarded with news about new technologies that seem to 
come out of nowhere and popup overnight.

Do I have the current technologies down? Noooo! I also have to learn Perl, 
XML, XHTML, DHTML, BTHTML (some new technology that I saw an ad for), and god 
only knows what other languages and technologies. My question is where does 
it end? How much does the average Joe Smoe have to cram his head with before 
he's a wizard hacker? Ugh...I think my brain's gonna explode...

--part1_16.29ea3cdb.2b3091ed_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

<HTML><FONT FACE=arial,helvetica><FONT  SIZE=2 FAMILY="SANSSERIF" FACE="Arial" LANG="0">I'm feeling quite overwhelmed about programming.<BR>
<BR>
I first got into programming with Python because of Eric Raymond's "How to Become a Hacker FAQ". At the time I was looking to become one of the Matrixy, super-duper green scrolling code breakers that the intelligence agencies were always after or something. Now I know what a true hacker is and that's the path I'm taking.<BR>
<BR>
But anyway, once I started programming and web design it was pretty cool. You know, I was one of the only people in my small-town prep area my age that could really do useful stuff with computers (or so I thought). But now that I am actively reading and learning about computers and technology, I feel so overwhelmed.<BR>
<BR>
Just last week I was thinking: "Yep, I've got Python down and I know that it's a solid language that a lot of people use. Once I get through college, I might be able to get a job knowing Python alone.", but I hadn't planned on stopping there. I'm also learning Java and C in my spare time.<BR>
<BR>
But now, I get to thinking about how many different technologies there are and how huge the technology industry is. I thought I was on my way to becoming a master after I had HTML, CSS, JavaScript, and Python down. But every day I am being bombarded with news about new technologies that seem to come out of nowhere and popup overnight.<BR>
<BR>
Do I have the current technologies down? Noooo! I also have to learn Perl, XML, XHTML, DHTML, BTHTML (some new technology that I saw an ad for), and god only knows what other languages and technologies. My question is where does it end? How much does the average Joe Smoe have to cram his head with before he's a wizard hacker? Ugh...I think my brain's gonna explode...</FONT></HTML>

--part1_16.29ea3cdb.2b3091ed_boundary--


From AJGables@cs.com  Tue Dec 17 10:03:03 2002
From: AJGables@cs.com (AJGables@cs.com)
Date: Tue Dec 17 10:03:03 2002
Subject: [Tutor] Re: Question from programmer
Message-ID: <6d.4cd1076.2b30960d@cs.com>

--part1_6d.4cd1076.2b30960d_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

I developed a password program where it askes you the password and if you 
dont get it rightin three turns it goes intio an infinte loop.  My question 
is how do I make it work.  How Do i get it to show up before I can access 
Python.  (How do i enforce the code)

                                Thank you
                                     programer

--part1_6d.4cd1076.2b30960d_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

<HTML><FONT FACE=arial,helvetica><FONT  COLOR="#400080" SIZE=3 FAMILY="FIXED" FACE="Courier New" LANG="0"><B>I developed a password program where it askes you the password and if you dont get it rightin three turns it goes intio an infinte loop.&nbsp; My question is how do I make it work.&nbsp; How Do i get it to show up before I can access Python.&nbsp; (How do i enforce the code)<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thank you<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; programer</B></FONT></HTML>

--part1_6d.4cd1076.2b30960d_boundary--


From yduppen@xs4all.nl  Tue Dec 17 10:09:05 2002
From: yduppen@xs4all.nl (Yigal Duppen)
Date: Tue Dec 17 10:09:05 2002
Subject: [Tutor] A slighty off topic question/rant for the experienced.
In-Reply-To: <16.29ea3cdb.2b3091ed@cs.com>
References: <16.29ea3cdb.2b3091ed@cs.com>
Message-ID: <200212171606.26647.yduppen@xs4all.nl>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> But now, I get to thinking about how many different technologies there =
are
> and how huge the technology industry is. I thought I was on my way to
> becoming a master after I had HTML, CSS, JavaScript, and Python down. B=
ut
> every day I am being bombarded with news about new technologies that se=
em
> to come out of nowhere and popup overnight.
>
> Do I have the current technologies down? Noooo! I also have to learn Pe=
rl,
> XML, XHTML, DHTML, BTHTML (some new technology that I saw an ad for), a=
nd
> god only knows what other languages and technologies. My question is wh=
ere
> does it end? How much does the average Joe Smoe have to cram his head w=
ith
> before he's a wizard hacker? Ugh...I think my brain's gonna explode...

No worries!
One of the most important things I've learned in the past few years (for =
the=20
record, I started CompSci in 1995) is that most of the time, most of the=20
"cool new stuff" isn't that new. It's just a combination of some old stuf=
f,=20
tied together with a cool label.=20

Take for example the *MLs you mentioned. Once you know XML and HTML, the=20
others (SGML, XHTML, DHTML) are not exciting at all (don't know about=20
BTHTML). Sure, they might have different keywords and such, but the basic=
s=20
are all the same. In this case, a way of expressing data structure in a h=
uman=20
readable easy-to-process manner (XML) and some basic layout techniques (H=
TML,=20
XHTML, LaTeX, Word, even stuff like Quark Xpress).=20

Take for (yet another) example the languages you mentioned. You know C an=
d=20
Python? Then languages such as Java, C++, Smalltalk, Pascal... are just a=
=20
matter of finding the right keywords in a manual and learning the 'right'=
 way=20
of expressing yourself by studying code examples. You know Perl and HTML?=
 Say=20
hello to PHP.=20

And another one: you know how one communication protocol (such TCP/IP) wo=
rks?=20
The rest ain't that different. Sure, they might use different names, slig=
htly=20
different algorithms or whatever, but essentially they're not that differ=
ent.

It seems to be the same with natural languages; once you know a few langu=
ages,=20
getting to know more becomes so much easier.=20

So my advice:
1. No worries.
2. Whenever you read about a 'cool new technology', glance at it and don'=
t do=20
anything with it until you feel you need it.=20
3. No worries.
4. Don't get intimidated. No one knows everything about every technology.
5. No worries.
6. There's no rule number 6.
7. No worries.

YDD
- --=20
http://www.xs4all.nl/~yduppen
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE9/z1yLsKMuCf5EdwRAlttAJ9u+seINNXfe6Fjkh1fwYRCfXf+GgCfWOyC
+pQNxoyIsawOQhZ3VVN9p6I=3D
=3DAsVP
-----END PGP SIGNATURE-----



From missive@hotmail.com  Tue Dec 17 10:53:10 2002
From: missive@hotmail.com (Lee Harr)
Date: Tue Dec 17 10:53:10 2002
Subject: [Tutor] Re: getting pixel colors from a bitmap image - speed
Message-ID: <F132f0scL9NtDEJmGzr00000206@hotmail.com>

>I am trying to get the colour of a pixel in a bitmap image. i know i
>could use the PIL, like so:

>import Image
>im = Image.open('input.bmp')
>print 'pixel colour is:', im.getpixel((23,45))

>But the program i have in mind needs to do this many times a second, and
>i thought maybe there is a faster way to do this, esp. as the PIL warns
>about the speed of using this method.

>Does any one know if there is a similar call either in the PIL or in
>another library, which is faster?


I doubt that it is _much_ faster (if at all... I have not done any
benchmarking) but another way to do this would be with pygame and
its surfarray module. surfarray uses Numeric to speed up processing
images at the pixel level.

Probably best to just pick one and try it and see if it is "fast
enough". If not you can then profile and try to get through the
bottleneck.




_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail



From mcp.bov@insightbb.com  Tue Dec 17 11:10:03 2002
From: mcp.bov@insightbb.com (Mike P)
Date: Tue Dec 17 11:10:03 2002
Subject: [Tutor] file operations and formatting
Message-ID: <000b01c2a5e6$a6712810$1de4dc0c@ct192133a>

>----- Original Message -----
>From: "Scott Widney" <SWidney@ci.las-vegas.nv.us>
>To: "'andy surany'" <mongo57a@comcast.net>; <tutor@python.org>
>Sent: Monday, December 16, 2002 11:38 PM
>Subject: RE: [Tutor] file operations and formatting
>
>
>> > a=99.99 # a float
>> > b='hello world'
>> > file=open('junk.txt','w')
>> >
>> > What I want is to write a and b to junk.txt with a space in
>> > between (I'm using file.write).
>>
>> ### Here's the short answer
>> >>> a = 99.99
>> >>> b = 'hello world'
>> >>> fd = file('junk.txt', 'w')
>> >>> fd.write("%f %s" % a, b)

Is there some difference between using open('whatever','w') and
file('whatever','w')?

Regards,

Mike P


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.427 / Virus Database: 240 - Release Date: 12/6/2002



From francois.granger@free.fr  Tue Dec 17 11:54:02 2002
From: francois.granger@free.fr (Fran=?ISO-8859-1?B?5w==?=ois Granger)
Date: Tue Dec 17 11:54:02 2002
Subject: [Tutor] file operations and formatting
In-Reply-To: <000b01c2a5e6$a6712810$1de4dc0c@ct192133a>
Message-ID: <BA251531.5F32F%francois.granger@free.fr>

on 17/12/02 17:09, Mike P at mcp.bov@insightbb.com wrote:

> Is there some difference between using open('whatever','w') and
> file('whatever','w')?

Short answer: it is the same.

Longer answer:

 open is the old way, file is a recent addition.

-- 
Le courrier est un moyen de communication. Les gens devraient
se poser des questions sur les implications politiques des choix (ou non
choix) de leurs outils et technologies. Pour des courriers propres :
<http://marc.herbert.free.fr/mail/> -- <http://minilien.com/?IXZneLoID0>



From alan.gauld@bt.com  Tue Dec 17 12:20:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 17 12:20:02 2002
Subject: [Tutor] A slighty off topic question/rant for the experienced
 .
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0970229B@i2km11-ukbr.domain1.systemhost.net>

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C2A5F0.61B5A8E0
Content-Type: text/plain;
	charset="iso-8859-1"

 >  I'm feeling quite overwhelmed about programming. 
 
If it's any consolation, so do most professional programmers.
After a while you just give up trying to know it all and 
focus on the areas where you earn your pennies. Even that 
is a tough load - but that's one reason programmers get 
paid so much. We are in the fastest moving industry of 
all time. 

>  But now, I get to thinking about how many different technologies there
are  
>  and how huge the technology industry is. I thought I was on my way to  
>  becoming a master after I had HTML, CSS, JavaScript, and Python down.  
 
Yeah, I thought assembler, pascal and Smalltalk was a good starter and 
once I got Unix scripting and C++ that would just about do it for me... :-)
 
 >  Do I have the current technologies down?  
 
And you never will. What is current today will be passe in 5 years or less.
Look at my list above, how many of those are still hot topics? I'm talking 
about 1988 - only 14 years ago.
 
> My question is where does it end?  
 
You gotta hope it doesn't - its what keeps the paychecks high!
 
> How much does the average Joe Smoe have to cram his head with before  
> he's a wizard hacker?  
 
Actually not as much as you think. To be a wizard its better to know a few
key 
skills really well than to know a little of everything! My pesonal wizard
list would be,
in approximate order:
 
1. C
2. C++ and/or Java
3. Unix shell scripting(Korn by preference)
4. A scripting language - Python maybe?
5. SQL for databases
6. HTML and XML
 
You need a familiarity with some other things like
Lisp(or some other FP language), Perl, some Web principles, any GUI
toolkit...
But you don't need to be an expert, just familiar.
 
Then finally become a guru in some particular area - databases, GUIs, 
network programming, OS kernels, device drivers, whatever...
 
Its not easy, it takes a lot of time and study. But better than trying to
learn everything.
 
> Ugh...I think my brain's gonna explode...  
 
KABOOOM!!!
 
- mine just did... :-)
 
Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld
<http://www.freenetpages.co.uk/hp/alan.gauld>  

 

------_=_NextPart_001_01C2A5F0.61B5A8E0
Content-Type: text/html;
	charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY>
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT 
face=Tahoma></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002><FONT face="Courier New" 
color=#0000ff>&nbsp;&gt; &nbsp;</FONT></SPAN>I'm feeling quite overwhelmed about 
programming.<SPAN class=610431117-17122002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002><FONT face="Courier New" color=#0000ff>If 
it's any consolation, so do most professional 
programmers.</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002><FONT face="Courier New" 
color=#0000ff>After a while you just give up trying to know it all and 
</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002><FONT face="Courier New" 
color=#0000ff>focus on the areas where you earn your pennies. Even that 
</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002><FONT face="Courier New" color=#0000ff>is 
a tough load - but that's one reason programmers get 
</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002><FONT face="Courier New" 
color=#0000ff>paid so much. We are in the fastest moving industry of 
</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002><FONT face="Courier New" color=#0000ff>all 
time.</FONT>&nbsp;</SPAN><BR><BR><SPAN class=610431117-17122002><FONT 
face="Courier New" color=#0000ff><FONT face=Arial color=#000000>&gt; 
</FONT>&nbsp;</FONT></SPAN>But now, I get to thinking about how many different 
technologies there are&nbsp;<SPAN class=610431117-17122002><FONT 
face="Courier New" color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002><FONT face="Courier New" 
color=#0000ff>&gt; </FONT>&nbsp;</SPAN>and how huge the technology industry is. 
I thought I was on my way to&nbsp;<SPAN class=610431117-17122002><FONT 
face="Courier New" color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002><FONT face="Courier New" 
color=#0000ff>&gt; </FONT>&nbsp;</SPAN>becoming a master after I had HTML, CSS, 
JavaScript, and Python down.&nbsp;<SPAN class=610431117-17122002><FONT 
face="Courier New" color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002>Yeah, I thought assembler, pascal and 
Smalltalk was a good starter and </SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002>once I got Unix scripting and C++ that 
would just about do it for me... :-)</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002><FONT face="Courier New" 
color=#0000ff>&nbsp;&gt; &nbsp;</FONT></SPAN>Do I have the current technologies 
down?&nbsp;<SPAN class=610431117-17122002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002>And you never will. What is current today 
will be passe in 5 years or less.</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002>Look at my list above, how many of those 
are still hot topics? I'm talking </SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002>about 1988 - only 14 years 
ago.</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=610431117-17122002></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002></SPAN></FONT></FONT><FONT face=Arial><FONT 
size=2>&gt;<FONT lang=0 FAMILY="SANSSERIF">&nbsp;My question is where does it 
end?&nbsp;<SPAN class=610431117-17122002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><FONT lang=0 FAMILY="SANSSERIF"><SPAN 
class=610431117-17122002></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><FONT lang=0 FAMILY="SANSSERIF"><SPAN 
class=610431117-17122002>You gotta hope it doesn't - its what keeps the 
paychecks high!</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><FONT lang=0 FAMILY="SANSSERIF"><SPAN 
class=610431117-17122002></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002>&gt;&nbsp;</SPAN>How much does the average Joe Smoe 
have to cram his head with before&nbsp;<SPAN class=610431117-17122002><FONT 
face="Courier New" color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002><FONT face="Courier New" 
color=#0000ff>&gt;</FONT>&nbsp;</SPAN>he's a wizard hacker?&nbsp;<SPAN 
class=610431117-17122002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002>Actually not as much as you think. To be a wizard its 
better to know a few key </SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002>skills really well than to know a little of everything! 
My pesonal wizard list would be,</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002>in approximate order:</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002>1. C</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002>2. C++ and/or Java</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002>3. Unix shell scripting(Korn by 
preference)</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002>4. A scripting language - Python 
maybe?</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002>5. SQL for databases</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002>6. HTML and XML</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002>You need a familiarity with some other things 
like</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002>Lisp(or some other FP language),&nbsp;Perl, some Web 
principles, any GUI toolkit...</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002>But you don't need to be an expert, just 
familiar.</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002>Then finally become a guru in some particular area - 
databases, GUIs, </SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002>network programming, OS kernels, device drivers, 
whatever...</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002>Its not easy, it takes a lot of time and study. But 
better than trying to learn everything.</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=610431117-17122002>&gt;&nbsp;</SPAN>Ugh...I think my brain's gonna 
explode...</FONT></FONT>&nbsp;</FONT><FONT face="Courier New" color=#0000ff 
size=2><SPAN class=610431117-17122002>&nbsp;</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=610431117-17122002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=610431117-17122002><FONT face=Arial color=#000000 
size=3>KABOOOM!!!</FONT></SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=610431117-17122002><FONT face=Arial color=#000000 
size=3></FONT></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" color=#0000ff><SPAN class=610431117-17122002><FONT 
face=Arial color=#000000 size=2>- mine just did... 
:-)</FONT></SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff><SPAN 
class=610431117-17122002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=610431117-17122002>
<P><FONT size=2>Alan g.<BR>Author of the 'Learning to Program' web site<BR><A 
target=_blank 
href="http://www.freenetpages.co.uk/hp/alan.gauld">http://www.freenetpages.co.uk/hp/alan.gauld</A></FONT> 
</P></SPAN></FONT><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=610431117-17122002>&nbsp;</SPAN></FONT></DIV></BODY></HTML>

------_=_NextPart_001_01C2A5F0.61B5A8E0--


From alan.gauld@bt.com  Tue Dec 17 12:23:03 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 17 12:23:03 2002
Subject: [Tutor] Re: Question from programmer
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0970229C@i2km11-ukbr.domain1.systemhost.net>

>  question is how do I make it work.   
> How Do i get it to show up before I can access Python.   

Try running 

C:> python -i passwordscript.py

That will stop in the interpreter after your code runs. 
I think that's what you want?

Alan g.


From dyoo@hkn.eecs.berkeley.edu  Tue Dec 17 14:01:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue Dec 17 14:01:02 2002
Subject: [Tutor] question about python in Emacs  [major mode documentation]
In-Reply-To: <7497DCA1C240C042B28F6657ADFD8E0974DA69@i2km11-ukbr.domain1.systemhost.net>
Message-ID: <Pine.LNX.4.44.0212171057520.23108-100000@hkn.eecs.berkeley.edu>


On Tue, 17 Dec 2002 alan.gauld@bt.com wrote:

> > anyone can answer.  Is there a way to highlight a block of
> > text and then indent the whole block,
>
> Yes, its standard emacs functionality not python mode per se.
>
> The command is indent-region
>
> Select the region in the normal manner either by mouse otr using the
> keyboard, then type M-x indent-region
>
> Or use the keyboard shortcut, which I can't recall but you can find, as
> usual by typing M-x describe-function indent-region

Hi Issac,

By the way, Emacs provides nice major-mode documentation if you press:

    C-h m

It's invaluable when using any new major-mode, since it gives
documentation to more effectively use Emacs as a programming tool.  In
python-mode, for example, 'C-h m' will give a summary of all the
Python-specific shortcuts.


Good luck!



From scot@possum.in-berlin.de  Tue Dec 17 19:09:01 2002
From: scot@possum.in-berlin.de (Scot Stevenson)
Date: Tue Dec 17 19:09:01 2002
Subject: [Tutor] A slighty off topic question/rant for the experienced.
In-Reply-To: <16.29ea3cdb.2b3091ed@cs.com>
References: <16.29ea3cdb.2b3091ed@cs.com>
Message-ID: <200212172326.05982.scot@possum.in-berlin.de>

Hello Jmllr, 

> But now, I get to thinking about how many different technologies there are
> and how huge the technology industry is. [...]  But
> every day I am being bombarded with news about new technologies that seem
> to come out of nowhere and popup overnight.

If this makes you feel better: 

My primary field is medicine. Some of the fun things you are taught during 
medical school are:

1. If it is in a book, don't trust it, because it is probably already out of 
date. Only journals have any chance of being on top of things. 

2. There are at least three journals in any given field that you have to read 
cover to cover to be up to date. Unfortunately, you don't have time to read 
_one_ in any detail. In fact, considering the amount being published, it is 
probably physically impossible to keep up with all news in a whole host of 
medical fields. However, if you are not up to date, somebody might get killed 
and/or some lawyer fresh out of law school might sue you till kingdom come. 

3. About once a month or once a decade, depending on what field you are in, 
somebody will find out something so totally different from what the old view 
of the world is, that you can forget everything you learned. I was taught 
that ulcers were caused by stress in one year, and then the next year there 
was suddenly this thing called /Helicobacter pylorum/ (which I think has a 
different name by now, too). More interesting for the cocktail crowd: We were 
taught that there is no anatomical substrate for the /G-Punkt/. Well, guess 
what...

There is one difference that I must admit I find puzzling: In medicine, older 
doctors are considered better, because they have all of this experience. In 
the computer industry, they seem to try to kick everybody out when they have 
to start shaving once a day. However, C doesn't seem to have changed that 
much over time, and Unix certainly hasn't. What's with this Youth Cult you 
guys got running here?

In other words, there are lots of fields like this, and all you can do is try 
to keep up with the most important things so you don't kill somebody. And 
just think how boring it would have been to be born in one of those ages 
where nothing really changed for centuries - Europe in the 12th Century must 
have been a really, really fun place for the curious...

Y, Scot

-- 
  Scot W. Stevenson -- scot@possum.in-berlin.de -- Zepernick, Germany



From dyoo@hkn.eecs.berkeley.edu  Tue Dec 17 19:54:41 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue Dec 17 19:54:41 2002
Subject: [Tutor] unscribe me please
In-Reply-To: <128.1de310d1.2b300cbc@aol.com>
Message-ID: <Pine.LNX.4.44.0212171652160.4218-100000@hkn.eecs.berkeley.edu>


On Tue, 17 Dec 2002 JettaRock01@aol.com wrote:

> In a message dated 12/16/2002 6:50:17 PM Eastern Standard Time,
> tutor-request@python.org writes:
>
> > http://mail.python.org/mailman/listinfo/tutor

Hi Jetta,


Are you trying to unsubscribe?  If so, you can unsubscribe by following
the link:

    http://mail.python.org/mailman/listinfo/tutor

and scan down to the bottom of the page.  You should see something about
editing your own options, and from there, you should see an "unsubscribe"
button.


Best of wishes to you!



From magnus@thinkware.se  Tue Dec 17 20:53:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Dec 17 20:53:02 2002
Subject: [Tutor] file operations and formatting
In-Reply-To: <000b01c2a5e6$a6712810$1de4dc0c@ct192133a>
Message-ID: <5.1.0.14.0.20021218024756.02d49e78@www.thinkware.se>

At 11:09 2002-12-17 -0500, Mike P wrote:
>Is there some difference between using open('whatever','w') and
>file('whatever','w')?

See
http://www.python.org/doc/current/lib/built-in-funcs.html

The background is the new style classes, and the union of
types and classes. For more about that, read:

http://www.python.org/doc/current/whatsnew/sect-rellinks.html#SECTION000310000000000000000

The idea is that the builtin types should behave as
classes. You should be able to subclass string or
int or file, to extend them with new features. Then
it makes sence that the name of the class is also used
as a constructor. Right?

If you do

calls Person:
     def __init__(fname, lname):
         self._fname = fname
         self._lname = lname

p = Person('Brian', 'Cohen')

to instanciate a Person object, you should be able to do

f = file('hello.txt', 'w')

to instanciate a file object.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Tue Dec 17 21:35:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Dec 17 21:35:01 2002
Subject: [Tutor] A slighty off topic question/rant for the
 experienced.
In-Reply-To: <16.29ea3cdb.2b3091ed@cs.com>
Message-ID: <5.1.0.14.0.20021218015517.02caf298@www.thinkware.se>

At 09:42 2002-12-17 -0500, Jmllr891@cs.com wrote:
>I first got into programming with Python because of Eric Raymond's "How to 
>Become a Hacker FAQ". At the time I was looking to become one of the 
>Matrixy, super-duper green scrolling code breakers that the intelligence 
>agencies were always after or something.

He he. That niche is already taken by me! ;)

>But anyway, once I started programming and web design it was pretty cool. 
>You know, I was one of the only people in my small-town prep area my age 
>that could really do useful stuff with computers (or so I thought). But 
>now that I am actively reading and learning about computers and 
>technology, I feel so overwhelmed.

Just take a step at a time, and let yourself enjoy
where it takes you. Never expect to "finish". Are
you planning on just feeding birds from the age of
30, or what? The fact that we continue to learn new
stuff all the way to retirement and far beyond is one
of the great things with computing.

>Just last week I was thinking: "Yep, I've got Python down and I know that 
>it's a solid language that a lot of people use. Once I get through 
>college, I might be able to get a job knowing Python alone.", but I hadn't 
>planned on stopping there. I'm also learning Java and C in my spare time.

What did Eric say in the text you mentioned above? (I should
know, I translated it to Swedish, see
http://www1.tripnet.se/~mly/open/faqs/hacker-howto.se.html)

"But be aware that you won't reach the skill level of a hacker
or even merely a programmer if you only know one or two languages
-- you need to learn how to think about programming problems in a
general way, independent of any one language. To be a real hacker,
you need to get to the point where you can learn a new language in
days by relating what's in the manual to what you already know. This
means you should learn several very different languages."

You can certainly do a lot of useful stuff with Python alone, even
if there isn't a huge demand for it in the market today. But if you
have a passion for programming and learn a few languages, you will
see that you can take on a new one rather quickly. And I think Python
is a good way to start.

If you for instance know Python, C and C++, you will have little
problems understanding Java, but you won't automatically know all
the standard (or non-standard) libraries for Java, so you will have
a lot to learn there, but you will start on a high level.

But there is a dfference between knowing something and really understanding 
it. I think
you know what I mean. We finally become "enlightened" in some way I 
guess... It will
take time--years. Don't expect anything else, but don't worry about that. 
Whatever stage
we are at in our development, there are things we can handle with ease, 
other things
that are challenges, and yet other things that are impossible. Just find 
the right mix of
things to do for your current level of competence. Not too easy, not too hard.

A book that migh be interesting after "How to Become a Hacker" is Hunt & 
Thomas:
"The Pragmatic Programmer". If you get it and it feels like too much, put 
it aside and
get back to it later. It will fit you eventually. (I think.)

>But now, I get to thinking about how many different technologies there are 
>and how huge the technology industry is. I thought I was on my way to 
>becoming a master after I had HTML, CSS, JavaScript, and Python down. But 
>every day I am being bombarded with news about new technologies that seem 
>to come out of nowhere and popup overnight.

Wisdom is eternal. The rest is details. ;) We catch up with
the details we need. Wisdom hopefully accumulates over time...

If you learn how to learn and how to handle systems and problems, you will 
handle
these things as you go along. A good Java Programmer is not first of all 
someone
who knows Java. It's first of all someone who is good at programming, and 
secondly
someone who has a routine in Java.

But not everybody has this generic ability to jump onto a new field and 
quickly become a
valuable resource there. Of course, it's partly a matter of intelligence, 
and rather much
passion and interest, but I also think it helps a lot to have the right 
kind of education. I
feel that my M.Sc education lifted my level of awareness quite a lot. I had 
been working
as a technician before University, and I felt that I went from being able 
to use technology
and theories to really understanding what lies behind them. This is somehow 
a generic
understanding of the world, that will help you use the experience you 
aquired in one
situation in a seemingly completely different situations.

A lot of things I learnt about measuring resistors have been very useful in 
helping my
wife in her epideiological research. It's confusing for her sometimes, when 
I "invent"
a mathematical formula out of thin air in a field that I don't really know. 
I've never heard
of the kinds of statistical analyses that she does, and still the thing I 
"make up" matches
the results that she reaches using a school book method. (Only I reach my 
result much
faster, and it seems the small difference between my result and hers is 
that her school
book method uses an approximation that isn't really exact...)

Sometimes I feel that I really understand what Yoda is talking about! :)
We can learn to understand how things work. Not some particular detail, but
things in general. Mathematics is a powerful tool here. And physics is 
obviously
a foundation for understanding the world. But it's not really a matter of 
memorizing
formulas and other boring stuff. It's about reaching a deeper understanding.

It's as if we can become aligned with "the Force" of nature, flow with it,
use it to our benefit, and find thruth through it. (I don't exepect to lift any
vehicles with my mind though...)

You know, Einstein has said that to understand the theory of relativity, he
imagined himself riding on a ray of light. When you think about it, you
realize that he must have had an extraordinary intuitive understanding of
nature -- physics -- to be able to learn something, and develop such deep
theories from such experiments of the mind. Anyone can "imagine" things,
but unless what we imagine really reflects reality, it won't lead to any Nobel
prize in physics...

>Do I have the current technologies down? Noooo! I also have to learn Perl, 
>XML, XHTML, DHTML, BTHTML (some new technology that I saw an ad for), and 
>god only knows what other languages and technologies. My question is where 
>does it end? How much does the average Joe Smoe have to cram his head with 
>before he's a wizard hacker? Ugh...I think my brain's gonna explode...

It's the same for all of us, whatever academic field we are in.
I feel that I'm constantly learning when I work. I learn more
about programming, I learn about team work, I learn about how
to share my knowledge, and I learn about the areas that my
clients work with, whether it's medical research or financial
transactions. If I don't feel that I learn, I get bored and stop
doing a really good job. That's why you shouldn't use overqualified
programmers in your projects. They will make overly complicated
software so that it's a challenge for them.

Maybe one day I will learn how to be brief.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From gp@pooryorick.com  Tue Dec 17 22:16:00 2002
From: gp@pooryorick.com (Poor Yorick)
Date: Tue Dec 17 22:16:00 2002
Subject: [Tutor] A slighty off topic question/rant for the  experienced.
References: <5.1.0.14.0.20021218015517.02caf298@www.thinkware.se>
Message-ID: <3DFFE883.6050108@pooryorick.com>

As a novice programmer, I particularly enjoyed reading the replies of 
Magnus and Scot.  Thanks for the inspiration.

Poor Yorick
gp@pooryorick.com

Magnus Lycka wrote:

> At 09:42 2002-12-17 -0500, Jmllr891@cs.com wrote:
>
>> I first got into programming with Python because of Eric Raymond's 
>> "How to Become a Hacker FAQ". At the time I was looking to become one 
>> of the Matrixy, super-duper green scrolling code breakers that the 
>> intelligence agencies were always after or something.
>
>
> He he. That niche is already taken by me! ;)
>
>> But anyway, once I started programming and web design it was pretty 
>> cool. You know, I was one of the only people in my small-town prep 
>> area my age that could really do useful stuff with computers (or so I 
>> thought). But now that I am actively reading and learning about 
>> computers and technology, I feel so overwhelmed.
>
>
> Just take a step at a time, and let yourself enjoy
> where it takes you. Never expect to "finish". Are
> you planning on just feeding birds from the age of
> 30, or what? The fact that we continue to learn new
> stuff all the way to retirement and far beyond is one
> of the great things with computing.
>
>> Just last week I was thinking: "Yep, I've got Python down and I know 
>> that it's a solid language that a lot of people use. Once I get 
>> through college, I might be able to get a job knowing Python alone.", 
>> but I hadn't planned on stopping there. I'm also learning Java and C 
>> in my spare time.
>
>
> What did Eric say in the text you mentioned above? (I should
> know, I translated it to Swedish, see
> http://www1.tripnet.se/~mly/open/faqs/hacker-howto.se.html)
>
> "But be aware that you won't reach the skill level of a hacker
> or even merely a programmer if you only know one or two languages
> -- you need to learn how to think about programming problems in a
> general way, independent of any one language. To be a real hacker,
> you need to get to the point where you can learn a new language in
> days by relating what's in the manual to what you already know. This
> means you should learn several very different languages."
>
> You can certainly do a lot of useful stuff with Python alone, even
> if there isn't a huge demand for it in the market today. But if you
> have a passion for programming and learn a few languages, you will
> see that you can take on a new one rather quickly. And I think Python
> is a good way to start.
>
> If you for instance know Python, C and C++, you will have little
> problems understanding Java, but you won't automatically know all
> the standard (or non-standard) libraries for Java, so you will have
> a lot to learn there, but you will start on a high level.
>
> But there is a dfference between knowing something and really 
> understanding it. I think
> you know what I mean. We finally become "enlightened" in some way I 
> guess... It will
> take time--years. Don't expect anything else, but don't worry about 
> that. Whatever stage
> we are at in our development, there are things we can handle with 
> ease, other things
> that are challenges, and yet other things that are impossible. Just 
> find the right mix of
> things to do for your current level of competence. Not too easy, not 
> too hard.
>
> A book that migh be interesting after "How to Become a Hacker" is Hunt 
> & Thomas:
> "The Pragmatic Programmer". If you get it and it feels like too much, 
> put it aside and
> get back to it later. It will fit you eventually. (I think.)
>
>> But now, I get to thinking about how many different technologies 
>> there are and how huge the technology industry is. I thought I was on 
>> my way to becoming a master after I had HTML, CSS, JavaScript, and 
>> Python down. But every day I am being bombarded with news about new 
>> technologies that seem to come out of nowhere and popup overnight.
>
>
> Wisdom is eternal. The rest is details. ;) We catch up with
> the details we need. Wisdom hopefully accumulates over time...
>
> If you learn how to learn and how to handle systems and problems, you 
> will handle
> these things as you go along. A good Java Programmer is not first of 
> all someone
> who knows Java. It's first of all someone who is good at programming, 
> and secondly
> someone who has a routine in Java.
>
> But not everybody has this generic ability to jump onto a new field 
> and quickly become a
> valuable resource there. Of course, it's partly a matter of 
> intelligence, and rather much
> passion and interest, but I also think it helps a lot to have the 
> right kind of education. I
> feel that my M.Sc education lifted my level of awareness quite a lot. 
> I had been working
> as a technician before University, and I felt that I went from being 
> able to use technology
> and theories to really understanding what lies behind them. This is 
> somehow a generic
> understanding of the world, that will help you use the experience you 
> aquired in one
> situation in a seemingly completely different situations.
>
> A lot of things I learnt about measuring resistors have been very 
> useful in helping my
> wife in her epideiological research. It's confusing for her sometimes, 
> when I "invent"
> a mathematical formula out of thin air in a field that I don't really 
> know. I've never heard
> of the kinds of statistical analyses that she does, and still the 
> thing I "make up" matches
> the results that she reaches using a school book method. (Only I reach 
> my result much
> faster, and it seems the small difference between my result and hers 
> is that her school
> book method uses an approximation that isn't really exact...)
>
> Sometimes I feel that I really understand what Yoda is talking about! :)
> We can learn to understand how things work. Not some particular 
> detail, but
> things in general. Mathematics is a powerful tool here. And physics is 
> obviously
> a foundation for understanding the world. But it's not really a matter 
> of memorizing
> formulas and other boring stuff. It's about reaching a deeper 
> understanding.
>
> It's as if we can become aligned with "the Force" of nature, flow with 
> it,
> use it to our benefit, and find thruth through it. (I don't exepect to 
> lift any
> vehicles with my mind though...)
>
> You know, Einstein has said that to understand the theory of 
> relativity, he
> imagined himself riding on a ray of light. When you think about it, you
> realize that he must have had an extraordinary intuitive understanding of
> nature -- physics -- to be able to learn something, and develop such deep
> theories from such experiments of the mind. Anyone can "imagine" things,
> but unless what we imagine really reflects reality, it won't lead to 
> any Nobel
> prize in physics...
>
>> Do I have the current technologies down? Noooo! I also have to learn 
>> Perl, XML, XHTML, DHTML, BTHTML (some new technology that I saw an ad 
>> for), and god only knows what other languages and technologies. My 
>> question is where does it end? How much does the average Joe Smoe 
>> have to cram his head with before he's a wizard hacker? Ugh...I think 
>> my brain's gonna explode...
>
>
> It's the same for all of us, whatever academic field we are in.
> I feel that I'm constantly learning when I work. I learn more
> about programming, I learn about team work, I learn about how
> to share my knowledge, and I learn about the areas that my
> clients work with, whether it's medical research or financial
> transactions. If I don't feel that I learn, I get bored and stop
> doing a really good job. That's why you shouldn't use overqualified
> programmers in your projects. They will make overly complicated
> software so that it's a challenge for them.
>
> Maybe one day I will learn how to be brief.
>
>




From Jmllr891@cs.com  Tue Dec 17 23:07:48 2002
From: Jmllr891@cs.com (Jmllr891@cs.com)
Date: Tue Dec 17 23:07:48 2002
Subject: [Tutor] reply to my repliers
Message-ID: <6e.27b475e0.2b314dc4@cs.com>

--part1_6e.27b475e0.2b314dc4_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

I had a post recently titled 'A slightly off topic question/rant for the 
experienced'. I got quite a few replies compared to what I usually get (I got 
about six or seven). I really hate leaving people hanging so, to anyone who 
emailed me back (Alan, Magnus, etc.): thanks, your advice helped me out a 
lot!

--part1_6e.27b475e0.2b314dc4_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

<HTML><FONT FACE=arial,helvetica><FONT  SIZE=2 FAMILY="SANSSERIF" FACE="Arial" LANG="0">I had a post recently titled 'A slightly off topic question/rant for the experienced'. I got quite a few replies compared to what I usually get (I got about six or seven). I really hate leaving people hanging so, to anyone who emailed me back (Alan, Magnus, etc.): thanks, your advice helped me out a lot!</FONT></HTML>

--part1_6e.27b475e0.2b314dc4_boundary--


From shalehperry@attbi.com  Wed Dec 18 00:45:01 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Wed Dec 18 00:45:01 2002
Subject: [Tutor] A slighty off topic question/rant for the experienced.
In-Reply-To: <200212172326.05982.scot@possum.in-berlin.de>
References: <16.29ea3cdb.2b3091ed@cs.com> <200212172326.05982.scot@possum.in-berlin.de>
Message-ID: <200212172143.53830.shalehperry@attbi.com>

On Tuesday 17 December 2002 14:26, Scot Stevenson wrote:
>
> There is one difference that I must admit I find puzzling: In medicine,
> older doctors are considered better, because they have all of this
> experience. In the computer industry, they seem to try to kick everybod=
y
> out when they have to start shaving once a day. However, C doesn't seem=
 to
> have changed that much over time, and Unix certainly hasn't. What's wit=
h
> this Youth Cult you guys got running here?
>

because programming is itself still young.  There is also this craziness =
in=20
the profession that unless you are working 11+ hour days you are not real=
ly=20
working.  That gets hard on the older folks (and it aint easy on us 25 ye=
ar=20
olds either).

On top of this computers are still about constant change.  $199.99 multim=
edia=20
ready machines exist today that do more than machines did 2 years ago for=
 4=20
times that.  We routinely write 100 line Python apps that would have been=
 10x=20
that in C.  Young people just respond better to change, they are maleable=
=2E

How many coders have you met who have a few stock answers to every proble=
m?  I=20
seem to run into one or two at every job and it seems the older the coder=
 the=20
more likely they are to fall into the behavior.

However the "old timers" are the people who companies call at 3 in the mo=
rning=20
to fly across the country.  Experience is still valuable.

I think part of the "programming is for young people" is due in part to t=
he=20
fact that the young people make more noise.  We chat on irc, mailing list=
s,=20
slashdot, etc.  Look at the output of a college student vs. someone 10 ye=
ars=20
older.  Hell in the last 2 years I have cut my output by 2/3s so my home =
life=20
has some meaning.  This seems to be the big factor.  Young, single people=
=20
(let's not leave the ladies out (-:) have all the time to chat, code, thi=
nk,=20
and bullshit.  Me, I have to be home by 6 to help get dinner on the table=
=2E =20
They eat quickly and code until 3am while I hang out with my wife.
In the end coding takes time.  The younger they are the more time they ar=
e=20
willing to set aside.


From shalehperry@attbi.com  Wed Dec 18 01:05:02 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Wed Dec 18 01:05:02 2002
Subject: [Tutor] A slighty off topic question/rant for the experienced.
In-Reply-To: <16.29ea3cdb.2b3091ed@cs.com>
References: <16.29ea3cdb.2b3091ed@cs.com>
Message-ID: <200212172203.34480.shalehperry@attbi.com>

On Tuesday 17 December 2002 06:42, Jmllr891@cs.com wrote:
>
> Do I have the current technologies down? Noooo! I also have to learn Pe=
rl,
> XML, XHTML, DHTML, BTHTML (some new technology that I saw an ad for), a=
nd
> god only knows what other languages and technologies. My question is wh=
ere
> does it end? How much does the average Joe Smoe have to cram his head w=
ith
> before he's a wizard hacker? Ugh...I think my brain's gonna explode...

I am 25 and have been employed in computers since I was 18 (I have been a=
=20
computer user for about 8 months longer).  Why the background? I think it=
=20
helps set up why I am about to climb up on the soap box so please bear wi=
th=20
me.

When times were good I dropped out of college and made the "real money". =
 Now=20
I see the errors of my ways but I am now married and have a wife who depe=
nds=20
on me.  Finding time (and money) to go back to school is not easy.  So do=
 it=20
right the first time.

What led me on this road was the false belief that since I knew how to wr=
ite=20
code college was a waste of time.  Friend let me tell you, knowing where =
a=20
semicolon goes does not a programmer make.  Languages are just a means of=
=20
expressing youself.  It is the underlying theories, algorithms, data=20
structures, thoughts that make a programmer.  It is possible to get this =
at=20
work but it is much, much easier to get it in school where you have the t=
ime=20
to learn.  Most employers are not interested in hearing "sure I can do th=
at,=20
just give me a month or two to learn how".  They can just hire someone wh=
o=20
already knows.  Some things are also quite difficult to pick up on your o=
wn. =20
Someone is bound to reply saying "man, I never set foot in no school and =
look=20
at me".  Good for them, every person has their path.  This is my own=20
experience and that of several people I know.  many are stuck in low to m=
id=20
level jobs because they can write perfectly fine wrapper scripts but can =
not=20
do the deep architect level code work.

and now for something completely different (-:

My suggestions on learning to be a better coder:

* learn one of each type of language.  Learn Lisp or Forth or ML.  Break =
your
  habits often.  A C coder can write C in any language but a truly good c=
oder
  writes in the idiom of his current language.  This means learning more =
than
  just how to write a for loop or a function call.  If you saw someone's
  python code and they never used a class or a dictionary you might just
  wonder why they used python.  Then there are perl coders who try to use=
 a
  regex or a hash for absolutely everything, even when a simple string op=
 or
  list would suffice (and that is not a perl slam, we all do it sometimes=
).

* when you read a book try to avoid "XXX solutions" where XXX is some
  language.  As another poster commented languages come and go but the
  solutions are still there.  Read books which talk about the act of
  programming not where to place a semi-colon or the right library routin=
e to
  call.  A book like "Design Patterns" is relevant every day of my progra=
mming
  life while "improved Delphi" was only good for 3 months.

* never, ever let yourself stagnate.  This is my other hard earned lesson=
 from
  the dot-com boom.  I was employed for 3 years working on a pet project.
  However in that time work never forced me to do something new or diffic=
ult.
  It is in the new and difficult that we learn, expand, grow, and change.

* other side of the coin, find projects you enjoy and write them.  Just t=
ry to
  avoid being pigeonholed.

Enough of the sermon.  Let me end with one of my favorite music quotes fr=
om a=20
band with the funny name of "Jimmy's Chicken Shack".

"Because living increases knowledge, and when you die, you're dead".


From idiot1@netzero.net  Wed Dec 18 01:26:01 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Wed Dec 18 01:26:01 2002
Subject: [Tutor] making proigress
References: <000901c2a596$6c99ee60$2502a8c0@emily.ewndsr01.nj.comcast.net>
Message-ID: <3E0014BF.7090706@netzero.net>

ok, I tried it in idle, and it worked fine. sshing into tmy server, I fired up 
python interactive mode, and tried the code, and it screwed the pooch. 
Apparentlyu this is a version screw, and I need towork up a flavor that 
handles version differences well. I will go study the string module, it has a 
LOT of good things in it for string tasks, and as long as the program is 
loading it anyway, why not use them?
.

andy surany wrote:
> Hi Kirk,
> 
> I just tried the logic in question (aliasline.find(listname+':/"')==-1)
> and the expression works fine (python 2.2.1). Note that I simply tried
> it in python command line using a string variable versus reading a line
> in the file.
> 
> Being not much more than a newbie myself, you might try the same thing.
> Go to your command line and execute the basic logic. Won't take you more
> than a minute to write - and you can determine whether this is a 1.5.2
> problem or not.
> 
> Here is the logic I used:
> 
> import string
> listname='ok'
> a='jjj ok:/" lll'
> a.find(listname+':/"') # You get an answer of 4 here
> a='jjj kkk'
> a.find(listname+':/"') # You get an answer of -1 here
> a=''
> a.find(listname+':/"') # You get an answer of -1 here
> 
> HTH.
> 
> Regards,
> 
> Andy
> -----Original Message-----
> From: Kirk Bailey <idiot1@netzero.net>
> To: tutor@python.org <tutor@python.org>
> Date: Tuesday, December 17, 2002 1:02 AM
> Subject: [Tutor] making proigress
> 
> 
> 
>>OK, I added some code.
>>f1 = open('./lists/aliases.tinylist','r')       #180 open the aliases
> 
> fi$
> 
>>f2 = open('./lists/aliases.new','w')    # and a temp file
>>while 1:                                # create a loop
>>        aliasline=string.strip(f1.readline())   #
>>                print aliasline,'\n<br>'        ###TESTCODE###
>>                if aliasline=="":
>>                break                   # break the loop!
>>                if aliasline.find(listname+':/"')==-1:  # if this is
> 
> NOT
> 
>>                                   f2.write(aliasline+"\n")#
>>                f1.close()                              # close the
> 
> files
> 
>>                f2.close()                              #190
>>
>>
>>and I got this error:
>>Traceback (innermost last):
>>  File "/www/www.tinylist.org/cgi-bin/TLlistkill2.py", line 187, in ?
>>    if aliasline.find(listname+':/"')==-1: # if this is NOT
>>AttributeError: 'string' object has no attribute 'find'
>>
>>Advice? this is python 1.5.2, is this important?
>>--
>>
>>end
>>
>>Respectfully,
>>             Kirk D Bailey
>>
>>
>>+---------------------"Thou Art Free." -Eris-----------------------+
>>| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
>>| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
>>| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
>>+------------------Thinking| NORMAL |Thinking----------------------+
>>                           +--------+
>>
>>---------------------------------------------
>>Introducing NetZero Long Distance
>>1st month Free!
>>Sign up today at: www.netzerolongdistance.com
>>
>>_______________________________________________
>>Tutor maillist  -  Tutor@python.org
>>http://mail.python.org/mailman/listinfo/tutor
> 
> 
> 
> 


-- 

end

Respectfully,
              Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                            +--------+

---------------------------------------------
Introducing NetZero Long Distance
1st month Free!
Sign up today at: www.netzerolongdistance.com


From idiot1@netzero.net  Wed Dec 18 01:34:01 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Wed Dec 18 01:34:01 2002
Subject: [Tutor] making proigress
References: <5.1.0.14.0.20021217121551.02d121e0@www.thinkware.se>
Message-ID: <3E00167E.7040702@netzero.net>


Magnus Lycka wrote:
> At 01:01 2002-12-17 -0500, Kirk Bailey wrote:
> 
>> Advice? this is python 1.5.2, is this important?
> 
> 
> Yes, it makes all the difference.
> 
> Do you really HAVE to work with that old version?
Until I can pony up the shekels for a 40Gb drive for a upgrade to my FreeBSD 
version and python- my hardware guru says we need to put in more space so I 
can drag in all the extra space consuming stuff with the newer versions, and 
still have LOTS of elbow room for existing stuff we dare not part with,

As for MUST WE continue with 1.5.2, the answer therefore is for now, YES, 
sadly enough. Wife is not able to work anymore, illness, and our income went 
from 2 paychecks to 1, so everything is scheduled, and with a LONG lead time.


> 
> String methods came in 1.6 or 2.0, don't remember
> which, and it makes little difference because you
> should never use 1.6.x, it's buggy.
> 
> Basically, for 1.5.2 or prior, change all
> 
> "a string".some_method(a, b, c)
> 
> to
> 
> import string
> ...
> string.some_method("a string", a, b, c)
> 
> Obviously, you use the old style a few lines above, in:
>                 aliasline=string.strip(f1.readline())   #
> That's kocher in 1.5.2, but in modern python it would be
> written as
>                 aliasline=f1.readline().strip()
> 
> To be 1.5.2 complient, you must be consistent with this and
> do:
>                if string.find(aliasline, listname+':/"')==-1:  # if this is
> instead of
Ah, saved em some research, although I think I will read the module again just 
for giggles, it never hurts.


>                if aliasline.find(listname+':/"')==-1:  # if this is
> 
> BTW, you seem to have indentation problems with your code,
> mixing tabs and spaces. I suggest that you always run your
> programs with "python -tt" to root out such evil.
> 
That is an artifact of mouse copying from a ssh terminal emulator  (PuTTY, 
it's free, it's secure, it works well) into nutscrape mismessenger. In the 
script, it is all tabs, and nice and even.

> 
> 


-- 

end

Respectfully,
              Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                            +--------+

---------------------------------------------
Introducing NetZero Long Distance
1st month Free!
Sign up today at: www.netzerolongdistance.com


From idiot1@netzero.net  Wed Dec 18 02:02:02 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Wed Dec 18 02:02:02 2002
Subject: [Tutor] making proigress
References: <5.1.0.14.0.20021217121551.02d121e0@www.thinkware.se>
Message-ID: <3E001D42.6030804@netzero.net>

But here's a brainbuster: how do we get a nobody owned and run script to issue 
and execute the 'newaliases' command? Can I change the permissions for the 
command, OR can I create a soft link to a COMMAND? 'newaliases' comes with 
sendmail, and is not strictly speaking a part of un*x at all, even though 
FreeBSD normally ships with sendmail.

well, I just tried using links to run the program, no luck at all... sigh... 
any advice?


end

Respectfully,
              Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                            +--------+

---------------------------------------------
Introducing NetZero Long Distance
1st month Free!
Sign up today at: www.netzerolongdistance.com


From dyoo@hkn.eecs.berkeley.edu  Wed Dec 18 02:37:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed Dec 18 02:37:01 2002
Subject: [Tutor] A slighty off topic question/rant for the experienced.
 [SICP]
In-Reply-To: <200212172203.34480.shalehperry@attbi.com>
Message-ID: <Pine.LNX.4.44.0212172229580.15893-100000@hkn.eecs.berkeley.edu>


> * learn one of each type of language.  Learn Lisp or Forth or ML.
>
[some text cut]
>
> * when you read a book try to avoid "XXX solutions" where XXX is some
>   language.  As another poster commented languages come and go but the
>   solutions are still there.  Read books which talk about the act of
>   programming not where to place a semi-colon or the right library
>   routine to call.  A book like "Design Patterns" is relevant every day
>   of my programming life while "improved Delphi" was only good for 3
>   months.


The wonderful thing about the Web is that there are a heck of a lot of
good online resources, all freely available.  In the spirit of this
thread, this is also pretty "non-Python" related.  *grin*


One of those really hard resources is called "The Structure and
Interpretation of Computer Programs":

    http://www-mitpress.mit.edu/sicp/

SICP has the infuriating property of being incomprehensible or
illuminating.  And usually at the same time.  Either way, I think it's
refreshing to try something that isn't claiming to be the next technology
or hot thing... and SICP is definitely something that's not immediately
applicable.  (Although it does try to show how to actually write an
apply() and eval() function.)


It is a hard book.  And some of the reviews of the book at Amazon.com are
extraordinarily harsh.

But there are a lot of good gems in it.  I feel that the most valuable
part of the book are the exercises: the authors really took the effort to
ask hard questions of all types, and not just the "Write a program that
does this...", but more often "What happens when we tinker with this part
of a program...?"


Anyway, forgive me for doing this cheerleader routine for SICP.  Hmmm...
I seem to do it every few months or so:

    http://mail.python.org/pipermail/tutor/2001-May/005286.html

*grin*


Hope this helps!



From alan.gauld@bt.com  Wed Dec 18 04:43:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed Dec 18 04:43:02 2002
Subject: [Tutor] A slighty off topic question/rant for the experienced
 . [SICP]
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0974DA6C@i2km11-ukbr.domain1.systemhost.net>

> SICP has the infuriating property of being incomprehensible or
> illuminating.  

I wholeheartedly endorse Danny comments.
I still don't flly grok the last section(how to built a Lisp 
interpreter) but i still got useful insights out of it. My 
only complaint is it is far too math focussed for non formally 
educated readers. But if you have solid high school math it 
should be OK.

It is one of several books that I found really educational
( another being Code Complete by McConnell. Every programmer 
  should be forced to read both books IMHO!)

If SCIP is too hard a slightly easier intro is 
How to Design Programs, also in print and online at:

http://www.htdp.org

This teaches a general formula for writing functions in Scheme 
and is less math biased but the approach applies generally. 
Once you read htdp SCIP should be fairly straightforward.

> It is a hard book.  And some of the reviews of the book at 
> Amazon.com are extraordinarily harsh.

Amazon reviews reflect the reader as much as the book.
They are valuable but must be read in context.

> part of the book are the exercises: 

Personally I never do the exercises in books, I prefer to devise 
my own. But some folks seem to find them useful - sufficently so 
that I've added excercises to my latest book as a result of 
feedback on my last...

> does this...", but more often "What happens when we tinker 
> with this part of a program...?"

Which I find the most useful and is usually how I teach myself.

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld


From Adam Vardy <anvardy@roadrunner.nf.net>  Wed Dec 18 09:49:01 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Wed Dec 18 09:49:01 2002
Subject: [Tutor] A slighty off topic question/rant for the experienced.
In-Reply-To: <200212172203.34480.shalehperry@attbi.com>
References: <16.29ea3cdb.2b3091ed@cs.com>
 <200212172203.34480.shalehperry@attbi.com>
Message-ID: <16129557561.20021218111839@roadrunner.nf.net>

Wednesday, December 18, 2002, 2:33:34 AM, you wrote:

>> When times were good I dropped out of college and made the "real money".  Now 
>> I see the errors of my ways but I am now married and have a wife who depends 
>> on me.  Finding time (and money) to go back to school is not easy.  So do it 
>> right the first time.

>> What led me on this road was the false belief that since I knew how to write 
>> code college was a waste of time.  Friend let me tell you, knowing where a 
>> semicolon goes does not a programmer make.  Languages are just a means of

What kind of school do you guys praise?  Some kind of university? Or
some kind of college?  Examples you might compare?

Do you like to learn abstractly, or practically?

>> and now for something completely different (-:

>> My suggestions on learning to be a better coder:

>> * learn one of each type of language.  Learn Lisp or Forth or ML.  Break your

It's not likely you'll find books on those things.

>>   habits often.  A C coder can write C in any language but a truly good coder
>>   writes in the idiom of his current language.  This means learning more than
>>   just how to write a for loop or a function call.  If you saw someone's
>>   python code and they never used a class or a dictionary you might just
>>   wonder why they used python.

Well, if they'll keep on doing that, maybe their code will make good
examples for beginning coders. To learn concepts one step at a time.

-- 
Adam Vardy



From dclapp@qwest.net  Wed Dec 18 10:31:01 2002
From: dclapp@qwest.net (Doug Clapp)
Date: Wed Dec 18 10:31:01 2002
Subject: [Tutor] happy holidays and thanks for the fish...
Message-ID: <000e01c2a6aa$4ffc9680$d4c8a8c0@mn.rr.com>

This is a multi-part message in MIME format.

------=_NextPart_000_000B_01C2A678.04A984E0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Dear python tutors,

On behalf of all the (many, I'm sure) lurkers on this list, I'd like to =
thank Danny, Magnus and the other python wizards who have so graciously =
given their time and knowledge to the rest of us on this list.

We're here, we're learning, and we truly appreciate your contributions.  =
Thanks!

Doug Clapp
------=_NextPart_000_000B_01C2A678.04A984E0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Dear python tutors,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>On behalf of all the (many, I'm sure) =
lurkers on=20
this list, I'd like to thank Danny, Magnus and the other python wizards =
who have=20
so graciously given their time and knowledge to the rest of us on this=20
list.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>We're here, we're learning, and we =
truly appreciate=20
your contributions.&nbsp; Thanks!</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Doug Clapp</FONT></DIV></BODY></HTML>

------=_NextPart_000_000B_01C2A678.04A984E0--



From S.Huijgen@Student.TUDelft.NL  Wed Dec 18 10:54:01 2002
From: S.Huijgen@Student.TUDelft.NL (Stephan Huijgen)
Date: Wed Dec 18 10:54:01 2002
Subject: [Tutor] using MATLAB & Python under Windows2000
References: <000e01c2a6aa$4ffc9680$d4c8a8c0@mn.rr.com>
Message-ID: <002d01c2a6ad$da8e5830$6501a8c0@superyethzer>

This is a multi-part message in MIME format.

------=_NextPart_000_002A_01C2A6B6.3C3A2F20
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

LS,

I am now trying to use Python as a language and I would like to use =
Python as a integrator with MATLAB. I have seen working examples with =
Python and MATLAB under Linux, but I do not have Linux, but Windows =
2000. I understood this would work aswell, but I do not know how.=20
I have installed Numpy, Pymat and as GUI builder I use wxPython.=20
I am searching the web to look for examples, but so far nothing yet..=20
I am almost desperate. Please can you help me with this problem.=20
How do I run a MATLAB m-file from Python?=20

thanks in advance.

best regards,

Stephan Huijgen

------=_NextPart_000_002A_01C2A6B6.3C3A2F20
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1126" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2>LS,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I am now trying to use Python as a =
language and I=20
would like to use Python as a integrator with MATLAB. I have seen =
working=20
examples with Python and MATLAB under Linux, but I do not have Linux, =
but=20
Windows 2000. I understood this would work aswell, but I do not know =
how.=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I have installed Numpy, Pymat and as =
GUI builder I=20
use wxPython. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I am searching the web to look for =
examples, but so=20
far nothing yet.. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I am almost desperate. Please can you =
help me with=20
this problem. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>How do I run a MATLAB m-file from =
Python?=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>thanks in advance.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>best regards,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Stephan=20
Huijgen<BR></FONT></FONT></DIV></DIV></BODY></HTML>

------=_NextPart_000_002A_01C2A6B6.3C3A2F20--



From dyoo@hkn.eecs.berkeley.edu  Wed Dec 18 13:14:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed Dec 18 13:14:01 2002
Subject: [Tutor] A slighty off topic question/rant for the experienced
 . [SICP]
In-Reply-To: <7497DCA1C240C042B28F6657ADFD8E0974DA6C@i2km11-ukbr.domain1.systemhost.net>
Message-ID: <Pine.LNX.4.44.0212181008280.29739-100000@hkn.eecs.berkeley.edu>


On Wed, 18 Dec 2002 alan.gauld@bt.com wrote:

> I still don't flly grok the last section(how to built a Lisp
> interpreter) but i still got useful insights out of it.

Hi Alan,


You might find this interesting:

    http://hkn.eecs.berkeley.edu/~dyoo/python/pyscheme/index.html

*grin*



From sholden@holdenweb.com  Wed Dec 18 13:21:01 2002
From: sholden@holdenweb.com (Steve Holden)
Date: Wed Dec 18 13:21:01 2002
Subject: [Tutor] Seeking Expressions of Support
Message-ID: <02c101c2a649$048120b0$6ff26c42@holdenweb.com>

This is my last word on this subject until after Christmas. It's also about
as close as I'll ever get to spamming -- apologies to those of you who
receive multiple copies of this mail. Please send it on to any individual or
list with an interest in Python and related topics.

For PyCon DC 2003 to be a success it needs people to get involved. Then
Python will finally have low-cost  conferences. So take a look at the
following link, then don't mail me -- visit the Python Wiki PyCon page and
express your support (or not, as the case may be):

http://pydish.holdenweb.com/pycon/threat.html

Happy holidays
-----------------------------------------------------------------------
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/
Bring your musical instrument to PyCon!    http://www.python.org/pycon/
-----------------------------------------------------------------------




From alan.gauld@bt.com  Wed Dec 18 13:23:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed Dec 18 13:23:01 2002
Subject: [Tutor] A slighty off topic question/rant for the experienced
 .
Message-ID: <7497DCA1C240C042B28F6657ADFD8E097022A6@i2km11-ukbr.domain1.systemhost.net>

> >> My suggestions on learning to be a better coder:
> 
> >> * learn one of each type of language.  Learn Lisp or Forth 
> or ML.  Break your

Absolutely, thats why I used the list of languages in my earlier post.
Its concepts not current flavor languages that matter.

That's why my web tutor uses 3 languages - to ilustrate that 
although the synrtax is different the concepts are exactly 
the same in any imperative language(like Python).

> It's not likely you'll find books on those things.

Actually there is a vast array of literature on Lisp. There is 
a much smaller amount on ML and Forth (although it used to have 
a lot of books). Another good FP language with a reasonable 
book selection is Haskell.

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld


From alan.gauld@bt.com  Wed Dec 18 13:35:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed Dec 18 13:35:01 2002
Subject: [Tutor] A slighty off topic question/rant for the experienced
 .
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0974DA6E@i2km11-ukbr.domain1.systemhost.net>

> >> What led me on this road was the false belief that since I 
> >> knew how to write code college was a waste of time.  
> 
> What kind of school do you guys praise?  Some kind of university? Or
> some kind of college?  Examples you might compare?

At work we insist on university education(Masters preferred). 
You can be a coder (even a good one) with just high school or college 
level but it is very hard to move up the "value chain" into 
architect/design type roles from there.

You really need to understand more than just coding, you need to 
appreciate some more fundamental things, including fairly heavy 
math type things. Machine structures and compiler theory, 
state machines, queuing theory, algorithm design etc etc. 
You get those in a degree course.

Of course the type of degree course is another matter, we don't 
insist on CS or SE courses, we will take anyone with a good numerical 
degree(engineering/math/science etc) with significant programming 
experience.

> Do you like to learn abstractly, or practically?

You need both. It's essential for a good designer to be able 
to think abstractly and to write good code and develop performant 
systems you must think practically too.

Two books that illustrate this in different ways are:

The Pragmatic Programmer - I think Magnus already mentioned it.

IT Architectures & Middleware - really about building large 
distributed systems. But covers the real world issues of 
building industry strength software well.

I recommend both.

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld


From magnus@thinkware.se  Wed Dec 18 13:43:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 18 13:43:02 2002
Subject: [Tutor] A slighty off topic question/rant for the
 experienced.
In-Reply-To: <16129557561.20021218111839@roadrunner.nf.net>
References: <200212172203.34480.shalehperry@attbi.com>
 <16.29ea3cdb.2b3091ed@cs.com>
 <200212172203.34480.shalehperry@attbi.com>
Message-ID: <5.1.0.14.0.20021218183843.02d21ca0@www.thinkware.se>

At 11:18 2002-12-18 -03-30, Adam Vardy wrote:
> >> When times were good I dropped out of college and made the "real=20
> money".  Now
> >> I see the errors of my ways but I am now married and have a wife who=
=20
> depends
> >> on me.  Finding time (and money) to go back to school is not easy.  =
So=20
> do it
> >> right the first time.

I have a few almost finished engineers among my friends,
and while they have done all but a little of their education,
it still sticks out as a flaw in them that they didn't manage
to finish properly. I imagine an employer might well wonder if
they will leave their job assignments almost done as well...

I still feel that it might be good to have som experience of the real
world before studying at an academic level. It makes it much easier
to understand the theories if you understand what they represent in
the real world. I felt sorry about my friends who had hardly ever
seen a resistor or a capacitor before they started with the electric
circuit theory. It was just meaningless words to them, and so many
new things at once. I got a solid theoretical explanation for things
I understood fairly well in practice. They got their brains filled
with words that meant nothing for them.

But don't wait too long...

A friend of mine decided to start studying at the university this
fall, at the age of 37. His wife is also going back to her studies.
They have three teen age children who can't exepect a lot of christmas
gifts or summer trips for a few years to come...

> >> What led me on this road was the false belief that since I knew how =
to=20
> write
> >> code college was a waste of time.  Friend let me tell you, knowing=20
> where a
> >> semicolon goes does not a programmer make.  Languages are just a mea=
ns of
>
>What kind of school do you guys praise?  Some kind of university? Or
>some kind of college?  Examples you might compare?

I studied for my M.Sc.E.E. at Chalmers, www.chalmers.se
Good place. At least if you happen to be in Sweden. :)
G=F6teborg is also a nice town with some good Python coders.
Alex Martelli's employer AB Strakt is from there, and
several of the employees studied in Chalmers.

>Do you like to learn abstractly, or practically?

If you really understand something, you can use it practically.
Being able to do something practically might not mean that you
really understand. If you just get a routine in doing routine
work, you might well be unable to apply what you have learned
when the context changes. On the other hand, hands-on experience
might well help you to get a good understanding of theories. I
think a good mix is required.

In my opinion, it's important to try to really understand things. We
all felt (I think) that in the lectures you could either sit and
listen to what the professor said, and try to really understand this,
OR you could write lecture notes, but doing both was too much.
Fortunately where I was studying people we usually selling lecture
notes for a reasonable cost, so I could sit and listen and think.

Many other students spent much more time than I did practicing. In
maths (and most M.Sc.E.E. subjects are math in a form or another)
practicing typically means doing these math assignments in the
books. Hundreds of boring and similar looking exercises. Yuk. I
could rarely do more than a few, and I rarely made any "high scores"
on the exams.

Once though, I felt that a math exam went better than usual. An
unusually simple exam it seemed to me. When I was walking down the
tunnel of sighs (which was the popular name of the corridor where
the maths department displayed exam results) I saw a few of the guys
who had previously scored 23-24 out of 25 on these exams. I was
normally happy with my 17-18 points. They weren't sighing, they
were almost crying, complaining that the exam was sooo difficult,
and wondering who the hell 3-87-4168 was (no names were posted)
who managed to score 23 on this exam from hell. Of course I got
curious when I heard my Chalmers id number like that.

Later I asked the Ph.D. student who wrote the exam in what way it
was different from other exams. He said "Well, I didn't want it to
be a typical exam, looking exactly like these Math C exams aways do,
so I varied the questions a little, combining things and formulating
things a little differently. This tend to confuse students, so as a
compensation, you have to lower the level of the mathematics a bit."
This slightly lower level was obviously the reason I scored higher
than usual (and a little luck). The difference from "typical" exams
didn't bother me, since I didn't practice enough to know how a
typical exam would look. (I'm sure these guys did four or five old
exams from previous years when they were preparing. Probably exhausted
when it came to exam...)

For them, the confusion from being slightly different (something I
never noticed) penalized them about twice as much as the simpler
mathematics helped them. These guys scored 17-18 points as I used
to do... :)

It turned out that my friends had not really studied how to solve
mathematical probelms, they had worked very hard trying to learn how
to solve maths exams, something people do very rarely after they
graduate. I don't think they even understood the difference. Not then.
Maybe when they had to face the real world...

It's really interesting that they were so completely lost when the
things they (thought they had) learned was placed in a slightly
different context. It's as if they would never recognize a wolf if
it wore a sheep fur on its back...

It was the same with a physics exam we had. I overheard the same
always-best-in-class guys complain about a problem I solved in three
lines. They wrote page up and page down and couldn't solve it. "Did
the professor really talk about circular polarization?" they asked.
I had never made any calculations on that, but we had the formula book.
I looked at polarization, and there we had "elliptical polarization".
I found a formula that I could easily twist into an expression giving
me the value they asked for from the values they gave. I was lacking
an angle though, but I guessed that the angle must describe the
proportion between the big and small axis in the ellipse, so I just
assumed it had to be 45 degrees (well, pi/4 radians) for a circle.
That was all. Copy formula. Note that circle leads to theta =3D pi / 4.
Enter values and type result. I thought it was the simples question
in the exam.

I surely hope these other guys (who were three years younger than me,
fresh from secondary school) saw the light eventually, otherwise I fear
that my idea that you learn how to learn and how to solve problems in thi=
s
education is not true.

For me it was a big help to have worked for a year as an electro technici=
an.
It meant that what I learnt in school wasn't all new. It explained phenom=
ena
I was well aware of. To get there without that experience would have been=
 a bit
like studying colour composition if you are blind from birth.

> >> * learn one of each type of language.  Learn Lisp or Forth or=20
> ML.  Break your
>
>It's not likely you'll find books on those things.

Sure you will! On the net even. There have been links to some free
Lisp family books already. For ML, the French OO variaty OCaml might
be interesting. See http://caml.inria.fr/oreilly-book/

I don't know about Forth, I used to code some FIG-Forth on my old
C-64 back in the 80's. It feels a bit ... old? But perhaps I'm being
stupid. It's certainly a useful language in some niches, for instance
in small embedded systems. I think there are still cheap microcontrollers
that can be programmed in Forth. (See http://www.pmb.net/projects/68HC11.=
html)



--=20
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From mongo57a@comcast.net  Wed Dec 18 14:48:55 2002
From: mongo57a@comcast.net (andy surany)
Date: Wed Dec 18 14:48:55 2002
Subject: [Tutor] Pmw question
Message-ID: <004901c2a6ce$4eaf99c0$2502a8c0@emily.ewndsr01.nj.comcast.net>

Hello list!

I'm looking at supplementing my Python/Tkinter application with Pmw
widgets. The application runs on both a Linux and win32 platform. I
found the tar file for Pmw on SourceForge - but I can't seem to find the
distribution for win32. This led me to believe that Pmw was not
available for win32 - but in searching the web, I find lots of
references to Pmw and win32.

Can anyone "point" me in the right direction for the win32 distribution?

TIA

Andy



From carroll@tjc.com  Wed Dec 18 14:49:24 2002
From: carroll@tjc.com (Terry Carroll)
Date: Wed Dec 18 14:49:24 2002
Subject: [Tutor] A slighty off topic question/rant for the  experienced.
In-Reply-To: <5.1.0.14.0.20021218015517.02caf298@www.thinkware.se>
Message-ID: <Pine.LNX.4.44.0212181146470.24476-100000@mauve.rahul.net>

On Wed, 18 Dec 2002, Magnus Lycka wrote:

 
> Maybe one day I will learn how to be brief.

"I am sorry to write you such a long letter.
I don't have time to write a short one."

 - Oscar Wilde


-- 
Terry Carroll        |  
Santa Clara, CA      |   "The parties are advised to chill." 
carroll@tjc.com      |       - Mattel, Inc. v. MCA Records, Inc.,
Modell delendus est  |         no. 98-56577 (9th Cir. July 24, 2002)



From Doug.Shawhan@gecits.ge.com  Wed Dec 18 15:12:01 2002
From: Doug.Shawhan@gecits.ge.com (Doug.Shawhan@gecits.ge.com)
Date: Wed Dec 18 15:12:01 2002
Subject: [Tutor] happy holidays and thanks for the fish...
Message-ID: <47B6167F8E69D31194BA0008C7918D4205C54FE7@msxcvg02itscge.gecits.ge.com>

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C2A6D1.7ECE2510
Content-Type: text/plain;
	charset="iso-8859-1"

Hear hear!

-----Original Message-----
From: Doug Clapp [mailto:dclapp@qwest.net]
Sent: Wednesday, December 18, 2002 9:30 AM
To: tutor@python.org
Subject: [Tutor] happy holidays and thanks for the fish...


Dear python tutors,
 
On behalf of all the (many, I'm sure) lurkers on this list, I'd like to
thank Danny, Magnus and the other python wizards who have so graciously
given their time and knowledge to the rest of us on this list.
 
We're here, we're learning, and we truly appreciate your contributions.
Thanks!
 
Doug Clapp


------_=_NextPart_001_01C2A6D1.7ECE2510
Content-Type: text/html;
	charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 5.50.4912.300" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><SPAN class=687091020-18122002><FONT face=Arial color=#0000ff size=2>Hear 
hear!</FONT></SPAN></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
  <DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma 
  size=2>-----Original Message-----<BR><B>From:</B> Doug Clapp 
  [mailto:dclapp@qwest.net]<BR><B>Sent:</B> Wednesday, December 18, 2002 9:30 
  AM<BR><B>To:</B> tutor@python.org<BR><B>Subject:</B> [Tutor] happy holidays 
  and thanks for the fish...<BR><BR></FONT></DIV>
  <DIV><FONT face=Arial size=2>Dear python tutors,</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>On behalf of all the (many, I'm sure) lurkers on 
  this list, I'd like to thank Danny, Magnus and the other python wizards who 
  have so graciously given their time and knowledge to the rest of us on this 
  list.</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>We're here, we're learning, and we truly 
  appreciate your contributions.&nbsp; Thanks!</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>Doug Clapp</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------_=_NextPart_001_01C2A6D1.7ECE2510--


From lumbricus@gmx.net  Wed Dec 18 15:13:01 2002
From: lumbricus@gmx.net (lumbricus@gmx.net)
Date: Wed Dec 18 15:13:01 2002
Subject: [Tutor] Re: Question from programmer
References: <6d.4cd1076.2b30960d@cs.com>
Message-ID: <30156.1040242291@www3.gmx.net>

Hi!

> I developed a password program where it askes you the password and if you 
> dont get it rightin three turns it goes intio an infinte loop.

*ROTFLMAO*

>  My                                                   
> question 
> is how do I make it work.  

What exactly do you mean by 'it'?

> How Do i get it to show up before I can access 

What is 'it' again?

> Python.  (How do i enforce the code)

Enforce code? (How long have I been away? I don't understand anything)
Show what you got.
 
>                                 Thank you
>                                      programer

SCNR, J"o!

-- 
sigfault

+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!



From rustynewton@comcast.net  Wed Dec 18 15:26:09 2002
From: rustynewton@comcast.net (Rusty Newton)
Date: Wed Dec 18 15:26:09 2002
Subject: [Tutor] need advice
Message-ID: <004a01c2a6e2$f51355e0$6401a8c0@huntsv01.al.comcast.net>

This is a multi-part message in MIME format.

--Boundary_(ID_oSw/303+VvN1awOENwn+9w)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7BIT

heya!

im a beginning programmer in python, i know a decent bit by now but anyways 
i was looking to try to program a mud of some sort and i was wondering if anyone
had some suggestions as to what area i should look into and start learning and reading
about for the online part of it? anyone have any muds they have made or some
suggestions on websites or somthing? anyways thank you!

-rusty

--Boundary_(ID_oSw/303+VvN1awOENwn+9w)
Content-type: text/html; charset=iso-8859-1
Content-transfer-encoding: 7BIT

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1126" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>heya!</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>im a beginning programmer in python, i know a 
decent bit by now but anyways </FONT></DIV>
<DIV><FONT face=Arial size=2>i was looking to try to program a mud of some sort 
and i was wondering if anyone</FONT></DIV>
<DIV><FONT face=Arial size=2>had some suggestions as to what area i should look 
into and start learning and reading</FONT></DIV>
<DIV><FONT face=Arial size=2>about for the online part of it? anyone have any 
muds they have made or some</FONT></DIV>
<DIV><FONT face=Arial size=2>suggestions on websites or somthing? anyways thank 
you!</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>-rusty</FONT></DIV></BODY></HTML>

--Boundary_(ID_oSw/303+VvN1awOENwn+9w)--


From lumbricus@gmx.net  Wed Dec 18 15:29:04 2002
From: lumbricus@gmx.net (lumbricus@gmx.net)
Date: Wed Dec 18 15:29:04 2002
Subject: [Tutor] Pmw question
References: <004901c2a6ce$4eaf99c0$2502a8c0@emily.ewndsr01.nj.comcast.net>
Message-ID: <32766.1040243219@www3.gmx.net>

Hi!

> Hello list!
> 
> I'm looking at supplementing my Python/Tkinter application with Pmw
> widgets. The application runs on both a Linux and win32 platform. I
> found the tar file for Pmw on SourceForge - but I can't seem to find the
> distribution for win32. 

I don't know about pmw, but what you are looking for is 
probably _in_ the tarball?
winzip should be able to handle it.

> TIA
> 
> Andy

HTH, J"o!

-- 
sigfault

+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!



From abli@freemail.hu  Wed Dec 18 15:31:45 2002
From: abli@freemail.hu (Abel Daniel)
Date: Wed Dec 18 15:31:45 2002
Subject: [Tutor] Pmw question
In-Reply-To: <004901c2a6ce$4eaf99c0$2502a8c0@emily.ewndsr01.nj.comcast.net>
References: <004901c2a6ce$4eaf99c0$2502a8c0@emily.ewndsr01.nj.comcast.net>
Message-ID: <20021218203034.GA1590@hooloovoo>

andy surany (mongo57a@comcast.net) wrote:
> I'm looking at supplementing my Python/Tkinter application with Pmw
> widgets. The application runs on both a Linux and win32 platform. I
> found the tar file for Pmw on SourceForge - but I can't seem to find the
> distribution for win32. This led me to believe that Pmw was not
> available for win32 - but in searching the web, I find lots of
> references to Pmw and win32.
> 
> Can anyone "point" me in the right direction for the win32 distribution?
I think you use the same tarball.
Pmw is built on top of tkinter, all written in python.
I dont think there is anything platform-dependent in the code.

abli
abli@freemail.hu


From mongo57a@comcast.net  Wed Dec 18 16:30:03 2002
From: mongo57a@comcast.net (andy surany)
Date: Wed Dec 18 16:30:03 2002
Subject: [Tutor] Pmw question
Message-ID: <006201c2a6dc$d7dd0f80$2502a8c0@emily.ewndsr01.nj.comcast.net>

Ok, I looked at other win distributions that I have and it looks like
the .exe is simply a "copy to the appropriate directory" program, so
I'll give it a try.

In the Linux world, should I simply execute the tar in
/usr/lib/python2.2/site-packages?

Thanks again.


-----Original Message-----
From: Abel Daniel <abli@freemail.hu>
To: tutor@python.org <tutor@python.org>
Date: Wednesday, December 18, 2002 3:32 PM
Subject: Re: [Tutor] Pmw question


>andy surany (mongo57a@comcast.net) wrote:
>> I'm looking at supplementing my Python/Tkinter application with Pmw
>> widgets. The application runs on both a Linux and win32 platform. I
>> found the tar file for Pmw on SourceForge - but I can't seem to find
the
>> distribution for win32. This led me to believe that Pmw was not
>> available for win32 - but in searching the web, I find lots of
>> references to Pmw and win32.
>>
>> Can anyone "point" me in the right direction for the win32
distribution?
>I think you use the same tarball.
>Pmw is built on top of tkinter, all written in python.
>I dont think there is anything platform-dependent in the code.
>
>abli
>abli@freemail.hu
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor



From magnus@thinkware.se  Wed Dec 18 16:36:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 18 16:36:01 2002
Subject: [Tutor] Pmw question
In-Reply-To: <20021218203034.GA1590@hooloovoo>
References: <004901c2a6ce$4eaf99c0$2502a8c0@emily.ewndsr01.nj.comcast.net>
 <004901c2a6ce$4eaf99c0$2502a8c0@emily.ewndsr01.nj.comcast.net>
Message-ID: <5.1.0.14.0.20021218221048.02b61890@www.thinkware.se>

At 21:30 2002-12-18 +0100, Abel Daniel wrote:
>andy surany (mongo57a@comcast.net) wrote:
> > Can anyone "point" me in the right direction for the win32 distribution?
>I think you use the same tarball.
>Pmw is built on top of tkinter, all written in python.
>I dont think there is anything platform-dependent in the code.

I can verify that. Just unpack the tar-ball in
site-packages.

A computer without GNU tar is not a computer! ;)

Even if you don't fully appreciate the Unix environment,
I suggest that software developers install cygwin or
some similar set of Unix tools. Not only for 'tar', but
for the hundreds of utilities a programmer has severe
difficulties without, such as grep, find, diff, which,
man, wc, tail etc.

But be sure that the path to your windows Python comes
before the path to the cygwin binaries, unless the cygwin
version of Python is what you want.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Wed Dec 18 16:39:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 18 16:39:02 2002
Subject: Python and MUD Re: [Tutor] need advice
In-Reply-To: <004a01c2a6e2$f51355e0$6401a8c0@huntsv01.al.comcast.net>
Message-ID: <5.1.0.14.0.20021218223815.02a5eea0@www.thinkware.se>

Hi Rusty, just a little nag: Try to write more descriptive
subjects to your mails. Almost all people who post questions
here want advice. Something about MUD would have been more
helpful...

At 14:15 2002-12-18 -0800, Rusty Newton wrote:
>im a beginning programmer in python, i know a decent bit by now but anyways
>i was looking to try to program a mud of some sort and i was wondering if 
>anyone
>had some suggestions as to what area i should look into and start learning 
>and reading
>about for the online part of it? anyone have any muds they have made or some
>suggestions on websites or somthing? anyways thank you!

It's been done. Have you searched Vaults of Parnassus?
http://py.vaults.ca/apyllo.py?find=mud


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Wed Dec 18 16:47:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 18 16:47:01 2002
Subject: [Tutor] happy holidays and thanks for the fish...
In-Reply-To: <000e01c2a6aa$4ffc9680$d4c8a8c0@mn.rr.com>
Message-ID: <5.1.0.14.0.20021218224257.02a5c678@www.thinkware.se>

At 09:29 2002-12-18 -0600, Doug Clapp wrote:
>On behalf of all the (many, I'm sure) lurkers on this list, I'd like to 
>thank Danny, Magnus and the other python wizards who have so graciously 
>given their time and knowledge to the rest of us on this list.

It's all part of my grand master plan to make very expensive
Python mentors and consultants in high demand all over the
world. Especially in tax paradises in the sub tropics. The
big catch is that Python is all too easy to learn, so there
might not actually be a real need for a lot of mentors and
consultants. :(

>We're here, we're learning, and we truly appreciate your 
>contributions.  Thanks!

You're welcome. I'll fly away this weekend and return on
January 4 or 5. Hm... should start thinking of what to pack
except the obvious (i.e. laptop and some books).

/Magnus

P.S. Anyone seen the movie yet?


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From Doug.Shawhan@gecits.ge.com  Wed Dec 18 17:11:10 2002
From: Doug.Shawhan@gecits.ge.com (Doug.Shawhan@gecits.ge.com)
Date: Wed Dec 18 17:11:10 2002
Subject: [Tutor] moinmoin
Message-ID: <47B6167F8E69D31194BA0008C7918D4205C54FEC@msxcvg02itscge.gecits.ge.com>

Hi folks. I don't want to mispost here if this question is too off-topic. 

Has anyone here had experience with the MoinMoin wikki? I can find no
mailing list specifically for it and would like to get some aid and advice
with some botheration.

Thanks!

d 


From magnus@thinkware.se  Wed Dec 18 17:19:04 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 18 17:19:04 2002
Subject: [Tutor] Pmw question
In-Reply-To: <006201c2a6dc$d7dd0f80$2502a8c0@emily.ewndsr01.nj.comcast.n
 et>
Message-ID: <5.1.0.14.0.20021218225030.02ab94d0@www.thinkware.se>

At 16:31 2002-12-18 -0500, andy surany wrote:
>In the Linux world, should I simply execute the tar in
>/usr/lib/python2.2/site-packages?

No. A tar file can't be executed. It's not a program,
it's an archive file. There are many things you might
want to do with an archive file. You might want to
update it with changed or additional content. You might
want to list it. You might want to unpack it. If you
unpack it you might want to use any of a number of different
options. Most real unix programs DO NOT use a captive user
interface where you click on checkboxes or select things
from menues. That's very unproductive in the long run.
Instead Unix chooses the slightly tougher start, and
forces the user to get some idea of what he's doing before
he starts. You give instructions to tar by command line
flags. This is much faster to work with than any GUI once
you know it, and it's at least a thousand times easier and
more reliable to automate. Try to drive WinZip from a
python script if you can!

$ man tar

I suggest that you read "Unix in a Nutshell" or some
similar, good book. You can also have a look at
http://www.thinkware.se/cgi-bin/thinki.cgi/UnixPhilosophy
(One of the few Thinki pages I never had anything to
do with... :)

In Linux you should do something like:

$ cd cd /usr/lib/python2.2/site-packages/
$ tar xzvf Pmw.1.1.tar.gz

In WinDOS you go to a slightly different directory and
run the same tar command. If you have some brain dead
GUI unarchiver instead, you might have to be very careful
to make sure that the paths in the tar-file are used.
You don't want to end up with all your files directly in
your site-packages directory.

But as I wrote, I suggest that you use the same, good tools
in Windows. In NT/Win2k it works well (also in XP I guess.)
DOS derivates like Win98 and Win ME are not so good though,
but bash is certainly much better than command.com...

See http://www.cygwin.com/


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From mongo57a@comcast.net  Wed Dec 18 17:34:01 2002
From: mongo57a@comcast.net (andy surany)
Date: Wed Dec 18 17:34:01 2002
Subject: [Tutor] Pmw question
Message-ID: <007501c2a6e5$bd290960$2502a8c0@emily.ewndsr01.nj.comcast.net>

Sorry - bad choice of "words" on my part. I do understand tar... but I
appreciate the correction since others on the list may have also
misinterpreted.

Thanks.

-----Original Message-----
From: Magnus Lycka <magnus@thinkware.se>
To: andy surany <mongo57a@comcast.net>; Abel Daniel <abli@freemail.hu>;
tutor@python.org <tutor@python.org>
Date: Wednesday, December 18, 2002 5:18 PM
Subject: Re: [Tutor] Pmw question


>At 16:31 2002-12-18 -0500, andy surany wrote:
>>In the Linux world, should I simply execute the tar in
>>/usr/lib/python2.2/site-packages?
>
>No. A tar file can't be executed. It's not a program,
>it's an archive file. There are many things you might
>want to do with an archive file. You might want to
>update it with changed or additional content. You might
>want to list it. You might want to unpack it. If you
>unpack it you might want to use any of a number of different
>options. Most real unix programs DO NOT use a captive user
>interface where you click on checkboxes or select things
>from menues. That's very unproductive in the long run.
>Instead Unix chooses the slightly tougher start, and
>forces the user to get some idea of what he's doing before
>he starts. You give instructions to tar by command line
>flags. This is much faster to work with than any GUI once
>you know it, and it's at least a thousand times easier and
>more reliable to automate. Try to drive WinZip from a
>python script if you can!
>
>$ man tar
>
>I suggest that you read "Unix in a Nutshell" or some
>similar, good book. You can also have a look at
>http://www.thinkware.se/cgi-bin/thinki.cgi/UnixPhilosophy
>(One of the few Thinki pages I never had anything to
>do with... :)
>
>In Linux you should do something like:
>
>$ cd cd /usr/lib/python2.2/site-packages/
>$ tar xzvf Pmw.1.1.tar.gz
>
>In WinDOS you go to a slightly different directory and
>run the same tar command. If you have some brain dead
>GUI unarchiver instead, you might have to be very careful
>to make sure that the paths in the tar-file are used.
>You don't want to end up with all your files directly in
>your site-packages directory.
>
>But as I wrote, I suggest that you use the same, good tools
>in Windows. In NT/Win2k it works well (also in XP I guess.)
>DOS derivates like Win98 and Win ME are not so good though,
>but bash is certainly much better than command.com...
>
>See http://www.cygwin.com/
>
>
>--
>Magnus Lycka, Thinkware AB
>Alvans vag 99, SE-907 50 UMEA, SWEDEN
>phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
>http://www.thinkware.se/  mailto:magnus@thinkware.se
>



From magnus@thinkware.se  Wed Dec 18 17:51:35 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 18 17:51:35 2002
Subject: [Tutor] moinmoin
In-Reply-To: <47B6167F8E69D31194BA0008C7918D4205C54FEC@msxcvg02itscge.ge
 cits.ge.com>
Message-ID: <5.1.0.14.0.20021218233857.02ab9618@www.thinkware.se>

At 17:10 2002-12-18 -0500, Doug.Shawhan@gecits.ge.com wrote:
>Hi folks. I don't want to mispost here if this question is too off-topic.

No worry.

>Has anyone here had experience with the MoinMoin wikki? I can find no
>mailing list specifically for it and would like to get some aid and advice
>with some botheration.

Sure, Thinki ( http://www.thinkware.se/cgi-bin/thinki.cgi/ ) is a MoinMoin
installation (which I ought to have upgraded a long time ago. (Hey, I did
upgrade it a long time ago! :)

There are certainly mailing lists. You find them here:
http://moin.sourceforge.net/

There seems to be some trouble with the sourceforce mailing list
archives though. Both lists are fairly low traffic, but MoinMoin
is actively developed.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Wed Dec 18 17:59:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Dec 18 17:59:02 2002
Subject: [Tutor] Pmw question
In-Reply-To: <007501c2a6e5$bd290960$2502a8c0@emily.ewndsr01.nj.comcast.n
 et>
Message-ID: <5.1.0.14.0.20021218235401.02a3deb8@www.thinkware.se>

At 17:35 2002-12-18 -0500, andy surany wrote:
>Sorry - bad choice of "words" on my part. I do understand tar... but I
>appreciate the correction since others on the list may have also
>misinterpreted.

Ok, I suppose "extract" was the word you were loking for.
In that case, yes.

With the current version of Pmw you should end up with the
following new directories under site-packages.

---Pmw
    +---Alpha_99_9_example
    =A6   +---lib
    +---Pmw_1_1
        +---bin
        +---contrib
        +---demos
        +---doc
        +---lib
        +---tests

Are many people here using Pmw? In my opinion, Tkinter is all
to weak without something extra like Pmw, but I thought the
Tix support in current Python was good enough to replace Pmw.
But when I really tried, it turned out that at least with
ActivePython 2.2.1, the Tix support isn't anything like the
rich library on the Tix web site. I found no Grid widget for
instance.

So I guess I might stay with wxPython for some more time...


--=20
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From abli@freemail.hu  Wed Dec 18 18:18:02 2002
From: abli@freemail.hu (Abel Daniel)
Date: Wed Dec 18 18:18:02 2002
Subject: [Tutor] Pmw question
In-Reply-To: <5.1.0.14.0.20021218235401.02a3deb8@www.thinkware.se>
References: <007501c2a6e5$bd290960$2502a8c0@emily.ewndsr01.nj.comcast.net> <5.1.0.14.0.20021218235401.02a3deb8@www.thinkware.se>
Message-ID: <20021218231725.GB877@hooloovoo>

 Magnus Lycka (magnus@thinkware.se) wrote:
> Are many people here using Pmw?
I do.

> In my opinion, Tkinter is all
> to weak without something extra like Pmw, but I thought the
> Tix support in current Python was good enough to replace Pmw.
> But when I really tried, it turned out that at least with
> ActivePython 2.2.1, the Tix support isn't anything like the
> rich library on the Tix web site. I found no Grid widget for
> instance.
I tried Tkinter first, then changed to Pmw when i needed a listbox with
dynamic scrollbars.
However, i think pmw's biggest advantage is not in the widgets itselves,
but in the framework. The "megawidget' idea, which lets you make one
widget from (for example) a frame, which has dozens of other widgets on
it. And to do this transparently. You can alway access the lower level-
building blocks. If you need to change one thing, you dont have to
override something deeply hidden in the structure, (which is essentially
re-making the widget except using inheritance and overriding instead of
copy-paste) you can do it with one method call. Its much cleaner.

> So I guess I might stay with wxPython for some more time...
I plan to try that, too. And pyGtk, and pyQt, and pyKde, and....

abli
abli@freemail.hu


From michael@trollope.org  Wed Dec 18 18:30:02 2002
From: michael@trollope.org (Michael Powe)
Date: Wed Dec 18 18:30:02 2002
Subject: [Tutor] A slighty off topic question/rant for the experienced .
In-Reply-To: <7497DCA1C240C042B28F6657ADFD8E097022A6@i2km11-ukbr.domain1.systemhost.net>; from alan.gauld@bt.com on Wed, Dec 18, 2002 at 06:17:55PM -0000
References: <7497DCA1C240C042B28F6657ADFD8E097022A6@i2km11-ukbr.domain1.systemhost.net>
Message-ID: <20021218152859.A23394@titan.spiretech.com>

On Wed, Dec 18, 2002 at 06:17:55PM -0000, alan.gauld@bt.com wrote:
> > >> My suggestions on learning to be a better coder:
> > 
> > >> * learn one of each type of language.  Learn Lisp or Forth 
> > or ML.  Break your
> 
> Absolutely, thats why I used the list of languages in my earlier post.
> Its concepts not current flavor languages that matter.
> 
> That's why my web tutor uses 3 languages - to ilustrate that 
> although the synrtax is different the concepts are exactly 
> the same in any imperative language(like Python).
> 
> > It's not likely you'll find books on those things.
> 
> Actually there is a vast array of literature on Lisp. There is 
> a much smaller amount on ML and Forth (although it used to have 
> a lot of books). Another good FP language with a reasonable 
> book selection is Haskell.

in fact, i believe daniel friedman has written a book, "the little ml'er" that
corresponds to his books "the little schemer" and "the seasoned schemer".

ah yes, http://www.cs.indiana.edu/~dfried/.  also deserving of mention is
"scheme and the art of programming."

mp


From Adam Vardy <anvardy@roadrunner.nf.net>  Wed Dec 18 19:08:02 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Wed Dec 18 19:08:02 2002
Subject: [Tutor] Fun
Message-ID: <4962974592.20021218203537@roadrunner.nf.net>

I glanced at the Library Reference looking for something fun to try.
One command apparently will print a calendar for you. So I give it a
try, but...

>>> calendar (2000)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: 'module' object is not callable
>>> s=calendar (2000)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: 'module' object is not callable
>>>

-- 
Adam Vardy



From dyoo@hkn.eecs.berkeley.edu  Wed Dec 18 19:15:14 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed Dec 18 19:15:14 2002
Subject: [Tutor] making proigress   [using sudo with Python scripts]
In-Reply-To: <3E001D42.6030804@netzero.net>
Message-ID: <Pine.LNX.4.44.0212181551480.9264-100000@hkn.eecs.berkeley.edu>


On Wed, 18 Dec 2002, Kirk Bailey wrote:

> But here's a brainbuster: how do we get a nobody owned and run script to
> issue and execute the 'newaliases' command?

Hi Kirk,

This isn't really too Python related, (but then, we've been way off
tangent recently... *grin*).

In Unix, a program takes on the privileges of the user who executes the
program.  If we're not taking Unix's setuid/setgid mechanisms into
account, then it really doesn't matter who "owns" the program, but it's
more important who "runs" it.


You should probably be using 'sudo' or something like it to solve these
permission problems. The utility 'sudo' grants temporary root privilege to
normal users:

    http://www.courtesan.com/sudo/

There's a nice BSD-oriented tutorial of sudo on O'Reilly's ONLamp.com:

    http://www.onlamp.com/pub/a/bsd/2002/08/29/Big_Scary_Daemons.html

By using sudo, you can write Python scripts that do serious system
administrative tasks like automating the regeneration of the aliases file
in sendmail.


I'd discourage a 'setuid' approach to Unix permissions without
understanding its dangers: there seems to be a constant stream of 'setuid'
security holes that pop up every so often on the security newsgroups, so
getting 'setuid' right is not an easy thing to do.  In some cases, there's
no alternative to a setuid wrapper --- Mailman, for example, uses one ---
but most any setuid program should be held with suspicion.


Good luck to you!



From dyoo@hkn.eecs.berkeley.edu  Wed Dec 18 19:16:03 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed Dec 18 19:16:03 2002
Subject: [Tutor] Fun
In-Reply-To: <4962974592.20021218203537@roadrunner.nf.net>
Message-ID: <Pine.LNX.4.44.0212181609290.9264-100000@hkn.eecs.berkeley.edu>


On Wed, 18 Dec 2002, Adam Vardy wrote:

> I glanced at the Library Reference looking for something fun to try.
> One command apparently will print a calendar for you. So I give it a
> try, but...
>
> >>> calendar (2000)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: 'module' object is not callable
> >>> s=calendar (2000)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: 'module' object is not callable
> >>>


Hi Adam,


I'm assuming that we ran:

###
>>> import calendar
###


right before doing anything else.  What this does is give us access to the
calendar module:

###
>>> calendar
<module 'calendar' from
'/home/dyoo/local/Python-2.2.1/lib/python2.2/calendar.pyc'>
>>>
>>> dir(calendar)
['EPOCH', 'FRIDAY', 'February', 'January', 'MONDAY', 'SATURDAY', 'SUNDAY',
 'SliceType', 'THURSDAY', 'TUESDAY', 'WEDNESDAY', '__all__',
 '__builtins__', '__doc__', '__file__', '__name__', '_center',
 '_colwidth', '_firstweekday', '_indexer', '_localized_day',
 '_localized_month', '_spacing', 'calendar', 'day_abbr', 'day_name',
 'error', 'firstweekday', 'format3c', 'format3cstring', 'isleap',
 'leapdays', 'localtime', 'mdays', 'mktime', 'month', 'month_abbr',
 'month_name', 'monthcalendar', 'monthrange', 'prcal', 'prmonth',
 'prweek', 'setfirstweekday', 'strftime',  'timegm', 'week',
 'weekday', 'weekheader']
###



But it still means that when we want to grab stuff inside the calendar
module, we still need to use a "fully qualified" name that digs within the
calendar module:

###
>>> calendar.week        ##  The "week" function in the "calendar" module
<function week at 0x8160684>
>>> calendar.calendar    ##  The "calendar" function in the "calendar"
                         ##  module
<function calendar at 0x8160404>
###



Hope this helps!



From mongo57a@comcast.net  Wed Dec 18 20:24:02 2002
From: mongo57a@comcast.net (andy surany)
Date: Wed Dec 18 20:24:02 2002
Subject: [Tutor] Pmw question
Message-ID: <008001c2a6fd$5dedd6c0$2502a8c0@emily.ewndsr01.nj.comcast.net>

Yes, that is what my extract looks like.

I have been using Tkinter for the last few months - and found it
adequate. You can do almost everything with it - though you may have =
to
write a good deal more code than you would like. I am now moving to t=
he
next level in the development of my UI: plotting and charting. I trie=
d
hooking programs like PythonPlot - and while it works, it does not of=
fer
much in the way of flexibility. So I'm turning to Pmw in the hopes th=
at
maybe I can use some "pre fab" capabilities. Depending on what I find=
, I
may turn to something like reportlab - but I have high hopes that I'l=
l
be able to use the capabilities within Pmw.

BTW, if anyone could recommend an "enhanced" PythonPlot, I would
certainly appreciate it......

Andy




-----Original Message-----
=46rom: Magnus Lycka <magnus@thinkware.se>
To: andy surany <mongo57a@comcast.net>; tutor@python.org
<tutor@python.org>
Date: Wednesday, December 18, 2002 5:59 PM
Subject: Re: [Tutor] Pmw question


At 17:35 2002-12-18 -0500, andy surany wrote:
>Sorry - bad choice of "words" on my part. I do understand tar... but=
 I
>appreciate the correction since others on the list may have also
>misinterpreted.

Ok, I suppose "extract" was the word you were loking for.
In that case, yes.

With the current version of Pmw you should end up with the
following new directories under site-packages.

---Pmw
    +---Alpha_99_9_example
    =A6   +---lib
    +---Pmw_1_1
        +---bin
        +---contrib
        +---demos
        +---doc
        +---lib
        +---tests

Are many people here using Pmw? In my opinion, Tkinter is all
to weak without something extra like Pmw, but I thought the
Tix support in current Python was good enough to replace Pmw.
But when I really tried, it turned out that at least with
ActivePython 2.2.1, the Tix support isn't anything like the
rich library on the Tix web site. I found no Grid widget for
instance.

So I guess I might stay with wxPython for some more time...


--
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor




From dyoo@hkn.eecs.berkeley.edu  Wed Dec 18 21:42:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed Dec 18 21:42:02 2002
Subject: [Tutor] Fun (fwd)  [more information on source files?]
Message-ID: <Pine.LNX.4.44.0212181840180.15528-100000@hkn.eecs.berkeley.edu>

Hi Adam,

I'm redirecting your question to the rest of Tutor, so that everyone there
has an opportunity to help answer your question.


Good luck to you!


---------- Forwarded message ----------
Date: Wed, 18 Dec 2002 23:04:52-0330
From: Adam Vardy <anvardy@roadrunner.nf.net>
To: Danny Yoo<dyoo@hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] Fun


Hi Danny,

Wednesday, December 18, 2002, 8:45:33 PM, you wrote:

>> On Wed, 18 Dec 2002, Adam Vardy wrote:

>> But it still means that when we want to grab stuff inside the calendar
>> module, we still need to use a "fully qualified" name that digs within the
>> calendar module:

>> ###
>>>> calendar.week        ##  The "week" function in the "calendar" module
>> <function week at 0x8160684>
>>>> calendar.calendar    ##  The "calendar" function in the "calendar"
>>                          ##  module
>> <function calendar at 0x8160404>
>> ###



>> Hope this helps!

Yes.  Got it now!

        November                  December\nMo Tu We Th Fr Sa Su      M
h Fr Sa Su      Mo Tu We Th Fr Sa Su\n                   1
4  5                   1  2  3\n 2  3  4  5  6  7  8       6  7  8  9 1
     4  5  6  7  8  9 10\n 9 10 11 12 13 14 15      13 14 15 16 17 18 1
 12 13 14 15 16 17\n16 17 18 19 20 21 22      20 21 22 23 24 25 26
 21 22 23 24\n23 24 25 26 27 28 29      27 28 29 30               25 26
 30 31\n30 31\n'

Kinda packed. But all there.

Say Danny, would you have any clue if a guy could find source files
somewhere around, for interesting random examples. On a web search I
can find an odd few, but haven't found a pile of examples in one
archive.

I think I remember doing some kind of perpetual calendar in high
school. Not really what I was after.  But I do like to keep track of
dates. :)  At least while I gotta keep sticking to numbers, and no
pixels zig zagging around yet.

I've come to a fairly boggy area in my book.


-- 
Adam Vardy




From lumbricus@gmx.net  Wed Dec 18 23:38:02 2002
From: lumbricus@gmx.net (lumbricus@gmx.net)
Date: Wed Dec 18 23:38:02 2002
Subject: [Tutor] Fun (fwd)  [more information on source files?]
References: <Pine.LNX.4.44.0212181840180.15528-100000@hkn.eecs.berkeley.edu>
Message-ID: <5461.1040272620@www3.gmx.net>

Hi!

> Hi Adam,

[ snip ]

>  21 22 23 24\n23 24 25 26 27 28 29      27 28 29 30               25 26
>  30 31\n30 31\n'
> 
> Kinda packed. But all there.

If it looks ugly to you, print it :-)
>>> print calendar.calendar(2002)
 
[ snip ]

> Adam Vardy

HTH, J"o!


-- 
sigfault

+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!



From idiot1@netzero.net  Thu Dec 19 01:27:01 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Thu Dec 19 01:27:01 2002
Subject: [Tutor] making proigress   [using sudo with Python scripts]
References: <Pine.LNX.4.44.0212181551480.9264-100000@hkn.eecs.berkeley.edu>
Message-ID: <3E016677.6040802@netzero.net>

Right now I have a crontab set to run newaliass every 30 minutes, but after 
getting the thing to referr to the aliases file with a soft link, bypassing a 
bigheadache, I would rather get the script to handle the task RIGHT NOW and 
not have to wait. But you are right, this is no longer kiddyland we are 
playing with.

Oh- I just installed sudo. (yay, rah, first time I did something like that, no 
helper, read the flipping manual on doing it first, ftp from within the 
server, got the tarball, did the entire thing. I'm pleased with myself.) And 
when I told my cohosting provoder, a good friend, he had a minor security 
keniption, and told me he has to pay more attention to INTERNAL network 
security now. Hmm, reassuring statement.

But clarify a issue for me. Here is an error from the log:
f1 = open('./lists/aliases.tinylist','r')	#180 open the aliases file
IOError: [Errno 2] No such file or directory: './lists/aliases.tinylist'

strange. Does open not accept relative path names? I suppose I COULD whip up 
the absolute path, other scripts do, but will this not accept relative path 
declarations?



Danny Yoo wrote:
> 
> On Wed, 18 Dec 2002, Kirk Bailey wrote:
> 
> 
>>But here's a brainbuster: how do we get a nobody owned and run script to
>>issue and execute the 'newaliases' command?
> 
> 
> Hi Kirk,
> 
> This isn't really too Python related, (but then, we've been way off
> tangent recently... *grin*).
> 
> In Unix, a program takes on the privileges of the user who executes the
> program.  If we're not taking Unix's setuid/setgid mechanisms into
> account, then it really doesn't matter who "owns" the program, but it's
> more important who "runs" it.
> 
> 
> You should probably be using 'sudo' or something like it to solve these
> permission problems. The utility 'sudo' grants temporary root privilege to
> normal users:
> 
>     http://www.courtesan.com/sudo/
> 
> There's a nice BSD-oriented tutorial of sudo on O'Reilly's ONLamp.com:
> 
>     http://www.onlamp.com/pub/a/bsd/2002/08/29/Big_Scary_Daemons.html
> 
> By using sudo, you can write Python scripts that do serious system
> administrative tasks like automating the regeneration of the aliases file
> in sendmail.
> 
> 
> I'd discourage a 'setuid' approach to Unix permissions without
> understanding its dangers: there seems to be a constant stream of 'setuid'
> security holes that pop up every so often on the security newsgroups, so
> getting 'setuid' right is not an easy thing to do.  In some cases, there's
> no alternative to a setuid wrapper --- Mailman, for example, uses one ---
> but most any setuid program should be held with suspicion.
> 
> 
> Good luck to you!
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


-- 

end

Respectfully,
              Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                            +--------+

---------------------------------------------
Introducing NetZero Long Distance
1st month Free!
Sign up today at: www.netzerolongdistance.com


From janos.juhasz@VELUX.com  Thu Dec 19 02:25:01 2002
From: janos.juhasz@VELUX.com (janos.juhasz@VELUX.com)
Date: Thu Dec 19 02:25:01 2002
Subject: [Tutor] capture :LPT
Message-ID: <OF94D2E3A3.52C289FC-ONC1256C94.0026A47B@LocalDomain>

Dear Gurus,

I have an ERP like program, that can't use the WINDOWS printing correct=
ly,
but printing nicely to DOS printers.
My idea was to printing to the - for example - :LPT2 port, where wouldn=
't
be any printer device just a a program, that could capture all the data=

sent to the printer.
It would be a python program.
It would filter and reshape the printing and would send it to a real pr=
int
device on any other port.

I have tried it with  p =3D open("LPT1:", "rb") and an infinite loop, b=
ut it
just hung up. :(

>>> p =3D open("LPT1:", "rb")
>>> while 1:
...   print p.read(1)

Is it possible under MS?

Best regards,
-----------------------
Juh=E1sz J=E1nos
IT department
E-Mail: janos.juhasz@VELUX.com
=




From magnus@thinkware.se  Thu Dec 19 05:17:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu Dec 19 05:17:01 2002
Subject: [Tutor] making proigress   [using sudo with Python scripts]
In-Reply-To: <3E016677.6040802@netzero.net>
References: <Pine.LNX.4.44.0212181551480.9264-100000@hkn.eecs.berkeley.edu>
Message-ID: <5.1.0.14.0.20021219110006.02b4fa20@www.thinkware.se>

At 01:25 2002-12-19 -0500, Kirk Bailey wrote:
>But clarify a issue for me. Here is an error from the log:
>f1 = open('./lists/aliases.tinylist','r')       #180 open the aliases file
>IOError: [Errno 2] No such file or directory: './lists/aliases.tinylist'
>
>strange. Does open not accept relative path names?

It certainly does, but it can only open existing files for reading.

>I suppose I COULD whip up the absolute path, other scripts do, but will 
>this not accept relative path declarations?

Put something like "print os.getcwd()" (you might need to print to a
log file perhaps?) before the open(). Relative paths are relative from
the location that the executing process considers to be its current
working directory... This is probably not what you think--and it could
change if the system is configured differently.

I suggest that you set some variable

BASE_DIR = '/some/path'

in the beginning of your script, and then either do

os.chdir(BASE_DIR)

before you start messing with files, or join your BASE_DIR with the
relative names when you open.

aliasesFile = file(os.path.join(BASE_DIR, 'lists/aliases.tinylist', 'r')

This way you can relocate your files by just changing
BASE_DIR. Of course, you could also read BASE_DIR from
a config file or environment variable etc.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From muldersmaarten@hotmail.com  Thu Dec 19 06:07:01 2002
From: muldersmaarten@hotmail.com (Maarten Mulders)
Date: Thu Dec 19 06:07:01 2002
Subject: [Tutor] (no subject)
Message-ID: <F118QfG1ME21RwrMQFp000211ef@hotmail.com>

Is there a command that clears the complete (shell)screen, like ClrScr or 
CLS or something?

_________________________________________________________________
MSN Zoeken, voor duidelijke zoekresultaten! 
http://search.msn.nl/worldwide.asp



From magnus@thinkware.se  Thu Dec 19 06:26:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu Dec 19 06:26:01 2002
Subject: [Tutor] capture :LPT
In-Reply-To: <OF94D2E3A3.52C289FC-ONC1256C94.0026A47B@LocalDomain>
Message-ID: <5.1.0.14.0.20021219112841.02d38f38@www.thinkware.se>

At 08:24 2002-12-19 +0100, janos.juhasz@VELUX.com wrote:
>I have an ERP like program, that can't use the WINDOWS printing correctly,
>but printing nicely to DOS printers.

I'm not sure whether you mean that the output can't reach the printer,
or if it gets ugly. Either way, I don't think Python is the right tool
for this. A DOS printer device isn't a file...

If you do manage to get your text into Python, are you able to print
them from your python program in a simple way, or are you just getting
into deeper trouble? ;) DOS/Windows is a flawed platform. Many things
that are trivial in for instance Unix are much more complicated there.

Maybe this will help?
http://support.microsoft.com/default.aspx?scid=KB;en-us;q154498
http://service1.symantec.com/SUPPORT/pca.nsf/docid/1999111116163612
http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm
http://www.lexpro.co.za/en/sundry/dos2win.html
http://www.columbia.edu/~em36/wpdos/anyprinter.html


Otherwise, look at some of these pages
http://members.cox.net/dos/print01.htm (LPT2DSK or PRN2FILE -- then you
can use Python if you wish.)
http://www.geocities.com/DOSPrint/
http://www.dosprint.com/

Good Luck!

As always, you can find a lot of information with Google.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Thu Dec 19 06:33:03 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu Dec 19 06:33:03 2002
Subject: [Tutor] (no subject)
In-Reply-To: <F118QfG1ME21RwrMQFp000211ef@hotmail.com>
Message-ID: <5.1.0.14.0.20021219122859.02d6b130@www.thinkware.se>

At 11:54 2002-12-19 +0100, Maarten Mulders wrote:
>Is there a command that clears the complete (shell)screen, like ClrScr or 
>CLS or something?

Check the mailing list archive...let's see...was it two months
ago?

The short answer is: Not in python.

These kinds of things are inherently platform and context dependent.
There are different solutions depending on operating system and how
you run your program.

import os
dummy = os.system('CLS')

might be what you are looking for, but that depends...


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From alan.gauld@bt.com  Thu Dec 19 07:07:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu Dec 19 07:07:01 2002
Subject: [Tutor] A slighty off topic question/rant for the experienced
 .
Message-ID: <7497DCA1C240C042B28F6657ADFD8E097022AA@i2km11-ukbr.domain1.systemhost.net>

> the real world. I felt sorry about my friends who had hardly ever
> seen a resistor or a capacitor before they started with the electric
> circuit theory. It was just meaningless words to them, 

Me too. I worked for 9 years as a technician before going to 
university to do my degree. Some topics - the math! and quantum 
mechanics - I found very hard after 9 years out of school but 
the electronics bits were easy.

> Fortunately where I was studying people we usually selling lecture
> notes for a reasonable cost, so I could sit and listen and think.

Hah! I wish. We had to take notes and listen.... :-)

On the topic of studying exam technique rathger than the topic in 
question, one class test completely confused many students. It 
was first year electrical theory and instead of drawing the 
circuits in the usual rectangular style the prof drew the lines 
at all kinds of weird angles. Many students then couldn't figure 
out which were in series and which in parallel. It was  a sobering 
lesson.

The equivalent thing in CS would be if a programming exam asked 
about the operation of function written in a language the students 
had never studied. Provided it was the same programming style it 
should be possible to work with it, but many students would, 
I suspect, just panic...

> I don't know about Forth, I used to code some FIG-Forth on my old
> in small embedded systems. I think there are still cheap 
> microcontrollers that can be programmed in Forth. (See 

The monitor program on Sun workstations is in forth. The masochistic 
can halt their sparcstation, drop into that big white screen and 
start forthing away! :-)

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld


From gp@pooryorick.com  Thu Dec 19 07:22:02 2002
From: gp@pooryorick.com (Poor Yorick)
Date: Thu Dec 19 07:22:02 2002
Subject: [Tutor] capture :LPT
References: <OF94D2E3A3.52C289FC-ONC1256C94.0026A47B@LocalDomain>
Message-ID: <3E01B9EA.1050305@pooryorick.com>

You may not be able to use Python to print directly to your parallel 
port, but you could use Python to print from a file, and then use the 
os.system command to tell DOS to print the file you created.

Poor Yorick
gp@pooryorick.com

janos.juhasz@VELUX.com wrote:

>Dear Gurus,
>
>I have an ERP like program, that can't use the WINDOWS printing correctly,
>but printing nicely to DOS printers.
>My idea was to printing to the - for example - :LPT2 port, where wouldn't
>be any printer device just a a program, that could capture all the data
>sent to the printer.
>It would be a python program.
>It would filter and reshape the printing and would send it to a real print
>device on any other port.
>
>I have tried it with  p = open("LPT1:", "rb") and an infinite loop, but it
>just hung up. :(
>
>>>>p = open("LPT1:", "rb")
>>>>while 1:
>>>>
>...   print p.read(1)
>
>Is it possible under MS?
>
>Best regards,
>-----------------------
>Juhász János
>IT department
>E-Mail: janos.juhasz@VELUX.com
>
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>




From gp@pooryorick.com  Thu Dec 19 07:28:01 2002
From: gp@pooryorick.com (Poor Yorick)
Date: Thu Dec 19 07:28:01 2002
Subject: [Tutor] capture :LPT
References: <OF94D2E3A3.52C289FC-ONC1256C94.0026A47B@LocalDomain> <3E01B9EA.1050305@pooryorick.com>
Message-ID: <3E01BB57.6000809@pooryorick.com>

Typo alert:  "from a file" should read "to a file".

Poor Yorick wrote:

> You may not be able to use Python to print directly to your parallel 
> port, but you could use Python to print from a file, and then use the 
> os.system command to tell DOS to print the file you created.
>
> Poor Yorick
> gp@pooryorick.com
>
> janos.juhasz@VELUX.com wrote:
>
>> Dear Gurus,
>>
>> I have an ERP like program, that can't use the WINDOWS printing 
>> correctly,
>> but printing nicely to DOS printers.
>> My idea was to printing to the - for example - :LPT2 port, where 
>> wouldn't
>> be any printer device just a a program, that could capture all the data
>> sent to the printer.
>> It would be a python program.
>> It would filter and reshape the printing and would send it to a real 
>> print
>> device on any other port.
>>
>> I have tried it with  p = open("LPT1:", "rb") and an infinite loop, 
>> but it
>> just hung up. :(
>>
>>>>> p = open("LPT1:", "rb")
>>>>> while 1:
>>>>>
>> ...   print p.read(1)
>>
>> Is it possible under MS?
>>
>> Best regards,
>> -----------------------
>> Juhász János
>> IT department
>> E-Mail: janos.juhasz@VELUX.com
>>
>>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
>




From python.tutorial@jarava.org  Thu Dec 19 09:17:01 2002
From: python.tutorial@jarava.org (Javier JJ)
Date: Thu Dec 19 09:17:01 2002
Subject: [Tutor] Advice required: Documentation Writing / Sofware Testing
References: <0E5508EBA1620743B409A2B8365DE16FDC829D@SOVEREIGN>
Message-ID: <012701c2a769$2ac16fc0$0100a8c0@uno>

Hi all!

I am a longtime lurker of this list, and sometimes I even have something
to say (besides asking for whatever). But today I'm in "begging" mode,
so if you could possibly help me: I just wanted to know if any of the
wise minds around this forum could point me torwards resources for a new
job I'm getting into.

I've just been offered a very interesting job in a small company. Part
of my duties will be to create / maintain this company's product's docs,
whitepapers, etc. so I'd like to know of any resources / advice on
writing documentation. I'm not so much interested on the "how tos", on
the nuts and bolts of documentation software use (I don't know for sure
how they do it actually on the company), but more on something like
"style guides" and "dos and dont's" of the _writing_ itself. Specially
since English is not my mother tongue (quite obvious one, that!) and
I'll have to document both in English and Spanish.

On second thoughts, I'd also like any advice on a good "system" for
generating docs. I have used (briefly) LaTeX, and DocBook, and the
classical "HTML and play with it"... but is there any "killer app", any
"must have" for this?

And now for the second part of the query :) Another thing I'll probably
have to do sooner or later (probably sooner than later) is to get myself
involved in the testing of the aforementioned products (testing and
documentation are part of QA in this company). Any advice / resources /
tips on the matter?

I know I'm asking for quite a bit, but I have grown used to the quality
of the advice here, so I thought I'd just try to make good use of it ;)

Thanks a lot

  Javier


--
ŤWork like you don't need the money.
  Dance like nobody's watching.
 Love like you've never been hurt.Å¥




From polb@blueyonder.co.uk  Thu Dec 19 12:53:03 2002
From: polb@blueyonder.co.uk (paul butler)
Date: Thu Dec 19 12:53:03 2002
Subject: [Tutor] RE:Advice required: Documentation Writing / Sofware
Message-ID: <0a6ff05531713c2PCOW034M@blueyonder.co.uk>

Here's a few Amazon 4 star picks:
{HYPERLINK "/exec/obidos/tg/detail/-/0028641469/ref=pd_sim_books_1/102-3859412-5275367?v=glance&s=books"}The Complete Idiot's Guide to Technical Writing by Krista Van Laan
{HYPERLINK "/exec/obidos/tg/detail/-/0028641469/ref=pd_sim_books_1/102-3859412-5275367?v=glance&s=books"}
{HYPERLINK "/exec/obidos/tg/detail/-/0966994906/ref=pd_sim_books_4/102-3859412-5275367?v=glance&s=books"}Untechnical Writing - How to Write About Technical Subjects and 
Products So Anyone Can Understand 

How to Communicate Technical Information: A Handbook of Software and 
Hardware Documentation
by {HYPERLINK "/exec/obidos/search-handle-url/index=books&field-author=Price%2C%20Jonathan/102-3859412-5275367"}Jonathan Price, {HYPERLINK "/exec/obidos/search-handle-url/index=books&field-author=Korman%2C%20Henry/102-3859412-5275367"}Henry Korman 

Reportlab.com might be well worth a look

hope this helps

Paul Butler


From alan.gauld@bt.com  Thu Dec 19 13:08:13 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu Dec 19 13:08:13 2002
Subject: [Tutor] Advice required: Documentation Writing / Sofware Test
 ing
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0974DA71@i2km11-ukbr.domain1.systemhost.net>

> whitepapers, etc. so I'd like to know of any resources / advice on
> writing documentation. I'm not so much interested on the "how tos", on
> ...
> On second thoughts, I'd also like any advice on a good "system" for
> generating docs. I have used (briefly) LaTeX, and DocBook, and the
> classical "HTML and play with it"... but is there any "killer 
> app", any "must have" for this?

Depends on their funds.

But the classic app for large scale documentation that must support 
multiple versions, multiple platforms(web, paper, PDF etc) is Adobe 
FrameMaker. There really is little to compare with it.

Look at the Adobe site for details. The UI takes a little getting 
used to - its not like MS Word - as it is a document publishing system 
and optimised for that. It is also not cheap! But it is the publishing
industry standard tool for large documents. Many book publishers will 
accept little else.

Next best is probably LaTeX with its array of conversion filters. 

And in all cases backed up with good version control - CVS for example.


Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld


From Adam Vardy <anvardy@roadrunner.nf.net>  Thu Dec 19 16:11:16 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Thu Dec 19 16:11:16 2002
Subject: [Tutor] Motion
Message-ID: <165138865087.20021219174027@roadrunner.nf.net>

Suppose I'd like to start off with something simple like moving a
letter around the screen, pretend he's your man, and you move him
around by some control, mouse or something. How do you start with
that? How do you place the letter anywhere on screen?

-- 
Adam Vardy



From unixguru@newsguy.com  Thu Dec 19 16:24:06 2002
From: unixguru@newsguy.com (Gareth)
Date: Thu Dec 19 16:24:06 2002
Subject: [Tutor] Incorrect padding errors; base64 on UNIX vs Windows
Message-ID: <200212192122.NAA87754@newsguy.com>

I have two scripts running as part of a set of automation tests. One sends
various attachments to a mail server; the other retrieves the mail and
processes it for attachments. (The idea being to exercise an underlying proxy
on client machines.)

If I run the retrieval script on UNIX, it retrieves the mail and detaches all
the attachments. Each attachment matches the original file when diffed.
Perfect. Couldn't ask for anything more.

On Windows (2000 SP3), however, I constantly receive the following once the
mail has been downloaded and is being processed for attachments:
Traceback (most recent call last):
  File "gm2.py", line 110, in ?
  File "gm2.py", line 31, in writeparts
  File "C:\Python22\lib\mhlib.py", line 731, in getbody
    return self.getbodyparts()
  File "C:\Python22\lib\mhlib.py", line 723, in getbodyparts
    part = SubMessage(self.folder, n, mf)
  File "C:\Python22\lib\mhlib.py", line 744, in __init__
    self.body = Message.getbodytext(self)
  File "C:\Python22\lib\mhlib.py", line 705, in getbodytext
    mimetools.decode(self.fp, output, encoding)
  File "C:\Python22\lib\mimetools.py", line 137, in decode
    return base64.decode(input, output)
  File "C:\Python22\lib\base64.py", line 31, in decode
    s = binascii.a2b_base64(line)
binascii.Error: Incorrect padding

I did wonder if it might have been something in the proxy that's actually
being tested, which might have been reassembling attachments incorrectly.
Happens on a vanilla Windows system, though.

So, my question becomes: what's different in the base64 handling on Win32
versus UNIX? Why does Win32 raise padding errors for the exact same message,
but UNIX sails through fine? Even my Python distributions are pretty close:
2.2.0 on UNIX; 2.2.1 on Windows.

Is there something I can/should do if the platform is Win32 to make sure the
padding is correct? Is this a spurious error? The attachments were all binary
- didn't want to deal with possible CR/LF/EOF issues just yet. :-)

(I haven't included the .py files involved, since they're pretty much lifted
directly from copyrighted books. However, refer to Programming Python (2nd
Ed.), page 630 to see how I do the decode. I tried decoding files attached via
the other script, and also files sent from real mail clients - same result.)

Any insight into how to go about addressing this would be appreciated. I'm at
my wits' end with this problem, and just seem to keep going around in circles
(ie making the problem worse). Google didn't offer any insight, other than to
report this used to be broken some time ago (around 1.5.2 if I recall), and
subsequently fixed.

Thanks
Gareth



From dyoo@hkn.eecs.berkeley.edu  Thu Dec 19 17:02:04 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu Dec 19 17:02:04 2002
Subject: [Tutor] Motion
In-Reply-To: <165138865087.20021219174027@roadrunner.nf.net>
Message-ID: <Pine.LNX.4.44.0212191400200.8026-100000@hkn.eecs.berkeley.edu>


On Thu, 19 Dec 2002, Adam Vardy wrote:

> Suppose I'd like to start off with something simple like moving a letter
> around the screen, pretend he's your man, and you move him around by
> some control, mouse or something. How do you start with that? How do you
> place the letter anywhere on screen?

The Pygame module might be useful for this: it gives enough control over
the display so that even writing arcade games is possible:

    http://pygame.org


Hope this helps!



From rustynewton@comcast.net  Thu Dec 19 17:46:35 2002
From: rustynewton@comcast.net (Rusty Newton)
Date: Thu Dec 19 17:46:35 2002
Subject: [Tutor] tkinter scrolling
Message-ID: <001201c2a7bf$bebacae0$6401a8c0@huntsv01.al.comcast.net>

This is a multi-part message in MIME format.

--Boundary_(ID_R9SiFLua7Z3dnSc95DyOig)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7BIT

hail!

creating a text game, i have a textbox widget and entry widget, when you type somthing in the
entry widget it takes the text from it and prints it in the textbox widget,  when the text gets to the
bottom of the textbox widget i want it to automatically scroll down with the text so the text doesnt
go off the screen hehe =P anyone know how to do this? ive been looking through the scrolling methods
and such for the text field and scroll bar but i still cant figure it out! heres my code so far =] all the
comments are for my own sake hehe

from Tkinter import *
global loc_x,loc_y#define the variables for the x,y coordinates used in virtual mapping
loc_x = 0
loc_y = 0

class App:

##  Create GUI 

    def __init__(self, master):#creates the master widget self

        frame = Frame(master)#defines the master frame 
        frame.pack()#makes it visible
        
        #this creates the text box display
        self.text_box = Text(frame, state=DISABLED, bg="black", fg="green", wrap=WORD)
        self.text_box.grid(row=0, column=0, columnspan=4)
               
        #this creates the text entry box 
        self.text_entry = Entry(frame, bg="black", fg="green", insertbackground="white")
        self.text_entry.grid(row=1, column=0, sticky=E+W)
        self.text_entry.bind("<Return>", self.enter_command)#binds the enter key to the entrybox

        #creates the enterbutton
        self.text_enterbutton = Button(frame, text="ENTER", fg="blue", command=self.button_enter)
        self.text_enterbutton.grid(row=1, column=1, sticky=E+W)

        #creates the quitbutton
        self.text_quitbutton = Button(frame, text="QUIT", fg="blue", command=frame.quit)
        self.text_quitbutton.grid(row=1, column=2, sticky=E+W)
 
    def enter_command(self, event):
        #this is what happens when you press the enter button
        #in the entry text box
                self.text_box.config(state=NORMAL)
                sending_text = self.text_entry.get() + "\n"
                self.text_box.insert(END, sending_text)
                self.text_entry.selection_range(0, END)
                self.text_box.config(state=DISABLED)
    def button_enter(self):
        #this is what happens when you click the enter button
        #after entering text in the text entry box
                self.text_box.config(state=NORMAL)
                sending_text = self.text_entry.get() + "\n"
                self.text_box.insert(END, sending_text)
                self.text_entry.selection_range(0, END)
                self.text_box.config(state=DISABLED)
        

root = Tk()#creates the root widget to run everything

app = App(root)#creates a instance of the class app as a child to the parent root widget

root.mainloop()#starts the main tk loop to start checking all its child widgets



--Boundary_(ID_R9SiFLua7Z3dnSc95DyOig)
Content-type: text/html; charset=iso-8859-1
Content-transfer-encoding: 7BIT

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1126" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>hail!</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>creating a text game, i have a textbox widget and 
entry widget, when you type somthing in the</FONT></DIV>
<DIV><FONT face=Arial size=2>entry widget it takes the text from it and prints 
it in the textbox widget,&nbsp; when the text gets to the</FONT></DIV>
<DIV><FONT face=Arial size=2>bottom of the textbox widget i want it to 
automatically scroll down with the text so the text doesnt</FONT></DIV>
<DIV><FONT face=Arial size=2>go off the screen hehe =P anyone know how to do 
this? ive been looking through the scrolling methods</FONT></DIV>
<DIV><FONT face=Arial size=2>and such for the text field and scroll bar but i 
still cant figure it out! heres my code so far =] all the</FONT></DIV>
<DIV><FONT face=Arial size=2>comments are for my own sake hehe</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>from Tkinter import *<BR>global loc_x,loc_y#define 
the variables for the x,y coordinates used in virtual mapping<BR>loc_x = 
0<BR>loc_y = 0</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>class App:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>##&nbsp; Create GUI </FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp; def __init__(self, 
master):#creates the master widget self</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; frame = 
Frame(master)#defines the master frame 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; frame.pack()#makes it 
visible<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #this creates the text box 
display<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.text_box = 
Text(frame, state=DISABLED, bg="black", fg="green", 
wrap=WORD)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.text_box.grid(row=0, column=0, 
columnspan=4)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
#this creates the text entry box <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.text_entry = Entry(frame, bg="black", fg="green", 
insertbackground="white")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.text_entry.grid(row=1, column=0, 
sticky=E+W)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.text_entry.bind("&lt;Return&gt;", self.enter_command)#binds the enter key 
to the entrybox</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #creates 
the enterbutton<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.text_enterbutton = Button(frame, text="ENTER", fg="blue", 
command=self.button_enter)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.text_enterbutton.grid(row=1, column=1, sticky=E+W)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #creates 
the quitbutton<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.text_quitbutton = Button(frame, text="QUIT", fg="blue", 
command=frame.quit)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.text_quitbutton.grid(row=1, column=2, 
sticky=E+W)<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp; def enter_command(self, 
event):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #this is what happens when 
you press the enter button<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #in the 
entry text 
box<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.text_box.config(state=NORMAL)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
sending_text = self.text_entry.get() + 
"\n"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.text_box.insert(END, 
sending_text)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.text_entry.selection_range(0, 
END)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.text_box.config(state=DISABLED)<BR>&nbsp;&nbsp;&nbsp; def 
button_enter(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #this is what 
happens when you click the enter 
button<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #after entering text in the 
text entry 
box<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.text_box.config(state=NORMAL)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
sending_text = self.text_entry.get() + 
"\n"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.text_box.insert(END, 
sending_text)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.text_entry.selection_range(0, 
END)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.text_box.config(state=DISABLED)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>root = Tk()#creates the root widget to run 
everything</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>app = App(root)#creates a instance of the class app 
as a child to the parent root widget</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>root.mainloop()#starts the main tk loop to start 
checking all its child widgets</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><BR></FONT>&nbsp;</DIV></BODY></HTML>

--Boundary_(ID_R9SiFLua7Z3dnSc95DyOig)--


From magnus@thinkware.se  Thu Dec 19 18:15:23 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu Dec 19 18:15:23 2002
Subject: [Tutor] Motion
In-Reply-To: <165138865087.20021219174027@roadrunner.nf.net>
Message-ID: <5.1.0.14.0.20021219231022.02a92ca8@www.thinkware.se>

At 17:40 2002-12-19 -03-30, Adam Vardy wrote:
>Suppose I'd like to start off with something simple like moving a
>letter around the screen, pretend he's your man, and you move him
>around by some control, mouse or something. How do you start with
>that? How do you place the letter anywhere on screen?

What makes you think this is simple? :)

Let's just say it varies...

Performing calculations and logical tricks is one thing, but when
we move objects on the screen, everything depends on how the
operating system interfaces with the screen. There is unfortunately
no standard for that. (If there ever could be--user interfaces can
be very different.)

This means that you must decide what kind of environment you use.
The first thing to consider is probably whether you want a graphical
user interface of a text based user interface.

Surprisingly, the task you mention might be easier to do with a
complex graphical user interface, than with a plain simple text
based interface. At least in Windows, and certainly if you want it
to be cross platform.

The most common Python GUI toolkits, such as Tkinter and wxPython
works the same (well, close at least) in Windows, Linux and some
more operating systems.

The most common toolkit for screen manipulation in text mode, curses,
doesn't work in Windows as far as I know. At least not without a lot
of fiddling.

Here's something little to try...

 >>> from Tkinter import *
 >>> import time
 >>> root = Tk()
 >>> c = Canvas(root)
 >>> c.pack()
 >>> o = c.create_oval((10,10,20,20))
 >>> for i in range(10):
...     c.move(o,i,i)
...     root.update()
...     time.sleep(1)

(If you don't see anything happening, chances are that the GUI
window is hidden behind your Python interpreter as you put it
back in focus as you type. Check your taskbar if you are in
windows, and click on the Tk thingie...)

Unfortunately, the Tkinter docs in the standard library reference
is...well...it's better than it used to be...but it's still very
thin. But guess what! I think section 16.4 is just the thing for
you to start with. The turtle module!

Start by running the turtle.py file that you find in the lib-tk
directory. Then have a look at the contents of turtle.py. The
demo() function shows how to use this module.

Then you fire up python, import turtle and play... There you go.

The next step is to handle input from mouse or keyboard... Tkinter
can do that too...


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From scot@possum.in-berlin.de  Thu Dec 19 18:27:01 2002
From: scot@possum.in-berlin.de (Scot Stevenson)
Date: Thu Dec 19 18:27:01 2002
Subject: [Tutor] Advice required: Documentation Writing / Sofware Testing
In-Reply-To: <012701c2a769$2ac16fc0$0100a8c0@uno>
References: <0E5508EBA1620743B409A2B8365DE16FDC829D@SOVEREIGN> <012701c2a769$2ac16fc0$0100a8c0@uno>
Message-ID: <200212192333.54734.scot@possum.in-berlin.de>

Hello Javier, 

> On second thoughts, I'd also like any advice on a good "system" for
> generating docs. I have used (briefly) LaTeX, and DocBook, and the
> classical "HTML and play with it"... but is there any "killer app", any
> "must have" for this?

If you want to be able to output the same stuff in different formats, you 
might want to try the XML Version of DocBook, because you get to write it in 
ASCII (vi is great for this, as it is for just about everything), move it to 
just about any given format, and it seems to have good language support - 
German is fine, at least. 

Writing in a "lower language" like LaTeX (which I was doing stuff in before) 
has the disadvantage tempting you to try just one more trick or format the 
bugger just that much cooler. With DocBook, you don't get much control over 
the final layout, and that is just fine for me.

Y, Scot

-- 
  Scot W. Stevenson -- scot@possum.in-berlin.de -- Zepernick, Germany



From magnus@thinkware.se  Thu Dec 19 18:38:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu Dec 19 18:38:02 2002
Subject: [Tutor] tkinter scrolling
In-Reply-To: <001201c2a7bf$bebacae0$6401a8c0@huntsv01.al.comcast.net>
Message-ID: <5.1.0.14.0.20021220003903.02d63228@www.thinkware.se>

At 16:35 2002-12-19 -0800, Rusty Newton wrote:
>when the text gets to the
>bottom of the textbox widget i want it to automatically scroll down with 
>the text so the text doesnt
>go off the screen
...
>                 self.text_box.insert(END, sending_text)

should be followed by "self.text_box.see(END)"

Simple, right?


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From hall@ouhep1.nhn.ou.edu  Thu Dec 19 19:18:02 2002
From: hall@ouhep1.nhn.ou.edu (Isaac Hall)
Date: Thu Dec 19 19:18:02 2002
Subject: [Tutor] Motion
In-Reply-To: <5.1.0.14.0.20021219231022.02a92ca8@www.thinkware.se>
Message-ID: <Pine.LNX.4.44.0212191804050.21789-100000@ouhep1.nhn.ou.edu>

 
> Unfortunately, the Tkinter docs in the standard library reference
> is...well...it's better than it used to be...but it's still very
> thin. But guess what! I think section 16.4 is just the thing for
> you to start with. The turtle module!
> 
> Start by running the turtle.py file that you find in the lib-tk
> directory. Then have a look at the contents of turtle.py. The
> demo() function shows how to use this module.
> 
> Then you fire up python, import turtle and play... There you go.
> 
> The next step is to handle input from mouse or keyboard... Tkinter
> can do that too...
> 
> 
> 

I would point out for people looking for good documentation on Tkinter 
that I came across on a google search that comes from the NMT that has 
really helped me alot.  It list almost everything one can do with Tkinter.

The only incompleteness is that they do not talk at all about the 
.pack() and .place() methods, and instead only use .grid().

I will let you be the judge of whether that is a drawback or an 
advantage.

Whatever the case, I found this document very easy to read and understand

It is located here in postscript format:
http://www.nmt.edu/tcc/help/pubs/tkinter.ps

and here in PDF format
http://www.nmt.edu/tcc/help/pubs/tkinter.pdf

Cheers,
Ike
-- 



From ramrom@earthling.net  Thu Dec 19 19:36:01 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Thu Dec 19 19:36:01 2002
Subject: [Tutor] Advice required: Documentation Writing / Sofware
 Testing
In-Reply-To: <012701c2a769$2ac16fc0$0100a8c0@uno>
References: <0E5508EBA1620743B409A2B8365DE16FDC829D@SOVEREIGN>
Message-ID: <5.2.0.9.0.20021219170822.03622470@66.28.54.253>

--=====================_27814705==.ALT
Content-Type: text/plain; charset="us-ascii"; format=flowed

Gailer's Guidelines for Applaudable Documentation:
0 Ensure that management is committed to quality documentation. Help create 
a quality assurance guideline, and commitment to adhering to it.
1 Use active rather than passive verbs (e.g. "push the button" rather than 
"the button is pushed")
2 Talk directly to the reader (e.g. "you" rather than "the user")
3 Be brief (e.g "rename changes the name of a file" rather than "rename 
enables the user to ...")
4 Be consistent. If you use a certain term to refer to something, always 
use exactly the same term. You are writing a technical document, not a novel.
5 Avoid italics or quotes as the sole attempt to tell the reader that this 
is a new term. Whenever introducing a new term, explain it the first time.
6 Be complete and accurate. If documenting a command explain all the 
ramifications. Note that, among others, Microsoft's documentation almost 
always fails to explain everything a command does, and often has errors in 
the explanation. That costs each reader lost time experimenting an 
debugging. If a command can raise errors, list the errors with the command.
7 Provide a glossary that explains all technical terminology that is 
specific to whatever you're documenting, and any terms that might be 
outside the range of knowledge of the intended reader.
8 Different readers have different strategies for searching the index. So 
index things under various headings to make it easy for anyone to find what 
they're looking for. Also include references to chapter and section 
headings in the index. It can be very frustrating to (1) search the index, 
then have to look in the TOC (table of contents) to find the term.
9 Indicate e.g. by bolding the page number(s) in the index that are the 
main references for a term.
10 Understand the differences between e.g. and i.e., between effect and affect.
11 Be complete (2). Ensure (same as insure) that everything the reader 
needs to know is covered.
12 When documenting commands and functions, use meaningful names for 
parameters (arguments). Bad example:
   find <string1> <string2>. This forces the reader to look below to 
ascertain which argument is the string to be searched and which is the 
string sought. IBM handled this beautifully: find <needle> <haystack>.
13 Teach management and technical people the importance of quality 
documentation. Good documentation helps create happy customers, and reduces 
the need for technical support. Since many companies charge $$$ for 
technical support, this may be a conflict of interest, but customer 
satisfaction should come first.
14 Have technical sections reviewed by the responsible coder, engineer, 
designer.
15 Create a mechanism for keeping this current.
16 Use revision bars and a section that documents all changes from previous 
edition.
17 Publish on-line, and keep the on-line documentation up-to-date. It is a 
lot easier for users to read up-to-date documentation, than to wade through 
1000s of articles to see what has changed. If this is done religiously the 
on-line documentation can be the next edition when going to press.

There's probably more to say. Let me know if this helps. If you want 
further services in independent review of documentation and ideas for 
automating some of the above let me know.

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625

--=====================_27814705==.ALT
Content-Type: text/html; charset="us-ascii"

<html>
<body>
Gailer's Guidelines for Applaudable Documentation:<br>
0 Ensure that management is committed to quality documentation. Help
create a quality assurance guideline, and commitment to adhering to
it.<br>
1 Use active rather than passive verbs (e.g. &quot;push the button&quot;
rather than &quot;the button is pushed&quot;)<br>
2 Talk directly to the reader (e.g. &quot;you&quot; rather than &quot;the
user&quot;)<br>
3 Be brief (e.g &quot;rename changes the name of a file&quot; rather than
&quot;rename enables the user to ...&quot;)<br>
4 Be consistent. If you use a certain term to refer to something, always
use exactly the same term. You are writing a technical document, not a
novel.<br>
5 Avoid italics or quotes as the sole attempt to tell the reader that
<i>this is a new term</i>. Whenever introducing a new term, explain it
the first time.<br>
6 Be complete and accurate. If documenting a command explain all the
ramifications. Note that, among others, Microsoft's documentation almost
always fails to explain everything a command does, and often has errors
in the explanation. That costs each reader lost time experimenting an
debugging. If a command can raise errors, list the errors with the
command.<br>
7 Provide a glossary that explains all technical terminology that is
specific to whatever you're documenting, and any terms that might be
outside the range of knowledge of the intended reader.<br>
8 Different readers have different strategies for searching the index. So
index things under various headings to make it easy for anyone to find
what they're looking for. Also include references to chapter and section
headings in the index. It can be very frustrating to (1) search the
index, then have to look in the TOC (table of contents) to find the
term.<br>
9 Indicate e.g. by bolding the page number(s) in the index that are the
main references for a term.<br>
10 Understand the differences between e.g. and i.e., between effect and
affect.<br>
11 Be complete (2). Ensure (same as insure) that everything the reader
needs to know is covered.<br>
12 When documenting commands and functions, use meaningful names for
parameters (arguments). Bad example:<br>
&nbsp; find &lt;string1&gt; &lt;string2&gt;. This forces the reader to
look below to ascertain which argument is the string to be searched and
which is the string sought. IBM handled this beautifully: find
&lt;needle&gt; &lt;haystack&gt;.<br>
13 Teach management and technical people the importance of quality
documentation. Good documentation helps create happy customers, and
reduces the need for technical support. Since many companies charge $$$
for technical support, this may be a conflict of interest, but customer
satisfaction should come first.<br>
14 Have technical sections reviewed by the responsible coder, engineer,
designer.<br>
15 Create a mechanism for keeping this current. <br>
16 Use revision bars and a section that documents all changes from
previous edition.<br>
17 Publish on-line, and keep the on-line documentation up-to-date. It is
a lot easier for users to read up-to-date documentation, than to wade
through 1000s of articles to see what has changed. If this is done
religiously the on-line documentation can be the next edition when going
to press.<br><br>
There's probably more to say. Let me know if this helps. If you want
further services in independent review of documentation and ideas for
automating some of the above let me know.<br>
<x-sigsep><p></x-sigsep>
Bob Gailer<br>
<a href="mailto:ramrom@earthling.net" eudora="autourl">mailto:ramrom@earthling.net</a><br>
303 442 2625<br>
</body>
</html>

--=====================_27814705==.ALT--



From zswongg@hotmail.com  Thu Dec 19 21:27:01 2002
From: zswongg@hotmail.com (Wong Zhee Shiong)
Date: Thu Dec 19 21:27:01 2002
Subject: [Tutor] return class-call or value
Message-ID: <F121NZyp994GYVzRS0I00005491@hotmail.com>

Hi all,

Below is a common class example found in textbooks.
>>>class P:
...    def __init__(self, p1, p2):
...        self.dat=(p1,p2)
...    def __add__(self,other):
...        return self.__class__(self.dat[0] + other.dat[0], \
...                              self.dat[1] + other.dat[1])
...        # or perhaps "return P(...)"
...
If I replace the return statement with a value, i.e.
     return (self.dat[0] + other.dat[0], self.dat[1] + other.dat[1])
I still get the same result for >>> p = P(1,1) as before replacement, but 
what do I miss (wrong) about returning a value in OOP sense?

Thanks,
wong


_________________________________________________________________
The new MSN 8: smart spam protection and 3 months FREE*.  
http://join.msn.com/?page=features/junkmail&xAPID=42&PS=47575&PI=7324&DI=7474&SU= 
http://www.hotmail.msn.com/cgi-bin/getmsg&HL=1216hotmailtaglines_smartspamprotection_3mf



From dyoo@hkn.eecs.berkeley.edu  Thu Dec 19 22:33:03 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu Dec 19 22:33:03 2002
Subject: [Tutor] return class-call or value
In-Reply-To: <F121NZyp994GYVzRS0I00005491@hotmail.com>
Message-ID: <Pine.LNX.4.44.0212191921440.16517-100000@hkn.eecs.berkeley.edu>


On Fri, 20 Dec 2002, Wong Zhee Shiong wrote:

> >>>class P:
> ...    def __init__(self, p1, p2):
> ...        self.dat=(p1,p2)
> ...    def __add__(self,other):
> ...        return self.__class__(self.dat[0] + other.dat[0], \
> ...                              self.dat[1] + other.dat[1])
> ...        # or perhaps "return P(...)"
> ...
> If I replace the return statement with a value, i.e.
>      return (self.dat[0] + other.dat[0], self.dat[1] + other.dat[1])
>
> I still get the same result for
>
>    p = P(1,1)
>
> as before replacement, but what do I miss (wrong) about returning a
> value in OOP sense?


Hello!

Make sure that you're actually testing the thing that you changed.
*grin*

You need to test to see how your change affected the adding of these P
instances; you didn't notice a difference because your test was checking
to see if the initializer of your class is still working.

*** spoiler space ahead ***









*** spoiler space ***

Actually, to really be rigorous, try adding three P instances together:
you should definitely notice a difference in the behavior of the code,
depending on what kind of thing the __add__ function returns.

The thing that you're tinkering with is related to the mathematical idea
of "closure":

    http://mathworld.wolfram.com/SetClosure.html

where we can say that "+" is our binary operator that acts on two P
elements.


Good luck to you!



From dyoo@hkn.eecs.berkeley.edu  Thu Dec 19 22:44:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu Dec 19 22:44:01 2002
Subject: [Tutor] Fun (fwd)  [more information on source files / Useless
 Python!]
In-Reply-To: <Pine.LNX.4.44.0212181840180.15528-100000@hkn.eecs.berkeley.edu>
Message-ID: <Pine.LNX.4.44.0212191938410.16517-100000@hkn.eecs.berkeley.edu>

> Would you have any clue if a guy could find source files somewhere
> around, for interesting random examples. On a web search I can find an
> odd few, but haven't found a pile of examples in one archive.

Hi Adam,

Yes, there's a great web site called "Useless Python", maintained by Rob
Andrews:

    http://uselesspython.com/

It's chock full of little snippets of programs, and they're guaranteed to
be random, if not interesting.  *grin*



From GREENDAY31087@aol.com  Fri Dec 20 00:00:02 2002
From: GREENDAY31087@aol.com (GREENDAY31087@aol.com)
Date: Fri Dec 20 00:00:02 2002
Subject: [Tutor] Well...
Message-ID: <31.319f1e41.2b33fd9b@aol.com>

--part1_31.319f1e41.2b33fd9b_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

I'm just learning about python and programming in general so bear with me. 

Some lame questions that should be easy for everyone else...

-Could someone explain why GUI toolkits such as Tkinter are needed and used?

-Why is it that when a program finishes up, it immediately quits? Some 
programs have outcomes I'd like to view...How can I make it pause (like in 
DOS)?

That's about it for now. I'm sure I'll be stumped on a piece of cake again so 
look out...


--part1_31.319f1e41.2b33fd9b_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

<HTML><FONT FACE=arial,helvetica><FONT  SIZE=2 FAMILY="SANSSERIF" FACE="Arial" LANG="0">I'm just learning about python and programming in general so bear with me. <BR>
<BR>
Some lame questions that should be easy for everyone else...<BR>
<BR>
-Could someone explain why GUI toolkits such as Tkinter are needed and used?<BR>
<BR>
-Why is it that when a program finishes up, it immediately quits? Some programs have outcomes I'd like to view...How can I make it pause (like in DOS)?<BR>
<BR>
That's about it for now. I'm sure I'll be stumped on a piece of cake again so look out...<BR>
<BR>
</FONT></HTML>
--part1_31.319f1e41.2b33fd9b_boundary--


From thomi@thomi.imail.net.nz  Fri Dec 20 05:24:02 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Fri Dec 20 05:24:02 2002
Subject: [Tutor] Well...
In-Reply-To: <31.319f1e41.2b33fd9b@aol.com>
References: <31.319f1e41.2b33fd9b@aol.com>
Message-ID: <20021220231858.18c599bf.thomi@thomi.imail.net.nz>

> 
> -Could someone explain why GUI toolkits such as Tkinter are needed and
> used?
> 

because, sooner or later, you are going to want to make a program which
does something more then what is possable in a standard text box. or are
you asking about why use TKinter, as opposed to programming the GUI
yourself?

> -Why is it that when a program finishes up, it immediately quits? Some
> 
> programs have outcomes I'd like to view...How can I make it pause
> (like in DOS)?
> 

there are several ways to do this. to make a program pause for a number
of seconds, you can do this:

import time
time.sleep(5)

obviously, the import line goes at the start of your program, and the
time.sleep line goes at the end. in fact, it should be the last command
which is called.

or, you can do this, which asks the user to hit enter:

raw_input('Hit Enter to Exit Program')

try it !



-- 
DOS: n., A small annoying boot virus that causes random spontaneous
system
     crashes, usually just before saving a massive project.  Easily
cured by
     UNIX.  See also MS-DOS, IBM-DOS, DR-DOS.
(from David Vicker's .plan)
Thomi Richards,
thomi@imail.net.nz


From =?Windows-1251?B?YW50b25tdWhpbiDt4CByYW1ibGVyLnJ1?= <antonmuhin@rambler.ru>  Fri Dec 20 06:02:02 2002
From: =?Windows-1251?B?YW50b25tdWhpbiDt4CByYW1ibGVyLnJ1?= <antonmuhin@rambler.ru> (=?Windows-1251?B?YW50b25tdWhpbiDt4CByYW1ibGVyLnJ1?=)
Date: Fri Dec 20 06:02:02 2002
Subject: [Tutor] Advice required: Documentation Writing / Sofware Testing
In-Reply-To: <012701c2a769$2ac16fc0$0100a8c0@uno>
References: <0E5508EBA1620743B409A2B8365DE16FDC829D@SOVEREIGN>
 <012701c2a769$2ac16fc0$0100a8c0@uno>
Message-ID: <432494096.20021220140106@rambler.ru>

Hello, Javier!

Just several URLs you may find interesting:

http://stipo.larc.nasa.gov/sp7084/
http://libraries.mit.edu/subjects/style_usage.html
http://webster.commnet.edu/writing/writing.htm
http://web.mit.edu/uaa/www/writing/links/

Of course there should be tons of other resources.

Best regards,
Anton.



From magnus@thinkware.se  Fri Dec 20 07:37:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri Dec 20 07:37:01 2002
Subject: [Tutor] return class-call or value
In-Reply-To: <F121NZyp994GYVzRS0I00005491@hotmail.com>
Message-ID: <5.1.0.14.0.20021220105247.02a49a18@www.thinkware.se>

At 10:26 2002-12-20 +0800, Wong Zhee Shiong wrote:
>I still get the same result for >>> p = P(1,1) as before replacement, but 
>what do I miss (wrong) about returning a value in OOP sense?

No you don't.

In the first case you return an instance of the P class,
which has all the properties and behaviour of that class.
In the second case you return a tuple. That tuple doesn't
have those qualities at all.

But your class is rather abstract, so it might be difficult
to see the difference. Let's play with an unfinished Money
class instead.

 >>> class Money:
...     def __init__(self, cur, val):
...             self.cur = cur
...             self.val = float(val)
...     def __str__(self):
...             return "%s %.2f" % (self.cur, self.val)
...     def __add__(self, other):
...             assert self.cur == other.cur, "Currency conversion not 
implemented"
...             return self.__class__(self.cur, self.val + other.val)
...
 >>> a, b, c = Money('$', 5), Money('$', 7.5), Money('SEK', 1400.5)
 >>> print a, b, c
$ 5.00 $ 7.50 SEK 1400.50
 >>> x = a+b
 >>> print x
$ 12.50
 >>> x = a+c
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
   File "<interactive input>", line 8, in __add__
AssertionError: Currency conversion not implemented

If __add__ had returned self.val + other.val instead of creating a
new Money instance, x whould have been a float, not a Money object.
It would no longer have a currency, or a way to print itself in a
pretty way.



-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Fri Dec 20 07:53:03 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri Dec 20 07:53:03 2002
Subject: [Tutor] Well...
In-Reply-To: <31.319f1e41.2b33fd9b@aol.com>
Message-ID: <5.1.0.14.0.20021220134043.02987690@www.thinkware.se>

At 23:59 2002-12-19 -0500, GREENDAY31087@aol.com wrote:
>-Could someone explain why GUI toolkits such as Tkinter are needed and used?

I'm not sure what you are actually asking here...

Python does not have any intrinsic way of creating buttons,
windows, menues etc. It's not a part of the core language, like
arithmetic and basic file manipulation. One reason for this is
that Python works on many different platforms that are inherently
very different when it comes to user interface issues, and another
reason is to reduce the effort of developing and maintaining the
Python project. It's big enough as it is, and there are so many
GUI toolkits developed by others that it's much wiser from a
resource point of view to use an existing product instead of
inventing the wheel again.

So, some kind of GUI toolkit is needed to create programs
with a graphical user interface like Word, Excel etc has.
Without such a toolkit, or library, you are limited to just
handling communication through interfaces such as just reading
keyboard input or files, and output is limited to writing files
of just linearly printing text in some kind of terminal/console
/DOS-prompt etc.

Of course, this is not the whole truth. For instance, a lot of
progams communicate through computer networks, and you can
create a good user interface by using a web server and letting
the users use a web browser that takes care of the visualization
of the user interface. In that case you don't use a GUI toolkit.

Is this what you are asking for, or are you questioning the
usefulness of the graphical user interface concept?


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From michael@trollope.org  Fri Dec 20 10:17:01 2002
From: michael@trollope.org (Michael Powe)
Date: Fri Dec 20 10:17:01 2002
Subject: [Tutor] Well...
In-Reply-To: <31.319f1e41.2b33fd9b@aol.com>; from GREENDAY31087@aol.com on Thu, Dec 19, 2002 at 11:59:07PM -0500
References: <31.319f1e41.2b33fd9b@aol.com>
Message-ID: <20021220071603.A24936@titan.spiretech.com>

On Thu, Dec 19, 2002 at 11:59:07PM -0500, GREENDAY31087@aol.com wrote:
> I'm just learning about python and programming in general so bear with me. 
> 
> Some lame questions that should be easy for everyone else...
> 
> -Could someone explain why GUI toolkits such as Tkinter are needed and used?

i think the short answer is, so you don't have to reinvent the wheel.
a gui toolkit is about controlling the cursor on the screen.  keeping
track of the location of the cursor, moving it, setting and changing
the rgb of the screen pixels, capturing the click of a mouse,
associating user input with variables, based on screen location of the
input, &c are non-trivial exercises.  you could learn how to do this
(in C and assembler) and do it every time you wrote a program ... or
you could use a library written by someone else, who has done all that
work and put it together in a package that can be reused by anyone
wanting to create an interface.

> -Why is it that when a program finishes up, it immediately quits? Some 
> programs have outcomes I'd like to view...How can I make it pause (like in 
> DOS)?

print to screen or to file; or write a simple pause function with sleep.

note, however, that if you are running in an xterm, you may encounter a
problem with printing to screen due to the way xterms are constructed.
i'm not sure exactly how or why this is done (though i have seen the explanation,
i just can't remember it) -- but when you call some programs in an xterm window,
it actually writes a second window over the top of the original and writes
your program output to that window.   then when your program exits, the
second window exits also and you are returned to the original.  the most
obvious example of this behavior is reading a manpage.  i saw tom dickey
post an explanation of this behavior once to a newsgroup but in my aged 
decrepitude, i can't remember it.  ;-(

as to why a program quits immediately, well i think that part is
probably obvious -- a program only does what you tell it to do.  the
problems arise in the split between what you told it, what you thought
you told it, and what you actually wanted.  ;-)

mp



From SWidney@ci.las-vegas.nv.us  Fri Dec 20 11:32:03 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Fri Dec 20 11:32:03 2002
Subject: [Tutor] Well...
Message-ID: <0E5508EBA1620743B409A2B8365DE16FDC82C4@SOVEREIGN>

> > -Why is it that when a program finishes up, it immediately 
> > quits? Some programs have outcomes I'd like to view...
> > How can I make it pause (like in DOS)?
> > 
> 
> there are several ways to do this. to make a program pause 
> for a number of seconds, you can do this:
> 
> import time
> time.sleep(5)
> 
> obviously, the import line goes at the start of your program,
> and the time.sleep line goes at the end. in fact, it should
> be the last command which is called.
> 
> or, you can do this, which asks the user to hit enter:
> 
> raw_input('Hit Enter to Exit Program')
> 

I know that python also has the -i commandline option, which puts you into
interactive mode when the program ends or if there is an exception. I've
used it a few times during testing. What are the potential pitfalls of using
it?


Scott


From alan.gauld@bt.com  Fri Dec 20 12:21:39 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri Dec 20 12:21:39 2002
Subject: [Tutor] Well...
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0974DA74@i2km11-ukbr.domain1.systemhost.net>

> I know that python also has the -i commandline option, which 

> used it a few times during testing. What are the potential 
> pitfalls of using it?

The biggest pitfall is that it leaves you in a python >>> promt
with all of the context still set up - including any unclosed 
files etc. This may be what you want - to inspect object values etc.
Its very good for debuggoing as you've discovered.

But it may not be obvious to other users that they don't have a 
default python prompt, and if they try to use values they may 
get unexpected results because the program chamged the default 
pythonic behaviour.

Thus it doesn't do quite the same as using raw_input() which 
holds the program open but doesn't allow the user to tinker with
the results. The first option is grewat for developers but bad 
for users. The second is the opposite!

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld


From carroll@tjc.com  Fri Dec 20 14:38:09 2002
From: carroll@tjc.com (Terry Carroll)
Date: Fri Dec 20 14:38:09 2002
Subject: [Tutor] Advice required: Documentation Writing / Sofware  Testing
In-Reply-To: <5.2.0.9.0.20021219170822.03622470@66.28.54.253>
Message-ID: <Pine.LNX.4.44.0212201046420.24476-100000@mauve.rahul.net>

On Thu, 19 Dec 2002, Bob Gailer wrote:

> 1 Use active rather than passive verbs (e.g. "push the button" rather than 
> "the button is pushed")

I'm a big fan of active voice in ordinary writing, but in some technical
contexts (in particular, specifications), passive voice is the right way
to go.

When I was a computer architect, I would write specifcations that said
something like "... if the operands are equal, bits 34-35 are set to
zeroes."  The thing is, it didn't matter what set those bits: it could be
the Arithmetic Logic Unit, the microcode, the macrocode, an emulattion
layer, whatever.  The only important thing is that the bits got set.  
Saying "... if the operands are equal, the ALU sets bits 34-35 to zeroes"
would have wrongly assigned responsibility for the setting.

I realize this is a pretty specialized area, but as long as we're talking 
about technical writing, I thought I'd bring it up.  I agree with Bob when 
it comes to user documentation, though (and I'm afraid I've already 
deleted the message that started this thread, so he may very well be right 
on the bulls-eye for this thread).

> 4 Be consistent. If you use a certain term to refer to something, always
> use exactly the same term. You are writing a technical document, not a
> novel.
>
> 5 Avoid italics or quotes as the sole attempt to tell the reader that
> this is a new term. Whenever introducing a new term, explain it the
> first time.

I would also say, if you're using some arcane terms, don't be afraid to 
define them multiple times in teh documentation (consistently, of course), 
if the documentation is going to be used as both a reference and tutorial.  
It's kind of maddening to me to look something up in a manual, only to 
find out that understanding the concept I'm lookingup depends on 
specialized definitions, and then having to look them up, and from there 
to more definitions, etc.

Or else, give good examples, so that resort to other parts of the text are 
not necessary.

By the way, on examples: make them examples of as little as possible,
restricting their scope to the thing being explained.  It's kind of
frustrating to look up the description of function X, only to find that
the example needlessly requires that the reader also has to understand 
functions Y and Z.

For example, if you're using Fibonacci numbers as an example of recursion,
don't toss in use of persistent variables as an optimization technique so
that later calls don't have to recurse all the way down (except maybe as a
*second* example, of optimization of recursion).  Just show recursion.

(This is, by the way, my major complaint about the O'Reilley "Programming 
Python" text.  I go to Chapter 6 to understand functions in Python, and 
the author makes me understand about packing first.  I don't care about 
packing.  I care about functions.)

> 8 Different readers have different strategies for searching the index.
> So index things under various headings to make it easy for anyone to
> find what they're looking for. Also include references to chapter and
> section headings in the index. It can be very frustrating to (1) search
> the index, then have to look in the TOC (table of contents) to find the
> term.

The index should also be prepared by at least one person who is not the 
author, and who can bring a fresh perspective to the organization -- 
because that's what your reader is going to have.

Also, consider indexing a subject, not only under the term you use, but 
also under the term someone who doesn't yet know your terminology mught 
use.  For example, if you have a function trim() that removes blanks, 
consider "stripping blanks: see trim()."  If you have a command FIND that 
finds a string in a piece of text, consider "locating a string: see FIND".

This is especially important when you can't know what to look under unless 
you already know the answer you're looking up.  If my question is "how do 
I specify formatting a string," I want to be able to look up "format" or 
"string", not "%s".

> 9 Indicate e.g. by bolding the page number(s) in the index that are the 
> main references for a term.

I would also say that the index should indicate where the main reference 
for a term is discussed.  Not that this is different from what Bob said, I 
just think it's important enough to say twice.  :-)


-- 
Terry Carroll        |  
Santa Clara, CA      |   "The parties are advised to chill." 
carroll@tjc.com      |       - Mattel, Inc. v. MCA Records, Inc.,
Modell delendus est  |         no. 98-56577 (9th Cir. July 24, 2002)



From j.pollack@m.cc.utah.edu  Fri Dec 20 14:46:17 2002
From: j.pollack@m.cc.utah.edu (Joshua Pollack)
Date: Fri Dec 20 14:46:17 2002
Subject: [Tutor] optimizing a simple radioactive decay simulation
Message-ID: <3E0371E1.2000603@m.cc.utah.edu>

This is a multi-part message in MIME format.

--Boundary_(ID_nfgE2KDQiWnFJZ5cFG1KgA)
Content-type: text/plain; charset=us-ascii; format=flowed
Content-transfer-encoding: 7BIT

Hi guys:

I just finished the semester and had some time to look back at the 
archives.  My programming skills
are only so-so, I'm pretty new to python, but I have had a little 
probability theory and this shortcut makes the radioactive decay 
simulation short and sweet.  Instead of flipping coins more than a 
million times, you can draw a binomial random variable with a mean equal 
to the remaining coins and prob of success 0.5.  It's kind of cheating 
in that you don't actually flip all those coins but works just as well 
and is quite a bit faster.  Here's my output for one such simulation.

Undecayed heads: 499479
Undecayed heads: 249731
Undecayed heads: 125012
Undecayed heads: 62644
Undecayed heads: 31278
Undecayed heads: 15499
Undecayed heads: 7616
Undecayed heads: 3778
Undecayed heads: 1867
Undecayed heads: 916
Undecayed heads: 493
Undecayed heads: 239
Undecayed heads: 128
Undecayed heads: 64
Undecayed heads: 34
Undecayed heads: 21
Undecayed heads: 10
Undecayed heads: 5
Undecayed heads: 4
Undecayed heads: 3
Undecayed heads: 3
Undecayed heads: 2
Undecayed heads: 2
Undecayed heads: 0
Halflives: 24
0.235000014305 seconds


P.S.- thanks to Bob Gailer for providing the structure, I just changed 
the flipping mechanism.

Joshua Pollack
UC Berkeley
Integrative Biology
jpollack@socrates.berkeley.edu

--Boundary_(ID_nfgE2KDQiWnFJZ5cFG1KgA)
Content-type: text/plain; name=flipper.py
Content-transfer-encoding: 7BIT
Content-disposition: inline; filename=flipper.py

import time,rv
start=time.time()
numcoins=1000000
halflives=0
while numcoins>=1:
    newgeneration=rv.binomial(numcoins,0.5)
    halflives+=1
    print "Undecayed heads:",newgeneration
    numcoins=newgeneration
print "Halflives:", halflives
print time.time()-start,"seconds"

--Boundary_(ID_nfgE2KDQiWnFJZ5cFG1KgA)--


From Adam Vardy <anvardy@roadrunner.nf.net>  Fri Dec 20 16:00:42 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Fri Dec 20 16:00:42 2002
Subject: [Tutor] Motion
In-Reply-To: <5.1.0.14.0.20021219231022.02a92ca8@www.thinkware.se>
References: <5.1.0.14.0.20021219231022.02a92ca8@www.thinkware.se>
Message-ID: <139224581801.20021220172858@roadrunner.nf.net>

Thursday, December 19, 2002, 7:45:21 PM, you wrote:

>> At 17:40 2002-12-19 -03-30, Adam Vardy wrote:
>>Suppose I'd like to start off with something simple like moving a
>>letter around the screen, pretend he's your man, and you move him
>>around by some control, mouse or something. How do you start with
>>that? How do you place the letter anywhere on screen?

>> What makes you think this is simple? :)

>> Let's just say it varies...

>> Performing calculations and logical tricks is one thing, but when
>> we move objects on the screen, everything depends on how the
>> operating system interfaces with the screen. There is unfortunately
>> no standard for that. (If there ever could be--user interfaces can
>> be very different.)

Well, ah...
this is what you'd do on a 1984 C64.

POKE 1024+Y*40+X,MAN

OR call the kernal plot routine

SYS Plot, y,x,0: PRINT MAN;

[Man = some Letter of interest]

>> This means that you must decide what kind of environment you use.
>> The first thing to consider is probably whether you want a graphical
>> user interface of a text based user interface.

>> Surprisingly, the task you mention might be easier to do with a
>> complex graphical user interface, than with a plain simple text
>> based interface. At least in Windows, and certainly if you want it
>> to be cross platform.

>> The most common Python GUI toolkits, such as Tkinter and wxPython
>> works the same (well, close at least) in Windows, Linux and some
>> more operating systems.

Only thing is, here we go with novelletes that read to me like..."
Isn't there a serious problem hidden in here: what happens when the __init__ function returns and the frame variable goes out of scope?

Just relax; there's actually no need to keep a reference to the widget instance.
"

This must be some Martian trying to chat me up from a Fredrick Pohl
novel.

Then there's the link at...

"example is adapted from the "hello world" program in Matt Conway's A
Tkinter Life Preserver ."

Apparently the Life Preserver is Error 404: File Not Found
Tossed out in a cold Martian sea, glug glug...

Relaxing, as your muscle fibres decompose.

-- 
Adam Vardy



From magnus@thinkware.se  Fri Dec 20 17:25:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri Dec 20 17:25:02 2002
Subject: [Tutor] Motion
In-Reply-To: <139224581801.20021220172858@roadrunner.nf.net>
References: <5.1.0.14.0.20021219231022.02a92ca8@www.thinkware.se>
 <5.1.0.14.0.20021219231022.02a92ca8@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021220231514.041374d8@www.thinkware.se>

At 17:28 2002-12-20 -03-30, Adam Vardy wrote:
>Well, ah...
>this is what you'd do on a 1984 C64.
>
>POKE 1024+Y*40+X,MAN

:) It's many years since I played with the C64, and I certainly
don't remember the addresses. Don't even know where the manuals
are right now... But Python is not a machine. Python runs on many
different types of computers, from palm tops to main frames. They
don't have a lot in common regarding graphics hardware.

There is no native way to manipulate memory or hardware registers
directly from Python.

It was simpler in those days, but I can't say I want it back. I
remember how hard it was to read the letters on the screen when
you tried to squeeze 64 character into a line...

>Only thing is, here we go with novelletes that read to me like..."
>Isn't there a serious problem hidden in here: what happens when the 
>__init__ function returns and the frame variable goes out of scope?

Somewhere around here I lost you. I don't have the faintest idea
what this and the reast has to do with this email thread...

>Just relax; there's actually no need to keep a reference to the widget 
>instance.

It's a bit confusing how the underlying code in the GUI tool kits
hold "invisible" references to things. I usually keep explicit
references in my programs anyway, after all, you often want to do
things with your widgets from the program...


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From ramrom@earthling.net  Fri Dec 20 17:31:24 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Fri Dec 20 17:31:24 2002
Subject: [Tutor] Advice required: Documentation Writing / Sofware
 Testing
In-Reply-To: <Pine.LNX.4.44.0212201046420.24476-100000@mauve.rahul.net>
References: <5.2.0.9.0.20021219170822.03622470@66.28.54.253>
Message-ID: <5.2.0.9.0.20021220151825.0332c8d0@66.28.54.253>

At 11:35 AM 12/20/2002 -0800, Terry Carroll wrote:
>I'm a big fan of active voice in ordinary writing, but in some technical
>contexts (in particular, specifications), passive voice is the right way 
>to go.

I agree. I was reacting, in part, to Memorex's guidelines insisting that 
operator instructions be passive.

>By the way, on examples: make them examples of as little as possible,
>restricting their scope to the thing being explained.  It's kind of
>frustrating to look up the description of function X, only to find that
>the example needlessly requires that the reader also has to understand
>functions Y and Z.

Yeah, and I've seen this in other Python books. A chapter on database 
interaction had an example whose major focus was the soundex algorithm, and 
had (as I recall) one SQL Insert and one SQL Select statement. I had to 
wade thru a lot of stuff to find the SQL.

>The index should also be prepared by at least one person who is not the
>author, and who can bring a fresh perspective to the organization --
>because that's what your reader is going to have.

It's good to also have a member of the target audience review the document. 
I was once asked to review a course in IBM's MVS JCL. I said "I can't do 
that; I don't know JCL." At which point the response was "That's exactly 
what we're looking for." (Unfortunately, as I waded thru the course my one 
consistent and never answered question was WHY JCL in the first place when 
there are much easier ways???)

>Also, consider indexing a subject, not only under the term you use, but
>also under the term someone who doesn't yet know your terminology mught
>use.  For example, if you have a function trim() that removes blanks,
>consider "stripping blanks: see trim()."  If you have a command FIND that
>finds a string in a piece of text, consider "locating a string: see FIND".
>
>This is especially important when you can't know what to look under unless
>you already know the answer you're looking up.  If my question is "how do
>I specify formatting a string," I want to be able to look up "format" or
>"string", not "%s".

YES YES.

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625



From ole_jensen@dbmail.dk  Fri Dec 20 19:12:03 2002
From: ole_jensen@dbmail.dk (Ole Jensen)
Date: Fri Dec 20 19:12:03 2002
Subject: [Tutor] NEWBIE QUEASTION ALERT - how to restart program?
Message-ID: <002401c2a885$62fbefb0$854c73d5@oleioq8ex4m1zx>

This is a multi-part message in MIME format.

------=_NextPart_000_0021_01C2A88D.C4B5A950
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Alright, as the subject says - Im not the most educated man in python =
(or any other language), but I been going through some tutorials.=20
And as I have expanded the trials in order not to just copy and paste I =
was wondering how it is possible to go back in the script/file in order =
to restart certain section in order for the program not just to shut =
down... well e.g.:

This program has been modified from the area calculator found in the =
instant hacking tutorial =
http://www.hetland.org/python/instant-hacking.php
_________________________________________________________________________=
__
  # Area calculator
  print "WELCOME TO THE AREA CALCULATOR"
  print "------------------------------"
  print ""
  print ""

  # Import the sleep mode in order to display results before shut down
  from time import sleep

  # meny
  print "Select a shape"
  print "1: Quadrangle"
  print "2: Circle"
  shape =3D input(">>>")

  if shape =3D=3D 1:
      print "Is it a:"
      print ""
      print "1: square"
      print "2: rectangle"
      quad_shape =3D input(">>>")

      if quad_shape =3D=3D 1:
          print "Square"
          S =3D input("What is the lenght of any side?")
          print ""
          print "The area is",S**2
          sleep(5)

      elif quad_shape=3D=3D 2:
          print "rectangle"
          L =3D input("What is the lenght?")
          W =3D input("What is the width?")
          print ""
          if L =3D=3D W:
              print "this not a rectangle moron!"
              sleep(5)
          else:
              print "The area is",L*W
              sleep(5)

      else:
          print "SHUT THE FUCK UP BIATCH!!!"
          sleep(5)

  elif shape =3D=3D 2:
      print "circle"
      R =3D input("What is the radius?")
      print ""
      print "The area of the circle is:",R**2*3.14
      sleep(5)
     =20
  else:
      print "Grow up man... 1 or 2!!!"
      sleep(5)
_________________________________________________________________

If you run this program independently the window will close automaticly =
after it has been run, now instead of just closing the window how would =
it be possiple to re-run the program, e.g. in the first many you have a =
choice of: 1 or 2. if the user presses any other key, the program will =
print "grow up man... 1 or 2!!!" and shut down/close the window (given =
after waiting 5 seconds), now instead I would like the program to ask =
the question again... how is that done...?

given it maight not be crutial, but I really would like to know how its =
done. and finally I should say I have no understanding of how the loops =
work (I've gone through tutorials about the FOR-loops and WHILE-loops =
but they make no sense to me) so if loops are esantial to what i want to =
achive I was wondering if any of you reading this could guide me to some =
very basic walk-through's of loops

thanx for listing and for any help you provide!

sincerly Ole Jensen

------=_NextPart_000_0021_01C2A88D.C4B5A950
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1126" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Alright, as the subject says - Im not =
the most=20
educated man in python (or any other language), but I been going through =
some=20
tutorials. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>And as I have expanded the trials in =
order not to=20
just copy and paste I was wondering how it is possible to go back in the =

script/file in order to restart certain section in order for the program =
not=20
just to shut down... well e.g.:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>This program has been modified from the =
area=20
calculator found in the instant hacking tutorial <A=20
href=3D"http://www.hetland.org/python/instant-hacking.php">http://www.het=
land.org/python/instant-hacking.php</A></FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>________________________________________________________________=
___________</FONT></DIV>
<BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px">
  <DIV><FONT face=3DArial size=3D2># Area calculator<BR>print "WELCOME =
TO THE AREA=20
  CALCULATOR"<BR>print "------------------------------"<BR>print =
""<BR>print=20
  ""</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2># Import the sleep mode in order to =
display=20
  results before shut down<BR>from time import sleep</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2># meny<BR>print "Select a =
shape"<BR>print "1:=20
  Quadrangle"<BR>print "2: Circle"<BR>shape =3D =
input("&gt;&gt;&gt;")</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>if shape =3D=3D =
1:<BR>&nbsp;&nbsp;&nbsp; print "Is it=20
  a:"<BR>&nbsp;&nbsp;&nbsp; print ""<BR>&nbsp;&nbsp;&nbsp; print "1:=20
  square"<BR>&nbsp;&nbsp;&nbsp; print "2: =
rectangle"<BR>&nbsp;&nbsp;&nbsp;=20
  quad_shape =3D input("&gt;&gt;&gt;")</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; if quad_shape =
=3D=3D=20
  1:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
  "Square"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; S =3D =
input("What is the=20
  lenght of any side?")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
print=20
  ""<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "The area=20
  is",S**2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
sleep(5)</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; elif =
quad_shape=3D=3D=20
  2:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
  "rectangle"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; L =3D =
input("What is=20
  the lenght?")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; W =3D =
input("What is=20
  the width?")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
  ""<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if L =3D=3D=20
  =
W:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
print=20
  "this not a rectangle=20
  =
moron!"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;=20
  sleep(5)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  =
else:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
  print "The area=20
  =
is",L*W<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;=20
  sleep(5)</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;=20
  else:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "SHUT THE =
FUCK UP=20
  BIATCH!!!"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
sleep(5)</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>elif shape =3D=3D =
2:<BR>&nbsp;&nbsp;&nbsp; print=20
  "circle"<BR>&nbsp;&nbsp;&nbsp; R =3D input("What is the=20
  radius?")<BR>&nbsp;&nbsp;&nbsp; print ""<BR>&nbsp;&nbsp;&nbsp; print =
"The area=20
  of the circle is:",R**2*3.14<BR>&nbsp;&nbsp;&nbsp;=20
  sleep(5)<BR>&nbsp;&nbsp;&nbsp; <BR>else:<BR>&nbsp;&nbsp;&nbsp; print =
"Grow up=20
  man... 1 or 2!!!"<BR>&nbsp;&nbsp;&nbsp; =
sleep(5)</FONT></DIV></BLOCKQUOTE>
<DIV dir=3Dltr><FONT face=3DArial=20
size=3D2>________________________________________________________________=
_</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>If you run this program =
independently the=20
window will close automaticly after it has been run, now instead of just =
closing=20
the window how would it be possiple to re-run the program, e.g. in the =
first=20
many you have a choice of: 1 or 2. if the user presses any other key, =
the=20
program will print "grow up man... 1 or 2!!!" and shut down/close the =
window=20
(given after waiting 5 seconds), now instead I would like the program to =
ask the=20
question again... how is that done...?</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>given it maight not be =
crutial, but I=20
really would like to know how its done. and finally I should say I have =
no=20
understanding of how the loops work (I've gone through tutorials about =
the=20
FOR-loops and WHILE-loops but they make no sense to me) so if loops are =
esantial=20
to what i want to achive I was wondering if any of you reading this =
could guide=20
me to some very basic walk-through's of loops</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>thanx for listing and for any =
help you=20
provide!</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>sincerly Ole =
Jensen</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial =
size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0021_01C2A88D.C4B5A950--



From ole_jensen@dbmail.dk  Fri Dec 20 19:28:02 2002
From: ole_jensen@dbmail.dk (Ole Jensen)
Date: Fri Dec 20 19:28:02 2002
Subject: [Tutor] NEWBIE QUEASTION ALERT - how to restart program?
Message-ID: <005401c2a887$aab8bc00$854c73d5@oleioq8ex4m1zx>

This is a multi-part message in MIME format.

------=_NextPart_000_0051_01C2A890.0C6AD480
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


Alright, as the subject says - Im not the most educated man in python =
(or any other language), but I been going through some tutorials.=20
And as I have expanded the trials in order not to just copy and paste I =
was wondering how it is possible to go back in the script/file in order =
to restart certain section in order for the program not just to shut =
down... well e.g.:

This program has been modified from the area calculator found in the =
instant hacking tutorial =
http://www.hetland.org/python/instant-hacking.php
_________________________________________________________________________=
__
  # Area calculator
  print "WELCOME TO THE AREA CALCULATOR"
  print "------------------------------"
  print ""
  print ""

  # Import the sleep mode in order to display results before shut down
  from time import sleep

  # meny
  print "Select a shape"
  print "1: Quadrangle"
  print "2: Circle"
  shape =3D input(">>>")

  if shape =3D=3D 1:
      print "Is it a:"
      print ""
      print "1: square"
      print "2: rectangle"
      quad_shape =3D input(">>>")

      if quad_shape =3D=3D 1:
          print "Square"
          S =3D input("What is the lenght of any side?")
          print ""
          print "The area is",S**2
          sleep(5)

      elif quad_shape=3D=3D 2:
          print "rectangle"
          L =3D input("What is the lenght?")
          W =3D input("What is the width?")
          print ""
          if L =3D=3D W:
              print "this not a rectangle!"
              sleep(5)
          else:
              print "The area is",L*W
              sleep(5)

      else:
          print "wrong key!!!"
          sleep(5)

  elif shape =3D=3D 2:
      print "circle"
      R =3D input("What is the radius?")
      print ""
      print "The area of the circle is:",R**2*3.14
      sleep(5)
     =20
  else:
      print "Grow up man... 1 or 2!!!"
      sleep(5)
_________________________________________________________________

If you run this program independently the window will close automaticly =
after it has been run, now instead of just closing the window how would =
it be possiple to re-run the program, e.g. in the first many you have a =
choice of: 1 or 2. if the user presses any other key, the program will =
print "grow up man... 1 or 2!!!" and shut down/close the window (given =
after waiting 5 seconds), now instead I would like the program to ask =
the question again... how is that done...?

given it maight not be crutial, but I really would like to know how its =
done. and finally I should say I have no understanding of how the loops =
work (I've gone through tutorials about the FOR-loops and WHILE-loops =
but they make no sense to me) so if loops are esantial to what i want to =
achive I was wondering if any of you reading this could guide me to some =
very basic walk-through's of loops

thanx for listing and for any help you provide!

sincerly Ole Jensen

PS this mail is been resent due to I got replay to my old mail reading =
something like this: "Policy =3D Dirty Words" this was properbly because =
the program code contained certain words that some people might not =
like.... the word has been removed an I am hoping the mail will go =
through now...
------=_NextPart_000_0051_01C2A890.0C6AD480
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1126" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Alright, as the subject says - Im not =
the most=20
educated man in python (or any other language), but I been going through =
some=20
tutorials. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>And as I have expanded the trials in =
order not to=20
just copy and paste I was wondering how it is possible to go back in the =

script/file in order to restart certain section in order for the program =
not=20
just to shut down... well e.g.:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>This program has been modified from the =
area=20
calculator found in the instant hacking tutorial <A=20
href=3D"http://www.hetland.org/python/instant-hacking.php">http://www.het=
land.org/python/instant-hacking.php</A></FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>________________________________________________________________=
___________</FONT></DIV>
<BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px">
  <DIV><FONT face=3DArial size=3D2># Area calculator<BR>print "WELCOME =
TO THE AREA=20
  CALCULATOR"<BR>print "------------------------------"<BR>print =
""<BR>print=20
  ""</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2># Import the sleep mode in order to =
display=20
  results before shut down<BR>from time import sleep</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2># meny<BR>print "Select a =
shape"<BR>print "1:=20
  Quadrangle"<BR>print "2: Circle"<BR>shape =3D =
input("&gt;&gt;&gt;")</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>if shape =3D=3D =
1:<BR>&nbsp;&nbsp;&nbsp; print "Is it=20
  a:"<BR>&nbsp;&nbsp;&nbsp; print ""<BR>&nbsp;&nbsp;&nbsp; print "1:=20
  square"<BR>&nbsp;&nbsp;&nbsp; print "2: =
rectangle"<BR>&nbsp;&nbsp;&nbsp;=20
  quad_shape =3D input("&gt;&gt;&gt;")</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; if quad_shape =
=3D=3D=20
  1:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
  "Square"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; S =3D =
input("What is the=20
  lenght of any side?")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
print=20
  ""<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "The area=20
  is",S**2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
sleep(5)</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; elif =
quad_shape=3D=3D=20
  2:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
  "rectangle"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; L =3D =
input("What is=20
  the lenght?")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; W =3D =
input("What is=20
  the width?")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print=20
  ""<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if L =3D=3D=20
  =
W:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
print=20
  "this not a=20
  =
rectangle!"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;=20
  sleep(5)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  =
else:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
  print "The area=20
  =
is",L*W<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;=20
  sleep(5)</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;=20
  else:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "wrong=20
  key!!!"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
sleep(5)</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>elif shape =3D=3D =
2:<BR>&nbsp;&nbsp;&nbsp; print=20
  "circle"<BR>&nbsp;&nbsp;&nbsp; R =3D input("What is the=20
  radius?")<BR>&nbsp;&nbsp;&nbsp; print ""<BR>&nbsp;&nbsp;&nbsp; print =
"The area=20
  of the circle is:",R**2*3.14<BR>&nbsp;&nbsp;&nbsp;=20
  sleep(5)<BR>&nbsp;&nbsp;&nbsp; <BR>else:<BR>&nbsp;&nbsp;&nbsp; print =
"Grow up=20
  man... 1 or 2!!!"<BR>&nbsp;&nbsp;&nbsp; =
sleep(5)</FONT></DIV></BLOCKQUOTE>
<DIV dir=3Dltr><FONT face=3DArial=20
size=3D2>________________________________________________________________=
_</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>If you run this program =
independently the=20
window will close automaticly after it has been run, now instead of just =
closing=20
the window how would it be possiple to re-run the program, e.g. in the =
first=20
many you have a choice of: 1 or 2. if the user presses any other key, =
the=20
program will print "grow up man... 1 or 2!!!" and shut down/close the =
window=20
(given after waiting 5 seconds), now instead I would like the program to =
ask the=20
question again... how is that done...?</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>given it maight not be =
crutial, but I=20
really would like to know how its done. and finally I should say I have =
no=20
understanding of how the loops work (I've gone through tutorials about =
the=20
FOR-loops and WHILE-loops but they make no sense to me) so if loops are =
esantial=20
to what i want to achive I was wondering if any of you reading this =
could guide=20
me to some very basic walk-through's of loops</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>thanx for listing and for any =
help you=20
provide!</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>sincerly Ole =
Jensen</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>PS this mail&nbsp;is been =
resent due to I=20
got replay to my old mail reading something like this: <FONT=20
face=3D"Times New Roman" size=3D3>"Policy =3D Dirty Words" this was =
properbly because=20
the program code contained certain words that some people might not =
like.... the=20
word has been removed an I am hoping&nbsp;the mail will go through=20
now...</FONT></FONT></DIV></BODY></HTML>

------=_NextPart_000_0051_01C2A890.0C6AD480--



From thomi@thomi.imail.net.nz  Fri Dec 20 20:03:02 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Fri Dec 20 20:03:02 2002
Subject: [Tutor] NEWBIE QUEASTION ALERT - how to restart program?
In-Reply-To: <005401c2a887$aab8bc00$854c73d5@oleioq8ex4m1zx>
References: <005401c2a887$aab8bc00$854c73d5@oleioq8ex4m1zx>
Message-ID: <20021221140159.2c68776c.thomi@thomi.imail.net.nz>

perhaps a loop, similar to this:

while 1:
	#insert program here

	print 'run again? (Y/N)'
	answer = raw_input('>>>')
	if (answer == 'n') or (answer == 'N'):
		break

-- 
 "Avoid the Gates of Hell.  Use Linux"

Thomi Richards,
thomi@imail.net.nz


From Don Arnold" <darnold02@sprynet.com  Fri Dec 20 20:18:01 2002
From: Don Arnold" <darnold02@sprynet.com (Don Arnold)
Date: Fri Dec 20 20:18:01 2002
Subject: [Tutor] NEWBIE QUEASTION ALERT - how to restart program?
References: <002401c2a885$62fbefb0$854c73d5@oleioq8ex4m1zx>
Message-ID: <094201c2a88e$89e58ce0$1813ba3f@defaultcomp>

----- Original Message -----
From: Ole Jensen
To: tutor@python.org
Sent: Friday, December 20, 2002 6:10 PM
Subject: [Tutor] NEWBIE QUEASTION ALERT - how to restart program?


Alright, as the subject says - Im not the most educated man in python (or
any other language), but I been going through some tutorials.
And as I have expanded the trials in order not to just copy and paste I was
wondering how it is possible to go back in the script/file in order to
restart certain section in order for the program not just to shut down...
well e.g.:

This program has been modified from the area calculator found in the instant
hacking tutorial http://www.hetland.org/python/instant-hacking.php
___________________________________________________________________________
<source snipped>

If you run this program independently the window will close automaticly
after it has been run, now instead of just closing the window how would it
be possiple to re-run the program, e.g. in the first many you have a choice
of: 1 or 2. if the user presses any other key, the program will print "grow
up man... 1 or 2!!!" and shut down/close the window (given after waiting 5
seconds), now instead I would like the program to ask the question again...
how is that done...?

given it maight not be crutial, but I really would like to know how its
done. and finally I should say I have no understanding of how the loops work
(I've gone through tutorials about the FOR-loops and WHILE-loops but they
make no sense to me) so if loops are esantial to what i want to achive I was
wondering if any of you reading this could guide me to some very basic
walk-through's of loops

--- my reply: ---
Loops _are_ essential to what you are trying to do: repeatedly execute a
body of suite of code. Python has 2 flavors of loop. The 'for' loop is
designed to repeat a set number of times. It executes your loop body once
for each item in the given sequence:

>>> for number in (1,2,3,4,5):
 print number, number * 5


1 5
2 10
3 15
4 20
5 25

The 'while' loop will execute its body as long as its condition is true.
It's an indefinite loop because it doesn't run a specific number of times.
Instead, some action inside the loop body eventually invalidates the loop
condition, causing it to terminate.

>>> from random import randint
>>> number = 0
>>> while number != 10:
 number = randint(1,10)
 print number


9
6
3
6
10
>>>

This is exactly the behavior you want: you want to repeat the loop until the
user chooses to quit. You can do this by adding a 'quit' option to your main
menu and then moving the code that should repeat inside a 'while' loop:

# Import the sleep mode in order to display results before shut down
from time import sleep

#flag to see if we're done
done = 0

# Area calculator
print "WELCOME TO THE AREA CALCULATOR"
print "------------------------------"

while not done:
    # menu
    print ""
    print ""
    print "Select a shape"
    print "1: Quadrangle"
    print "2: Circle"
    print "3: Quit"

    shape = input(">>>")

    if shape == 1:
        print "Is it a:"
        print ""
        print "1: square"
        print "2: rectangle"
        quad_shape = input(">>>")

        if quad_shape == 1:
            print "Square"
            S = input("What is the lenght of any side?")
            print ""
            print "The area is",S**2
            sleep(5)

        elif quad_shape== 2:
            print "rectangle"
            L = input("What is the lenght?")
            W = input("What is the width?")
            print ""
            if L == W:
                print "this not a rectangle moron!"
                sleep(5)
            else:
                print "The area is",L*W
                sleep(5)

        else:
            print "wrong key!!!"
            sleep(5)

    elif shape == 2:
        print "circle"
        R = input("What is the radius?")
        print ""
        print "The area of the circle is:",R**2*3.14
        sleep(5)

    elif shape == 3:
        done = 1

    else:
        print "Grow up man... 1, 2 or 3!!!"
        sleep(5)

## we fell out of the loop
print 'Finished.'
sleep(5)


HTH,
Don



From magnus@thinkware.se  Fri Dec 20 20:33:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri Dec 20 20:33:02 2002
Subject: [Tutor] NEWBIE QUEASTION ALERT - how to restart program?
In-Reply-To: <002401c2a885$62fbefb0$854c73d5@oleioq8ex4m1zx>
Message-ID: <5.1.0.14.0.20021221013830.04137390@www.thinkware.se>

Hi Ole,

At 01:10 2002-12-21 +0100, Ole Jensen wrote:
>Alright, as the subject says - Im not the most educated man in python (or 
>any other language), but I been going through some tutorials.

We all have to crawl before we can walk. No worry.

>If you run this program independently the window will close automaticly 
>after it has been run, now instead of just closing the window how would it 
>be possiple to re-run the program, e.g. in the first many you have a 
>choice of: 1 or 2. if the user presses any other key, the program will 
>print "grow up man... 1 or 2!!!" and shut down/close the window (given 
>after waiting 5 seconds), now instead I would like the program to ask the 
>question again... how is that done...?
>
>given it maight not be crutial, but I really would like to know how its 
>done. and finally I should say I have no understanding of how the loops 
>work (I've gone through tutorials about the FOR-loops and WHILE-loops but 
>they make no sense to me) so if loops are esantial to what i want to 
>achive I was wondering if any of you reading this could guide me to some 
>very basic walk-through's of loops

In this case, loops are exactly what you want. I hope I can
walk you through this.

A while-loop, which is what you would use here, is very similar to
an if statement. You understand the if-statement, right? Run the
intented code after the if-statement if the expression evaluates
to a value we consider as true. (I.e. not 0, or something empty.)

A while loop runs the indented block repeatedly as long as the
expression is true. Like this:

# menu
shape = 0
while shape is not in [1, 2]:
     print "Select a shape"
     print "1: Quadrangle"
     print "2: Circle"
     shape = input(">>>")

if shape...

Let's walk through this:

shape = 0 # This is just to make sure that the next line does what we want.
while shape is not in [1, 2]:  # shape is 0, neither 1 or 2, so the 
condition is true, run the indeted block
     print bla bla bla...
     shape = input(">>>") # Let's imagine I enter '5'
# The next line is not indented, so we have reached the en of the while-block
# So far, this is exactly as an if-statement, right? But hang on, now it 
gets different.
# After the end of the block, we return to the while-line again!
while shape is not in [1, 2]:  # shape is 5, so the condition is true, run 
the indeted block
     print bla bla bla...
     shape = input(">>>") # Let's imagine I enter '1'
while shape is not in [1, 2]:  # shape is 1, so the condition is true, end 
the loop
if shape... # whatever...

Obviously, it's importent that something happens in the while block that might
change the while-condition, or we will be stuck in the loop for ever. (Not 
completely
true, but let's leave break for later.)
>print ""

To print an empty line, just type

print

An empty string doesn't make any difference.
>    else:
>         print "SHUT THE XXXX UP XXXXX!!!"

Really, I don't think this kind of language is appropriate here,
and if you send things like that to a mailing list, you are likely
to get auto-responses from mail-filtering software here and there.
That happened to me when I included a somewhat colourful Monty Python
quote in an email to this very establishment...
>         sleep(5)

Instead of sleep, I'd use

raw_input('Press ENTER to continue')

raw_input() is like input, but it doesn't evaluate what you type,
it always return a string. Normally you'd use "x = raw_input(..."
but in this particular case, we don't care what it returns, we just
want it to prevent the program from rushing ahead...
>
>elif shape == 2:
>     print "circle"
>     R = input("What is the radius?")
>     print ""
>     print "The area of the circle is:",R**2*3.14

import math
R**2*math.pi

is more exact... (If you want an approximation, use 355./113.)

To return to your original question:

To be able to repeat the whole process, not just the little piece
I did above, you put the whole block inside a big while loop.

But if a loop spans too many lines, let's say more lines than fits
in your screen, it get's more difficult to follow what's happening.
In those cases, it's probably a good idea to split up the program
into several separate functions, instead of one big sequence like
you did. But let's take one step at a time.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From jimmy_130@lycos.com  Fri Dec 20 20:40:02 2002
From: jimmy_130@lycos.com (James M Lang)
Date: Fri Dec 20 20:40:02 2002
Subject: [Tutor] Did anybody get the Surnova worm, or is it just me?
Message-ID: <FKPCHGANPBLMECAA@mailcity.com>

Hey, I just got the Surnova worm. I manually deleted its main files, but it infected 991 of my files, including some of python. :(
I got two anti-virus programs, norton antivirus and AVG Anti-Virus System. Only AVG would detect it, but it couldn't fix or quarantine it. And the infected files are mostly system files. That's fine with me, I can always reinstall windows. But what do i do with Python?


_____________________________________________________________
Get 25MB, POP3, Spam Filtering with LYCOS MAIL PLUS for $19.95/year.
http://login.mail.lycos.com/brandPage.shtml?pageId=plus&ref=lmtplus


From magnus@thinkware.se  Fri Dec 20 21:10:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri Dec 20 21:10:02 2002
Subject: [Tutor] Did anybody get the Surnova worm, or is it just me?
In-Reply-To: <FKPCHGANPBLMECAA@mailcity.com>
Message-ID: <5.1.0.14.0.20021221030656.041c06d8@www.thinkware.se>

At 20:37 2002-12-20 -0500, James M Lang wrote:
>Hey, I just got the Surnova worm. I manually deleted its main files, but 
>it infected 991 of my files, including some of python. :(
>I got two anti-virus programs, norton antivirus and AVG Anti-Virus System. 
>Only AVG would detect it, but it couldn't fix or quarantine it. And the 
>infected files are mostly system files. That's fine with me, I can always 
>reinstall windows. But what do i do with Python?

You can reinstall Python as well of course!

What kind of python files are you talking about?
.pyc and .pyo files can be deleted if you just
have the corresponding .py files. They will be
regenerated as they are need.

.py files are simple text files. If there is some
junk in them that should be obvious, but I'm not
sure all windows editors can handle that right.

If other files (.exe, .dll, .pyd etc) are infected,
I'd suggest that you uninstall Python, make sure that
all infected files are gone, and reinstall it from
the net. But it's not so fun if you have a modem
connection I guess...


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From Adam Vardy <anvardy@roadrunner.nf.net>  Fri Dec 20 21:26:39 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Fri Dec 20 21:26:39 2002
Subject: [Tutor] Motion
In-Reply-To: <5.1.0.14.0.20021220231514.041374d8@www.thinkware.se>
References: <5.1.0.14.0.20021219231022.02a92ca8@www.thinkware.se>
 <5.1.0.14.0.20021219231022.02a92ca8@www.thinkware.se>
 <5.1.0.14.0.20021220231514.041374d8@www.thinkware.se>
Message-ID: <76244170388.20021220225527@roadrunner.nf.net>

Friday, December 20, 2002, 6:57:36 PM, you wrote:

>> There is no native way to manipulate memory or hardware registers
>> directly from Python.

You could also have a command to print letters on a graphics screen.
No point plotting.

>> It was simpler in those days, but I can't say I want it back. I
>> remember how hard it was to read the letters on the screen when
>> you tried to squeeze 64 character into a line...

>>Only thing is, here we go with novelletes that read to me like..."
>>Isn't there a serious problem hidden in here: what happens when the 
>>__init__ function returns and the frame variable goes out of scope?

>> Somewhere around here I lost you. I don't have the faintest idea
>> what this and the reast has to do with this email thread...

It's a quote from the TkInter introduction. I am summarizing how it
uses plenty of terms that may appear in a chapter of a book I was
reading, but none of it has sunk in my brain.  So, widgetwhaty, wish
it was less annoying. Rhetorically speaking.

The link was on page 4 of that Introduction.

-- 
Adam Vardy



From Adam Vardy <anvardy@roadrunner.nf.net>  Fri Dec 20 21:40:02 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Fri Dec 20 21:40:02 2002
Subject: [Tutor] Motion
In-Reply-To: <5.1.0.14.0.20021219231022.02a92ca8@www.thinkware.se>
References: <5.1.0.14.0.20021219231022.02a92ca8@www.thinkware.se>
Message-ID: <107244977519.20021220230854@roadrunner.nf.net>

Thursday, December 19, 2002, 7:45:21 PM, you wrote:

>> Here's something little to try...

Thanks for the oval!

Unlike my example, it doesn't leave the oval in the last spot. It
disappears from the last spot each time.

>> (If you don't see anything happening, chances are that the GUI
>> window is hidden behind your Python interpreter as you put it
>> back in focus as you type. Check your taskbar if you are in

Yeah, I noticed that. Fool thing.

>> Start by running the turtle.py file that you find in the lib-tk

Seems to be a little graphic demo.

-- 
Adam Vardy



From idiot1@netzero.net  Fri Dec 20 23:17:02 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Fri Dec 20 23:17:02 2002
Subject: [Tutor] (no subject)
References: <F118QfG1ME21RwrMQFp000211ef@hotmail.com>
Message-ID: <3E03EB17.2090502@netzero.net>

ASSUMING you are running unix, the opsys command 'clear' will do it.

In the os module:
system(command)
Execute the command (a string) in a subshell. This is implemented by calling 
the Standard C function system(), and has the same limitations. Changes to 
posix.environ, sys.stdin, etc. are not reflected in the environment of the 
executed command. The return value is the exit status of the process encoded 
in the format specified for wait(), except on Windows 95 and 98, where it is 
always 0. Note that POSIX does not specify the meaning of the return value of 
the C system() function, so the return value of the Python function is 
system-dependent. Availability: Unix, Windows.

so 'os.system('clear') ought to clear the console screen. This is NOT how to 
do it if you are trying to create a blank screen on a script generated web page!

If THAT is what you want, gin up  how you woould do it in a plain vanilla html 
page, then spew that out from the script.

Hope this helps.

Maarten Mulders wrote:
> Is there a command that clears the complete (shell)screen, like ClrScr 
> or CLS or something?
> 
> _________________________________________________________________
> MSN Zoeken, voor duidelijke zoekresultaten! 
> http://search.msn.nl/worldwide.asp
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


-- 

end

Respectfully,
              Kirk D Bailey


+---------------------"Thou Art Free." -Eris-----------------------+
| http://www.howlermonkey.net  mailto:highprimate@howlermonkey.net |
| KILL spam dead!      http://www.scambusters.org/stopspam/#Pledge |
| http://www.tinylist.org  +--------+   mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking----------------------+
                            +--------+

---------------------------------------------
Introducing NetZero Long Distance
1st month Free!
Sign up today at: www.netzerolongdistance.com


From michael@trollope.org  Fri Dec 20 23:28:02 2002
From: michael@trollope.org (Michael Powe)
Date: Fri Dec 20 23:28:02 2002
Subject: [Tutor] Advice required: Documentation Writing / Sofware Testing
In-Reply-To: <5.2.0.9.0.20021220151825.0332c8d0@66.28.54.253>; from ramrom@earthling.net on Fri, Dec 20, 2002 at 03:27:13PM -0700
References: <5.2.0.9.0.20021219170822.03622470@66.28.54.253> <Pine.LNX.4.44.0212201046420.24476-100000@mauve.rahul.net> <5.2.0.9.0.20021220151825.0332c8d0@66.28.54.253>
Message-ID: <20021220202702.A4354@titan.spiretech.com>

On Fri, Dec 20, 2002 at 03:27:13PM -0700, Bob Gailer wrote:

> At 11:35 AM 12/20/2002 -0800, Terry Carroll wrote:

[ ... ]

> >Also, consider indexing a subject, not only under the term you use, but
> >also under the term someone who doesn't yet know your terminology mught
> >use.  For example, if you have a function trim() that removes blanks,
> >consider "stripping blanks: see trim()."  If you have a command FIND that
> >finds a string in a piece of text, consider "locating a string: see FIND".

> >This is especially important when you can't know what to look under unless
> >you already know the answer you're looking up.  If my question is "how do
> >I specify formatting a string," I want to be able to look up "format" or
> >"string", not "%s".
> 
> YES YES.

I find it curious how badly indexed most technical books are.
indexing ought properly to be an automated procedure, in which a list
of index terms is prepared and then the text is formatted for
processing to build the index.  but it seems that most books are not
done this way.  even o'reilly, which processes and prints most if not
all of its books in unix, generally has horrible indexing.  but both
TeX and troff provide index-building functions!  it is a common
occurrence to look up an item in the index, check the text; and then
later find an unindexed reference to the term that contained
information i needed.  sometimes, it almost seems like the indexing
procedure consists of somebody reading through the text and
arbitrarily deciding which terms on a page or in a section to index.

mp


From magnus@thinkware.se  Sat Dec 21 07:53:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat Dec 21 07:53:01 2002
Subject: [Tutor] Motion
In-Reply-To: <76244170388.20021220225527@roadrunner.nf.net>
References: <5.1.0.14.0.20021220231514.041374d8@www.thinkware.se>
 <5.1.0.14.0.20021219231022.02a92ca8@www.thinkware.se>
 <5.1.0.14.0.20021219231022.02a92ca8@www.thinkware.se>
 <5.1.0.14.0.20021220231514.041374d8@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021221122942.041c41f0@www.thinkware.se>

At 22:55 2002-12-20 -03-30, Adam Vardy wrote:
>You could also have a command to print letters on a graphics screen.
>No point plotting.

Have a look at http://www.nmt.edu/tcc/help/pubs/tkinter.pdf
It talks about canvas text objects. I've typically made more
"office like" forms applications. I've never used Canvas for
real, but rather windows here the texts are standing still...

No big difference though... Put this in a file and run...

from Tkinter import *
import time
root = Tk()
c = Canvas(root)
c.pack()
o = c.create_text(0,0,text="Hello Adam!")
for i in range(100):
     c.move(o,i,i)
     root.update()
     time.sleep(0.1)

root.mainloop()

>It's a quote from the TkInter introduction. I am summarizing how it
>uses plenty of terms that may appear in a chapter of a book I was
>reading, but none of it has sunk in my brain.  So, widgetwhaty, wish
>it was less annoying. Rhetorically speaking.

I can agree that there could be more python documentation in
general and python GUI documentation in particular that is aimed
at people who hasn't done Python programming or other GUI
programming before.

With free software and free documentation, people typcally write
stuff that fills a need that they have--whether it's code or
documents.

>The link was on page 4 of that Introduction.

Try google if a link is dead, and it's probably a good idea
to alert the person responsible for a document or web page with
a dead link.

After all, you're not paying for this, so you can't expect
everything to be served on a silver platter. (Not that it would
be for products you pay for either...)


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Sat Dec 21 10:21:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat Dec 21 10:21:02 2002
Subject: [Tutor] Images + Tkinter
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66CA5C@mbtlipnt02.btlabs
 .bt.co.uk>
Message-ID: <5.1.0.14.0.20021221161927.02bfc008@www.thinkware.se>

I just remembered this old thread as I looked at the
PIL docs at New Mexico Tech...

At 17:50 2002-11-17 +0000, alan.gauld@bt.com wrote:
> > def window(tk):
> >     global photo       #### SIC!
> >     frame=Tkinter.Frame(tk)
> >     frame.pack()
> >     canvas=Tkinter.Canvas(frame,width=400,height=500)
> >     canvas.pack()
> >     photo=Tkinter.PhotoImage(file="picture.gif")
> >     canvas.create_rectangle(10,20,30,40, fill="red")
> >     canvas.create_image(200, 250, image=photo)
>
>Why doesn't this retain a reference to the image and stop it
>being dropped?

I just stumbled over this:

http://www.nmt.edu/tcc/help/pubs/pil.pdf

On page 6 it says there is a bug in PIL's PhotoImage, so
that reference count isn't bumped up as it should. I can't
personally verify that this is a bug and not a design choice,
but it's at least a known problem...



-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From GREENDAY31087@aol.com  Sat Dec 21 17:28:02 2002
From: GREENDAY31087@aol.com (GREENDAY31087@aol.com)
Date: Sat Dec 21 17:28:02 2002
Subject: [Tutor] 2nd bonehead question...
Message-ID: <8b.2125ca09.2b364494@aol.com>

--part1_8b.2125ca09.2b364494_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

What is the difference(s) between py and pyc?

--part1_8b.2125ca09.2b364494_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

<HTML><FONT FACE=arial,helvetica><FONT  SIZE=2 FAMILY="SANSSERIF" FACE="Arial" LANG="0">What is the difference(s) between py and pyc?</FONT></HTML>

--part1_8b.2125ca09.2b364494_boundary--


From magnus@thinkware.se  Sat Dec 21 17:57:03 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat Dec 21 17:57:03 2002
Subject: [Tutor] 2nd bonehead question...
In-Reply-To: <8b.2125ca09.2b364494@aol.com>
Message-ID: <5.1.0.14.0.20021221235403.02bcd400@www.thinkware.se>

At 17:26 2002-12-21 -0500, GREENDAY31087@aol.com wrote:
>What is the difference(s) between py and pyc?


.py is for source files--the kind of file you write.

.pyc is a .py file compiled into byte-code, a binary
format that the python interpreter reads. These files
are created automatically when a python module is
imported, if there isn't already an updated .pyc file.

You could say that .py and .pyc in Python corresponds to
.java and .class in Java, if that means anything to you.


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From shalehperry@attbi.com  Sat Dec 21 19:21:01 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Sat Dec 21 19:21:01 2002
Subject: [Tutor] 2nd bonehead question...
In-Reply-To: <5.1.0.14.0.20021221235403.02bcd400@www.thinkware.se>
References: <5.1.0.14.0.20021221235403.02bcd400@www.thinkware.se>
Message-ID: <200212211619.29024.shalehperry@attbi.com>

On Saturday 21 December 2002 14:58, Magnus Lycka wrote:
> At 17:26 2002-12-21 -0500, GREENDAY31087@aol.com wrote:
> >What is the difference(s) between py and pyc?
>
> .py is for source files--the kind of file you write.
>
> .pyc is a .py file compiled into byte-code, a binary
> format that the python interpreter reads. These files
> are created automatically when a python module is
> imported, if there isn't already an updated .pyc file.
>

taken a step further, the interpreter has some magic to use the .pyc firs=
t if=20
it exists otherwise it makes one from the .py file.  There is logic there=
 to=20
see if the pyc is older than the py and if so recreate it as well.

So basically, the pyc file provides the interpreter a way to give better=20
performance by not having to parse and translate the python source code i=
n=20
many cases.


From syrinx@simplecom.net  Sun Dec 22 03:10:03 2002
From: syrinx@simplecom.net (Scott)
Date: Sun Dec 22 03:10:03 2002
Subject: [Tutor] socket question
Message-ID: <20021222020519.00d64618.syrinx@simplecom.net>

How do I detect a zero-length tcp packet?  recv() doesn't seem to work
for this.  I think I'm missing something obvious.  TNX.


From Adam Vardy <anvardy@roadrunner.nf.net>  Sun Dec 22 10:06:42 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Sun Dec 22 10:06:42 2002
Subject: [Tutor] NEWBIE QUEASTION ALERT - how to restart program?
In-Reply-To: <005401c2a887$aab8bc00$854c73d5@oleioq8ex4m1zx>
References: <005401c2a887$aab8bc00$854c73d5@oleioq8ex4m1zx>
Message-ID: <1083105208.20021222113443@roadrunner.nf.net>

Friday, December 20, 2002, 8:56:55 PM, you wrote:

>> This program has been modified from the area calculator found in the instant hacking tutorial http://www.hetland.org/python/instant-hacking.php
>> ___________________________________________________________________________
>>   # Area calculator
>>   print "WELCOME TO THE AREA CALCULATOR"
>>   print "------------------------------"
>>   print ""
>>   print ""

<<snip>>

I thought this looked like a straightforward like program. But, then I
tried it. In PythonWin, when I ran it, it gave a sort of prompt, but
none of the print statements appeared you have there.  And kind of
hung at that point. hmm..

Then I tried typing a command.

--------------------------------------------------------------------

>python areacalc.py
  File "areacalc.py", line 84
    elif quad_shape== 2:
       ^
SyntaxError: invalid syntax


-- 
Adam Vardy



From mongo57a@comcast.net  Sun Dec 22 10:19:02 2002
From: mongo57a@comcast.net (andy surany)
Date: Sun Dec 22 10:19:02 2002
Subject: [Tutor] NEWBIE QUEASTION ALERT - how to restart program?
Message-ID: <001501c2a9cd$ba871540$2502a8c0@emily.ewndsr01.nj.comcast.net>

You might want to check your indentation.....
-----Original Message-----
From: Adam Vardy <anvardy@roadrunner.nf.net>
To: Ole Jensen <ole_jensen@dbmail.dk>; tutor@python.org
<tutor@python.org>
Date: Sunday, December 22, 2002 10:07 AM
Subject: Re: [Tutor] NEWBIE QUEASTION ALERT - how to restart program?


>
>Friday, December 20, 2002, 8:56:55 PM, you wrote:
>
>>> This program has been modified from the area calculator found in the
instant hacking tutorial
http://www.hetland.org/python/instant-hacking.php
>>>
________________________________________________________________________
___
>>>   # Area calculator
>>>   print "WELCOME TO THE AREA CALCULATOR"
>>>   print "------------------------------"
>>>   print ""
>>>   print ""
>
><<snip>>
>
>I thought this looked like a straightforward like program. But, then I
>tried it. In PythonWin, when I ran it, it gave a sort of prompt, but
>none of the print statements appeared you have there.  And kind of
>hung at that point. hmm..
>
>Then I tried typing a command.
>
>--------------------------------------------------------------------
>
>>python areacalc.py
>  File "areacalc.py", line 84
>    elif quad_shape== 2:
>       ^
>SyntaxError: invalid syntax
>
>
>--
>Adam Vardy
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor



From dman@dman.ddts.net  Sun Dec 22 14:07:02 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Sun Dec 22 14:07:02 2002
Subject: [Tutor] Re: socket question
In-Reply-To: <20021222020519.00d64618.syrinx@simplecom.net>
References: <20021222020519.00d64618.syrinx@simplecom.net>
Message-ID: <20021222191658.GA1685@dman.ddts.net>

--AhhlLboLdkugWU4S
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Dec 22, 2002 at 02:05:19AM -0600, Scott wrote:
| How do I detect a zero-length tcp packet?  recv() doesn't seem to work
| for this.  I think I'm missing something obvious.  TNX.

What is a zero-length TCP packet?  Are you referring to, for example,
ACKs that have to data portion?  recv() is a pretty natural function
-- it obtains the data from the underlyinig transport and gives it to
you.  If there is no data, you don't get any data.  Plain and simple.
The details of TCP (or UDP or IPX or choose-a-transport-protocol) are
hidden from you.  The kernel takes care of processing the transport
protocol correctly.

HTH,
-D

--=20
In the way of righteousness there is life;
along that path is immortality.
        Proverbs 12:28
=20
http://dman.ddts.net/~dman/

--AhhlLboLdkugWU4S
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj4GD6oACgkQO8l8XBKTpRSE8wCgh59fk0+t+sgiT0YQODQam8jg
P5YAnA5EvDyxaVXgGYoYAM4QGTTa9Ap1
=hheT
-----END PGP SIGNATURE-----

--AhhlLboLdkugWU4S--


From alan.gauld@bt.com  Sun Dec 22 18:11:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun Dec 22 18:11:02 2002
Subject: [Tutor] Motion
Message-ID: <7497DCA1C240C042B28F6657ADFD8E097022C0@i2km11-ukbr.domain1.systemhost.net>

> Well, ah...
> this is what you'd do on a 1984 C64.
> 
> POKE 1024+Y*40+X,MAN
> 
> OR call the kernal plot routine
> 
> SYS Plot, y,x,0: PRINT MAN;
> 

Yes, But the C64 knew exactly what kind of terminal it was 
controlling. Python doesn't have a clue (well actually on 
unix it has a clue via the TERM variable - but only a clue...)

> Only thing is, here we go with novelletes that read to me like..."
> Isn't there a serious problem hidden in here: what happens 
> when the __init__ function returns and the frame variable 
> goes out of scope?
> 
> Just relax; there's actually no need to keep a reference to 
> the widget instance.
> "

Tkiner is not trivial it is true, but its easier than trying to 
control an unknown interface with no standard API...

> "example is adapted from the "hello world" program in Matt Conway's A
> Tkinter Life Preserver ."

Conway was good in its day but its now seriously out of date, 
better to use Fred Lundhs tutor and the New Mexico site posted 
recently.

For your purpose you only need a simple frame containing a 
canvas widget. Then use the canvas methods to draw pretty 
much like the C64 plot functions.


Check out the tkinter section on the python web site for 
links to Lundh...

In fact the GUI intro on my tutor might suffice for your needs!

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld


From alan.gauld@bt.com  Sun Dec 22 18:24:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun Dec 22 18:24:02 2002
Subject: [Tutor] Advice required: Documentation Writing / Sofware Test
 ing
Message-ID: <7497DCA1C240C042B28F6657ADFD8E097022C1@i2km11-ukbr.domain1.systemhost.net>

NB This is way off topic!

> consistent and never answered question was WHY JCL in the 
> first place when there are much easier ways???)

Note to the innocent:
JCL is the Job Control Language used on IBM mainframes

The reason for "why" is to ensure, no guarantee, that when 
a program on a mainframe(a job) runs, it has the precise 
environment it needs. That is it will be sure to have 
enough memory (and no more) and enough disk space
(and no more), that enough environment space, I/O buffers 
etc etc will be available.

If the required environment cannot be guaranteed to be 
provided for the duration of the job it will not start.
(Even if the resources are physically available currently 
 as in when another job has reserved some but isn't using 
 them)

This is one way that mainframes are so rock solid and 
predictable, you have to specify exactly how much of 
everything you need to run a job. If it's available you 
get it, if not the job does not run. No other job can 
steal the resources from you once you start - so no /tmp 
getting filled up, no disks suddenly filling up and 
virtual memory dying etc etc.

JCL is an intrinsic part of the reliability of MVS applications.
Its a pain in the neck to produce - no program can run without 
one - but it keeps things solid. Of course if you get the JCL 
wrong your job may fall over through lack of resources but 
then its your fault and nobody else is affected.

A bit off topic, but an often misunderstood and under 
appreciated feature of mainframes - they are not reliable by 
accident, they are designed to be reliable! Mainframers view 
Unix much as Unix guys view NT...

Alan g.
(ONe time MVS support manager!)


From alan.gauld@bt.com  Sun Dec 22 18:38:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun Dec 22 18:38:02 2002
Subject: [Tutor] Advice required: Documentation Writing / Sofware Test
 ing
Message-ID: <7497DCA1C240C042B28F6657ADFD8E097022C2@i2km11-ukbr.domain1.systemhost.net>

> I find it curious how badly indexed most technical books are.
> indexing ought properly to be an automated procedure

In my experience (albeit limited) it's usually manual.

> information i needed.  sometimes, it almost seems like the indexing
> procedure consists of somebody reading through the text and
> arbitrarily deciding which terms on a page or in a section to index.

As I mentioned earlier the de-facto standard tool in publishing books 
is Adobe FrameMaker. Frame has powerful indexing tools but they work 
by going through the text and identifying the terms to be indexed and 
linking them to an index entry. This is good if you want to link GUI, 
UI and Tkinter all to a single reference, not so good if you want to 
index ALL occurences of GUI...

Also indexing is often not carried out by the author but by a 
third party. Frame's tools are powerful but not always so easy 
to use!

Alan G


From alan.gauld@bt.com  Sun Dec 22 18:45:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun Dec 22 18:45:02 2002
Subject: [Tutor] NEWBIE QUEASTION ALERT - how to restart program?
Message-ID: <7497DCA1C240C042B28F6657ADFD8E097022C3@i2km11-ukbr.domain1.systemhost.net>

> >python areacalc.py
>   File "areacalc.py", line 84
>     elif quad_shape== 2:
>        ^
> SyntaxError: invalid syntax

The mistake is almost certainly in the line or two above the reported error.
Look for indentation differences, unclosed strings or parens/brackets, 
strings with non matching quote types, etc...

Alan g.


From syrinx@simplecom.net  Mon Dec 23 02:40:02 2002
From: syrinx@simplecom.net (Scott)
Date: Mon Dec 23 02:40:02 2002
Subject: [Tutor] python formatting tool?
Message-ID: <20021223013514.169e1dd9.syrinx@simplecom.net>

Sometimes I come across a python module that looks alright, but I get a
lot of syntax errors.  So I go down the file line-by-line, stripping out
all the white space and replacing it with tabs, or vice-versa.  I just
have to massage it like that.  Then it works.  That's the only thing I
don't like about python's scoping rules.  Anyway, is there a good script
to "massage" my text that is smart enough to convert tabs and spaces and
hard-spaces, and unix-win, win-unix conversions and all that good stuff?
 Thanks.



From syrinx@simplecom.net  Mon Dec 23 02:51:02 2002
From: syrinx@simplecom.net (Scott)
Date: Mon Dec 23 02:51:02 2002
Subject: [Tutor] Re: socket question
Message-ID: <20021223014624.2f655e36.syrinx@simplecom.net>

On Sun, 22 Dec 2002 02:05:19 -0600
Scott <syrinx@simplecom.net> wrote:

> How do I detect a zero-length tcp packet?  recv() doesn't seem to work
> for this.  I think I'm missing something obvious.  TNX.

Let me clarify.  I'm looking for a server to "ping" me.  He's not going
to send any data at all.  Just a blank tcp packet (the header, which, I
think, is between 20 and 60 bytes).  How do I detect such a packet in
python?  Do I have to use server mode (listen() instead of receive()) ?


From francois.granger@free.fr  Mon Dec 23 04:36:01 2002
From: francois.granger@free.fr (Fran=?ISO-8859-1?B?5w==?=ois Granger)
Date: Mon Dec 23 04:36:01 2002
Subject: [Tutor] python formatting tool?
In-Reply-To: <20021223013514.169e1dd9.syrinx@simplecom.net>
Message-ID: <BA2C9770.5FA32%francois.granger@free.fr>

on 23/12/02 8:35, Scott at syrinx@simplecom.net wrote:

> Sometimes I come across a python module that looks alright, but I get a
> lot of syntax errors.  So I go down the file line-by-line, stripping out
> all the white space and replacing it with tabs, or vice-versa.  I just
> have to massage it like that.

See tabnanny in the documentation.

-- 
Le courrier est un moyen de communication. Les gens devraient
se poser des questions sur les implications politiques des choix (ou non
choix) de leurs outils et technologies. Pour des courriers propres :
<http://marc.herbert.free.fr/mail/> -- <http://minilien.com/?IXZneLoID0>



From rob@uselesspython.com  Mon Dec 23 10:08:02 2002
From: rob@uselesspython.com (Rob Andrews)
Date: Mon Dec 23 10:08:02 2002
Subject: [Tutor] RE: [Jython-users] difference b/w Python, CPython, Jython
In-Reply-To: <EFAA78F77E74D411A0F700508BDFEAD6089DCD04@mlbmx9.corp.harris.com>
Message-ID: <MPEOIFCOPCIHEDCLBLPBOEOFCNAA.rob@uselesspython.com>

This is a multi-part message in MIME format.

------=_NextPart_000_0002_01C2AA63.47F09AB0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Python and CPython are two different names for the same thing, namely the
distribution of python that is written and maintained in the C programming
language. Jython (which used to be called JPython) is a python distribution
written in 100% pure Java. When you see someone using the term 'python'
beginning with a non-capital 'p', this often refers to the language itself
instead of any particular implementation of it.

regards,
Rob
http://uselesspython.com (which needs volunteers)
Lock picking for sport and enjoyment:
http://groups.yahoo.com/group/locksports/

  -----Original Message-----
  From: jython-users-admin@lists.sourceforge.net
[mailto:jython-users-admin@lists.sourceforge.net]On Behalf Of Deng, Zemian
(Contractor)
  Sent: Monday, December 23, 2002 7:18 AM
  To: 'jython-users@lists.sourceforge.net'
  Subject: [Jython-users] difference b/w Python, CPython, Jython


  Hello friends,

  Can someone please give a me brief description between all these three?

  Thanks
  Zemian Deng
  =============
  System Integration Engineer | Phone: 321-724-3443
  HARRIS Corporation          | Email: zdeng@harris.com
  Network Support Division    | Melbourne, FL


------=_NextPart_000_0002_01C2AA63.47F09AB0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1126" name=3DGENERATOR></HEAD>
<BODY>
<DIV><SPAN class=3D721140815-23122002><FONT face=3DArial color=3D#0000ff =
size=3D2>Python=20
and CPython are two different names for the same thing, namely the =
distribution=20
of python that is written and maintained in the C programming language. =
Jython=20
(which used to be called JPython) is a python distribution written in =
100% pure=20
Java. When you see someone using the term 'python' beginning with a =
non-capital=20
'p', this often refers to the language itself instead of any particular=20
implementation of it.</FONT></SPAN></DIV>
<DIV><SPAN class=3D721140815-23122002><FONT face=3DArial color=3D#0000ff =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D721140815-23122002><FONT face=3DArial color=3D#0000ff =

size=3D2>regards,</FONT></SPAN></DIV>
<DIV><SPAN class=3D721140815-23122002><FONT face=3DArial color=3D#0000ff =

size=3D2>Rob</FONT></SPAN></DIV>
<DIV><SPAN class=3D721140815-23122002><FONT face=3DArial color=3D#0000ff =
size=3D2><A=20
href=3D"http://uselesspython.com">http://uselesspython.com</A> (which =
needs=20
volunteers)</FONT></SPAN></DIV>
<P><FONT size=3D2>Lock picking for sport and enjoyment:<BR><A=20
href=3D"http://groups.yahoo.com/group/locksports/"=20
target=3D_blank>http://groups.yahoo.com/group/locksports/</A></FONT> =
</P>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px =
solid; MARGIN-RIGHT: 0px">
  <DIV class=3DOutlookMessageHeader dir=3Dltr align=3Dleft><FONT =
face=3DTahoma=20
  size=3D2>-----Original Message-----<BR><B>From:</B>=20
  jython-users-admin@lists.sourceforge.net=20
  [mailto:jython-users-admin@lists.sourceforge.net]<B>On Behalf Of =
</B>Deng,=20
  Zemian (Contractor)<BR><B>Sent:</B> Monday, December 23, 2002 7:18=20
  AM<BR><B>To:</B> =
'jython-users@lists.sourceforge.net'<BR><B>Subject:</B>=20
  [Jython-users] difference b/w Python, CPython, =
Jython<BR><BR></FONT></DIV>
  <DIV><SPAN class=3D991491513-23122002>Hello friends,</SPAN></DIV>
  <DIV><SPAN class=3D991491513-23122002></SPAN>&nbsp;</DIV>
  <DIV><SPAN class=3D991491513-23122002>Can someone please give a me =
brief=20
  description between all these three? </SPAN></DIV>
  <DIV><SPAN class=3D991491513-23122002></SPAN>&nbsp;</DIV>
  <DIV><SPAN class=3D991491513-23122002>Thanks</SPAN></DIV>
  <P><I><FONT face=3DScript size=3D6>Zemian Deng</FONT></I> <BR><FONT=20
  face=3D"Courier New" =
size=3D2>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</FONT> <BR><FONT =
face=3D"Courier New"=20
  size=3D2>System Integration Engineer | Phone: 321-724-3443</FONT> =
<BR><FONT=20
  face=3D"Courier New" size=3D2>HARRIS=20
  Corporation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | =
Email:=20
  zdeng@harris.com</FONT> <BR><FONT face=3D"Courier New" =
size=3D2>Network Support=20
  Division&nbsp;&nbsp;&nbsp; | Melbourne, FL</FONT> </P>
  <DIV>&nbsp;</DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0002_01C2AA63.47F09AB0--




From aztech1200@yahoo.com  Mon Dec 23 11:23:03 2002
From: aztech1200@yahoo.com (Aztech Guy)
Date: Mon Dec 23 11:23:03 2002
Subject: [Tutor] Better (free) IDEs than IDLE for Linux ?
In-Reply-To: <7497DCA1C240C042B28F6657ADFD8E0974DA65@i2km11-ukbr.domain1.systemhost.net>
Message-ID: <20021223162210.23136.qmail@web9802.mail.yahoo.com>

--0-210206220-1040660530=:20322
Content-Type: text/plain; charset=us-ascii


I'm replying to this thread after a long time.
Thanks, to all (Alan, Derrick, Kevin, etc.) who responded. I learnt a lot of things from your posts (I read all of them, I think).
(Also, sorry for the rather long mail below).
Alan (and any others who have an opinion on what I say below), I just wanted to clarify a few points regarding your post below (and regarding a later one, where you asked - what does an IDE offer that UNIX (with vim/emacs/ctags/etc.) does not.
To address that last point (above) first - surely one thing an IDE offers (which the UNIX tools combination does not) - is graphical construction of the GUI - by drag and drop, setting widget properties, etc. - a la VB / Delphi / etc. ? Now, whether people consider that an advantage or not is another thing I'm interested in. As I said, I've done only a little GUI development (on either platform, Win or Lin). Done a very little bit of Win/C/SDK type development which is similar to the UNIX approach that you describe, i.e. just a text editor - both to write the code and to create resource files, then compile/edit/test/debug - both the logical errors and for GUI problems such as wrong size/placement of widgets etc. I think people would agree that this is a tedious and error-prone approach to getting the GUI just right. Also done a little in VB / Delphi as said earlier. But, I don't think its necessary to do a lot to realize the fact stated above - that visual GUI construction can't be done without an IDE or a GUI builder of some sort - (I used the term IDE since the products I've used on Win combined the editing/compiling/debugging features with the UI builder part, all in one product. I am aware, though, that they can be separate - I believe Glade is something on those lines - where it's mainly a GUI builder and can generate XML and/or C/C++ code (not sure of my facts here - caveat reader), but doesn't have editing/compiling/debugging support).
I am, however, interested in knowing what others think - those who done UI development (speaking both generally, about any language/toolkit combination, and specifically about Python-based GUI development) - i.e. whether they think it's "better" (that word again - maybe I should say - "they prefer") to design the UI purely via code (i.e. not using a GUI builder), then compile/run/see how it looks/if not ok, then modify the code - for changing the appearance) - or whether they find it preferable to use a GUI builder to interactively and visually prototype and finalize the GUI part, then plug in code to handle events, etc. I ask this, not to disparage anyone, but because I really want to know - what people who have more GUI experience prefer; realizing, of course, that my prefs. might differ.
A few final points :
I do have a good amount of UNIX dev. experience, all of it with the approach you describe below - vim et al - (with some limitations, see below) though it was mainly vi, not vim (earlier, on UNIX, not Linux). So I know what you are talking about - at least to some extent. For e.g., I'm fairly proficient with vi, and know about commands like cw, C, D, map, abbr, the colon commands (last line mode) like :w, :s, :n,ms/old/newpat/, :!, , even !! cmd to filter a range of lines thru the filter called "cmd", and it output of cmd replaces those lines in the vi buffer, shelling out of vi, even multiple levels, etc. Also with cc/gcc, make, ld, nm, sed, awk, grep, egrep, and the rest of the familiar UNIX command-line tools for general users as well as for s/w developers.
So I agree with a lot of what you say below. But, I also have some points to make.
The rest of them are inline with your words below, marked with [Az].
 alan.gauld@bt.com wrote:>  Which other (free) IDE's / enhanced Py interpreters do you like better the  >  standard Python interpreter and IDLE - for Linux ?   The best development environment for Linux(or any Unix) is Linux itself.Linux is a complete and fully integrated development environment, it just doesn't look like a Windows IDE thats all. Using vim and the :! command and a couple of xterm sessions may not look like an IDE but the fact that they all talk to one another and use a common language - text - means it is. And once you get used to it its more effective than any Visual Basic type IDE can ever hope to be. If you want more pampering use emacs(with python mode on) and geta whole bunch of other goodies too, including integration with RCS/CVSand grep etc.[Az] As said above, I have used RCS/grep/make etc.I don't want pampering - or, rather, I do :) - which is why I like the UNIX dev. env. myself - and have been known to evangelize it, like you. I agree that its the one of the best s/w dev. envs. I've worked on.  >  I am using PythonWin on Windows, is good enough for me at present.   [Az] I think I didn't word some of my statements precisely enough - possibly this caused you to interpret them differently from what I meant - I've found that this does happen at times when using email.
Case in point - my statement above - by "good enough for me", I did not mean to imply that nothing else is needed, or that the UNIX approach is bad (obviously) - I simply meant that for my present needs, as a relative beginner in GUI development, I hadn't yet found the need for anything more powerful or featureful. If you like the pythonwin editor you can get Scite for Linux - its the same editor but without the debugger etc. > Both non-GUI enhanced interpreters - of which I think IPython is one - and  >  proper GUI IDE's are of interest.  What exactly do you expect to gain using one of these "proper" IDEs over a multi window setup in native Linux? [Az] Another miswording by me - by "proper GUI IDE" I didn't mean to imply - if that's what you thought - since you quoted the word proper - that anything like a non-GUI-IDE is "improper" or whatever. Proper was used in the sense of "actual GUI tool" - i.e. the tool itself is a GUI app, and allows you to build GUI apps, as opposed to the command line + vi approach to building GUI apps. I was actually more interested in the GUI builder component of the IDE - for the reason given at the top of this mail - i.e. visual building and refining of my app's GUI - rather than the editing/compiling/debugging support -   I don't need an IDE for that - can manage quite well with vi and friends. Finally, as I said, I am not trying to criticize or start a flame war - was just asking questions with a view to learning. Let me also say that, despite my UNIX experience, I learned some things from your post - such as the stuff about stepping thru the lines found by grep (in *vim* as well as emacs - was vaguely aware that emacs is considered more powerful than vi (not vim, perhaps)) by many - due to eLisp and other reasons), but had never learnt it as vi was adequate for my needs - my approach for the grep would be to run the grep either from vi or from a shell (with filename and line number options enabled -l and -n), then redirect the output to a file,  either my own current file or a new file, edit that file, and use the filenames and line numbers to go edit those places in those files and do whatever changes were needed. (If you can type quite fast, as I can, this works reasonably well). But the ability of vim that you describe is easier - since, even for a fast typist, less need to type (to get to each filename and line number in that file) means faster development, and also less chance of typing errors). I had not updated myself with vim's features as opposed to traditional UNIX vi, hence didn't know that it could do all that. I guess it's a reminder of the need to constantly - or frequently - get back to the never-ending job of keeping oneself updated about new things - and also one of the benefits of mailing lists. Thanks.Az.
Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld 



---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now
--0-210206220-1040660530=:20322
Content-Type: text/html; charset=us-ascii

<P>I'm replying to this thread after a long time.
<P>Thanks, to all (Alan, Derrick, Kevin, etc.) who responded. I learnt a lot of things from your posts (I read all of them, I think).
<P>(Also, sorry for the rather long mail below).
<P>Alan (and any others who have an opinion on what I say below), I just wanted to clarify a few points regarding your post below (and regarding a later one, where you asked - what does an IDE offer that UNIX (with vim/emacs/ctags/etc.) does not.
<P>To address that last point (above) first - surely one thing an IDE offers (which the UNIX tools combination does not) - is graphical construction of the GUI - by drag and drop, setting widget properties, etc. - a la VB / Delphi / etc. ? Now, whether&nbsp;people consider that an advantage or not is another thing I'm interested in. As I said, I've done only a little GUI development (on&nbsp;either platform, Win or Lin). Done a very little bit of Win/C/SDK type development which is similar to the UNIX approach that you describe, i.e. just a text editor - both to write the code and to create resource files, then compile/edit/test/debug - both the logical errors and for GUI problems such as wrong size/placement of widgets etc. I think people would agree that this is a tedious and error-prone approach to getting the GUI just right. Also done a little in VB / Delphi as said earlier. But, I don't think its necessary to do a lot to realize the fact stated above&nbsp;- that visual GUI construction can't be done without an IDE or a GUI builder of some sort - (I used the term IDE since the products I've used on Win combined the editing/compiling/debugging features with the UI builder part, all in one product. I am aware, though, that they can be separate - I believe Glade is something on those lines - where it's mainly a GUI builder and can generate XML and/or C/C++ code (not sure of my facts here - caveat reader), but doesn't have editing/compiling/debugging support).
<P>I am, however, interested in knowing what others think - those who done UI development (speaking both generally, about any language/toolkit combination, and specifically about Python-based GUI development) - i.e. whether they think it's "better" (that word again - maybe I should say - "they prefer") to design the UI purely via code (i.e. not using a GUI builder), then compile/run/see how it looks/if not ok, then modify the code - for changing the appearance) - or whether they find it preferable to use a GUI builder to interactively and visually prototype and finalize the GUI part, then plug in code to handle events, etc. I ask this, not to disparage anyone, but because I really want to know - what people who have more GUI experience prefer; realizing, of course, that my prefs. might differ.
<P>A few final points :
<P>I do have a good amount of UNIX dev. experience, all of it with the approach you describe below - vim et al - (with some limitations, see below) though it was mainly vi, not vim (earlier, on UNIX, not Linux). So I know what you are talking about - at least to some extent. For e.g., I'm fairly proficient with vi, and know about commands like cw, C, D, map, abbr, the colon commands (last line mode) like :w, :s, :n,ms/old/newpat/, :!, , even !! cmd to filter a range of lines thru the filter called "cmd", and it output of cmd replaces those lines in the vi buffer, shelling out of vi, even multiple levels, etc. Also with cc/gcc, make, ld, nm, sed, awk, grep, egrep, and the rest of the familiar UNIX command-line tools for general users as well as for s/w developers.
<P>So I agree with a lot of what you say below. But, I also have some points to make.
<P>The rest of them are inline with your words below, marked with [Az].
<P>&nbsp;<B><I>alan.gauld@bt.com</I></B> wrote:
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">
<META content="MSHTML 5.50.4807.2300" name=GENERATOR>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>&gt; &nbsp;</FONT></SPAN>Which other (free) IDE's / enhanced Py interpreters do you like better&nbsp;the&nbsp;<SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>&gt; </FONT>&nbsp;</SPAN>standard Python interpreter and IDLE -&nbsp;for Linux ?&nbsp;<SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002></SPAN>&nbsp;</DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>The best development environment for Linux(or any Unix) is Linux itself.</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>Linux is a complete and fully integrated development environment, it </FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>just doesn't look like a Windows IDE thats all.</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>Using vim and the :! command and a couple of xterm sessions may not </FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>look like an IDE but the fact that they all talk to one another and </FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>use a common language - text - means it is. And once you get used </FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>to it its more effective than any Visual Basic type IDE can ever </FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>hope to be.</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>If you want more pampering use emacs(with python mode on) and get</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>a whole bunch of other goodies too, including integration with RCS/CVS</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>and grep etc.</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" size=2>[Az] As said above,&nbsp;I have used RCS/grep/make etc.</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New">I don't want pampering - or, rather, I do :) - which is why I like the UNIX dev. env. myself - and have been known to evangelize it, like you. I agree that its the one of the best s/w dev. envs. I've worked on.</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New"></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=010161217-16122002>&gt; &nbsp;</SPAN>I am using PythonWin on Windows, is good enough for me at present.&nbsp;<SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" size=2>[Az] I think I didn't word some of my statements precisely enough - possibly this caused you to interpret them differently from what I meant - I've found that this does happen at times when using email.<BR>Case in point - my statement above - by "good enough for me", I did not mean to imply that nothing else is needed, or that the UNIX approach is bad (obviously) - I simply meant that for my present needs, as a relative beginner in GUI development, I hadn't yet found the need for anything more powerful or featureful.</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New"></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>If you like the pythonwin editor you can get Scite for Linux </FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>- its the same editor but without the debugger etc.</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=010161217-16122002></SPAN><FONT face="Courier New"><FONT color=#0000ff><FONT size=2>&gt;<SPAN class=010161217-16122002>&nbsp;</SPAN></FONT></FONT></FONT>Both non-GUI enhanced interpreters - of which I think IPython is one - and&nbsp;<SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>&gt; </FONT>&nbsp;</SPAN>proper GUI IDE's are of interest.<SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002></SPAN>&nbsp;</DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>What exactly do you expect to gain using one of these "proper" </FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>IDEs over a multi window setup in native Linux?</FONT></SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=010161217-16122002>[Az] Another miswording by me - by "proper GUI IDE" I didn't mean to imply - if that's what you thought -&nbsp;since you quoted the word proper - that anything like a non-GUI-IDE is "improper" or whatever. Proper was used in the sense of "actual GUI tool" - i.e. the tool itself is a GUI app, and allows you to build GUI apps, as opposed to the command line + vi approach to building GUI apps. I was actually more interested in the GUI builder component of the IDE - for the reason given at the top of this mail - i.e. visual building and refining of my app's GUI - rather than the editing/compiling/debugging support -&nbsp;&nbsp; I don't need an IDE for that - can manage quite well with vi and friends.</SPAN></DIV>
<DIV><SPAN class=010161217-16122002></SPAN>&nbsp;</DIV>
<DIV><SPAN class=010161217-16122002>Finally, as I said, I am not trying to criticize or start a flame war - was just asking questions with a view to learning. Let me also say that, despite my UNIX experience, I learned some things from your post - such as the stuff about stepping thru the lines found by grep (in&nbsp;*vim* as well as emacs - was vaguely aware that emacs is considered more powerful than vi (not vim, perhaps)) by many - due to eLisp and other reasons), but had never&nbsp;learnt it as&nbsp;vi was adequate for my needs - my approach&nbsp;for the grep would be&nbsp;to run the grep either from vi or from&nbsp;a shell (with filename and line number options enabled -l and -n), then redirect the&nbsp;output to a file,&nbsp; either my own current file or a new file, edit that file, and use the filenames and line numbers to go edit those places in those files and do whatever changes were needed. (If you can&nbsp;type quite fast, as I can, this works reasonably well). But the ability&nbsp;of vim that you describe is easier - since, even for a fast typist, less need to type (to get to each filename and line number in that file) means faster development, and also less chance of typing errors). I had not updated myself with vim's features as opposed to traditional UNIX vi, hence didn't&nbsp;know that it could do all that. I guess it's a reminder of the need to constantly - or frequently - get back to the never-ending job of keeping oneself updated&nbsp;about new things - and also one of the benefits of mailing lists.</SPAN></DIV>
<DIV><SPAN class=010161217-16122002>&nbsp;</SPAN></DIV>
<DIV><SPAN class=010161217-16122002>Thanks.</SPAN></DIV>
<DIV><SPAN class=010161217-16122002>Az.</SPAN></DIV>
<DIV><SPAN class=010161217-16122002><FONT face="Courier New" color=#0000ff size=2>
<P><FONT size=2>Alan g.<BR>Author of the 'Learning to Program' web site<BR><A target=_blank href="http://www.freenetpages.co.uk/hp/alan.gauld">http://www.freenetpages.co.uk/hp/alan.gauld</A></FONT> </P></FONT></SPAN></DIV></BLOCKQUOTE><p><br><hr size=1>Do you Yahoo!?<br>
<a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Yahoo! Mail Plus</a> - Powerful. Affordable. <a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Sign up now</a>
--0-210206220-1040660530=:20322--


From alan.gauld@bt.com  Mon Dec 23 11:55:31 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon Dec 23 11:55:31 2002
Subject: [Tutor] Re: socket question
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0974DA77@i2km11-ukbr.domain1.systemhost.net>

> Let me clarify.  I'm looking for a server to "ping" me.  

> to send any data at all.  Just a blank tcp packet 

Umm, if its literally ping then you won't get tcp at all. 
ping doesn't use tcp it uses another IP protocol called ICMP.
It sends an ECHO_REQUEST and you have to respond with an 
ECHO_RESPONSE. (See man ping & man icmp)

> python?  Do I have to use server mode (listen() instead of 
> receive()) ?

If the other box is contacting you then you need to be 
listening for the right protocol in the right place.

Alan g.


From alan.gauld@bt.com  Mon Dec 23 12:27:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon Dec 23 12:27:01 2002
Subject: [Tutor] Better (free) IDEs than IDLE for Linux ?
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0974DA78@i2km11-ukbr.domain1.systemhost.net>

> is graphical construction of the GUI - by drag and drop, 

The basic Unix toolset does not have a GUI builder because such 
things didn't exist when Unix was written, but several standalone 
GUI builders now exist which integrate admirably with Unix - both 
free and commercial.

> Now, whether people consider that an advantage or not is 
> another thing I'm interested in. 

Its a big advantage for beginners and casual users but for experts 
its much faster to use a coding/resource file style of GUI creation.
I'm told (by ex colleagues who work there) that several Microdsoft 
developers still maintain some of the Office GUI using the text 
form of the resource files.... Whether that's a recommendation is 
of course another matter!

Personally I use Delphi on windows and Tkinter on Unix. I like 
both approaches. Tkinter is much more robust long term -it 
withstands window resizing etc better. But delphi is probably 
easier to draw ithe initial design. I have used SpecTcl and 
played with Glade under Unix too.

> a very little bit of Win/C/SDK type development which is 
> similar to the UNIX approach that you describe, 

No, not at all! That really is stone age banging together of 
stones! Using a good high level class library makes it much easier.
A more valid comparison would be using Swing/Awt in Java without 
a GUI builder.

> etc. I think people would agree that this is a tedious and 
> error-prone approach to getting the GUI just right. 

If you know what you are doing and have *designed* the GUI in 
advance - something thats usually done by a separate human 
factors team using something like Visio on a big project - then
the resource editor approach is very fast once you know the 
GUI "language" - somewhat similar to Tkinter programming (but using 
coordinates - yukk!)


> that visual GUI construction can't be done without an IDE or 
> a GUI builder of some sort 

Of course it can - Microsoft Office was built entirely without 
GUI builders for the whole of its windows 3 lifetime. In fact 
most Windows 3 apops were built that way. Nearly all X Windows 
apps were built that way till the last few years - X has lagged 
in GUI builder tools. But I'd admit for a casual user its more 
difficult without a builder tool.


> be separate - I believe Glade is something on those lines - 
> where it's mainly a GUI builder and can generate XML and/or 
> C/C++ code 

Correct, but its not an IDE. GUI builders are fine if thats 
what you like, but they are not *of necessity* IDEs.

> I am, however, interested in knowing what others think - 
> those who done UI development (speaking both generally, about 
> any language/toolkit combination, and specifically about 
> Python-based GUI development) 

For heavyweight GUI development I tend to use a GUI builder 
but I know many GUI experts who don't. On Unix I tend to use 
one of the commercial products such as XVT or TeleUse. On 
Windows I use Delphi.

But most of my Unix programming is not GUI based and so I 
don't need a GUI builder. A few admin screens, an app 
launcher, maybe an installer - all easily knocked together 
in Tkinter...

> prefer") to design the UI purely via code (

Designing a GUI like any other kind of design is best done
separately from the code that implements it. It should ideally 
be designed by someone who knows how users interact with 
computers. The programmers job is to take that designand 
turn it into code, ewither with tool support or by hand...

Unfortunately one of the reasons so many bad GUI tools exist 
is that too many organisations leave GUI design to the 
programmers. (See "About Face" by Alan Cooper for examples)

> for my present needs, as a relative beginner in GUI 
> development, I hadn't yet found the need for anything more 
> powerful or featureful. 

Sure, it actually sounds like your main need is a good 
GUI builder not necesarily an IDE per se...

> Finally, as I said, I am not trying to criticize or start a 
> flame war - was just asking questions with a view to 
> learning. 

Me neither and in fact I am playing Devils advocate slightly. 
But many folks are unaware of just how powerful the raw Unix 
environment is. They jump straight into a GUI IDE without 
realizing that Unix can ber more powerful. And worse, they 
often criticize Unix for its lack of IDE when they don't 
understand that Unix is by design an IDE in its own right...
 
> had not updated myself with vim's features as opposed to 
> traditional UNIX vi, hence didn't know that it could do all 
> that. 

I have an email friend who is a rabid emacs fan. He was 
bemoaning the fact he was forced to use vim at a recent job.
Most of the things he thought were missing were in fact 
there - he hadn't used vi for 10 years....

Microsoft C IDE was pretty bad 10 years ago too!

BTW I use both emacs and vim on Unix. ;-)

Somebody else sent me mail(I think offline) showing some 
real advantages of IDEs, so in fairness I'll point out 
what I thought were valid ones:

1) Code completion - knowledge of the language allows suggestions 
   of parameters etc. No editor, no matter how good the regex, is that
smart.

2) Project management - GUI front ends for make exist, but IDEs can add 
   some extra value here.

3) Syntax colouring - regex is OK but its possible to get confused. 
   A full language parsing IDE can do a better job.

So there are a few real advantages to IDEs, and thats fine provided 
you realize exactly what it is you are getting in real terms,  and that 
equally Unix has a number of other features that the IDEs dont(yet) 
support...

I'll make this my last word on this one :-)

Alan g.



From hall@nhn.ou.edu  Mon Dec 23 14:50:54 2002
From: hall@nhn.ou.edu (Isaac Hall)
Date: Mon Dec 23 14:50:54 2002
Subject: [Tutor] submitting batch jobs with python
Message-ID: <Pine.SOL.4.30.0212231321430.22908-100000@particle.nhn.ou.edu>

gracious tutor list members,

I am working on a program to submit several batch jobs with python.
when one submits a batch job from a shell here, the system returns several
lines of output telling you many things you need to know (like where the
ouput will be written, etc....)  I would like my program to capture this
information, but I am a little unclear as to how to do this.  It looks
like the call os.popen('command').read() is the way to go, but I do not
know what format this will put several lines into.  secondly, how will
this handle submitting say 200 jobs at once.  will each popen call only
capture the lines intended for that job?  any ideas?

Ike




From ramrom@earthling.net  Mon Dec 23 15:58:00 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Mon Dec 23 15:58:00 2002
Subject: [Tutor] submitting batch jobs with python
In-Reply-To: <Pine.SOL.4.30.0212231321430.22908-100000@particle.nhn.ou.e
 du>
Message-ID: <5.2.0.9.0.20021223133711.02d185f0@66.28.54.253>

--=======49C94C1=======
Content-Type: text/plain; x-avg-checked=avg-ok-790D3F98; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit

At 01:22 PM 12/23/2002 -0600, Isaac Hall wrote:
>I am working on a program to submit several batch jobs with python.
>when one submits a batch job from a shell here, the system returns several
>lines of output telling you many things you need to know (like where the
>ouput will be written, etc....)  I would like my program to capture this
>information, but I am a little unclear as to how to do this.  It looks
>like the call os.popen('command').read() is the way to go, but I do not
>know what format this will put several lines into.

os.popen('command').read()

will return a string with lines separated by '\n'

os.popen('command').readlines()

will return a list of lines

>how will this handle submitting say 200 jobs at once.  will each popen 
>call only
>capture the lines intended for that job?

Each popen call will run one batch job and return that job's output.

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625

--=======49C94C1=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-790D3F98
Content-Disposition: inline


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.431 / Virus Database: 242 - Release Date: 12/17/2002

--=======49C94C1=======--



From hall@nhn.ou.edu  Mon Dec 23 16:45:30 2002
From: hall@nhn.ou.edu (Isaac Hall)
Date: Mon Dec 23 16:45:30 2002
Subject: [Tutor] submitting batch jobs with python
In-Reply-To: <5.2.0.9.0.20021223133711.02d185f0@66.28.54.253>
Message-ID: <Pine.SOL.4.30.0212231524390.22908-100000@particle.nhn.ou.edu>

Hi Bob,
Thank you, and one quick follow up question if I may.
If I did something like this,

commands=[<list of commandlines to send>]
output=[]
for i in range(len(commands)):
	a=os.popen(command[i]).readlines
	output.append(a)

where it takes the system a second or two to respond with the lines it
gives, would each iteration of the loop occur two seconds apart, or would
the loop keep going while a popen().readlines() waited for the system
response?


On Mon, 23 Dec 2002, Bob Gailer wrote:

> At 01:22 PM 12/23/2002 -0600, Isaac Hall wrote:
> >I am working on a program to submit several batch jobs with python.
> >when one submits a batch job from a shell here, the system returns several
> >lines of output telling you many things you need to know (like where the
> >ouput will be written, etc....)  I would like my program to capture this
> >information, but I am a little unclear as to how to do this.  It looks
> >like the call os.popen('command').read() is the way to go, but I do not
> >know what format this will put several lines into.
>
> os.popen('command').read()
>
> will return a string with lines separated by '\n'
>
> os.popen('command').readlines()
>
> will return a list of lines
>
> >how will this handle submitting say 200 jobs at once.  will each popen
> >call only
> >capture the lines intended for that job?
>
> Each popen call will run one batch job and return that job's output.
>
> Bob Gailer
> mailto:ramrom@earthling.net
> 303 442 2625
>



From ramrom@earthling.net  Mon Dec 23 16:49:14 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Mon Dec 23 16:49:14 2002
Subject: [Tutor] submitting batch jobs with python
In-Reply-To: <Pine.SOL.4.30.0212231524390.22908-100000@particle.nhn.ou.e
 du>
References: <5.2.0.9.0.20021223133711.02d185f0@66.28.54.253>
Message-ID: <5.2.0.9.0.20021223143324.02d0fbb0@66.28.54.253>

--=======60CD238D=======
Content-Type: text/plain; x-avg-checked=avg-ok-790D3F98; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit


>commands=[<list of commandlines to send>]
>output=[]
>for i in range(len(commands)):
>         a=os.popen(command[i]).readlines
>         output.append(a)

shorten this to:

for cmd in commands:
         a=os.popen(cmd).readlines() # NOTE () after readlines!
         output.append(a)

then use list comprehension to shorten it to:

output = [os.popen(cmd).readlines() for cmd in commands]

>Would each iteration of the loop occur two seconds apart

Yes.

>the loop keep going while a popen().readlines() waited for the system 
>response?

To do that you'd need to use threads.

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625

--=======60CD238D=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-790D3F98
Content-Disposition: inline


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.431 / Virus Database: 242 - Release Date: 12/17/2002

--=======60CD238D=======--



From reavey@nep.net  Mon Dec 23 18:20:01 2002
From: reavey@nep.net (reavey)
Date: Mon Dec 23 18:20:01 2002
Subject: [Tutor] Thanks
Message-ID: <3E07964F.2050901@nep.net>

Sirs:
Thanks. Best wishes for a happy Christmas and New Year.

Re-v



From tony@tcapp.com  Tue Dec 24 00:25:01 2002
From: tony@tcapp.com (Tony Cappellini)
Date: Tue Dec 24 00:25:01 2002
Subject: [Tutor] getting input from keyboard
Message-ID: <5.1.0.14.0.20021223212959.023e6f58@smtp.sbcglobal.net>


How do I get keyboard input in python ?
I want to do the equivalent of this C code, in python


x=getch()

With the books that I have, there are no references in the index  to get, 
keyboard input, or in the Python help file.

What is the magic word I am looking for ?



From dman@dman.ddts.net  Tue Dec 24 01:02:02 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Tue Dec 24 01:02:02 2002
Subject: [Tutor] Re: getting input from keyboard
In-Reply-To: <5.1.0.14.0.20021223212959.023e6f58@smtp.sbcglobal.net>
References: <5.1.0.14.0.20021223212959.023e6f58@smtp.sbcglobal.net>
Message-ID: <20021224060102.GA1301@dman.ddts.net>

--gKMricLos+KVdGMg
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Dec 23, 2002 at 09:33:41PM -0800, Tony Cappellini wrote:
|=20
| How do I get keyboard input in python ?
| I want to do the equivalent of this C code, in python
|=20
| x=3Dgetch()

That isn't a standard C library function.  It is, I belive, a Borland
(or maybe a Microsoft) extension.  UNIX systems don't normally have
that function, since the intput to a program may or may not be
connected to a keyboard.

| With the books that I have, there are no references in the index  to get,=
=20
| keyboard input, or in the Python help file.
|=20
| What is the magic word I am looking for ?

That depends.

The raw_input() function obtains input from the program's stdin (which
will be the keyboard unless you use IO redirection).

If you are running python on windows, you can import the 'mswin' (or
somesuch) and obtain a function named getch().

If you want to react to just a single keystroke (rather than
line-buffered input) and be mostly cross-platform, use the ncurses
library.

HTH,
-D

--=20
Pride only breeds quarrels,
but wisdom is found in those who take advice.
        Proverbs 13:10
=20
http://dman.ddts.net/~dman/

--gKMricLos+KVdGMg
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj4H+B4ACgkQO8l8XBKTpRQ+6gCdENZ5cXOcdLimjQHE3+PrYX3X
j1QAn33J0LOZUzFA15E+uPrAiDlU9gTB
=e2yO
-----END PGP SIGNATURE-----

--gKMricLos+KVdGMg--


From rustynewton@comcast.net  Tue Dec 24 01:52:01 2002
From: rustynewton@comcast.net (Rusty Newton)
Date: Tue Dec 24 01:52:01 2002
Subject: [Tutor] ansi color
Message-ID: <003a01c2ab28$5da178a0$6401a8c0@huntsv01.al.comcast.net>

This is a multi-part message in MIME format.

--Boundary_(ID_hn3MmFN6FuLURhhbrBzM1w)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7BIT

me again! finally got my text game online, dont have a static IP yet but will soon, anyways
im trying to figure out how to change the color of the text that i output to the player, i really
have no idea on this one hehe, any help would be greatly appreciated =P if your interested in seeing
what i have so far contact me on aim   FrigidZephyr   or send me a email and ill put up the server
so you can see what little i have hehe =] , THANKS !!


-rusty 

--Boundary_(ID_hn3MmFN6FuLURhhbrBzM1w)
Content-type: text/html; charset=iso-8859-1
Content-transfer-encoding: 7BIT

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1126" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>me again! finally got my text game online, dont 
have a static IP yet but will soon, anyways</FONT></DIV>
<DIV><FONT face=Arial size=2>im trying to figure out how to change the color of 
the text that i output to the player, i really</FONT></DIV>
<DIV><FONT face=Arial size=2>have no idea on this one hehe, any help would be 
greatly appreciated =P if your interested in seeing</FONT></DIV>
<DIV><FONT face=Arial size=2>what i have so far contact me on aim&nbsp;&nbsp; 
FrigidZephyr&nbsp;&nbsp; or send me a email and ill put up the 
server</FONT></DIV>
<DIV><FONT face=Arial size=2>so you can see what little i have hehe =] , THANKS 
!!</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>-rusty&nbsp;</FONT></DIV></BODY></HTML>

--Boundary_(ID_hn3MmFN6FuLURhhbrBzM1w)--


From tony@tcapp.com  Tue Dec 24 01:53:02 2002
From: tony@tcapp.com (Tony Cappellini)
Date: Tue Dec 24 01:53:02 2002
Subject: [Tutor] Tutor Archives- dates corrupted
Message-ID: <5.1.0.14.0.20021223225809.0248df08@smtp.sbcglobal.net>


Has anyone noticed the dates on the Tutor archive page ?
http://mail.python.org/pipermail/tutor/

There are dates > 2002, and years back as far as 1980.

This is the first time I've looked at this page, so I don't know how long 
it's been there.
Has this already been reported ?



From aztech1200@yahoo.com  Tue Dec 24 09:53:17 2002
From: aztech1200@yahoo.com (Aztech Guy)
Date: Tue Dec 24 09:53:17 2002
Subject: [Tutor] Better (free) IDEs than IDLE for Linux ?
In-Reply-To: <7497DCA1C240C042B28F6657ADFD8E0974DA78@i2km11-ukbr.domain1.systemhost.net>
Message-ID: <20021224145203.37898.qmail@web9806.mail.yahoo.com>

--0-1447068599-1040741523=:37634
Content-Type: text/plain; charset=us-ascii


 
 alan.gauld@bt.com wrote:
programmers. (See "About Face" by Alan Cooper for examples)


[Az] Yes, I have that book. It's good. One nice example is about scroll bars - he argues that the up and down arrowheads on a scroll bar should be adjacent, not at opposite ends of the bar, to reduce mousing. Haven't seen that idea make its way into many apps though. Maybe it requires changes at the toolkit level and would break compatibility in some way.

Sure, it actually sounds like your main need is a good 
GUI builder not necesarily an IDE per se...

[Az]  Yes, that's so.

But many folks are unaware of just how powerful the raw Unix 


[Az] That's right on the mark. I think its partly because man pages are not as user-friendly as hypertext help of MS WIndows. It kind of forces you to read a lot more than you might need, to solve a small problem, in some cases at least. The man page for bash is a good example. But then again, ultimately, you need to know a lot, if not most, of that stuff anyway. I myself learned UNIX mainly by reading man pages and UNIX manuals from vendors, and trying out commands and scripts, reading and experimenting a lot. The level of automation and productivity increase that can be achieved with even basic stuff like common commands and shell scripting (not to mention Perl, Python, expect, etc.) is unbelievable to someone who hasn't really seen it in action. If only they knew how much it could help them ...

real advantages of IDEs, so in fairness I'll point out 
what I thought were valid ones:

So there are a few real advantages to IDEs, and thats fine provided 

[Az] Yes, those are real advantages.


I'll make this my last word on this one :-)


[Az]  Thanks, Alan, for the inputs. Me too :-)

 



---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now
--0-1447068599-1040741523=:37634
Content-Type: text/html; charset=us-ascii

<P>&nbsp;
<P>&nbsp;<B><I>alan.gauld@bt.com</I></B> wrote:
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">
<P>programmers. (See "About Face" by Alan Cooper for examples)<BR></P>
<P>[Az] Yes, I have that book. It's good. One nice example is about scroll bars - he argues that the up and down arrowheads on a scroll bar should be adjacent, not at opposite ends of the bar, to reduce mousing. Haven't seen that idea make its way into many apps though. Maybe it requires changes at the toolkit level and would break compatibility in some way.</P>
<P>Sure, it actually sounds like your main need is a good <BR>GUI builder not necesarily an IDE per se...</P>
<P>[Az]&nbsp; Yes, that's so.</P>
<P>But many folks are unaware of just how powerful the raw Unix <BR></P>
<P>[Az] That's right on the mark. I think its partly because man pages are not as user-friendly as hypertext help of MS WIndows. It kind of forces you to read a lot more than you might need, to solve a small problem, in some cases at least. The man page for bash is a good example. But then again, ultimately, you need to know a lot, if not most, of that stuff anyway. I myself learned UNIX mainly by reading man pages and UNIX manuals from vendors, and trying out commands and scripts, reading and experimenting a lot. The level of automation and productivity increase that can be achieved with even basic stuff like common commands and&nbsp;shell scripting (not to mention Perl, Python, expect,&nbsp;etc.) is unbelievable to someone who hasn't really seen it in action. If only they&nbsp;knew how much it could help them ...</P>
<P>real advantages of IDEs, so in fairness I'll point out <BR>what I thought were valid ones:<BR><BR>So there are a few real advantages to IDEs, and thats fine provided </P>
<P>[Az] Yes, those are real advantages.</P>
<P><BR>I'll make this my last word on this one :-)<BR></P>
<P>[Az]&nbsp; Thanks, Alan, for the inputs. Me too :-)</P>
<P>&nbsp;</P></BLOCKQUOTE><p><br><hr size=1>Do you Yahoo!?<br>
<a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Yahoo! Mail Plus</a> - Powerful. Affordable. <a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Sign up now</a>
--0-1447068599-1040741523=:37634--


From jeff@ccvcorp.com  Tue Dec 24 14:28:07 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Tue Dec 24 14:28:07 2002
Subject: [Tutor] Tutor Archives- dates corrupted
References: <5.1.0.14.0.20021223225809.0248df08@smtp.sbcglobal.net>
Message-ID: <3E08B55B.9060300@ccvcorp.com>

Tony Cappellini wrote:

> Has anyone noticed the dates on the Tutor archive page ?
> http://mail.python.org/pipermail/tutor/
>
> There are dates > 2002, and years back as far as 1980.


I believe that the dates on mail messages are set entirely by the 
originator.  If the person writing the message has their system clock 
set wrong, that wrong date stays with the message all the way to the 
archive.

Jeff Shannon
Technician/Programmer
Credit International




From dyoo@hkn.eecs.berkeley.edu  Tue Dec 24 14:38:11 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue Dec 24 14:38:11 2002
Subject: [Tutor] Re: getting input from keyboard
In-Reply-To: <20021224060102.GA1301@dman.ddts.net>
Message-ID: <Pine.LNX.4.44.0212241131340.14588-100000@hkn.eecs.berkeley.edu>


On Tue, 24 Dec 2002, Derrick 'dman' Hudson wrote:

> On Mon, Dec 23, 2002 at 09:33:41PM -0800, Tony Cappellini wrote:
> |
> | How do I get keyboard input in python ?
> | I want to do the equivalent of this C code, in python
> |
> | x=getch()
>
> The raw_input() function obtains input from the program's stdin (which
> will be the keyboard unless you use IO redirection).
>
> If you are running python on windows, you can import the 'mswin' (or
> somesuch) and obtain a function named getch().

Hello!

I've written a small Cookbook recipe to make using getch() somewhat
simpler:

    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892

It should work on Windows and Unix platforms; I hope it works for you.


Happy holidays!



From jeff@ccvcorp.com  Tue Dec 24 14:38:26 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Tue Dec 24 14:38:26 2002
Subject: [Tutor] Re: getting input from keyboard
References: <5.1.0.14.0.20021223212959.023e6f58@smtp.sbcglobal.net> <20021224060102.GA1301@dman.ddts.net>
Message-ID: <3E08B6DA.4010802@ccvcorp.com>

Derrick 'dman' Hudson wrote:

>The raw_input() function obtains input from the program's stdin (which
>will be the keyboard unless you use IO redirection).
>

Which (as Dman knows, but the original poster may not) reads a 'line' at 
a time -- it won't return until you hit enter, or (if reading from a 
file/socket/whatever) until a newline character is reached.

>If you are running python on windows, you can import the 'mswin' (or
>somesuch) and obtain a function named getch().
>
>If you want to react to just a single keystroke (rather than
>line-buffered input) and be mostly cross-platform, use the ncurses
>library.
>  
>

I'm pretty sure that the Windows module in question is 'msvcrt', which 
presumably wraps (much of) the mscvrt DLL.  (That's Microsoft Visual C 
Run Time library.)

I'm not sure if ncurses will work at all under Windows, so there really 
isn't any completely cross-platform way to grab a single keystroke. 
 Which, when you consider the number of different platforms, with 
different user-input interfaces, is hardly surprising.  (How do you grab 
keyboard input on a Palm?)

Jeff Shannon
Technician/Programmer
Credit International




From dyoo@hkn.eecs.berkeley.edu  Tue Dec 24 14:41:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue Dec 24 14:41:02 2002
Subject: [Tutor] Tutor Archives- dates corrupted
In-Reply-To: <5.1.0.14.0.20021223225809.0248df08@smtp.sbcglobal.net>
Message-ID: <Pine.LNX.4.44.0212241134220.14588-100000@hkn.eecs.berkeley.edu>


On Mon, 23 Dec 2002, Tony Cappellini wrote:

> Has anyone noticed the dates on the Tutor archive page ?
> http://mail.python.org/pipermail/tutor/
>
> There are dates > 2002, and years back as far as 1980.
>
> This is the first time I've looked at this page, so I don't know how long
> it's been there.

Hi Tony,

Yes, it's been noticed.  Previously, Mailman would take the dates of
messages from the messages themselves.  Unfortunately, some people's
computers are living in the future --- their computer clocks are set to
some weird date.

The mail admins have corrected this in Mailman's settings, so that the
dates of messages are now set to the arrival time of the message.
However, we haven't been able to figure out how to correct the futuristic
mail entries yet.


There are only a few messages in the future, so the problem doesn't appear
to be too widespread.  Ok, I'm lazy.  *grin* But if it does seem like a
big problem, email tutor-admin@python.org, and we'll try to hammer out a
solution.



From mongo57a@comcast.net  Tue Dec 24 14:56:00 2002
From: mongo57a@comcast.net (andy surany)
Date: Tue Dec 24 14:56:00 2002
Subject: [Tutor] Installing the Blt Package
Message-ID: <001201c2ab86$cc53b340$2502a8c0@emily.ewndsr01.nj.comcast.net>

Happy Holidays list members!

After installing the latest Pmw, I installed Blt2.4z. I followed the
instructions and I believe that everything was "made" successfully. If I
go into the Blt2.4z directory
(usr/lib/python2.2/site-packages/Pmw/Blt2.4z/demos/) and execute the Tcl
demo (./graph1.Tcl), it works.

However, when I try to execute BltGraph.py
(/usr/lib/python2.2/Pmw_1_1/demos/), I get the message box "BLT Package
has not been installed on this system".

Anyone know what's wrong? Do I need to add something to my path? or
modify a Python variable?

TIA.

Andy



From syrinx@simplecom.net  Wed Dec 25 01:05:02 2002
From: syrinx@simplecom.net (Scott)
Date: Wed Dec 25 01:05:02 2002
Subject: [Tutor] Re: socket question
In-Reply-To: <20021223170005.25520.22602.Mailman@mail.python.org>
References: <20021223170005.25520.22602.Mailman@mail.python.org>
Message-ID: <20021225000043.4c15313c.syrinx@simplecom.net>

> > Let me clarify.  I'm looking for a server to "ping" me.  
> > to send any data at all.  Just a blank tcp packet 
> Umm, if its literally ping then you won't get tcp at all. 
> ping doesn't use tcp it uses another IP protocol called ICMP.

I guess it wouldn't hurt to explain what I'm actually trying to do.  :)

I'm playing around with the yahoo messenger protocol, trying to figure
out how to get a yahoo webcam viewer to work under linux.

I'm sorry I used the word "ping."  Because I didn't mean that literally.
 What I meant is that sometimes the yahoo server will send what I called
a zero-length tcp packet, which is just a tcp header with no data
attached to it.  I assume it's the server's way of saying "Hey I got the
packet you sent, now I'm ready for more."  I know these are tcp packets
because I've examined them under ethereal and a couple of other packet
sniffers.

It seems that if I use socket.recv() and it's one of these empty
packets, my program hangs waiting for the data, which doesn't exist. 
I'm pretty sure I'm doing something wrong, but can't figure out what.




From lumbricus@gmx.net  Wed Dec 25 06:57:01 2002
From: lumbricus@gmx.net (lumbricus@gmx.net)
Date: Wed Dec 25 06:57:01 2002
Subject: [Tutor] Re: socket question
References: <20021225000043.4c15313c.syrinx@simplecom.net>
Message-ID: <10078.1040817367@www13.gmx.net>

Hi!

[ snip ]

> It seems that if I use socket.recv() and it's one of these empty
> packets, my program hangs waiting for the data, which doesn't exist. 
> I'm pretty sure I'm doing something wrong, but can't figure out what.

Try "socket.setblocking(0)"

HTH, J"ö!


-- 
sigfault

+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!



From aztech1200@yahoo.com  Wed Dec 25 14:37:01 2002
From: aztech1200@yahoo.com (Aztech Guy)
Date: Wed Dec 25 14:37:01 2002
Subject: [Tutor] Returning a list/dict as "read-only" from a method ?
Message-ID: <20021225192759.60084.qmail@web9801.mail.yahoo.com>

--0-1183573139-1040844479=:59877
Content-Type: text/plain; charset=us-ascii



Hi list,

This question is about how to return a list/dictionary from a method (of a class) in such a way that it stays "read-only" to the caller - or any other technique that is equivalent in terms of effect. Read on for the gory details (slightly long post, sorry):

I have a class - call it C1, whose purpose in life is to read data from a binary file, and maintain some of the data read, as member variables of the class. It should provide some methods that allow clients to get the values of that data. Some of the data is structured in nature (i.e. some of the individual data elements logically belong together, as in a C struct), so I was planning to return such data  - from one method, as a list - and from another method, as a dictionary. Now, some time back, in the "call-by-reference in Python" thread, people (Danny was one, I think) had showed the use of the id() function to identify when two different variables actually refer to the same piece of memory. As a test, I wrote a dummy class and 2 methods as above (one of which returned a list and the other a dictionary); when I printed id(<my_dict_or_list>) from within the method, and also from the caller of the method (invoked via a created object of that class, of course), I found that id() returns the same value in both places. I think this means that any caller of my object's method, can modify my member variable (list or dictionary) that I am returning via the method. I don't want to let this happen, obviously. (If I allowed it, then, each time the method was called, instead of simply returning the list/dictionary member variable originally created, I would have to re-read that data from the file, and return the re-read data instead of my original copy in my member variable. (I would not be able to simply return my original copy of the data, since the first caller (as also any subsequent callers) would have a reference to the very same member variable (as shown by the calls to id(), and hence could potentially have modified it, thereby changing my member variable from its original value read from the file.) This re-reading would be highly inefficient due to repeated file I/O to read the same data multiple times - as opposed to reading it once from the file, saving it in a member variable, and then simply returning that variable whenever the method was called from the 2nd time onwards.) So what I did next was to write a fragment of code inside each method (just after the code to read data from the file), to make a copy of the list/dictionary, and return that copy instead. Now, even if my caller modifies my return value, it doesn't matter, as they are only modifying a copy, and my original is intact. I do this create-and-return-a-copy each time the method is called. What occurred to me next, is that to perform the memory-to-memory copy - in the method - each time the method is called - is still inefficient - particularly if the list/dictionary's size is more than a few (or few hundred) bytes (though of course, its much faster than re-reading the data each time from the file). Is there any way that I can avoid the need to re-read data from the file, as well as the need to do a memory-to-memory copy, each time the method is called, and yet, prevent a caller from modifying my class's list/dictionary ?

I planned to do the memory-to-memory copy of the list/dictionary in a hand-coded fashion - by iterating through the list/dictionary's items. I am aware that there may be better ways to do this - like 'deepcopy' or some such, but haven't looked into them yet. Anyway, I don't think any other way of copying would help solve my problem, since what I am aiming at is to avoid the copy in the first place - except for a one-time copy, if needed.

Sample code for the first case is given below, followed by the output of a run.

class C1:
    def __init__(self, filename):
        # simulate reading data from the file and populating the dict.
        self.d1 = {}
        self.d1['key1'] = 'value1'
        self.d1['key2'] = 'value2'
        print 'in C1.__init__(), id(self.d1) = ', id(self.d1)

    def get_dict(self):
        return self.d1

def main():
    c1 = C1('dummy')
    main_dict = c1.get_dict()
    print 'in main(), before modifying main_dict, id(main_dict) = ', id(main_dict)
    print 'and main_dict = ', main_dict
    main_dict['key2'] = 'a different value'
    main_dict = c1.get_dict()
    print 'in main(), after modifying main_dict, id(main_dict) = ', id(main_dict)
    print 'and main_dict = ', main_dict
   
main()


>>> in C1.__init__(), id(self.d1) =  24213904
in main(), before modifying, id(main_dict) =  24213904
and main_dict =  {'key2': 'value2', 'key1': 'value1'}
in main(), after modifying, id(main_dict) =  24213904
and main_dict =  {'key2': 'a different value', 'key1': 'value1'}
>>>     

Hope I've made the problem clear. If not, let me know.


TIA 
Az

 



---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now
--0-1183573139-1040844479=:59877
Content-Type: text/html; charset=us-ascii

<P><BR>Hi list,</P>
<P>This question is about how to return a list/dictionary from a method (of a class) in such a way that it stays "read-only" to the caller - or any other technique that is equivalent in terms of effect. Read on for the gory details (slightly long post, sorry):</P>
<P>I have a class - call it C1, whose purpose in life is to read data from a binary file, and maintain some of the data read, as member variables of the class. It should provide some methods that allow clients to get the values of that data. Some of the data is structured in nature (i.e. some of the individual data elements logically belong together, as in a C struct), so I was planning to return such data&nbsp; - from one method, as a list - and from another method, as a dictionary. Now, some time back, in the "call-by-reference in Python" thread, people (Danny was one, I think) had showed the use of the id() function to identify when two different variables actually refer to the same piece of memory. As a test, I wrote a dummy class and 2 methods as above (one of which returned a list and the other a dictionary); when I printed id(&lt;my_dict_or_list&gt;) from within the method, and also from the caller of the method (invoked via a created object of that class, of course), I found that id() returns the same value in both places. I think this means that any caller of my object's method, can modify my member variable (list or dictionary) that I am returning via the method. I don't want to let this happen, obviously. (If I allowed it, then, each time the method was called, instead of simply returning the list/dictionary member variable originally created, I would have to re-read that data from the file, and return the re-read data instead of my original copy in my member variable. (I would not be able to simply return my original copy of the data, since the first caller (as also any subsequent callers) would have a reference to the very same member variable (as shown by the calls to id(), and hence could potentially have modified it, thereby changing my member variable from its original value read from the file.) This re-reading would be highly inefficient due to repeated file I/O to read the same data multiple times - as opposed to reading it once from the file, saving it in a member variable, and then simply returning that variable whenever the method was called from the 2nd time onwards.) So what I did next was to write a fragment of code inside each method (just after the code to read data from the file), to make a copy of the list/dictionary, and return that copy instead. Now, even if my caller modifies my return value, it doesn't matter, as they are only modifying a copy, and my original is intact. I do this create-and-return-a-copy each time the method is called. What occurred to me next, is that to perform the memory-to-memory copy - in the method - each time the method is called - is still inefficient - particularly if the list/dictionary's size is more than a few (or few hundred) bytes (though of course, its much faster than re-reading the data each time from the file). Is there any way that I can avoid the need to re-read data from the file, as well as the need to do a memory-to-memory copy, each time the method is called, and yet, prevent a caller from modifying my class's list/dictionary ?</P>
<P>I planned to do the memory-to-memory copy of the list/dictionary in a hand-coded fashion - by iterating through the list/dictionary's items. I am aware that there may be better ways to do this - like 'deepcopy' or some such, but haven't looked into them yet. Anyway, I don't think any other way of copying would help solve my problem, since what I am aiming at is to avoid the copy in the first place - except for a one-time copy, if needed.</P>
<P>Sample code for the first case is given below, followed by the output of a run.</P>
<P>class C1:<BR>&nbsp;&nbsp;&nbsp; def __init__(self, filename):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # simulate reading data from the file and populating the dict.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.d1 = {}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.d1['key1'] = 'value1'<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.d1['key2'] = 'value2'<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print 'in C1.__init__(), id(self.d1) = ', id(self.d1)</P>
<P>&nbsp;&nbsp;&nbsp; def get_dict(self):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return self.d1</P>
<P>def main():<BR>&nbsp;&nbsp;&nbsp; c1 = C1('dummy')<BR>&nbsp;&nbsp;&nbsp; main_dict = c1.get_dict()<BR>&nbsp;&nbsp;&nbsp; print 'in main(), before modifying main_dict, id(main_dict) = ', id(main_dict)<BR>&nbsp;&nbsp;&nbsp; print 'and main_dict = ', main_dict<BR>&nbsp;&nbsp;&nbsp; main_dict['key2'] = 'a different value'<BR>&nbsp;&nbsp;&nbsp; main_dict = c1.get_dict()<BR>&nbsp;&nbsp;&nbsp; print 'in main(), after modifying main_dict, id(main_dict) = ', id(main_dict)<BR>&nbsp;&nbsp;&nbsp; print 'and main_dict = ', main_dict<BR>&nbsp;&nbsp; <BR>main()</P>
<P><BR>&gt;&gt;&gt; in C1.__init__(), id(self.d1) =&nbsp; 24213904<BR>in main(), before modifying, id(main_dict) =&nbsp; 24213904<BR>and main_dict =&nbsp; {'key2': 'value2', 'key1': 'value1'}<BR>in main(), after modifying, id(main_dict) =&nbsp; 24213904<BR>and main_dict =&nbsp; {'key2': 'a different value', 'key1': 'value1'}<BR>&gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp; </P>
<P>Hope I've made the problem clear. If not, let me know.</P>
<P><BR>TIA <BR>Az</P>
<P>&nbsp;</P><p><br><hr size=1>Do you Yahoo!?<br>
<a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Yahoo! Mail Plus</a> - Powerful. Affordable. <a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Sign up now</a>
--0-1183573139-1040844479=:59877--


From dyoo@hkn.eecs.berkeley.edu  Wed Dec 25 14:41:10 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed Dec 25 14:41:10 2002
Subject: [Tutor] Writing an automatic document keyword finder?
In-Reply-To: <20021220202702.A4354@titan.spiretech.com>
Message-ID: <Pine.LNX.4.44.0212211956480.5395-100000@hkn.eecs.berkeley.edu>


> sometimes, it almost seems like the indexing procedure consists of
> somebody reading through the text and arbitrarily deciding which terms
> on a page or in a section to index.

Hi Michael,

Hmmm... maybe it might make a nice programming project to create an
keyword-finding program.  This would involve trying to automatically
identify important key phrases that represent the main ideas of a book.


But what is a key phrase, though?  Perhaps it's one that's used a lot. We
can cook up a quick histogram function to find the most frequently used
words:


###
def sorted_histogram(words):
    """Returns a list of (word, count) pairs, sorted."""
    counts = {}
    for w in words:
        counts[w] = counts.get(w, 0) + 1
    return sort_by_frequency(counts.items())


def sort_by_frequency(word_count_pairs):
    def mycmp(a, b):
        return cmp(a[1], b[1])
    word_count_pairs.sort(mycmp)
    return word_count_pairs


def main():
    import re
    text = open("diveintopython.txt").read()
    all_words = re.findall("\w+", text)
    print "The 20 most frequent words are:",
    print sorted_histogram(all_words)[-20:]


if __name__ == '__main__':
    main()
###


To test this out, I've taken the source of Mark Pilgrim's "Dive Into
Python" tutorial:

    http://diveintopython.org/

It would be very cool if we could build a good index for Dive Into Python,
since it's quite a nice tutorial.  I think making a good index does
require some manual effort, but wouldn't it be nice if some of the work
could be done automatically?


Let's see if this direct frequency-counting approach works out ok:

###
>>> main()
The 20 most frequent words are:
[('Example', 486),
 ('with', 595),
 ('we', 604),
 ('s', 611),
 ('this', 625),
 ('3', 631),
 ('for', 691),
 ('2', 704),
 ('Python', 800),
 ('that', 857),
 ('it', 904),
 ('you', 917),
 ('1', 1031),
 ('is', 1396),
 ('and', 1508),
 ('in', 1618),
 ('to', 1660),
 ('of', 1764),
 ('a', 2085),
 ('the', 3692)]
###


Hmmm...  This doesn't look too accurate.  At least 'Python' is in that
list, but thost other words are not really that representative of the
text's content.


This is happening is because some words are common for
structural/grammatical reasons --- the English language itself forces
certain words to appear in our sentences.  Perhaps we can organize a list
of "stop words" that we can use to ignore these particular common words.
(An alternative way of handling this might be to use a "part of speech
tagger", a tool that attaches a noun/verb/adjective/preposition sort of
tag on every word.)


Another reason is that keywords might not be just single words, but can be
multiple adjacent words, or whole phrases.  We might resolve this by
taking a sentence like:

    "I do not think it means what you think it means."

and take words pairwise:

    ["I do", "do not", "not think", "think it", "it means", ...]

to do our frequency counting on these pairwise words.  Or we can
generalize this further and widen our window to include triplets.

Hmmm... lots of things that we can try out!


I'm away from my nice Happy Hacking keyboard at home, so I can't finish
playing out these ideas till I get back... *grin* But does anyone want to
give it a shot?


Happy holidays to everyone!



From michael@trollope.org  Thu Dec 26 01:09:02 2002
From: michael@trollope.org (Michael Powe)
Date: Thu Dec 26 01:09:02 2002
Subject: [Tutor] Writing an automatic document keyword finder?
In-Reply-To: <Pine.LNX.4.44.0212211956480.5395-100000@hkn.eecs.berkeley.edu>
References: <20021220202702.A4354@titan.spiretech.com> <Pine.LNX.4.44.0212211956480.5395-100000@hkn.eecs.berkeley.edu>
Message-ID: <20021226060147.GA13874@cecilia>

--sdtB3X0nJg68CQEu
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Dec 25, 2002 at 11:33:05AM -0800, Danny Yoo wrote:

> > sometimes, it almost seems like the indexing procedure consists of
> > somebody reading through the text and arbitrarily deciding which terms
> > on a page or in a section to index.

> Hi Michael,

> Hmmm... maybe it might make a nice programming project to create an
> keyword-finding program.  This would involve trying to automatically
> identify important key phrases that represent the main ideas of a book.

> But what is a key phrase, though?  Perhaps it's one that's used a lot. We
> can cook up a quick histogram function to find the most frequently used
> words:

yes, it is an interesting puzzle.  actually, what i was suggesting was
that the method of marking index terms consisted of said reading.  by
this i was referring to the number of times i have found terms indexed
in one part of a book, only to find them used in important ways in
other parts of the book but not indexed there.

the actual parsing of the text to insert indexing markers is already
automated, i believe, for TeX and troff.  i think i read about that
somewhere, i'll have to look it up again.  you can give the indexing
program a list of words and it will properly mark them in the text so
that the a program like makeindex will pull them out and create the
indexes when the text is run through the marking-up software.

so the trick is, as you say, to determine what terms go into the
list.  after all, you can have multiple levels of indexing, e.g.:

search
 and replace,79
 and replace within a text block,87
 backward for a pattern,44
 combine opening a file with,51
 for general class of words,87
 global (see global replacement)
 ignoring case,85,104,107
 ... (from Learning the Vi Editor)

i really have to think that the best indexing is going to come from
the author or someone who knows the subject very well.

mp

--=20
  Michael Powe                                 Portland, Oregon USA
-------------------------------------------------------------------
"The most likely way for the world to be destroyed, most experts
agree, is by accident.  That's where we come in. We're computer
professionals. We cause accidents."
	       -- Nathaniel Borenstein, inventor of MIME

--sdtB3X0nJg68CQEu
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+CptLUFRfMHc4lysRAhTjAJ9NhCOUAiW3fdzHO32H2qtsNuXHPQCgrgf3
5uIiFGd4fz5OPeTgP/Drqh4=
=WzVq
-----END PGP SIGNATURE-----

--sdtB3X0nJg68CQEu--


From alan.gauld@bt.com  Thu Dec 26 07:10:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu Dec 26 07:10:01 2002
Subject: [Tutor] getting input from keyboard
Message-ID: <7497DCA1C240C042B28F6657ADFD8E097022D1@i2km11-ukbr.domain1.systemhost.net>

> How do I get keyboard input in python ?
> I want to do the equivalent of this C code, in python
> x=getch()

Assuming you are on Windows you need to import mscvrt
and use the getch() function in there.

If you are on Unix you use the curses(or ncurses) module 
which also has a getch() function.

> With the books that I have, there are no references in the 
> index  to get, keyboard input, or in the Python help file.

My online web tutor (and book!)has a topic on event driven 
programming which includes an example of using msvcrt.getch()

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld


From scot@possum.in-berlin.de  Thu Dec 26 14:26:00 2002
From: scot@possum.in-berlin.de (Scot Stevenson)
Date: Thu Dec 26 14:26:00 2002
Subject: [Tutor] Advice required: Documentation Writing / Sofware  Testing
In-Reply-To: <Pine.LNX.4.44.0212201046420.24476-100000@mauve.rahul.net>
References: <Pine.LNX.4.44.0212201046420.24476-100000@mauve.rahul.net>
Message-ID: <200212262013.02277.scot@possum.in-berlin.de>

Hello Terry, 

> (This is, by the way, my major complaint about the O'Reilley "Programming
> Python" text.  I go to Chapter 6 to understand functions in Python, and
> the author makes me understand about packing first.  I don't care about
> packing.  I care about functions.)

Just in case somebody from O'Reilley is hanging around here, I would like to 
second that - in fact, it is worse because Mark Lutz will define an object 
somewhere, and then dozens of pages later will use it in an example (the 
"quit" object comes to mind). Which means that if you are trying to look up 
something, you have to go all the way back to figure out just what he was 
talking about again.

If you're writing technical documentation: Please don't do that. 

Y, Scot

-- 
  Scot W. Stevenson -- scot@possum.in-berlin.de -- Zepernick, Germany



From alan.gauld@bt.com  Thu Dec 26 18:18:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu Dec 26 18:18:01 2002
Subject: [Tutor] Returning a list/dict as "read-only" from a method ?
Message-ID: <7497DCA1C240C042B28F6657ADFD8E097022D2@i2km11-ukbr.domain1.systemhost.net>

Some long description snipped....

> Some of the data is structured in nature (i.e. some of the 
> individual data elements logically belong together, as in a C struct),  

The Pythonic equivalent would then be a class...

> any caller of my object's method, can modify my member variable 

Specifically they can modify its contents, yes.
But if a class you can make it read only...

There are several ways to do this, ranging from setting 
the setattr method to None, to storing the data in private 
members and providing getXXX methods to return copies of 
the individual items (slightly more efficient than copying 
the class...) or if the members are primitive types returning 
the values...

Or in v2.2 you could use the properties feature of classes 
to make read-only attributes.

> re-reading would be highly inefficient due to repeated file I/O 

Depends on the caching on the target machine but potentially yes.

> to make a copy of the list/dictionary, and return that copy instead. 

Better than reading from the file, certainly.

> What occurred to me next, is that to perform the memory-to-memory 
> copy - in the method - each time the method is called 
> - is still inefficient - particularly if the list/dictionary's 
> size is more than a few (or few hundred) bytes 

Are you sure? Python is an interpreted language after all.
Premature optimisation is the root of much evil, to paraphrase 
a saying.

Until you are sure copying is causing you problems I'd stick with it.
You may be surprised. If it turns out to be megabytes at a time or if 
you do it inside a tight loop it may be serious but I doubt if a few 
kilobytes will make much difference.

> I am aware that there may be better ways to do this - like 'deepcopy' 

Indeed, there is a copy module with deepcopy. Not sure if its 
implemented in C or Python, I suspect the latter. But as I said 
try it before optimising it...

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld


From Adam Vardy <anvardy@roadrunner.nf.net>  Thu Dec 26 20:27:01 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Thu Dec 26 20:27:01 2002
Subject: [Tutor] Show commands
Message-ID: <174112139407.20021226215611@roadrunner.nf.net>

I am trying to follow an example. And it says
deck.deal([hand],5)

I am completely confused. It does something. But can I get some
program that could just show me all the commands or functions that are
run in order so I can see them? And try to follow what it's doing?
  

-- 
Adam Vardy



From selevin@attbi.com  Thu Dec 26 20:34:03 2002
From: selevin@attbi.com (selevin)
Date: Thu Dec 26 20:34:03 2002
Subject: [Tutor] New
Message-ID: <005d01c2ad47$ea8fc890$99b3b042@chara>

This is a multi-part message in MIME format.

------=_NextPart_000_005A_01C2AD1E.0117B430
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I am very new to this but I want to learn.
How do I cause the directory containing the file named python.exe to be =
listed in my system environment variable named path. How do I set a path =
and
 make the directory containing my new script file become the current =
directory.
Please help me or let me know where I can read on this=20
in simple terms.
Thank u.
Steve


------=_NextPart_000_005A_01C2AD1E.0117B430
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1126" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>I am very new to this but I want to learn.</DIV>
<DIV>How do I cause the directory containing the file named =
<B>python.exe</B> to=20
be listed in&nbsp;my system environment variable named =
<STRONG>path.</STRONG>=20
How do I set a path<STRONG> </STRONG>and</DIV>
<DIV>&nbsp;make the directory containing&nbsp;my new script file become =
the=20
current directory.</DIV>
<DIV>Please help me or let me know where I can read on this </DIV>
<DIV>in simple terms.</DIV>
<DIV>Thank u.</DIV>
<DIV>Steve</DIV>
<DIV><STRONG></STRONG>&nbsp;</DIV>
<DIV><STRONG></STRONG>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_005A_01C2AD1E.0117B430--




From dyoo@hkn.eecs.berkeley.edu  Fri Dec 27 03:08:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri Dec 27 03:08:01 2002
Subject: [Tutor] Show commands
In-Reply-To: <174112139407.20021226215611@roadrunner.nf.net>
Message-ID: <Pine.LNX.4.44.0212262356460.9733-100000@hkn.eecs.berkeley.edu>


On Thu, 26 Dec 2002, Adam Vardy wrote:

> I am trying to follow an example. And it says
> deck.deal([hand],5)

Hi Adam,


> I am completely confused.

That makes two of us.  *grin*

I'm actually not familiar with the example that you're using; I'm guessing
that it has something to do with shuffled decks and card games, but other
than that, not much else.

Can you point out where you found this example?  Is it part of some
tutorial?


> It does something. But can I get some program that could just show me
> all the commands or functions that are run in order so I can see them?
> And try to follow what it's doing?

The problem is that there is an abundance of commands and functions in
Python.  The documentors have collected descriptions of this "Standard
Library" here:

    http://python.org/doc/lib

but it might be a bit overwhelming; most of the functions are segmented
off into their own groups of modules, and it's exhaustive.  I wouldn't
recommend reading it like a novel.


I'm guessing that you're going through some sample program and trying to
figure out how it works.  If so, please feel free to post small programs
up on Tutor, and we can help point out parts of the program that might be
troubling for you, and give links to specific parts of the Standard
Library docs that should help.


Best of wishes to you!



From dyoo@hkn.eecs.berkeley.edu  Fri Dec 27 03:37:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri Dec 27 03:37:01 2002
Subject: [Tutor] New
In-Reply-To: <005d01c2ad47$ea8fc890$99b3b042@chara>
Message-ID: <Pine.LNX.4.44.0212270010400.9733-100000@hkn.eecs.berkeley.edu>


On Thu, 26 Dec 2002, selevin wrote:

> I am very new to this but I want to learn.

Hi Selevin,

Very cool; we'll do what we can to help.


> How do I cause the directory containing the file named python.exe to be
> listed in my system environment variable named path.

Before I say anything about this: are you sure you need to touch PATH? You
should not need to touch your environmental PATH unless you're doing
something slightly unusual.  Can you tell us more why you want to do this?

Setting PATH is very specific to the operating system of your system ---
it has very little to do with Python, which is why most Python
documentation will ignore the issue.  On Windows 95/98, the file
AUTOEXEC.BAT defines this environmental variable, and changes to it
require a reboot to get things to take effect.  On Windows 2k, it's
somewhere deep in the Control Panel/System applet, in the "Advanced" tab.

Setting path is not a uniform thing to explain, so we need more
information about your system.



> How do I set a path

Python has a function called 'os.chdir()' that will allow us to change the
current working directory of a program.  We can see more information about
it here:

    http://www.python.org/doc/lib/os-file-dir.html



> and make the directory containing my new script file become the current
> directory.

Hmmm... this might be slightly trickier --- your script may be
symbolically linked from several different places.

Can you tell us why you're trying to do this, though?


The name of your script should live in the list variable 'sys.argv', as
the first element of that list.  Here is an example that shows what
sys.argv[0] might look like:

###
dyoo@hkn:~$ cat bin/foo.py
#!/usr/bin/env python
import sys
print sys.argv[0]


dyoo@hkn:~$ bin/foo.py
bin/foo.py
###


So it might just be enough to pull out the 'path' portion of sys.argv[0],
and do a os.chdir() into that directory.  The 'os.path.dirname()' function
is good at extracting directory paths from a filename:

    http://www.python.org/doc/lib/module-os.path.html


If you have more questions, please feel free to ask on Tutor.  Good luck!



From thomi@thomi.imail.net.nz  Fri Dec 27 03:56:43 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Fri Dec 27 03:56:43 2002
Subject: [Tutor] python and blender?
Message-ID: <20021227215526.720634a1.thomi@thomi.imail.net.nz>

Has anyone here tried to do any python scripting for blender? I gave it
a go the other day, but it seems very complicated at first glance. i
just wanted to know how other people have been getting along, or if i am
actually the only person who has attempted such a thing :-)

-- 
DOS: n., A small annoying boot virus that causes random spontaneous
system
     crashes, usually just before saving a massive project.  Easily
cured by
     UNIX.  See also MS-DOS, IBM-DOS, DR-DOS.
(from David Vicker's .plan)
Thomi Richards,
thomi@imail.net.nz


From johnca@ourpla.net  Fri Dec 27 07:01:02 2002
From: johnca@ourpla.net (John Abbe)
Date: Fri Dec 27 07:01:02 2002
Subject: [Tutor] A little security
Message-ID: <a05111719ba31db925f94@[203.94.93.142]>

Is there any simpler way to use https with a Python CGI than using 
the stuff pointed at by today's Dr. Dobbs' Python-URL :

http://groups.google.com/groups?frame=left&th=3ad2d5de60bb5f05

The real question is how i hide a password, which for now i've 
implemented as a field that gets sent with the GET method. I'm 
guessing that https might be the simplest way, but am very open to 
any suggestions.

Life,
John
-- 
  All you  /\/\ John Abbe           "If you don't like the news,
      need \  / CatHerder            go out and make some of your own."
      is... \/  http://ourpla.net/john/                --Wes Nisker


From aztech1200@yahoo.com  Fri Dec 27 09:30:02 2002
From: aztech1200@yahoo.com (Aztech Guy)
Date: Fri Dec 27 09:30:02 2002
Subject: [Tutor] Returning a list/dict as "read-only" from a method ?
In-Reply-To: <7497DCA1C240C042B28F6657ADFD8E097022D2@i2km11-ukbr.domain1.systemhost.net>
Message-ID: <20021227142929.46179.qmail@web9804.mail.yahoo.com>

--0-1346377265-1040999369=:45862
Content-Type: text/plain; charset=us-ascii


Thanks for the reply. I will try out the solutions suggested and then summarize.

Az
 
 alan.gauld@bt.com wrote:Some long description snipped....

> Some of the data is structured in nature (i.e. some of the 
> individual data elements logically belong together, as in a C struct), 

The Pythonic equivalent would then be a class...


There are several ways to do this, ranging from setting 



---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now
--0-1346377265-1040999369=:45862
Content-Type: text/html; charset=us-ascii

<P>Thanks for the reply. I will try out the solutions suggested and then summarize.
<P><BR>Az
<P>&nbsp;
<P>&nbsp;<B><I>alan.gauld@bt.com</I></B> wrote:
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">Some long description snipped....<BR><BR>&gt; Some of the data is structured in nature (i.e. some of the <BR>&gt; individual data elements logically belong together, as in a C struct), <BR><BR>The Pythonic equivalent would then be a class...<BR><BR><BR>There are several ways to do this, ranging from setting <BR></BLOCKQUOTE><p><br><hr size=1>Do you Yahoo!?<br>
<a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Yahoo! Mail Plus</a> - Powerful. Affordable. <a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Sign up now</a>
--0-1346377265-1040999369=:45862--


From ATrautman@perryjudds.com  Fri Dec 27 13:30:01 2002
From: ATrautman@perryjudds.com (Alan Trautman)
Date: Fri Dec 27 13:30:01 2002
Subject: [Tutor] Advice required: Documentation Writing / Sofware Test
 ing
Message-ID: <0BA95581EDA7D611841B00A0C9AD25DD2B5928@mail.pjinet.com>

>Framemaker

I was an instructor for a series of computer classes whose training manuals
were all written in Framemaker. This is a very powerful and painful program
IMO. 

Two things I would look into prior to deciding to use it; 1. I recommend
deciding how much authoring of maintaining of the document you are going to
do. If you don't use it heavily and constantly I find almost nothing
intuitive about it and the relearning is painful. 2. If you are not trying
to make a collection (all) of the documents fit a certain standard many of
its features are harder to use than other products. I our case all 50+
courses used the same style for manuals and it looked very nicely consistent
and that's why we didn't convert much.

At my new position we have Standard Operating Procedures that have a
standard format but very flexible contents and we found the XML and XSL
provided and easier way to store and create the documents as they didn't
require much relearning about entering the information and a knowledgeable
person could just read the text file and find what they wanted to change if
the editor gave them problems.

If you do decide on Framemaker I would also try to take a class especially
on the template features which make it powerful otherwise as you finish
you'll find there were a lot of shortcuts in there.

Good Luck

Alan


From alan.gauld@bt.com  Fri Dec 27 14:41:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri Dec 27 14:41:01 2002
Subject: [Tutor] New
Message-ID: <7497DCA1C240C042B28F6657ADFD8E0974DA7C@i2km11-ukbr.domain1.systemhost.net>

>> How do I cause the directory containing the file named python.exe to be
>> listed in my system environment variable named path.
>
>Before I say anything about this: are you sure you need to touch PATH? You
>should not need to touch your environmental PATH unless you're doing
>something slightly unusual.  Can you tell us more why you want to do this?

Nope, its perfectly normal because the Windows installer doesn't 
set the PATH varioable - Mr Peters explained why many moons ago...
Itvdoes set the registry gubbins so that typing python at the 
Start->Run dialog works, and it sets the association so that 
clicking a .py file staryts python. But if you just start a 
DOS box and type Python it won't work....

So as a result you have to set it by hand.

> documentation will ignore the issue.  On Windows 95/98, the file
> AUTOEXEC.BAT defines this environmental variable

And you shopuld only need to add the following line at the end of
C:\AUTOEXEC.BAT

PATH=%PATH;<your python path>

where <your python path> is your actual python path (in my case its
D:\Python22)

and it will require a reboot to get things to take effect.  


> On Windows 2k, it's somewhere deep in the Control Panel/System applet
Or right click "My Computer" and select Properties.
Go to the "Advanced" tab and click the "Environment Variables" button
Click New on the top panel and add a line

Variable Name	PATH
Variable Value	<your python path>

Click OK, OK, OK.

Reboot.

We really neeed a FAQ for this group! :-(


Alan G.


From ramrom@earthling.net  Fri Dec 27 14:45:03 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Fri Dec 27 14:45:03 2002
Subject: [Tutor] python and blender?
In-Reply-To: <20021227215526.720634a1.thomi@thomi.imail.net.nz>
Message-ID: <5.2.0.9.0.20021227124408.02ba83d0@66.28.54.253>

--=======6B264CF8=======
Content-Type: text/plain; x-avg-checked=avg-ok-357BF25; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit

At 09:55 PM 12/27/2002 +1300, Thomi Richards wrote:
>  ...blender....

What's that?

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625

--=======6B264CF8=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-357BF25
Content-Disposition: inline


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.431 / Virus Database: 242 - Release Date: 12/17/2002

--=======6B264CF8=======--



From Adam Vardy <anvardy@roadrunner.nf.net>  Fri Dec 27 16:04:03 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Fri Dec 27 16:04:03 2002
Subject: [Tutor] Show commands
In-Reply-To: <Pine.LNX.4.44.0212262356460.9733-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.44.0212262356460.9733-100000@hkn.eecs.berkeley.edu>
Message-ID: <1967532406.20021227173329@roadrunner.nf.net>

Friday, December 27, 2002, 4:37:03 AM, you wrote:

>> On Thu, 26 Dec 2002, Adam Vardy wrote:

>> I am trying to follow an example. And it says
>> deck.deal([hand],5)

>> I'm actually not familiar with the example that you're using; I'm guessing
>> that it has something to do with shuffled decks and card games, but other
>> than that, not much else.

>> Can you point out where you found this example?  Is it part of some
>> tutorial?

Yeah. Learning with Python by Allen Downey, chapter 16.

http://www.ibiblio.org/obp/thinkCSpy/chap16.htm

>> It does something. But can I get some program that could just show me
>> all the commands or functions that are run in order so I can see them?
>> And try to follow what it's doing?

>> The problem is that there is an abundance of commands and functions in
>> Python.  The documentors have collected descriptions of this "Standard
>> Library" here:

I was actually seeking not Python commands, just would like to see the
commands from this card game demo thing that are run when I type a
command like the above.

How am I supposed to think about each of the terms in this command?

I see neither numbers, nor simple actions.

-- 
Adam Vardy



From thomi@thomi.imail.net.nz  Fri Dec 27 17:55:02 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Fri Dec 27 17:55:02 2002
Subject: [Tutor] python and blender?
In-Reply-To: <5.2.0.9.0.20021227124408.02ba83d0@66.28.54.253>
References: <20021227215526.720634a1.thomi@thomi.imail.net.nz>
 <5.2.0.9.0.20021227124408.02ba83d0@66.28.54.253>
Message-ID: <20021228115346.6664fedd.thomi@thomi.imail.net.nz>

On Fri, 27 Dec 2002 12:44:41 -0700 Thus said Bob Gailer
<ramrom@earthling.net>:

> At 09:55 PM 12/27/2002 +1300, Thomi Richards wrote:
> >  ...blender....

open source 3d modelling program. see www.blender3d.org or
www.blender.org


-- 
DOS: n., A small annoying boot virus that causes random spontaneous
system
     crashes, usually just before saving a massive project.  Easily
cured by
     UNIX.  See also MS-DOS, IBM-DOS, DR-DOS.
(from David Vicker's .plan)
Thomi Richards,
thomi@imail.net.nz


From selevin@attbi.com  Fri Dec 27 18:09:02 2002
From: selevin@attbi.com (selevin)
Date: Fri Dec 27 18:09:02 2002
Subject: [Tutor] New
Message-ID: <003301c2adfc$ddb2ed90$99b3b042@chara>

This is a multi-part message in MIME format.

------=_NextPart_000_0030_01C2ADD2.F46CE5B0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

>> How do I cause the directory containing the file named python.exe to =
be
>> listed in my system environment variable named path.
>
>Before I say anything about this: are you sure you need to touch PATH? =
You
>should not need to touch your environmental PATH unless you're doing
>something slightly unusual.  Can you tell us more why you want to do =
this?

Nope, its perfectly normal because the Windows installer doesn't=20
set the PATH varioable - Mr Peters explained why many moons ago...
Itvdoes set the registry gubbins so that typing python at the=20
Start->Run dialog works, and it sets the association so that=20
clicking a .py file staryts python. But if you just start a=20
DOS box and type Python it won't work....

So as a result you have to set it by hand.

> documentation will ignore the issue.  On Windows 95/98, the file
> AUTOEXEC.BAT defines this environmental variable

And you shopuld only need to add the following line at the end of
C:\AUTOEXEC.BAT

PATH=3D%PATH;<your python path>

where <your python path> is your actual python path (in my case its
D:\Python22)

and it will require a reboot to get things to take effect. =20


> On Windows 2k, it's somewhere deep in the Control Panel/System applet
Or right click "My Computer" and select Properties.
Go to the "Advanced" tab and click the "Environment Variables" button
Click New on the top panel and add a line

Variable Name PATH
Variable Value <your python path>

Click OK, OK, OK.

Reboot.

We really neeed a FAQ for this group! :-(


Alan G.

Iam using WinXP

I am reading Baldwins tutorial and in section Writing and using Scripts =
that's what he says:
You will need to cause the directory containing the file named =
python.exe to be listed in your system environment variable named path.=20

Do you know how to set the path?=20

If you already know how to set the path, go ahead and do it.  If you =
don't already know how, you may need to get some help.=20

I'm not going to try to tell you how to do it, because the procedure =
varies from one operating system to the next, and if you don't do it =
correctly, you may cause problems that are difficult to recover from.

Then open a command prompt window and make the directory containing your =
new script file become the current directory.

 If you don't know how to cause a particular directory to become your =
current directory, you will need to get someone who knows how to =
navigate the directory structure to show you.  It isn't rocket science, =
but it will be different for different operating systems, so you will =
need to know how to do it on your operating system.=20

Please help me

I need a very good and detailed explanation.

I am very new to this.=20

Thank you

Steve

------=_NextPart_000_0030_01C2ADD2.F46CE5B0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1126" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>&gt;&gt; How do I cause the directory containing the file named =
python.exe=20
to be<BR>&gt;&gt; listed in my system environment variable named=20
path.<BR>&gt;<BR>&gt;Before I say anything about this: are you sure you =
need to=20
touch PATH? You<BR>&gt;should not need to touch your environmental PATH =
unless=20
you're doing<BR>&gt;something slightly unusual.&nbsp; Can you tell us =
more why=20
you want to do this?<BR><BR>Nope, its perfectly normal because the =
Windows=20
installer doesn't <BR>set the PATH varioable - Mr Peters explained why =
many=20
moons ago...<BR>Itvdoes set the registry gubbins so that typing python =
at the=20
<BR>Start-&gt;Run dialog works, and it sets the association so that =
<BR>clicking=20
a .py file staryts python. But if you just start a <BR>DOS box and type =
Python=20
it won't work....<BR><BR>So as a result you have to set it by =
hand.<BR><BR>&gt;=20
documentation will ignore the issue.&nbsp; On Windows 95/98, the =
file<BR>&gt;=20
AUTOEXEC.BAT defines this environmental variable<BR><BR>And you shopuld =
only=20
need to add the following line at the end=20
of<BR>C:\AUTOEXEC.BAT<BR><BR>PATH=3D%PATH;&lt;your python =
path&gt;<BR><BR>where=20
&lt;your python path&gt; is your actual python path (in my case=20
its<BR>D:\Python22)<BR><BR>and it will require a reboot to get things to =
take=20
effect.&nbsp; <BR><BR><BR>&gt; On Windows 2k, it's somewhere deep in the =
Control=20
Panel/System applet<BR>Or right click "My Computer" and select =
Properties.<BR>Go=20
to the "Advanced" tab and click the "Environment Variables" =
button<BR>Click New=20
on the top panel and add a line<BR><BR>Variable Name PATH<BR>Variable =
Value=20
&lt;your python path&gt;<BR><BR>Click OK, OK, =
OK.<BR><BR>Reboot.<BR><BR>We=20
really neeed a FAQ for this group! :-(<BR><BR><BR>Alan G.</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Iam using WinXP</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I am reading Baldwins tutorial and in =
section=20
Writing and using Scripts that's what he says:</FONT></DIV>
<DIV>
<P>You will need to cause the directory containing the file named=20
<B>python.exe</B> to be listed in your system environment variable named =

<B>path</B>.=20
<P><B><FONT color=3D#ff0000>Do you know how to set the path?</FONT></B>=20
<P>If you already know how to set the path, go ahead and do it.&nbsp; If =
you=20
don't already know how, you may need to get some help.=20
<P>I'm not going to try to tell you how to do it, because the procedure =
varies=20
from one operating system to the next, and if you don't do it correctly, =
you may=20
cause problems that are difficult to recover from.</P>
<P>Then open a <I>command prompt</I> window and make the directory =
containing=20
your new script file become the current directory.</P>
<P>&nbsp;If you don't know how to cause a particular directory to become =
your=20
<I>current directory</I>, you will need to get someone who knows how to =
navigate=20
the directory structure to show you.&nbsp; It isn't rocket science, but =
it will=20
be different for different operating systems, so you will need to know =
how to do=20
it on your operating system. </P>
<P>Please help me</P>
<P>I need a very good and detailed explanation.</P>
<P>I am very new to this. </P>
<P>Thank you</P>
<P>Steve</P></DIV></BODY></HTML>

------=_NextPart_000_0030_01C2ADD2.F46CE5B0--




From shalehperry@attbi.com  Fri Dec 27 20:54:47 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Fri Dec 27 20:54:47 2002
Subject: [Tutor] python and blender?
In-Reply-To: <20021227215526.720634a1.thomi@thomi.imail.net.nz>
References: <20021227215526.720634a1.thomi@thomi.imail.net.nz>
Message-ID: <200212271753.06490.shalehperry@attbi.com>

On Friday 27 December 2002 00:55, Thomi Richards wrote:
> Has anyone here tried to do any python scripting for blender? I gave it
> a go the other day, but it seems very complicated at first glance. i
> just wanted to know how other people have been getting along, or if i a=
m
> actually the only person who has attempted such a thing :-)

I have wanted to in the past but the documentation was never there.  Perh=
aps=20
now I will look at it again.  Thanks for the nudge.


From apb_444@yahoo.com  Sat Dec 28 09:40:51 2002
From: apb_444@yahoo.com (Antony Benjamin)
Date: Sat Dec 28 09:40:51 2002
Subject: [Tutor] Shared Memory
Message-ID: <20021228141826.40083.qmail@web41205.mail.yahoo.com>

Dear Sir,
  Can I use shared memory and semaphores (
shmget,semget etc)in a python program.Currently I am
using Linux Platform.I also like to know whether it is
possible to call a python program/module in a C
program in Unix platform.What are the different forms
of IPC used in Python

I also like to know how to access modem(RS232) via
python program and also how to set baud rates for
serial ports.Is this platform dependent?

Thanks in advance

With Love,
Antony Benjamin
 

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com


From antoneheyward@hotmail.com  Sat Dec 28 11:04:00 2002
From: antoneheyward@hotmail.com (antone heyward)
Date: Sat Dec 28 11:04:00 2002
Subject: [Tutor] tkinter hourglass
Message-ID: <F10RfcjcMzfoV1qdiix0000019b@hotmail.com>

is there a tkinter hourglass and how can i use it?







_________________________________________________________________
The new MSN 8: smart spam protection and 3 months FREE*. 
http://join.msn.com/?page=features/junkmail&xAPID=42&PS=47575&PI=7324&DI=7474&SU= 
http://www.hotmail.msn.com/cgi-bin/getmsg&HL=1216hotmailtaglines_smartspamprotection_3mf



From drewp@bigasterisk.com  Sat Dec 28 15:54:02 2002
From: drewp@bigasterisk.com (Drew Perttula)
Date: Sat Dec 28 15:54:02 2002
Subject: [Tutor] tkinter hourglass
In-Reply-To: Your message of "Sat, 28 Dec 2002 16:02:27 GMT."
 <F10RfcjcMzfoV1qdiix0000019b@hotmail.com>
Message-ID: <200212282052.gBSKqts20980@bang.houseoflove>

> From: "antone heyward" <antoneheyward@hotmail.com>

> is there a tkinter hourglass and how can i use it?

Here's a simple usage that you can try in your interactive interpreter:

from Tkinter import *
root=Tk()
root.config(cursor="watch")

Now slide the mouse over the Tk window. Other cursor shapes include
"pencil", "pirate", "gumby", "top_left_arrow". I'm getting this list
from my "Practical Programming in Tcl and Tk" book, and they're also
listed in /usr/X11/include/X11/cursorfont.h on my setup.

-Drew



From dyoo@hkn.eecs.berkeley.edu  Sat Dec 28 17:03:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat Dec 28 17:03:02 2002
Subject: [Tutor] Show commands
In-Reply-To: <1967532406.20021227173329@roadrunner.nf.net>
Message-ID: <Pine.LNX.4.44.0212281331060.12117-100000@hkn.eecs.berkeley.edu>


On Fri, 27 Dec 2002, Adam Vardy wrote:

> >> I am trying to follow an example. And it says
> >> deck.deal([hand],5)
>
> >> I'm actually not familiar with the example that you're using; I'm
> >> guessing that it has something to do with shuffled decks and card
> >> games, but other than that, not much else.
>
> >> Can you point out where you found this example?  Is it part of some
> >> tutorial?
>
> Yeah. Learning with Python by Allen Downey, chapter 16.
>
> http://www.ibiblio.org/obp/thinkCSpy/chap16.htm


Hi Adam,

Ok, I see it now; we're going to look at section 16.4 on "Printing a
Hand".


Let's take a look at each command that's executed.

###
>>> deck = Deck()
###

This sets 'deck' to a new instance of a "Deck".  Our 'deck', then, is an
object that has these function-like 'methods' attached to them.  And
here's a call to one of those methods:

###
>>> deck.shuffle()
###

A method bundles up a collection of statements so that they look like a
single command. In order to see what's really happening in shuffle(), we
have to go back to the definition of the shuffle method.  Let me copy and
paste it here:


###
  def shuffle(self):
    import random
    nCards = len(self.cards)
    for i in range(nCards):
      j = random.randrange(i, nCards)
      self.cards[i], self.cards[j] = self.cards[j], self.cards[i]
###


The definition of a Deck's 'shuffle()' method was mentioned way back in
Chapter 15:

    http://www.ibiblio.org/obp/thinkCSpy/chap15.htm

and the author is borrowing parts of the program in Chapter 15 and using
it in Chapter 16.  Is this what was confusing you before?  Does the
definition of the shuffle function above make sense?


Although shuffle() itself is doing a bunch of stuff, the author decided
that the actions, taken as a whole, was "shuffling" the list of cards.



> I was actually seeking not Python commands, just would like to see the
> commands from this card game demo thing that are run when I type a
> command like the above.
>
> How am I supposed to think about each of the terms in this command?

We can think of them as single commands.  But we should realize that
there's more going underneath the surface: almost every command in there
is made up of smaller components.  For example, we can look at:

###
>>> deck.deal([hand], 5)
###

and say that a 'deck' is dealing 5 cards into a 'hand'.  We can be
handwavy like that, but if we really want to know what that means, we
should go back to the definition of 'deal()'.



A lot of programs work in this way, bundling up a bunch of compound
actions as a single name.  When we say deck.deal(), we're actually doing
quite a few things:

###
###  See Section 16.3 of thinkCSpy
###
def deal(self, hands, nCards=999):
    nHands = len(hands)
    for i in range(nCards):
      if self.isEmpty(): break    # break if out of cards
      card = self.popCard()       # take the top card
      hand = hands[i % nHands]    # whose turn is next?
      hand.addCard(card)          # add the card to the hand
###

But we can dive in a bit further: This deal() method itself uses other
compound actions like isEmpty() and addCard(), and those aren't
"built-in", but were written by the author previously in the code.



Let's dive in slightly more.  If we remember what 'addCard' means, then it
can be easier to say something like:

###
hand.addCard(card)
###

rather than:

###
hand.cards.append(card)
###


Even though both of these statements are equivalent to the machine, the
intention of the human who wrote the code is more clear with the first
version than the second!  The first version is involved with adding cards
to a hand.  The second version is involved with list appending into the
cards attribute of a hand.



The downside of making our own function is that we have to make sure they
group a set of related statements, and we should give a good, descriptive
name so that the name itself will remind us what's going on.  But we can
always go back to the original definition of the function to see what's
really happening.


I should stop talking right now.  *grin*

Does this make sense at the moment?  What parts seem strange or uncertain?



From gp@pooryorick.com  Sat Dec 28 18:39:02 2002
From: gp@pooryorick.com (Poor Yorick)
Date: Sat Dec 28 18:39:02 2002
Subject: [Tutor] Re: getting input from keyboard
References: <Pine.LNX.4.44.0212241131340.14588-100000@hkn.eecs.berkeley.edu>
Message-ID: <3E0E3637.4060304@pooryorick.com>

Danny Yoo wrote:

>
>Hello!
>
>I've written a small Cookbook recipe to make using getch() somewhat
>simpler:
>
>    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892
>

 Danny, it looks like your recipe has a typo.  self.impl will always end 
up being _GetchUnix().

    def __init__(self):
        try:
            self.impl = _GetchWindows()
        except ImportError: pass
        self.impl = _GetchUnix()

    def __call__(self): return self.impl()


Poor Yorick
gp@pooryorick.com




From Adam Vardy <anvardy@roadrunner.nf.net>  Sat Dec 28 20:30:02 2002
From: Adam Vardy <anvardy@roadrunner.nf.net> (Adam Vardy)
Date: Sat Dec 28 20:30:02 2002
Subject: [Tutor] Show commands
In-Reply-To: <Pine.LNX.4.44.0212281331060.12117-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.44.0212281331060.12117-100000@hkn.eecs.berkeley.edu>
Message-ID: <12681068890.20021228215938@roadrunner.nf.net>

Saturday, December 28, 2002, 7:43:30 PM, you wrote:

>> On Fri, 27 Dec 2002, Adam Vardy wrote:


>> Although shuffle() itself is doing a bunch of stuff, the author decided
>> that the actions, taken as a whole, was "shuffling" the list of cards.

I think I'm Ok with shuffling.


>> A lot of programs work in this way, bundling up a bunch of compound
>> actions as a single name.  When we say deck.deal(), we're actually doing
>> quite a few things:

>> ###
>> ###  See Section 16.3 of thinkCSpy
>> ###
>> def deal(self, hands, nCards=999):
>>     nHands = len(hands)
>>     for i in range(nCards):
>>       if self.isEmpty(): break    # break if out of cards
>>       card = self.popCard()       # take the top card
>>       hand = hands[i % nHands]    # whose turn is next?

This line I'm not sure about.

I am not sure what is [hand] or what is happening to it.

And there are some lines output, some indented, some are not. I don't
know where these lines come from.
Hand frank contains 2 of spades...

>> Does this make sense at the moment?  What parts seem strange or uncertain?

Those are the main things.

-- 
Adam Vardy



From carroll@tjc.com  Sat Dec 28 23:05:02 2002
From: carroll@tjc.com (Terry Carroll)
Date: Sat Dec 28 23:05:02 2002
Subject: [Tutor] Building a data structure from input
Message-ID: <Pine.GSU.4.44.0212281840250.2229-100000@waltz.rahul.net>

How would you approach this?  I'm going to have an input file with many
lines in the following form:

key   attribute-name1   value1
key   attribute-name2   value2
 ...
key   attribute-namen   valuen

For any given key, there will be a line with an attribute name and its
value.   Not all keys will have all attributes, though.

What I want to create a list of objects; one object per key, containing
the key, each of attributes 2, 4, 6 and 7, if they're defined -- but only
if either attribute 4 or 6 (or both) are defined for that particular key.

I think my explanation is poor, so let me make it more real.  The input is
the Unihan.txt file from unicode.org at
<ftp://ftp.unicode.org/Public/UNIDATA/Unihan.txt>.  This is a 26-meg file,
so don't browse it casually.

The attributes I want to store are the key, and
kDefinition, kMandarin, kBigFive, kGB0, but only if either kBigFive or
kGB0 are defined.

Here's one entry from this file:

U+570B	kAlternateKangXi	0219.016
U+570B	kAlternateMorohashi	04798
U+570B	kBigFive	B0EA
U+570B	kCCCII	21376F
U+570B	kCNS1986	1-594F
U+570B	kCNS1992	1-594F
U+570B	kCangjie	WIRM
U+570B	kCantonese	GWOK3
U+570B	kDaeJaweon	0447.090
U+570B	kDefinition	nation, country, nation-state
U+570B	kEACC	21376F
U+570B	kFrequency	1
U+570B	kGB1	2590
U+570B	kHanYu	10720.090
U+570B	kIRGDaeJaweon	0447.090
U+570B	kIRGDaiKanwaZiten	04798
U+570B	kIRGHanyuDaZidian	10720.090
U+570B	kIRGKangXi	0219.160
U+570B	kIRG_GSource	1-397A
U+570B	kIRG_JSource	0-5422
U+570B	kIRG_KPSource	KP0-D1B8
U+570B	kIRG_KSource	0-4F50
U+570B	kIRG_TSource	1-594F
U+570B	kIRG_VSource	1-5046
U+570B	kJapaneseKun	KUNI
U+570B	kJapaneseOn	KOKU
U+570B	kJis0	5202
U+570B	kKPS0	D1B8
U+570B	kKSC0	4748
U+570B	kKangXi	0219.160
U+570B	kKarlgren	118
U+570B	kKorean	KWUK
U+570B	kMandarin	GUO2
U+570B	kMatthews	3738
U+570B	kMorohashi	04798
U+570B	kNelson	1042
U+570B	kPhonetic	748
U+570B	kRSKangXi	31.8
U+570B	kRSUnicode	31.8
U+570B	kSBGY	530.39
U+570B	kSimplifiedVariant	U+56FD
U+570B	kTaiwanTelegraph	0948
U+570B	kTotalStrokes	11
U+570B	kXerox	241:056
U+570B	kZVariant	U+5700

I'm going to ignore nearly all of these lines, but want to have an object
that looks like this:

  unicode = "570B"
  definition = "nation, country, nation-state"
  # from kDefinition
  mandarin = "GUO2
  # from kMandarin
  Big5 = "B0EA"
  # from kBig5
  GB = <undefined>
  # from kGB0, not present

How would you approach this?  I can count on the unicode keys all being
together, and sorted, so that when I see a change in key, I know I have
the last attribute for the entry.  But then, I've already started reading
the first line for the next entry, so there's a minor complication of
having to worry about whether that need to be processed.  (Times like
this, I think a programming language needs an "unread" statement or method
-- something that, when a program eads a line, it could say, oh, now that
I see what's in that line, put it back, and let me read that next time
through the loop -- sort of like cheating at cards.)

I've thought about just creating an object for each line I see, and adding
attributes to the extent that I want to capture them, and then going back
through the list after I'm done to weed out any that don't have either the
Big5 or GB defined, with the "del" statement.  But I hate to make two
passes like this given the size of the data, and that just seems messy.

Ideas?

-- 
Terry Carroll        |
Santa Clara, CA      |   "The parties are advised to chill."
carroll@tjc.com      |       - Mattel, Inc. v. MCA Records, Inc.,
Modell delendus est  |         no. 98-56577 (9th Cir. July 24, 2002)




From LordxNikon@aol.com  Sat Dec 28 23:37:02 2002
From: LordxNikon@aol.com (LordxNikon@aol.com)
Date: Sat Dec 28 23:37:02 2002
Subject: [Tutor] You guys should make a chat....
Message-ID: <cf.20b49b8c.2b3fd599@aol.com>

--part1_cf.20b49b8c.2b3fd599_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

I suggest you guys make a chat 
for people to meet and share their 
tips and tricks anout python.
It would make sharing information
a lot easier. It would aslo help a lot 
of people get some more info 
to help them get started.

--part1_cf.20b49b8c.2b3fd599_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

<HTML><FONT FACE=arial,helvetica><FONT  SIZE=2 FAMILY="SANSSERIF" FACE="Arial" LANG="0">I suggest you guys make a chat <BR>
for people to meet and share their <BR>
tips and tricks anout python.<BR>
It would make sharing information<BR>
a lot easier. It would aslo help a lot <BR>
of people get some more info <BR>
to help them get started.</FONT></HTML>

--part1_cf.20b49b8c.2b3fd599_boundary--


From dyoo@hkn.eecs.berkeley.edu  Sun Dec 29 02:26:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun Dec 29 02:26:02 2002
Subject: [Tutor] You guys should make a chat....
In-Reply-To: <cf.20b49b8c.2b3fd599@aol.com>
Message-ID: <Pine.LNX.4.44.0212290027230.20453-100000@hkn.eecs.berkeley.edu>


On Sat, 28 Dec 2002 LordxNikon@aol.com wrote:

> I suggest you guys make a chat for people to meet and share their tips
> and tricks anout python. It would make sharing information a lot easier.
> It would aslo help a lot of people get some more info to help them get
> started.


Hello!


There actually is an Internet Relay Chat room set up for Python
programmers, hosted by the people who do the Twisted network libraries:

    http://twistedmatrix.com/users/jh.twistd/python/moin.cgi/

There's no formal relationship between Tutor and the #python IRC channel,
but I'm sure that the #python folks wouldn't mind questions. My own
experiences with #python have been positive; you may want to try them out.


I like the mailing list format on Tutor because it gives me the chance to
clarify my thoughts; I'm not a fast thinker, and I consistently edit my
sentences to sound less stupid, so a mailing list format is a strong
advantage for me.  *grin*

Please feel free to ask any Python questions here though; we'll be happy
to listen.  Good luck!



From dyoo@hkn.eecs.berkeley.edu  Sun Dec 29 02:32:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun Dec 29 02:32:02 2002
Subject: [Tutor] Re: getting input from keyboard
In-Reply-To: <3E0E3637.4060304@pooryorick.com>
Message-ID: <Pine.LNX.4.44.0212282327140.20453-100000@hkn.eecs.berkeley.edu>


On Sat, 28 Dec 2002, Poor Yorick wrote:

> Danny Yoo wrote:
>
> >
> >Hello!
> >
> >I've written a small Cookbook recipe to make using getch() somewhat
> >simpler:
> >
> >    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892
> >
>
>  Danny, it looks like your recipe has a typo.  self.impl will always end
> up being _GetchUnix().
>
>     def __init__(self):
>         try:
>             self.impl = _GetchWindows()
>         except ImportError: pass
>         self.impl = _GetchUnix()

Hi Poor Yorick,


Yikes!  You're right; the code is totally doing the wrong thing.  Thanks
for catching me on that one.


This should be one way to correct it:

###
     def __init__(self):
         try:
             self.impl = _GetchWindows()
         except ImportError: pass
         else:
             self.impl = _GetchUnix()
###


If that looks good with you, let's put a comment on that recipe with the
correction.


Thanks again!



From dyoo@hkn.eecs.berkeley.edu  Sun Dec 29 02:52:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun Dec 29 02:52:02 2002
Subject: [Tutor] Show commands
In-Reply-To: <12681068890.20021228215938@roadrunner.nf.net>
Message-ID: <Pine.LNX.4.44.0212282326300.20453-100000@hkn.eecs.berkeley.edu>


On Sat, 28 Dec 2002, Adam Vardy wrote:

> >> A lot of programs work in this way, bundling up a bunch of compound
> >> actions as a single name.  When we say deck.deal(), we're actually
> >> doing quite a few things:
>
> >> ###
> >> ###  See Section 16.3 of thinkCSpy
> >> ###
> >> def deal(self, hands, nCards=999):
> >>     nHands = len(hands)
> >>     for i in range(nCards):
> >>       if self.isEmpty(): break    # break if out of cards
> >>       card = self.popCard()       # take the top card
> >>       hand = hands[i % nHands]    # whose turn is next?
>
> This line I'm not sure about.
>
> I am not sure what is [hand] or what is happening to it.


Ah!  Ok, let's concentrate on that one line from before:

    deck.deal([hand], 5)

There's actually a few things happening on this line.  This might make
more sense if we break it down into three distinct chunks:

    all_hands = [hand]
    number_of_cards = 5
    deck.deal(all_hands, number_of_cards)

This sequence of three statements should have a similar effect.



The deck.deal() function takes in a list of hands, and also takes in how
many cards each hand should be dealt.  Imagine a group of people around a
poker table --- each person has a "hand".

    petes_hand = Hand()
    wendys_hand = Hand()
    geralds_hand = Hand()
    belindas_hand = Hand()

and to deal 7 cards from a deck, the dealing function needs to know which
hands to start passing cards into.  That's why the deck.deal() hand takes
in a list of hands:

    deck.deal([petes_hand,
               wendys_hand,
               geralds_hand,
               belindas_hand],
              7)

The thing that might look weird is that we're just building this list of
hands, right on the spot, simply so that deck.deal() knows about all of
the hands it needs to touch.  Even if it seems wasteful to build a list
just to collect hands together, it is still convenient: our deck.deal()
function can handle any number of people.  Even one person, which is how
we can read:

    deck.deal([hand], 5)

as

    "The deck deals 5 cards to the following hands: [hand,]"

A list that has one element is still a list.  It's a silly thing to say,
but it's actually not as obvious as it sounds: a lot of people often treat
a list of one-element as a "special case".  It's a hard habit to break.


We could technically hardcode things so that deck.deal() deals strictly
between two people, but that excludes group-oriented games like Blackjack
or Go-fish.  deck.deal() tries to capture that feeling of flipping the
cards toward each hand.  The deal()ing doesn't just dole the cards out:
it actively fans them out to each person --- er, hand.


By the way, in the above example, it turns out that since we're only
passing seven cards to a group of four hands, someone's going to have
fewer cards.  Try it out and see what happens.  Can you see whose hand is
left with fewer cards?


Anyway, hope that clears things up a little more.  *grin*  Good luck to
you.



From dyoo@hkn.eecs.berkeley.edu  Sun Dec 29 02:59:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun Dec 29 02:59:01 2002
Subject: [Tutor] Show commands  [correction]
In-Reply-To: <Pine.LNX.4.44.0212282326300.20453-100000@hkn.eecs.berkeley.edu>
Message-ID: <Pine.LNX.4.44.0212282355010.20453-100000@hkn.eecs.berkeley.edu>


> The deck.deal() function takes in a list of hands, and also takes in how
> many cards each hand should be dealt.

That was silly of me.  That's totally wrong.  Sorry, I was careless when I
typed that above.

I meant to say: deck.deal() takes in a list of hands, and also takes in a
number of cards that it should deal to those hands.  If we deal 20 cards
to 5 hands, each hand's going to have 4 cards by the end of the deal.


Sorry about the confusion!



From dyoo@hkn.eecs.berkeley.edu  Sun Dec 29 03:04:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun Dec 29 03:04:02 2002
Subject: [Tutor] Re: getting input from keyboard
In-Reply-To: <Pine.LNX.4.44.0212282327140.20453-100000@hkn.eecs.berkeley.edu>
Message-ID: <Pine.LNX.4.44.0212290001370.20453-100000@hkn.eecs.berkeley.edu>


On Sat, 28 Dec 2002, Danny Yoo wrote:

> >     def __init__(self):
> >         try:
> >             self.impl = _GetchWindows()
> >         except ImportError: pass
> >         self.impl = _GetchUnix()
.
>
> This should be one way to correct it:
>
> ###
>      def __init__(self):
>          try:
>              self.impl = _GetchWindows()
>          except ImportError: pass
>          else:
>              self.impl = _GetchUnix()
> ###


Oh good grief, not again.  I'm having a bad day, aren't I.  *grin*


Let me try that one more time.

###
      def __init__(self):
          try:
              self.impl = _GetchWindows()
          except ImportError:
              self.impl = _GetchUnix()
###



From Volker Hoffmann <volker@omega-fleet.dyndns.org>  Sun Dec 29 05:52:01 2002
From: Volker Hoffmann <volker@omega-fleet.dyndns.org> (Volker Hoffmann)
Date: Sun Dec 29 05:52:01 2002
Subject: [Tutor] Declare empty string variable?
Message-ID: <174475595.20021229115134@omega-fleet.dyndns.org>

Hi,

at first I just want to say hi. I've been reading on digests for a
couple of months (rather irregularily though) as I didn't have much
time for getting into python. Now I have some spare time and I'm gonna
be starting of with a possible stupid question :-).

I want to write a program that converts decimal numbers into binary
format. That should be a fairly easy task, but not with my limited
knowledge of python. Here's how my code looks so far:

> ### Decimal to Binary Conversion
> deci=input("Decimal? --> ")
> dual= <--- declaration
> ...
> while deci>0:
>     dual_tmp=deci%2
>     dual=dual_tmp, dual <--- change dual here
>     deci=deci/2
> print "Binary is", dual

Now I want the variable "dual" to be the output where the binary is
being stored. However, since I assume that all variables have to be
initialized in python I don't have any clue HOW to make dual a string
variable that's being updated every time in the while-loop.

Now, how do I have to declare "dual" to be a string and without any
value at the beginning? Is there any way like in pascal where it's
beging declared like this:

> var
>  dual:string;

Thanks in advance,
- Volker

-- 
"Earth is the cradle of mankind,
  but one cannot live in the cradle forever."
   - Konstantin Tsiolkovsky



From op73418@mail.telepac.pt  Sun Dec 29 07:33:02 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Sun Dec 29 07:33:02 2002
Subject: [Tutor] Declare empty string variable?
References: <174475595.20021229115134@omega-fleet.dyndns.org>
Message-ID: <002101c2af37$4218d160$a6150dd5@violante>

----- Original Message -----
From: "Volker Hoffmann" <volker@omega-fleet.dyndns.org>
To: "Python Tutor ML" <tutor@python.org>
Sent: Sunday, December 29, 2002 10:51 AM
Subject: [Tutor] Declare empty string variable?


> Hi,
>
> at first I just want to say hi. I've been reading on digests for a
> couple of months (rather irregularily though) as I didn't have much
> time for getting into python. Now I have some spare time and I'm gonna
> be starting of with a possible stupid question :-).
>
> I want to write a program that converts decimal numbers into binary
> format. That should be a fairly easy task, but not with my limited
> knowledge of python. Here's how my code looks so far:
>
> > ### Decimal to Binary Conversion
> > deci=input("Decimal? --> ")
> > dual= <--- declaration
> > ...
> > while deci>0:
> >     dual_tmp=deci%2
> >     dual=dual_tmp, dual <--- change dual here

Are you sure this is correct? From your description "dual" is supposed to be
a string, but on the right hand-side you have a tuple. So you should get an
error here.

> >     deci=deci/2
> > print "Binary is", dual
>
> Now I want the variable "dual" to be the output where the binary is
> being stored. However, since I assume that all variables have to be
> initialized in python I don't have any clue HOW to make dual a string
> variable that's being updated every time in the while-loop.
>
> Now, how do I have to declare "dual" to be a string and without any
> value at the beginning? Is there any way like in pascal where it's
> beging declared like this:
>
> > var
> >  dual:string;

The best thing is to switch into the Pythonic frame of mind. In Python a
variable is just a name (a tag, a label, what-you-will) that is bound (that
references) some Python object. Whenever Python sees something like

>>>myvariable = "a test"

It creates the name "myvariable" in the current namespace if it is not
already there and binds it to the Python object, a string in this case, "a
test". Next time you use myvariable in some expression Python just sticks in
"a test" automatically.

As you see from my description variables are created on the fly, so to
speak, no declarations are needed. So, to answer your question in a more
direct manner you just do

>>>dual = ""

and voilá, you now have a dual variable initialized to the empty string.

Just one last tidbit: variables are typeless, that is, they have no
associated types. As I said before they are just names. So you could also do

>>>dual = None

which looks more explicit, and then later do

>>>dual = "a test"

>
> Thanks in advance,
> - Volker

With my best regards,
G. Rodrigues

>
> --
> "Earth is the cradle of mankind,
>   but one cannot live in the cradle forever."
>    - Konstantin Tsiolkovsky




From op73418@mail.telepac.pt  Sun Dec 29 07:40:01 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Sun Dec 29 07:40:01 2002
Subject: [Tutor] You guys should make a chat....
References: <Pine.LNX.4.44.0212290027230.20453-100000@hkn.eecs.berkeley.edu>
Message-ID: <003101c2af38$48438890$a6150dd5@violante>

----- Original Message -----
From: "Danny Yoo" <dyoo@hkn.eecs.berkeley.edu>
To: <LordxNikon@aol.com>
Cc: <tutor@python.org>
Sent: Sunday, December 29, 2002 7:25 AM
Subject: Re: [Tutor] You guys should make a chat....


>
>
> On Sat, 28 Dec 2002 LordxNikon@aol.com wrote:
>
> > I suggest you guys make a chat for people to meet and share their tips
> > and tricks anout python. It would make sharing information a lot easier.
> > It would aslo help a lot of people get some more info to help them get
> > started.
>
>
> Hello!
>
>
> There actually is an Internet Relay Chat room set up for Python
> programmers, hosted by the people who do the Twisted network libraries:
>
>     http://twistedmatrix.com/users/jh.twistd/python/moin.cgi/
>
> There's no formal relationship between Tutor and the #python IRC channel,
> but I'm sure that the #python folks wouldn't mind questions. My own
> experiences with #python have been positive; you may want to try them out.
>
>
> I like the mailing list format on Tutor because it gives me the chance to
> clarify my thoughts; I'm not a fast thinker, and I consistently edit my
> sentences to sound less stupid, so a mailing list format is a strong
> advantage for me.  *grin*
>
> Please feel free to ask any Python questions here though; we'll be happy
> to listen.  Good luck!

I agree with Danny Yoo on this one. V. Nabokov states in the beginning of
his strong opinions that

"I think like a genius; I write like a distinguished author and I speak like
a child."

I share with V. Nabokov the last sentence. I can guarantee you that the same
happens in real-time IRC. In the mail format I can filter my own, sometimes
very muddled, thoughts, and I can at least try to polish a bit some of my
foreign english.

All the best,
G. Rodrigues



From dmandini@inet.hr  Sun Dec 29 09:02:03 2002
From: dmandini@inet.hr (djuro)
Date: Sun Dec 29 09:02:03 2002
Subject: [Tutor] beginner question
Message-ID: <001201c2af8e$28356540$5942cad5@hal>

Hello!

One easy question please.

How to fix this piece of code to print list elements horizontal on screen?

###
list = [1,2,3,4,5]

for i in list:
    print i

###

Regards

Djuro



From glingl@aon.at  Sun Dec 29 09:14:03 2002
From: glingl@aon.at (Gregor Lingl)
Date: Sun Dec 29 09:14:03 2002
Subject: [Tutor] Building a data structure from input
Message-ID: <3E0F0318.6080908@aon.at>


Hi Terry!

I've explored your problem a little bit with the interactive
Python interpreter. Maybe the results will give you some
clue on how to approach your task.

There is a special data structure in Python, which seems
appropriate to represent the your data as desired, the
dictionary - maybe better than in list. (Access to items
of a dictionary may be significantly faster than to elements
of a list, especially when the list is long.)

If you don't know how to use dictionaries, read section 5.4
in the Python tutorial http://www.python.org/doc/current/tut/tut.html

Here my (somewhat cleaned up) interactive session - with interspersed
remarks:

>>> import os
>>> os.chdir(r"I:\____danach\python\dictexample")
>>> f = open("testfile.txt")
>>> l = f.readlines()  # l is a list of lines in your file,
                       # you may read it line by line if the file is
                       # very big
>>> l[0]
'U+570B\tkAlternateKangXi\t0219.016\n'
>>> line = l[0].split()
>>> line
['U+570B', 'kAlternateKangXi', '0219.016']
>>> line[0][2:]
'570B'
>>> line[1][1:]
'AlternateKangXi'

# Now I want to associate with every code (e.g. "570B") a
# (nested) dictionary aof key-value pairs according to
# your problem statement:

>>> code = line[0][2:]
>>> code
'570B'
>>> key = line[1][1:]
>>> key
'AlternateKangXi'
>>> data = {} # empty dictionary

>>> data[code] = {}
>>> data[code][key] = line[2]

>>> data
{'570B': {'AlternateKangXi': '0219.016'}}

# now I observe, that there are "line"s with more
# than three elements. I get a string of the elements
# beginning with the third one by joining them again
# with blanks in between - using the join method of strings:
# example:

>>> " ".join(["a","be","bu"])
'a be bu'
>>> " ".join(["bu"])
'bu'                   # fortunately
 

# With this I define a function processline, which also takes
# care of the fact, that possibly there is still no entry in data
# for a given "code", so it has to create an empty dictionary first:

>>> data = {}
>>> def processline(line):
    code = line[0][2:]
    key = line[1][1:]
    entry = " ".join(line[2:])
    if code not in data.keys():
        data[code] = {}
    if key in valid:
            data[code][key] = entry

           
>>> for line in l:
    processline(line.split())

   
>>> data
{'570B': {'Mandarin': 'GUO2', 'Definition': 'nation, country, 
nation-state', 'BigFive': 'B0EA'}}

# I think this is a possible representation of what you wanted,
# as far as I understood it. Keys that don't have attributes,
# automatically will not be present in the dictionary.
# Now you can access the data via the "code" and the "keys" as
# follows:

>>> data["570B"]
{'Mandarin': 'GUO2', 'Definition': 'nation, country, nation-state', 
'BigFive': 'B0EA'}
 >>> data["570B"]["Definition"]
'nation, country, nation-state'
 >>> data["570B"]["Mandarin"]
'GUO2'
 >>>

This way I would approach this ....
Hope, this helps

Gregor

Terry Carroll schrieb:

>How would you approach this?  I'm going to have an input file with many
>lines in the following form:
>
>key   attribute-name1   value1
>key   attribute-name2   value2
> ...
>key   attribute-namen   valuen
>
>For any given key, there will be a line with an attribute name and its
>value.   Not all keys will have all attributes, though.
>...
>






From glingl@aon.at  Sun Dec 29 09:27:01 2002
From: glingl@aon.at (Gregor Lingl)
Date: Sun Dec 29 09:27:01 2002
Subject: [Tutor] beginner question
References: <001201c2af8e$28356540$5942cad5@hal>
Message-ID: <3E0F0647.1030401@aon.at>

djuro schrieb:

>Hello!
>
>One easy question please.
>
>How to fix this piece of code to print list elements horizontal on screen?
>
>###
>list = [1,2,3,4,5]
>
>for i in list:
>    print i
>
>###
>
Add a comma as follows:

   for i in list:
       print i,

Gregor

>
>Regards
>
>Djuro
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>  
>






From d.j.kniep@chello.nl  Sun Dec 29 18:32:22 2002
From: d.j.kniep@chello.nl (Dick Kniep)
Date: Sun Dec 29 18:32:22 2002
Subject: [Tutor] Subclasses?
Message-ID: <1041208323.13038.2.camel@kniep04.kniep>

Hi there,

Perhaps a silly question,  but I can't seem to find an answer in the
manuals.

If you look at the code of SQLDict (which is a superb piece of work by
the way), I noticed there were class definitions defined WITHIN another
class. I just don't understand what is achieved by that.

thanks in advance

-- 
Dick Kniep <d.j.kniep@chello.nl>
Lindix



From dyoo@hkn.eecs.berkeley.edu  Sun Dec 29 18:50:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun Dec 29 18:50:02 2002
Subject: [Tutor] Shared Memory  [IPC / pyserial]
In-Reply-To: <20021228141826.40083.qmail@web41205.mail.yahoo.com>
Message-ID: <Pine.LNX.4.44.0212291540590.1446-100000@hkn.eecs.berkeley.edu>


On Sat, 28 Dec 2002, Antony Benjamin wrote:

>   Can I use shared memory and semaphores (shmget,semget etc)in a python
> program.Currently I am using Linux Platform.I also like to know whether
> it is possible to call a python program/module in a C program in Unix
> platform.

Hi Antony,

Sorry for the late reply!  I was hoping someone else would touch this,
since I have no experience with IPC issues.  Still, I'm up for googling
some of this up... *grin*


Someone has written a module to get access to shared memory and
semaphores:

    http://gigue.peabody.jhu.edu/~mdboom/omi/source/shm_source/shm.html


> What are the different forms of IPC used in Python

The C2 Wiki page does have a section on Python IPC:

    http://c2.com/cgi/wiki?PythonIpc


There was also a thread on the main Python-list (comp.lang.python) that
might be useful for you:

    http://mail.python.org/pipermail/python-list/2002-September/120900.html




> I also like to know how to access modem(RS232) via python program and
> also how to set baud rates for serial ports.Is this platform dependent?

Here you go:

    http://pyserial.sourceforge.net/

'pyserial' is a module that tries to provide a nice, platform independent
way to access serial ports in Python.


Good luck to you!



From gp@pooryorick.com  Sun Dec 29 22:04:04 2002
From: gp@pooryorick.com (Poor Yorick)
Date: Sun Dec 29 22:04:04 2002
Subject: [Tutor] wxPython wxSplitterWindow Idiosyncrasies
Message-ID: <3E0FB79F.9090103@pooryorick.com>

In case anyone runs into the same problem, after hours of 
troubleshooting, I think the following two things must happen for 
wxSplitterWindow to work properly in a wxFrame:

1.  The splitter window must be created before the main menu is created. 
 It can be split at any point.

2.  A main menu must exist

When either of these things was not true, my splitter windows appeared, 
but failed to display any innards.  The OS was Windows 2000 Professional.

Poor Yorick
gp@pooryorick.com



From janos.juhasz@VELUX.com  Mon Dec 30 04:08:02 2002
From: janos.juhasz@VELUX.com (janos.juhasz@VELUX.com)
Date: Mon Dec 30 04:08:02 2002
Subject: [Tutor] pyLPD
Message-ID: <OF55CAB9F0.15F822AF-ONC1256C9F.00306C29@LocalDomain>

Dear Gurus,

i want to capture the stream that an unchangable program send to the
printer, reshape it and print it with nicer charset and size.
I wanted to working with LPT1: on windows, but it seems to bee impossib=
le.
Simply I can't capture the stream sent to it.

My new idea  is to set this unchangable program to print to an LPR port=
,
capture the stream sent with an LPD socket-server.
The LPD server can be written in python and would be responsible to res=
hape
the stream and print it via the normal windows way.

With "net use" i even can redirect the LPT1: to that LPR port, and so t=
he
LPT1: can be filtered accross this program to LPT2: for example.

Have got someone any idea, how to set up a so kind of LPD in python?

Best regards,
-----------------------
Juh=E1sz J=E1nos
IT department
E-Mail: janos.juhasz@VELUX.com
=




From op73418@mail.telepac.pt  Mon Dec 30 07:42:16 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Mon Dec 30 07:42:16 2002
Subject: [Tutor] Subclasses?
References: <1041208323.13038.2.camel@kniep04.kniep>
Message-ID: <001301c2b001$c38822d0$af130dd5@violante>

----- Original Message -----
From: "Dick Kniep" <d.j.kniep@chello.nl>
To: <tutor@python.org>
Sent: Monday, December 30, 2002 12:32 AM
Subject: [Tutor] Subclasses?


> Hi there,
>
> Perhaps a silly question,  but I can't seem to find an answer in the
> manuals.
>
> If you look at the code of SQLDict (which is a superb piece of work by
> the way), I noticed there were class definitions defined WITHIN another
> class. I just don't understand what is achieved by that.

I don't know the code in question, but answering in broad terms: Not much,
really, since it doesn't buy you anything special. It is mainly a way to
organize the code and bundle up classes that the author thought should be
bundled together. Python is not Java, where classes within classes *really*
are important. I remember reading recently a thread at python-dev where
Guido van Rossum asked for a real use-case for inner classes. After a while
W. Dorwald seemed to have found one since it got a "really cool!" from the
BDFL.

>
> thanks in advance
>
> --
> Dick Kniep <d.j.kniep@chello.nl>
> Lindix

With my best regards,
G. Rodrigues



From ahimsa@onetel.net.uk  Mon Dec 30 12:12:15 2002
From: ahimsa@onetel.net.uk (ahimsa)
Date: Mon Dec 30 12:12:15 2002
Subject: [Tutor] newbie request for help in setting up emacs for python
Message-ID: <1041268350.1100.344.camel@localhost.localdomain>

Hello

I'm totally unfamiliar with that complex beast called emacs (or xemacs)
and need a guide for dummies on how to configure it so that I can use it
for a python ide. Can someone point me in the right direction or specify
some tips on how to do it. I've tried reading the documentation at both
the python as well as the GNU emacs/Xemacs sites and find it more
confusing than enlightening ... which is probably not a very good
prognosis :-)
Cheers
AmF

-- 
"There is nothing beyond the text" - Jacques Derrida



From ramrom@earthling.net  Mon Dec 30 12:54:01 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Mon Dec 30 12:54:01 2002
Subject: [Tutor] Declare empty string variable?
In-Reply-To: <002101c2af37$4218d160$a6150dd5@violante>
References: <174475595.20021229115134@omega-fleet.dyndns.org>
Message-ID: <5.2.0.9.0.20021230102656.02bf9320@66.28.54.253>

--=======22533F2A=======
Content-Type: text/plain; x-avg-checked=avg-ok-DE17EEF; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit

### Decimal to Binary Conversion
 > deci=input("Decimal? --> ")
 > dual= <--- declaration
 > ...
 > while deci>0:
 >     dual_tmp=deci%2
 >     dual=dual_tmp, dual <--- change dual here

Observations:
  this program does not reassign to deci; therefore it is an endless loop.
  while deci>0: can just be while deci:

Try this:
dual = ''
deci = input("Decimal? --> ")
while deci:
   deci,b = divmod(deci,2)
   dual=str(b)+dual
print dual

If you plan to use this a lot (where performance might be impacted) an 
alternative is:
# dictionary uses hex digits as keys values are corresponding binary strings
dict = {'0': '0000', '1': '0001', ... '9': '1001', 'A': '1010', ... 'F': 
'1111'} # fill in the ellipses!
hex = '%X' % deci # convert decimal to string of hex characters
dual = ''.join([dict[x] for x in hex]) # translate and combine

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625

--=======22533F2A=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-DE17EEF
Content-Disposition: inline


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.431 / Virus Database: 242 - Release Date: 12/17/2002

--=======22533F2A=======--



From sxa@fluent.com  Mon Dec 30 13:25:02 2002
From: sxa@fluent.com (Sebastien Auclair)
Date: Mon Dec 30 13:25:02 2002
Subject: [Tutor] Calling Static method ?
Message-ID: <007001c2b030$901550b0$8ae4e9c0@sxapc>

Hi !
We are extending python with a C++ class of our own.
That class holds a static function that we need to access from python.
Our problem is that we can't find a way to call that function without having
python trying to instantiate that class (Its a singleton, no constructors
are declared in the sip bindings).
We want to use that function like A::func()  instead of A.func();

C++ >>>
    class A {
    public :
        A& void func();
};
<<<

PYTHON>>>
    import given_module
    ...
    given_module.A.func()

<<<




Thanks !



From dyoo@hkn.eecs.berkeley.edu  Mon Dec 30 13:59:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon Dec 30 13:59:01 2002
Subject: [Tutor] newbie request for help in setting up emacs for python
In-Reply-To: <1041268350.1100.344.camel@localhost.localdomain>
Message-ID: <Pine.LNX.4.44.0212301040390.18974-100000@hkn.eecs.berkeley.edu>


On 30 Dec 2002, ahimsa wrote:

> I'm totally unfamiliar with that complex beast called emacs (or xemacs)
> and need a guide for dummies on how to configure it so that I can use it
> for a python ide. Can someone point me in the right direction or specify
> some tips on how to do it.

Hi Ahimsa,

There are some instructions on setting up python-mode here:

    http://www.python.org/emacs/python-mode/installation.html

The instructions there will set up Emacs so that, when we open up '.py'
files, Emacs will switch into python-mode automatically.


If you're trying to learn Emacs, you may find the embedded tutorial useful
--- try typing "C-h t"  (Control h, followed by a 't'), which should bring
it up.

Good luck to you!



From mongo57a@comcast.net  Mon Dec 30 14:04:03 2002
From: mongo57a@comcast.net (andy surany)
Date: Mon Dec 30 14:04:03 2002
Subject: [Tutor] Re: Installing the Blt Package
Message-ID: <007d01c2b036$95106f40$2502a8c0@emily.ewndsr01.nj.comcast.net>

Still struggling with this..... can anyone help??? I would appreciate
any direction.....

Thanks.

-----Original Message-----
From: andy surany <mongo57a@comcast.net>
To: tutor@python.org <tutor@python.org>
Date: Tuesday, December 24, 2002 2:58 PM
Subject: Installing the Blt Package


>Happy Holidays list members!
>
>After installing the latest Pmw, I installed Blt2.4z. I followed the
>instructions and I believe that everything was "made" successfully. If
I
>go into the Blt2.4z directory
>(usr/lib/python2.2/site-packages/Pmw/Blt2.4z/demos/) and execute the
Tcl
>demo (./graph1.Tcl), it works.
>
>However, when I try to execute BltGraph.py
>(/usr/lib/python2.2/Pmw_1_1/demos/), I get the message box "BLT Package
>has not been installed on this system".
>
>Anyone know what's wrong? Do I need to add something to my path? or
>modify a Python variable?
>
>TIA.
>
>Andy
>



From dyoo@hkn.eecs.berkeley.edu  Mon Dec 30 15:02:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon Dec 30 15:02:02 2002
Subject: [Tutor] Calling Static method ?  [C extension writing and static
 methods]
In-Reply-To: <007001c2b030$901550b0$8ae4e9c0@sxapc>
Message-ID: <Pine.LNX.4.44.0212301117120.18974-100000@hkn.eecs.berkeley.edu>


On Mon, 30 Dec 2002, Sebastien Auclair wrote:

> We are extending python with a C++ class of our own. That class holds a
> static function that we need to access from python. Our problem is that
> we can't find a way to call that function without having python trying
> to instantiate that class (Its a singleton, no constructors are declared
> in the sip bindings).

Hi Sebastien,

Only a few of us here have experience writing extension modules; we may
not be able to give a satisfactory answer for you.  You may want to ask
about this on the main comp.lang.python newsgroup.


> We want to use that function like A::func()  instead of A.func();
>
> C++ >>>
>     class A {
>     public :
>         A& void func();
> };


In order for this to work, the func() method here needs to be declared as
static in C++, according to:

    http://www.ictp.trieste.it/texi/gpp/gpp_37.html


I'm a little rusty in C++, but let's try it out.  Here's a small C++ class
that demonstrates how to write a static method for a class we'll call A.

//////
#include <iostream>

class A {
public:
  static void sayHello() {
    cout << "Hello world!\n";
  }
};


void main() {
  A::sayHello();
}
//////




Ok, so that works.  Now we want to somehow wrap this in Python.  We want:

>     import given_module
>     ...
>     given_module.A.func()

to work, even when A is a class.  How do we go about this in C?


According to comments in Sourceforge, there is a mechanism for defining
static class methods in Python 2.2:

http://sourceforge.net/tracker/?func=detail&atid=305470&aid=418390&group_id=5470

Let's look for stuff on this 'staticmethod' thing, and I think we'll have
it.  Ah...

    http://www.python.org/2.2/descrintro.html#staticmethods


So perhaps we can call the staticmethod() builtin on the particular method
that we want to make static.  We can call staticmethod() during the
module's initialization.

Unfortunately, I'm just speculating, because I can't finish this example
till I get back to my computer.  I'll try finishing this up when I get
back.


(By the way, according to the documentation, the developmental Python 2.3
introduces a simpler way of setting this up in extension modules:

    http://www.python.org/dev/doc/devel/api/common-structs.html#l2h-816
)



I hope this helps!



From carroll@tjc.com  Mon Dec 30 16:03:26 2002
From: carroll@tjc.com (Terry Carroll)
Date: Mon Dec 30 16:03:26 2002
Subject: [Tutor] newbie request for help in setting up emacs for python
In-Reply-To: <1041268350.1100.344.camel@localhost.localdomain>
Message-ID: <Pine.GSU.4.44.0212301244230.2229-100000@waltz.rahul.net>

On 30 Dec 2002, ahimsa wrote:

> I'm totally unfamiliar with that complex beast called emacs (or xemacs)
> and need a guide for dummies on how to configure it so that I can use it
> for a python ide.


Wow, a question I can answer, or at least help on!  I justs started using
both Python and Emacs.

First, if you don't already have it, download the mode from
<http://www.python.org/emacs/python-mode/>.

I had to mess with emacs for quite a bit until I got it working well
enough for me.  Here's my .emacs file now (comments in the file  start
with ";;;"; my commentary (NOT in the file) is interspersed in
[brackets]):

;;; swap C-s & C-q and C-\ and C-^
(enable-flow-control)
[Normally, the CTRL-x CTRL-s sequence is used to save a file.  This screws
up on a lot of systems, which use CTRL-s to stop display and CTRL-q to
restart it.  The above line swaps CTRL-s and CTRL-\, and CTRL-q and
CTRL-^.  So for me, the command to save is now CTRL-x CTRL-\.  This is not
Python-specific, but I thought I'd include it.]

(global-set-key "\C-h" 'delete-backward-char)
(global-set-key "\C-xh" 'help)
;;;

[another non-python thing.  By default, emacs uses CTRL-x CTRL-h to get
help.  Every other system in the world uses CTRL-h for a backspace.  I set
it up so that CTRL-h is a backspace in emacs, and help is obtained with
CTRL-xh]

;;; set python mode:
(setq auto-mode-alist
      (cons '("\\.py$" . python-mode) auto-mode-alist))

[This line means that if you edit a file ending in .py, it goes into
python-mode]

(setq interpreter-mode-alist
      (cons '("python" . python-mode)
            interpreter-mode-alist))

[I'm not sure what this line does, but I found it in an example, it works,
so I don't mess with it.]

(autoload 'python-mode "python-mode" "Python editing mode." t)

[This line, I think, makes the python mode available in the first place.]

;;; configure python mode
;;; add these lines if you like color-based syntax highlighting
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)
(require 'paren)
(show-paren-mode 1)
[The above lines are the ones that make the bells and whistle of
python-mode work.  It's useful to show parenthesis matching, which words
are keywords compared to variables, etc. -- that sort of thing.]

> Can someone point me in the right direction or specify
> some tips on how to do it. I've tried reading the documentation at both
> the python as well as the GNU emacs/Xemacs sites and find it more
> confusing than enlightening ... which is probably not a very good
> prognosis :-)

No, I'm right with you there.  emacs is a hell of a lot more easy to use
than to configure, at least for a beginner.  I got frustrated trying to
configure it based on what I found on web pages, FAQs and help files.  I
ended up going down to the library and borrowing the O'Reilley emacs text,
"Learning GNU Emacs."  I spend an hour or so with it and my .emacs file,
and got it configured in a way that worked for me.  I particularly
recommend chapter 11, "Customizing Emacs".

-- 
Terry Carroll        |
Santa Clara, CA      |   "The parties are advised to chill."
carroll@tjc.com      |       - Mattel, Inc. v. MCA Records, Inc.,
Modell delendus est  |         no. 98-56577 (9th Cir. July 24, 2002)



From ATrautman@perryjudds.com  Mon Dec 30 16:12:02 2002
From: ATrautman@perryjudds.com (Alan Trautman)
Date: Mon Dec 30 16:12:02 2002
Subject: [Tutor] newbie request for help in setting up emacs for pytho
 n
Message-ID: <0BA95581EDA7D611841B00A0C9AD25DD2B5930@mail.pjinet.com>

Terry,

Thank you, I've been avoiding doing the task of making a working Emacs
configuration. The documentation didn't make a lot of sense to me either.

Alan

-----Original Message-----
From: Terry Carroll [mailto:carroll@tjc.com]
Sent: Monday, December 30, 2002 3:00 PM
To: tutor@python.org
Subject: Re: [Tutor] newbie request for help in setting up emacs for
python


On 30 Dec 2002, ahimsa wrote:

> I'm totally unfamiliar with that complex beast called emacs (or xemacs)
> and need a guide for dummies on how to configure it so that I can use it
> for a python ide.


Wow, a question I can answer, or at least help on!  I justs started using
both Python and Emacs.

First, if you don't already have it, download the mode from
<http://www.python.org/emacs/python-mode/>.

I had to mess with emacs for quite a bit until I got it working well
enough for me.  Here's my .emacs file now (comments in the file  start
with ";;;"; my commentary (NOT in the file) is interspersed in
[brackets]):

;;; swap C-s & C-q and C-\ and C-^
(enable-flow-control)
[Normally, the CTRL-x CTRL-s sequence is used to save a file.  This screws
up on a lot of systems, which use CTRL-s to stop display and CTRL-q to
restart it.  The above line swaps CTRL-s and CTRL-\, and CTRL-q and
CTRL-^.  So for me, the command to save is now CTRL-x CTRL-\.  This is not
Python-specific, but I thought I'd include it.]

(global-set-key "\C-h" 'delete-backward-char)
(global-set-key "\C-xh" 'help)
;;;

[another non-python thing.  By default, emacs uses CTRL-x CTRL-h to get
help.  Every other system in the world uses CTRL-h for a backspace.  I set
it up so that CTRL-h is a backspace in emacs, and help is obtained with
CTRL-xh]

;;; set python mode:
(setq auto-mode-alist
      (cons '("\\.py$" . python-mode) auto-mode-alist))

[This line means that if you edit a file ending in .py, it goes into
python-mode]

(setq interpreter-mode-alist
      (cons '("python" . python-mode)
            interpreter-mode-alist))

[I'm not sure what this line does, but I found it in an example, it works,
so I don't mess with it.]

(autoload 'python-mode "python-mode" "Python editing mode." t)

[This line, I think, makes the python mode available in the first place.]

;;; configure python mode
;;; add these lines if you like color-based syntax highlighting
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)
(require 'paren)
(show-paren-mode 1)
[The above lines are the ones that make the bells and whistle of
python-mode work.  It's useful to show parenthesis matching, which words
are keywords compared to variables, etc. -- that sort of thing.]

> Can someone point me in the right direction or specify
> some tips on how to do it. I've tried reading the documentation at both
> the python as well as the GNU emacs/Xemacs sites and find it more
> confusing than enlightening ... which is probably not a very good
> prognosis :-)

No, I'm right with you there.  emacs is a hell of a lot more easy to use
than to configure, at least for a beginner.  I got frustrated trying to
configure it based on what I found on web pages, FAQs and help files.  I
ended up going down to the library and borrowing the O'Reilley emacs text,
"Learning GNU Emacs."  I spend an hour or so with it and my .emacs file,
and got it configured in a way that worked for me.  I particularly
recommend chapter 11, "Customizing Emacs".

-- 
Terry Carroll        |
Santa Clara, CA      |   "The parties are advised to chill."
carroll@tjc.com      |       - Mattel, Inc. v. MCA Records, Inc.,
Modell delendus est  |         no. 98-56577 (9th Cir. July 24, 2002)


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


From carroll@tjc.com  Tue Dec 31 00:25:02 2002
From: carroll@tjc.com (Terry Carroll)
Date: Tue Dec 31 00:25:02 2002
Subject: [Tutor] newbie request for help in setting up emacs for pytho
 n
In-Reply-To: <0BA95581EDA7D611841B00A0C9AD25DD2B5930@mail.pjinet.com>
Message-ID: <Pine.GSU.4.44.0212302107200.3604-100000@waltz.rahul.net>

On Mon, 30 Dec 2002, Alan Trautman wrote:

> Thank you, I've been avoiding doing the task of making a working Emacs
> configuration. The documentation didn't make a lot of sense to me either.

No problem.  Since I'm new to Python, most of my "contributions" to this
list are in the form of requests for help, so I'm happy to be able to be
on the other side for a change.

One more thing: I'd advise those new to emacs to go to
http://www.refcards.com/about/emacs.html and print the appropriate 3-fold
reference card.  For me in the US, it's the one marked "US letter, three
column, PDF file".  Those in Europe will prefer the A4.  Print it on both
sides of a sheet of paper, and tri-fold it.  It's an excellent reference.

I don't know about you, but I find it easier to look down from my editing
session to look at a nice compact paper document than to swap over to a
browser and read a how-to online.  This reference card is great for that.
(The reference card is included in the emacs distribution, but in a
PostScript form, and I couldn't get a reasonably-sized copy to print.)

Since the original poster asked about xemacs as well, refcards.com also
has a page for that, at <http://www.refcards.com/about/xemacs.html>.


-- 
Terry Carroll        |
Santa Clara, CA      |   "The parties are advised to chill."
carroll@tjc.com      |       - Mattel, Inc. v. MCA Records, Inc.,
Modell delendus est  |         no. 98-56577 (9th Cir. July 24, 2002)



From dyoo@hkn.eecs.berkeley.edu  Tue Dec 31 01:04:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue Dec 31 01:04:02 2002
Subject: [Tutor] beginner question
In-Reply-To: <3E0F0647.1030401@aon.at>
Message-ID: <Pine.LNX.4.44.0212302143260.31050-100000@hkn.eecs.berkeley.edu>


> >How to fix this piece of code to print list elements horizontal on screen?
> >
> >###
> >list = [1,2,3,4,5]
> >
> >for i in list:
> >    print i
> >
> >###
> >
> Add a comma as follows:
>
>    for i in list:
>        print i,

Hi Djuro,

By the way, there's a section on the official Python tutorial dedicated to
printing issues here:

    http://www.python.org/doc/tut/node9.html

You might find it useful if you need more fine-grained control over
printing, since putting a trailing comma still introduces a space between
each item in your list.


Happy New Year!



From schalla@vasoftware.com  Tue Dec 31 04:44:02 2002
From: schalla@vasoftware.com (shobhan)
Date: Tue Dec 31 04:44:02 2002
Subject: [Tutor] How can i dump the DB data into a text file in CSV format
Message-ID: <3E1165A5.9080607@vasoftware.com>

--------------060705020604050000020005
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hi Pythoners,

Can anyone tell me how to connect to Oracle DB using Python and dump the 
data from a table called "logs" into a text file in CSV format..?
The text file thus created should be of the format (2002-12-30-logs.txt).
It would be fine if anyone can show a sample script.

Thanks in advance
Schalla

--------------060705020604050000020005
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title></title>
</head>
<body>
<font face="Helvetica, foo, sans-serif" size="-1">Hi Pythoners,<br>
<br>
Can anyone tell me how to connect to Oracle DB using Python and dump the
data from a table called "logs" into a text file in CSV format..?<br>
The text file thus created should be of the format (2002-12-30-logs.txt).<br>
It would be fine if anyone can show a sample script.<br>
<br>
Thanks in advance<br>
Schalla</font><br>
</body>
</html>

--------------060705020604050000020005--



From alan.gauld@bt.com  Tue Dec 31 05:53:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 31 05:53:02 2002
Subject: [Tutor] Advice required: Documentation Writing / Sofware Test
 ing
Message-ID: <7497DCA1C240C042B28F6657ADFD8E097022D7@i2km11-ukbr.domain1.systemhost.net>

> >Framemaker
> 
> I was an instructor for a series of computer classes whose 
> training manuals were all written in Framemaker. This is a very powerful
and 
> painful program IMO. 

Powerful yes, its no more painful than any other DTP package. The main 
thing to remember is it is NOT a word processor. Never try to treat 
it like you would Word - you'll just create headaches later on.

The big plus is that it is very fast to use once you learn it - it 
uses all the emacs keys for starters. If you know emacs you know 
most of Frame! We estimate that for big documents we save about 
15-20% time using Frame over Word.

Also it has a very efficient format control dialog that allows you 
to alter just about everything from a single dialog box.

> If you don't use it heavily and constantly I find almost nothing
> intuitive about it 

Personal tastes I guess, I find it more intuitive than Word.
But then UI used Frame for 3 years before I ever used Word! 
So although I now use Word about twice as often as Frame I 
still prefer Frame.

> to make a collection (all) of the documents fit a certain standard 

Exactly what Frame is strongest at. Its not designed to churn 
out one-off documents. It assumes you maintain multiple books
all in a similar layout, probably sharing chapters across them
(eg concepts chapters over a range of Web tool manuals) and 
publish those documents in multiple formats (postscript, 
XML, HTML, PDF, Hypertext, etc) It also has very strong versioning 
so that you can have the same manual with different sections 
for different versions of the tool (like a #ifdef in C!)

> many of its features are harder to use than other products. 

Not if you compare comparable products 
- like Pagemaker, Quark, Ventura etc.

> standard format but very flexible contents and we found the 
> XML and XSL provided and easier way to store and create the 
> documents

Frame 7 uses XML formatting as standard...

> If you do decide on Framemaker I would also try to take a 
> class 

I'd second that, it is a big conceptual jump from Word etc.
( Although to be honest, the manuals and help pages(written in Frame!)
  are very good - if you take the time to read your way through them!)

Alan g.


From alan.gauld@bt.com  Tue Dec 31 06:07:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 31 06:07:01 2002
Subject: [Tutor] You guys should make a chat....
Message-ID: <7497DCA1C240C042B28F6657ADFD8E097022D8@i2km11-ukbr.domain1.systemhost.net>

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C2B0BC.58C25CC0
Content-Type: text/plain;
	charset="iso-8859-1"

 > I suggest you guys make a chat for people to meet and share their 
 >  tips and tricks anout python.   It would make sharing information
 >  a lot easier.  
 
I believe there is a Wiki someplace. But a Chat is only useful for people
who are 
logged on at the same time. A mailing list(or newsgroup) gets a better
ruesult 
because people all round the world can join in.
 
> It would aslo help a lot of people get some more info to help them get
started.  
 
How so? They can browse the archives of the mailing list (and newsgroups!)
so the 
same info as would be on a chat is available for a long time.
 
Alan g. 
Author of the Learn to Program website 
http://www.freenetpages.co.uk/hp/alan.gauld/
<http://www.freenetpages.co.uk/hp/alan.gauld/>  


------_=_NextPart_001_01C2B0BC.58C25CC0
Content-Type: text/html;
	charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY>
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT 
face=Tahoma></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=433025710-31122002><FONT color=#0000ff>&nbsp;&gt; </FONT></SPAN>I suggest 
you guys make a chat for people to meet and share their&nbsp;<BR><SPAN 
class=433025710-31122002><FONT color=#0000ff>&nbsp;<FONT color=#000000>&gt; 
</FONT>&nbsp;</FONT></SPAN>tips and tricks anout python.<SPAN 
class=433025710-31122002><FONT color=#0000ff>&nbsp; &nbsp;</FONT></SPAN>It would 
make sharing information<BR><SPAN class=433025710-31122002><FONT 
color=#0000ff>&nbsp;<FONT color=#000000>&gt; </FONT>&nbsp;</FONT></SPAN>a lot 
easier.&nbsp;<SPAN class=433025710-31122002><FONT 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=433025710-31122002></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=433025710-31122002>I believe there is a Wiki someplace. But a Chat is only 
useful for people who are </SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=433025710-31122002>logged on at the same time. A mailing list(or 
newsgroup) gets a better ruesult </SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=433025710-31122002>because people all round the world can join 
in.</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=433025710-31122002></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT lang=0 FAMILY="SANSSERIF"><FONT size=2><SPAN 
class=433025710-31122002>&gt;&nbsp;</SPAN>It would aslo help a lot of people get 
some more info to help them get started.</FONT></FONT>&nbsp;<SPAN 
class=433025710-31122002><FONT color=#0000ff 
size=2>&nbsp;</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial><SPAN class=433025710-31122002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><SPAN class=433025710-31122002><FONT color=#0000ff 
size=2>How so? They can browse the archives of the mailing list (and 
newsgroups!) so the </FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial><SPAN class=433025710-31122002><FONT color=#0000ff 
size=2>same info as would be on a chat</FONT>&nbsp;<FONT color=#0000ff size=2>is 
available for a long time.</FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN 
class=433025710-31122002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#0000ff size=2><SPAN class=433025710-31122002>
<P><FONT face="Courier New" size=2>Alan g.</FONT> <BR><FONT face="Courier New" 
size=2>Author of the Learn to Program website</FONT> <BR><FONT 
face="Courier New" size=2><A target=_blank 
href="http://www.freenetpages.co.uk/hp/alan.gauld/">http://www.freenetpages.co.uk/hp/alan.gauld/</A></FONT> 
</P></SPAN></FONT></DIV></BODY></HTML>

------_=_NextPart_001_01C2B0BC.58C25CC0--


From alan.gauld@bt.com  Tue Dec 31 06:15:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 31 06:15:02 2002
Subject: [Tutor] pyLPD
Message-ID: <7497DCA1C240C042B28F6657ADFD8E097022D9@i2km11-ukbr.domain1.systemhost.net>

> I wanted to working with LPT1: on windows, but it seems to 
> bee impossible.
> Simply I can't capture the stream sent to it.

Have you checked the MODE command? Its DOS but works even in W2K etc...

Heres the /? output:
-----------------------------------------------------
C:\>mode /?
Configures system devices.

Serial port:       MODE COMm[:] [BAUD=b] [PARITY=p] [DATA=d] [STOP=s]
                                [to=on|off] [xon=on|off] [odsr=on|off]
                                [octs=on|off] [dtr=on|off|hs]
                                [rts=on|off|hs|tg] [idsr=on|off]

Device Status:     MODE [device] [/STATUS]

Redirect printing: MODE LPTn[:]=COMm[:]

Select code page:  MODE CON[:] CP SELECT=yyy

Code page status:  MODE CON[:] CP [/STATUS]

Display mode:      MODE CON[:] [COLS=c] [LINES=n]

Typematic rate:    MODE CON[:] [RATE=r DELAY=d]
----------------------------------------------------


Note the bit about redirecting LPTn....

HTH,

Alan g.


From alan.gauld@bt.com  Tue Dec 31 06:20:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 31 06:20:02 2002
Subject: [Tutor] Subclasses?
Message-ID: <7497DCA1C240C042B28F6657ADFD8E097022DA@i2km11-ukbr.domain1.systemhost.net>

> Guido van Rossum asked for a real use-case for inner classes. 

Don't know the thread and am no Java expert but aren't inner 
classes the only way to fake lambas in Java?

Stoopid language! :-)

Alan G.



From alan.gauld@bt.com  Tue Dec 31 06:23:04 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 31 06:23:04 2002
Subject: [Tutor] newbie request for help in setting up emacs for pytho
 n
Message-ID: <7497DCA1C240C042B28F6657ADFD8E097022DB@i2km11-ukbr.domain1.systemhost.net>

> If you're trying to learn Emacs, you may find the embedded 
> tutorial useful
> --- try typing "C-h t"  (Control h, followed by a 't'), which 
> should bring it up.

I second that but add the caveat that the tutor is generic 
and quite old so it doesn't cover the use of menus, mouse or cursor 
keys. All of which should wotrk pretty much as expected! So 
you aren't forced to use C-n to move down a line etc you can 
just use the down arrow! (Of course C-n is faster if you 
touch type... and less painful if you swap the CTRL and 
CapsLock keys on a PC keyboard!)

Alan G.


From ahimsa@onetel.net.uk  Tue Dec 31 06:33:00 2002
From: ahimsa@onetel.net.uk (ahimsa)
Date: Tue Dec 31 06:33:00 2002
Subject: [Tutor] idle or lack thereof ...
Message-ID: <1041334333.947.365.camel@localhost.localdomain>

Hi again
I'm sorry to keep going on about this idle, but I must be having a brain
fugue or some such 'cos I seem to be having a really hard time figuring
this out. I followed up on a suggestion and found 'idle' buried within
the Tools sub-directory. When I went to go and call it this is the
output.
________

[ahimsa@localhost ahimsa]$ /usr/lib/python2.2/Tools/idle/idle.py
Traceback (most recent call last):
  File "/usr/lib/python2.2/Tools/idle/idle.py", line 3, in ?
    import PyShell
  File "/usr/lib/python2.2/Tools/idle/PyShell.py", line 13, in ?
    from Tkinter import *
  File "/usr/local/lib/python2.2/lib-tk/Tkinter.py", line 35, in ?
    import _tkinter # If this fails your Python may not be configured
for Tk
ImportError: No module named _tkinter
[ahimsa@localhost ahimsa]$ 
_______

Could someone give me a couple of suggestions how to "configure" python
for Tk please.

Thanks (once again) :)

AmF


-- 
ahimsa <ahimsa@onetel.net.uk>



From alan.gauld@bt.com  Tue Dec 31 06:34:03 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 31 06:34:03 2002
Subject: [Tutor] newbie request for help in setting up emacs for pytho
 n
Message-ID: <7497DCA1C240C042B28F6657ADFD8E097022DC@i2km11-ukbr.domain1.systemhost.net>

> (setq interpreter-mode-alist
>       (cons '("python" . python-mode)
>             interpreter-mode-alist))
> 
> [I'm not sure what this line does, but I found it in an 
> example, it works, so I don't mess with it.]

If it aint broke... is a good thing to follow in emacs.

Programmatically what it does (in Python style) is:

interpreter_mode_list = interpreter_mode_list.append( ('python',
python_mode) )

Actually it might be insert() rather than append, I can't 
remember the sequence from cons...

> No, I'm right with you there.  emacs is a hell of a lot more 
> easy to use than to configure, at least for a beginner.  

Not just for beginners! I've used emacs for 10 years now and 
still mess with my .emacs files as little as possible!

Alan g.


From aztech1200@yahoo.com  Tue Dec 31 08:07:03 2002
From: aztech1200@yahoo.com (Aztech Guy)
Date: Tue Dec 31 08:07:03 2002
Subject: [Tutor] How can i dump the DB data into a text file in CSV format
In-Reply-To: <3E1165A5.9080607@vasoftware.com>
Message-ID: <20021231130657.22747.qmail@web9802.mail.yahoo.com>

--0-861122756-1041340017=:22292
Content-Type: text/plain; charset=us-ascii


Hi,
Here's an overview ...
[ Disclaimer: I haven't tried Python+DBI yet; but I've read about it; and it's similar to Perl+DBI+DBD, Java+JDBC, and C+ODBC in concept, the last two of which I've used a lot. And I've read enough of Perl+DBI+DBD docs, though, to realize that its similar in concept as I said above. My guess is that Python+DBI(+DBD?) should be roughly on the same lines, though of course with a Pythonic flavour. Don't take what I say as absolutely accurate, though - you'll have to do some research on the Net to find the exact equivalents in Python.]
- Get (if not already present on your system) the DBI+DBD (not sure of the exact names in Python) modules from the Net. (Try the Python site www.python.org, the Vaults of Parnassus, Google, etc. to find out where to get it from).
- DBI (in Perl, at least) stands for Data Base Interface, and DBD stands for Data Base Driver.
The DBI is a database-indepent layer. Your Perl/Python program talks to it. 
This is similar to the Driver Manager in ODBC.
The DBI in turn talks to the DBD layer, which is specific to the database you are using. There  should be different DBD's for different databases. So you'll have to get one for Oracle - may need to check if it works with your particular Oracle version.
The DBD is similar to the database-specific database driver in ODBC - you need a separate ODBC driver for each database that you want to connect to.
Once you have got all the above software, your program should be written something on these lines :
- Open a connection to the database from Python program.
You'll have to specify the database as a "URL" (like a JDBC URL in concept, though not maybe in syntax), which will include the database name, user name and password, maybe the machine on which it is (the host name). The connect call will return a 'handle' of some sort which you will use for all further operations on that database, such as executing statements, getting results, etc.
- Write your SQL statement to get the data you want from the table you want.
(You'll need to know SQL here - if you don't, I can't help you with that - it's too long a topic to explain right now - try Googling for SQL tutorials and Database tutorials to understand the basics of both - it's not very difficult - a super-short explanation is that database hold many tables, tables are like spreadsheets (contain rows and columns, and SQL is a way of reading rows and / or columns, and any combination of them, and also of updating (adding/modifying/deleting) the same. About.com is also a good site for learning about this stuff)
- Once you've written your SQL statement, you will have to pass it to the DBD using the appropriate syntax. After this, if the SQL statement executed successfully, you can use other Py/DBD statements to read the data returned by the statement, row by row, with each row containing the columns you've specified. You may also need to use statements to access each column of each row). All this will have to be done in (probably) two nested loops - the outer loop iterates over rows, and the inner one over the columns of the current row. 
- Next, inside the inner loop, you now have the values of each row+column, i.e. a "cell" as a Python variable. Write it out to a text file in CSV format. (You should have opened a text file - to write to - before the outer loop). CSV stands for Comma Separated Values - its a simple format - there is a comma between any two consecutive values, and (optionally - if the string contains white space), double quotes around strings - its probably to always use double quotes. 
- So, in the inner loop, for each numeric variable, write it out as is; for each string variable, you may have to prefix and suffix it with double quotes and then write it out.
- At the end of each inner loop,  print a newline.
After the outer loop, close the text file.
If all went well, you should have the output you need.
Sample pseudocode:
db_handle = connect( <Py-DBD-URL> )
stmt = exec_stmt(db_handle, "<your SQL stmt>")
results = stmt.get_resultSet
while results.hasMoreRows()
    row = results.getNextRow()
    while row.hasMoreColumns()
         col = row.getNextColumn()
         txtfile.write( col ) # formatted as necessary
     end while col
     print a newline
  end while row
close textfile
close stmt
close db_handle
Hope this helps
Az.
 
 
.
 shobhan <schalla@vasoftware.com> wrote:Hi Pythoners,

Can anyone tell me how to connect to Oracle DB using Python and dump the data from a table called "logs" into a text file in CSV format..?
The text file thus created should be of the format (2002-12-30-logs.txt).
It would be fine if anyone can show a sample script.

Thanks in advance
Schalla



---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now
--0-861122756-1041340017=:22292
Content-Type: text/html; charset=us-ascii

<P>Hi,
<P>Here's an overview ...
<P>[ Disclaimer: I haven't tried Python+DBI yet; but I've read about it; and it's similar to Perl+DBI+DBD, Java+JDBC, and C+ODBC in concept, the last two of which I've used a lot. And I've read enough of Perl+DBI+DBD docs, though, to realize that its similar in concept as I said above. My guess is that Python+DBI(+DBD?) should be roughly on the same lines, though of course with a Pythonic flavour. Don't take what I say as absolutely accurate, though - you'll have to do some research on the Net to find the exact equivalents in Python.]
<P>- Get (if not already present on your system) the DBI+DBD (not sure of the exact names in Python) modules from the Net.&nbsp;(Try the Python site <A href="http://www.python.org">www.python.org</A>, the Vaults of Parnassus,&nbsp;Google, etc. to find out where to get it from).
<P>-&nbsp;DBI (in Perl, at least)&nbsp;stands for Data Base Interface, and DBD stands for Data Base Driver.
<P>The DBI is a database-indepent layer. Your Perl/Python program talks to it. 
<P>This is similar to the Driver Manager in ODBC.
<P>The DBI in turn talks to&nbsp;the DBD layer, which is specific to the database you are using. There&nbsp;&nbsp;should be different&nbsp;DBD's for different databases. So you'll have to get one for Oracle - may need to check if it works with your particular Oracle version.
<P>The DBD is similar to the database-specific database driver in ODBC - you need a separate ODBC driver for each database that you want to connect to.
<P>Once you have got all the above software, your program should be written something on these lines :
<P>- Open a connection to the database from Python program.
<P>You'll have to specify the database as a "URL" (like a JDBC URL in concept, though not maybe in syntax), which will include the database name, user name and password, maybe the machine on which it is (the host name). The connect call will return a 'handle' of some sort which you will use for all further operations on that database, such as executing statements, getting results, etc.
<P>- Write your SQL statement to get the data you want from the table you want.
<P>(You'll need to know SQL here - if you don't, I can't help you with that - it's too long a topic to explain right now - try Googling for SQL tutorials and Database tutorials to understand the basics of both - it's not very difficult - a super-short explanation is that database hold many tables, tables are like spreadsheets (contain rows and columns, and SQL is a way of reading rows and / or columns, and any combination of them, and also of updating (adding/modifying/deleting) the same. About.com is also a good site for learning about this stuff)
<P>- Once you've written your SQL statement, you will have to pass it to the DBD using the appropriate syntax. After this, if the SQL statement executed successfully, you can use other Py/DBD statements to read the data returned by the statement, row by row, with each row containing the columns you've specified. You may also need to use statements to access each column of each row). All this will have to be done in (probably) two nested loops - the outer loop iterates over rows, and the inner one over the columns of the current row. 
<P>- Next, inside the inner loop, you now have the values of each row+column, i.e. a "cell" as a Python variable. Write it out to a text file in CSV format. (You should have opened a text file - to write to - before the outer loop). CSV stands for Comma Separated Values - its a simple format - there is a comma between any two consecutive values, and (optionally - if the string contains white space), double quotes around strings - its probably to always use double quotes. 
<P>- So, in the inner loop, for each numeric variable, write it out as is; for each string variable, you may have to prefix and suffix it with double quotes and then write it out.
<P>- At the end of each inner loop,&nbsp; print a newline.
<P>After the outer loop, close the text file.
<P>If all went well, you should have the output you need.
<P>Sample pseudocode:
<P>db_handle = connect( &lt;Py-DBD-URL&gt; )
<P>stmt = exec_stmt(db_handle, "&lt;your SQL stmt&gt;")
<P>results = stmt.get_resultSet
<P>while results.hasMoreRows()
<P>&nbsp;&nbsp;&nbsp; row = results.getNextRow()
<P>&nbsp;&nbsp;&nbsp; while row.hasMoreColumns()
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; col = row.getNextColumn()
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtfile.write( col ) # formatted as necessary
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end while col
<P>&nbsp;&nbsp;&nbsp;&nbsp; print a newline
<P>&nbsp; end while row
<P>close textfile
<P>close stmt
<P>close db_handle
<P>Hope this helps
<P>Az.
<P>&nbsp;
<P>&nbsp;
<P>.
<P>&nbsp;<B><I>shobhan &lt;schalla@vasoftware.com&gt;</I></B> wrote:
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid"><FONT face="Helvetica, foo, sans-serif" size=-1>Hi Pythoners,<BR><BR>Can anyone tell me how to connect to Oracle DB using Python and dump the data from a table called "logs" into a text file in CSV format..?<BR>The text file thus created should be of the format (2002-12-30-logs.txt).<BR>It would be fine if anyone can show a sample script.<BR><BR>Thanks in advance<BR>Schalla</FONT><BR></BLOCKQUOTE><p><br><hr size=1>Do you Yahoo!?<br>
<a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Yahoo! Mail Plus</a> - Powerful. Affordable. <a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Sign up now</a>
--0-861122756-1041340017=:22292--


From ahimsa@onetel.net.uk  Tue Dec 31 09:57:02 2002
From: ahimsa@onetel.net.uk (ahimsa)
Date: Tue Dec 31 09:57:02 2002
Subject: [Tutor] Emacs as editor
Message-ID: <1041346659.1100.368.camel@localhost.localdomain>

Thanks Danny and Alan
I spent the morning with emacs using the C-h t and scribbling down basic
commands just in case I ended up getting totally befuddled in the midst
of things ... which I suspect is quite probable for the first few runs
around the block.
Cheers and happy New year for those to whom this applies.

Andrew
-- 
ahimsa <ahimsa@onetel.net.uk>



From ahimsa@onetel.net.uk  Tue Dec 31 10:11:14 2002
From: ahimsa@onetel.net.uk (ahimsa)
Date: Tue Dec 31 10:11:14 2002
Subject: [Tutor] Re: emacs & python help
In-Reply-To: <20021231110701.9278.50802.Mailman@mail.python.org>
References: <20021231110701.9278.50802.Mailman@mail.python.org>
Message-ID: <1041347513.1100.380.camel@localhost.localdomain>

Thanks Terry
I'm going to have to work with this for a while to let it begin to make
some sense to me. I got so used to just using IDLE that all this is a
little foreign to me.
I think that I do have the python mode already - I stumbled across it
the other day when trying to check it out and promptly recoiled from it
in horror :)
I'll give your script a going over and see what I can make of it - may I
pick your brains if (see I'm being optimistic here!!) I get stuck?

All the best
Andrew
-- 

________________________%%%%%%%%%%%%%%%%%____________________________

Proudly sent using Ximian Evolution 1.2.1 on a Linux Red Hat 8.0 box.



From alan.gauld@bt.com  Tue Dec 31 12:23:21 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Dec 31 12:23:21 2002
Subject: [Tutor] Re: emacs & python help
Message-ID: <7497DCA1C240C042B28F6657ADFD8E097022DE@i2km11-ukbr.domain1.systemhost.net>

> some sense to me. I got so used to just using IDLE that all this is a
> little foreign to me.


FWIW learning emacs helps in IDLE since IDLE uses the basic 
emacs keystrokes(C-n,C-p etc)... Maybe thats an added incentive?

Alan g.


From ramrom@earthling.net  Tue Dec 31 13:04:02 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Tue Dec 31 13:04:02 2002
Subject: [Tutor] How can i dump the DB data into a text file in CSV
 format
In-Reply-To: <3E1165A5.9080607@vasoftware.com>
Message-ID: <5.2.0.9.0.20021231105230.01a0bb70@66.28.54.253>

--=======2462518=======
Content-Type: multipart/alternative; x-avg-checked=avg-ok-6633D6F; boundary="=====================_2460207==.ALT"


--=====================_2460207==.ALT
Content-Type: text/plain; x-avg-checked=avg-ok-6633D6F; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit

At 03:08 PM 12/31/2002 +0530, shobhan wrote:
>Can anyone tell me how to connect to Oracle DB using Python and dump the 
>data from a table called "logs" into a text file in CSV format..?

I suggest using cx_oracle (http://www.computronix.com/utilities.shtml).

import cx_Oracle
conn = cx_Oracle.connect(xxx/yyy@zzz)
c = conn.cursor()
c.execute('select 1,2, 3 from dual')
l = c.fetchall()
# now you have a list of tuples, one tuple per row.

There have been several discussions on this list regarding modules for csv 
files. I have not tried it, but look at 
http://tratt.net/laurie/python/asv/. "ASV is a platform independent Python 
module to input, manipulate and output `simple' database storage file 
formats such as CSV (Comma Seperated Value) ....". I do not take credit for 
spelling here!

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625


--=====================_2460207==.ALT
Content-Type: text/html; x-avg-checked=avg-ok-6633D6F; charset=us-ascii
Content-Transfer-Encoding: 8bit

<html>
<body>
At 03:08 PM 12/31/2002 +0530, shobhan wrote:<br>
<blockquote type=cite class=cite cite><font face="Helvetica, Helvetica" size=2>Can
anyone tell me how to connect to Oracle DB using Python and dump the data
from a table called &quot;logs&quot; into a text file in CSV
format..?</font></blockquote><br>
I suggest using cx_oracle
(<a href="http://www.computronix.com/utilities.shtml" eudora="autourl">http://www.computronix.com/utilities.shtml</a>).<br><br>
import cx_Oracle&nbsp; <br>
conn = cx_Oracle.connect(xxx/yyy@zzz)<br>
c = conn.cursor()<br>
c.execute('select 1,2, 3 from dual')<br>
l = c.fetchall()<br>
# now you have a list of tuples, one tuple per row.<br><br>
There have been several discussions on this list regarding modules for
csv files. I have not tried it, but look at
<a href="http://tratt.net/laurie/python/asv/" eudora="autourl">http://tratt.net/laurie/python/asv/</a>.
&quot;ASV is a platform independent Python module to input, manipulate
and output `simple' database storage file formats such as CSV (Comma
Seperated Value) ....&quot;. I do not take credit for spelling 
here!<br>
<x-sigsep><p></x-sigsep>
Bob Gailer<br>
<a href="mailto:ramrom@earthling.net" eudora="autourl">mailto:ramrom@earthling.net</a><br>
303 442 2625<br>
</body>
</html>


--=====================_2460207==.ALT--

--=======2462518=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-6633D6F
Content-Disposition: inline


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.431 / Virus Database: 242 - Release Date: 12/17/2002

--=======2462518=======--



From dyoo@hkn.eecs.berkeley.edu  Tue Dec 31 14:03:37 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue Dec 31 14:03:37 2002
Subject: [Tutor] idle or lack thereof ...
In-Reply-To: <1041334333.947.365.camel@localhost.localdomain>
Message-ID: <Pine.LNX.4.44.0212311042250.13937-100000@hkn.eecs.berkeley.edu>


On 31 Dec 2002, ahimsa wrote:

> I'm sorry to keep going on about this idle, but I must be having a brain
> fugue or some such 'cos I seem to be having a really hard time figuring
> this out.

Hi Ahimsa,

Don't worry about it; let's try to figure out what's happening.


> I followed up on a suggestion and found 'idle' buried within the Tools
> sub-directory. When I went to go and call it this is the output.
>
> [ahimsa@localhost ahimsa]$ /usr/lib/python2.2/Tools/idle/idle.py
> Traceback (most recent call last):
>   File "/usr/lib/python2.2/Tools/idle/idle.py", line 3, in ?
>     import PyShell
>   File "/usr/lib/python2.2/Tools/idle/PyShell.py", line 13, in ?
>     from Tkinter import *
>   File "/usr/local/lib/python2.2/lib-tk/Tkinter.py", line 35, in ?
>     import _tkinter # If this fails your Python may not be configured
> for Tk
> ImportError: No module named _tkinter


Ah, I see.  It looks like you're using a locally-compiled version of
Python.  You may want to check if you have a library called "Tcl/Tk"
installed on your system.  The _tkinter module is an extension that makes
Tcl/Tk graphics libraries available to Python, and that error message is
saying that it can't find the graphics library.  Tkinter is a graphics
toolkit library that it uses to display the windows of IDLE, so that's why
it's a prerequisite.


You'll want to look to see if the 'development' stuff for Tcl/Tk is
installed with your system.  On a Debian Linux system, for example, the
package 'tk8.3-dev' is the one you'll want to install.  Once you've found
and installed the development packages, a recompile of Python should
autodetect the graphics library.

I'm only guessing that you're using a Linux though; what kind of Unix
distribution are you using?


Good luck to you!



From tlo@aw.sgi.com  Tue Dec 31 14:34:02 2002
From: tlo@aw.sgi.com (Terence Lo)
Date: Tue Dec 31 14:34:02 2002
Subject: [Tutor] fast recursive directory compares
Message-ID: <00ea01c2b103$83ff4c80$ca411dc6@ms.aliaswavefront.com>

Ok, suppose that i have directories Dir1 and Dir2 which each contain
multiple nested subdirectories.
i'm trying to generate a listing of files that are

1) present in dir1 but not present in dir2 *and*
2) present in dir2 but not present in dir1.

what i'd like to do is something similar to what xdiff does when comparing
two files.

i have a process in place, but it is quite slow and i am trying to find a
faster way.

any ideas?

if there isn't any python code which does this easily, i might just write my
own :)

thx in advance. happy new year everybody.

-T




From op73418@mail.telepac.pt  Tue Dec 31 16:03:34 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Tue Dec 31 16:03:34 2002
Subject: [Tutor] Subclasses?
References: <7497DCA1C240C042B28F6657ADFD8E097022DA@i2km11-ukbr.domain1.systemhost.net>
Message-ID: <000701c2b110$c6530d80$58120dd5@violante>

----- Original Message -----
From: <alan.gauld@bt.com>
To: <op73418@mail.telepac.pt>; <tutor@python.org>
Sent: Tuesday, December 31, 2002 11:16 AM
Subject: RE: [Tutor] Subclasses?


> > Guido van Rossum asked for a real use-case for inner classes.
>
> Don't know the thread and am no Java expert but aren't inner
> classes the only way to fake lambas in Java?

I'm not a Java expert either (thank God!) and it's been a long time since I
last touched it (thank you, thank you, Lord!) but yes, that is a way to view
them. Since the inner class is automatically connected with the outer class
and can steer it you can use them to fake closures and stuff like that.

>
> Stoopid language! :-)

No disagreements here. And boring as hell!

>
> Alan G.

With my best regards,
G. Rodrigues




From rickp@telocity.com  Tue Dec 31 16:33:10 2002
From: rickp@telocity.com (Rick Pasotto)
Date: Tue Dec 31 16:33:10 2002
Subject: [Tutor] fast recursive directory compares
In-Reply-To: <00ea01c2b103$83ff4c80$ca411dc6@ms.aliaswavefront.com>
References: <00ea01c2b103$83ff4c80$ca411dc6@ms.aliaswavefront.com>
Message-ID: <20021231213253.GK1381@tc.niof.net>

On Tue, Dec 31, 2002 at 02:33:36PM -0500, Terence Lo wrote:
> Ok, suppose that i have directories Dir1 and Dir2 which each contain
> multiple nested subdirectories. i'm trying to generate a listing of
> files that are
> 
> 1) present in dir1 but not present in dir2 *and*
> 2) present in dir2 but not present in dir1.
> 
> what i'd like to do is something similar to what xdiff does when
> comparing two files.

Just to clarify, are two files the same if:

1) their names are the same (regardless of contents)? or
2) their contents are the same (regardless of name)? or
3) both their names and contents are the same? or
4) they *are* the same (ie, under unix their inodes are the same)?

-- 
"All men recognize the right of revolution; that is, the right to
refuse allegiance to and to resist, the government, when its tyranny
or its inefficiency are great and unendurable." -- Henry David Thoreau
    Rick Pasotto    rick@niof.net    http://www.niof.net


From ramrom@earthling.net  Tue Dec 31 16:34:03 2002
From: ramrom@earthling.net (Bob Gailer)
Date: Tue Dec 31 16:34:03 2002
Subject: [Tutor] fast recursive directory compares
In-Reply-To: <00ea01c2b103$83ff4c80$ca411dc6@ms.aliaswavefront.com>
Message-ID: <5.2.0.9.0.20021231134449.02bdc600@66.28.54.253>

--=======117754AB=======
Content-Type: text/plain; x-avg-checked=avg-ok-6633D6F; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit

At 02:33 PM 12/31/2002 -0500, Terence Lo wrote:

>Ok, suppose that i have directories Dir1 and Dir2 which each contain
>multiple nested subdirectories.
>i'm trying to generate a listing of files that are
>
>1) present in dir1 but not present in dir2 *and*
>2) present in dir2 but not present in dir1.
>
>what i'd like to do is something similar to what xdiff does when comparing
>two files.
>
>i have a process in place, but it is quite slow and i am trying to find a
>faster way.
>
>any ideas?

Crude but functional (deals with just top level directory... you did not 
specify what happens to subdirectories):

 >>> d1 = os.listdir('e:\\d1')
 >>> d1
['ReadMe.rtf', 'Sample Logo2.jpg', 'setup.exe', 'warp6.jpg']
 >>> d2 = os.listdir('e:\\d2')
 >>> d2
['GTremove.exe', 'GTRipple.exe', 'logo.bmp', 'ReadMe.rtf']
 >>> d1.sort()
 >>> d2.sort()
 >>> e1=[(d,1) for d in d1]
 >>> e2=[(d,2) for d in d2]
 >>> x1=0
 >>> x2=0
 >>> while 1:
...     if e1[x1][0] < e2[x2][0]: # file is in 1 and not in 2
...             x1+=1
...     elif e1[x1][0] > e2[x2][0]: # file is in 2 and not in 1
...             x2+=1
...     else: # file is in both
...             del e1[x1]
...             del e2[x2]
...     if x1 >= len(e1) or x2 >= len(e2): break
...
 >>> e1
[('Sample Logo2.jpg', 1), ('setup.exe', 1), ('warp6.jpg', 1)]
 >>> e2
[('GTRipple.exe', 2), ('GTremove.exe', 2), ('logo.bmp', 2)]

On window I'd be tempted to use:
d1 = popen('dir e:\d1 /s /b /on').readlines()
to get all files in the directory and its subdirectories in pathname order,
then use the above comprehensions and loop to remove duplicates

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625

--=======117754AB=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-6633D6F
Content-Disposition: inline


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.431 / Virus Database: 242 - Release Date: 12/17/2002

--=======117754AB=======--



From drewp@bigasterisk.com  Tue Dec 31 19:13:01 2002
From: drewp@bigasterisk.com (Drew Perttula)
Date: Tue Dec 31 19:13:01 2002
Subject: [Tutor] tkinter hourglass
In-Reply-To: Your message of "Tue, 31 Dec 2002 20:05:14 -0330."
 <142133879428.20021231200514@roadrunner.nf.net>
Message-ID: <200301010012.h010Cjs00873@bang.houseoflove>

[replying to list]

Adam wrote:
> Drew wrote:
> >> Here's a simple usage that you can try in your interactive interpreter:
> 
> >> from Tkinter import *
> >> root=Tk()
> >> root.config(cursor="watch")
> 
> >> Now slide the mouse over the Tk window. Other cursor shapes include
> 
> I just tried those commands, and get a window, but it is blank and
> unresponsive. Hung.

I'm in Linux/X11; that simple example may not work in other systems. You
may also have to run root.mainloop() to "bring Tk to life" before you
can see the cursor change on some systems. In Tk/unix, I think setting
the cursor sends a command to the X server right away which is why I
can observe the effect without even starting the event loop.

-Drew




From trivas7@rawbw.com  Tue Dec 31 19:29:04 2002
From: trivas7@rawbw.com (Thomas Rivas)
Date: Tue Dec 31 19:29:04 2002
Subject: [Tutor] idle or lack thereof
In-Reply-To: <20021231170005.1744.86884.Mailman@mail.python.org>
References: <20021231170005.1744.86884.Mailman@mail.python.org>
Message-ID: <200212311640.37188.trivas7@rawbw.com>

On Tuesday 31 December 2002 09:00 am, tutor-request@python.org wrote:

> From: ahimsa <ahimsa@onetel.net.uk>
> To: tutor@python.org
> Date: 31 Dec 2002 11:32:55 +0000
> Subject: [Tutor] idle or lack thereof ...
>
> Hi again
> I'm sorry to keep going on about this idle, but I must be having a brain
> fugue or some such 'cos I seem to be having a really hard time figuring
> this out. I followed up on a suggestion and found 'idle' buried within
> the Tools sub-directory. When I went to go and call it this is the
> output.
> ________
>
> [ahimsa@localhost ahimsa]$ /usr/lib/python2.2/Tools/idle/idle.py
> Traceback (most recent call last):
>   File "/usr/lib/python2.2/Tools/idle/idle.py", line 3, in ?
>     import PyShell
>   File "/usr/lib/python2.2/Tools/idle/PyShell.py", line 13, in ?
>     from Tkinter import *
>   File "/usr/local/lib/python2.2/lib-tk/Tkinter.py", line 35, in ?
>     import _tkinter # If this fails your Python may not be configured
> for Tk
> ImportError: No module named _tkinter
> [ahimsa@localhost ahimsa]$
> _______
>
> Could someone give me a couple of suggestions how to "configure" python
> for Tk please.
>
> Thanks (once again) :)
>
> AmF


Ahimsa--

Looking at the last line in your traceback("import Error: No module named 
_tkinter") I suspect you don't have the tk and tcl libraries on your system. 
Under KPackage on Mandrake 9.0 tk is installed as an rpm (Red Hat Package 
Manager) package  under the libraries section described as "Tk GUI toolkit 
for Tcl" (which is also installed in the same libraries section as tcl), and 
" a X Windows widget set designed to work closely with the tcl scripting 
language." IDLE comes with the Python installation; I invoke it by typing 
"idle" at the command line (well, actually I use the Python-headed icon I put 
on my KDE panel) Make sure you have these two libraries installed on your 
system.

Thomas Rivas
-- 
Simplicity does not proceed complexity, but follows it.--A. Perlis




From carroll@tjc.com  Tue Dec 31 21:28:02 2002
From: carroll@tjc.com (Terry Carroll)
Date: Tue Dec 31 21:28:02 2002
Subject: [Tutor] Re: emacs & python help
In-Reply-To: <1041347513.1100.380.camel@localhost.localdomain>
Message-ID: <Pine.GSU.4.44.0212311414170.8613-100000@waltz.rahul.net>

On 31 Dec 2002, ahimsa wrote:

> I'll give your script a going over and see what I can make of it - may I
> pick your brains if (see I'm being optimistic here!!) I get stuck?

Sure, but do so on the list.  I'm pretty new to emacs myself, so I'm no
expert, and it's a good bet that I might not be able to answer your
questions -- and some others have already shown how they know so much more
than I do about it, so you'll probably get better quality answers posting
here.

-- 
Terry Carroll        |
Santa Clara, CA      |   "The parties are advised to chill."
carroll@tjc.com      |       - Mattel, Inc. v. MCA Records, Inc.,
Modell delendus est  |         no. 98-56577 (9th Cir. July 24, 2002)