From idiot1@netzero.net  Tue Oct  1 06:31:53 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Tue, 01 Oct 2002 01:31:53 -0400
Subject: [Tutor] site uopdate, software update
Message-ID: <3D993349.ECE3E0C2@netzero.net>

Tinylist 1.4.0 is now on the shelf for your downloading pleasure. The site is
also updated.
-- 

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
Unlimited Long Distance only $29.95/ month!
Sign Up Today! www.netzerolongdistance.com


From charlie@begeistert.org  Tue Oct  1 11:10:14 2002
From: charlie@begeistert.org (Charlie Clark)
Date: Tue, 01 Oct 2002 10:10:14 +0000
Subject: [Tutor] re: turn a file into a dictionary
In-Reply-To: <20020930155502.31867.31028.Mailman@mail.python.org>
References: <20020930155502.31867.31028.Mailman@mail.python.org>
Message-ID: <20021001101014.820.3@gormenghast.1033465957.fake>

On 2002-09-30 at 15:55:02 [+0000], you wrote:
> The file is an access control list for a set of financial statements,
> consisting of sheets in an Excel workbook. At present, I have a VBA
> macro which gets username from the network login, looks them up in the
> ACL, then hides all but the permitted sheets. The macro is stored in the
> same workbook, so it is defeated by disabling macros. I could simply
> build another workbook to contain the macro only, and have it act on the
> financial statements, but I want to combine all my reporting tools
> behind a Python front end.
You definitely need to have those sheets away from the macro. I would 
suggest putting them in separate, password-protected files at the very 
least; sounds like you need something stronger though if the data you are 
trying to hide is in any way sensitive: using Zope with ExternalFiles for 
document management springs to mind.
 
> The ACL file is relatively static and small, so I think what I will wind
> up doing is a cross between Magnus' and Charlie's advice: I'll use
> interactive Python one time to create and maintain the dictionary, then
> shelve it, so the front-end to the report system just needs to unshelve i=
t.
You might also like to know that there is a COM module for Python meaning 
you can replace all your Visual Basic with Python and manipulate Excel 
directly from Python.
 
> Many thanks to both Magnus and Charlie for patiently dealing with
> chowder-headed ideas!
No worries. I have more than enuff of my own but that's what the list is fo=
r.

Charlie
-- 
Charlie Clark
Helmholtzstr. 20
D=1Asseldorf
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226


From nano@intermatik.co.id  Tue Oct  1 09:19:51 2002
From: nano@intermatik.co.id (nano)
Date: 01 Oct 2002 15:19:51 +0700
Subject: [Tutor] download dialog-box
Message-ID: <1033460279.7356.48.camel@jrwd.internal.intermatik.com>

hi pythoners,

i want to develop a website. i want to link some files from my webpage,
so it can be downloaded by the client who access it. how can i make the script to
download those files, by using download-dialog box (the one that usually
pop-up when we click a link for downloading something...)
i've asked similar question to u once, but there's no answer that use
this download-dialog box.
squirrel-mail have the script, but it's in php (download.php).
can you masters help this rookie?

thanks very much,

nano'
==let's make our world better==



From mylene.reiners@cmg.com  Tue Oct  1 11:28:22 2002
From: mylene.reiners@cmg.com (Mylene Reiners)
Date: Tue, 1 Oct 2002 12:28:22 +0200
Subject: [Tutor] download dialog-box
Message-ID: <B569A4D2254ED2119FE500104BC1D5CD01A694E6@NL-EIN-MAIL01>

Nano,

do you want to do this using python, or is this a general (HTML) question?

Mylene

-----Original Message-----
From: nano
To: python-tutor
Sent: 10/1/2002 10:19 AM
Subject: [Tutor] download dialog-box

hi pythoners,

i want to develop a website. i want to link some files from my webpage,
so it can be downloaded by the client who access it. how can i make the
script to
download those files, by using download-dialog box (the one that usually
pop-up when we click a link for downloading something...)
i've asked similar question to u once, but there's no answer that use
this download-dialog box.
squirrel-mail have the script, but it's in php (download.php).
can you masters help this rookie?

thanks very much,

nano'
==let's make our world better==


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


From alan.gauld@bt.com  Tue Oct  1 17:19:42 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 1 Oct 2002 17:19:42 +0100
Subject: [Tutor] download dialog-box
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C91B@mbtlipnt02.btlabs.bt.co.uk>

> i want to develop a website. i want to link some files from 
> my webpage, so it can be downloaded by the client 

> download those files, by using download-dialog box (the one 
> that usually pop-up when we click a link for downloading something...)

So what's the problem? Create an HTML file with links 
to the downloadable files. Assuming the browser can't open them 
directly (GIF, JPG etc) then when someone clicks the link 
it will just work... If the browser can open them they might 
need to right click or shift click - depending on the browser...

Can you be more specific about whats different in your case 
so that we can offer specific answers?

> i've asked similar question to u once, but there's no answer that use
> this download-dialog box.

The download box is browser specific and comes as part of 
the normal download process. Theres normally nothing extra 
to be done at the server end to bring the dialog up.

> squirrel-mail have the script, but it's in php (download.php).
> can you masters help this rookie?

I could look the script up to see what it does but I'm no 
PHP guru so I'll ask you for more info instead ;-)

Alan g.


From annika.scheffler@gmx.net  Tue Oct  1 17:24:13 2002
From: annika.scheffler@gmx.net (Annika Scheffler)
Date: Tue, 1 Oct 2002 18:24:13 +0200 (MEST)
Subject: [Tutor] sort method
Message-ID: <21909.1033489453@www62.gmx.net>

Hi,

I am quite new to Python and I need your help:

Can you give me a very simple example of the list.sort method?
For instance I would like to sort this list:

l = "We all place a great deal of reliance on the Theory and Practice of
science, but the hopeful intentions of so many inventions can be quite buggered
up in appliance.".split()

How do I use the sort method?

If I simply write l.sort() , it doesn't work...what do I need to add?

Thanks a lot,
Annika



-- 
Ravens fly in flights, but the egale flies
alone.

+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Günstige DSL- & Modem/ISDN-Tarife!



From rob@uselesspython.com  Tue Oct  1 17:39:36 2002
From: rob@uselesspython.com (Rob)
Date: Tue, 1 Oct 2002 11:39:36 -0500
Subject: [Tutor] sort method
In-Reply-To: <21909.1033489453@www62.gmx.net>
Message-ID: <MPEOIFCOPCIHEDCLBLPBGECKCHAA.rob@uselesspython.com>

>>> l = "what have we here".split()
>>> l
['what', 'have', 'we', 'here']
>>> l.sort()
>>> l
['have', 'here', 'we', 'what']
>>>

Works for me.

Rob

> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> Annika Scheffler
> Sent: Tuesday, October 01, 2002 11:24 AM
> To: tutor@python.org
> Subject: [Tutor] sort method
>
>
> Hi,
>
> I am quite new to Python and I need your help:
>
> Can you give me a very simple example of the list.sort method?
> For instance I would like to sort this list:
>
> l = "We all place a great deal of reliance on the Theory and Practice of
> science, but the hopeful intentions of so many inventions can be
> quite buggered
> up in appliance.".split()
>
> How do I use the sort method?
>
> If I simply write l.sort() , it doesn't work...what do I need to add?
>
> Thanks a lot,
> Annika
>
>
>
> --
> Ravens fly in flights, but the egale flies
> alone.
>
> +++ GMX - Mail, Messaging & more  http://www.gmx.net +++
> NEU: Mit GMX ins Internet. Günstige DSL- & Modem/ISDN-Tarife!
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>




From shalehperry@attbi.com  Tue Oct  1 17:48:57 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue, 1 Oct 2002 09:48:57 -0700
Subject: [Tutor] sort method
In-Reply-To: <21909.1033489453@www62.gmx.net>
References: <21909.1033489453@www62.gmx.net>
Message-ID: <200210010948.57102.shalehperry@attbi.com>

On Tuesday 01 October 2002 09:24, Annika Scheffler wrote:
> Hi,
>
> I am quite new to Python and I need your help:
>
> Can you give me a very simple example of the list.sort method?
> For instance I would like to sort this list:
>
> l =3D "We all place a great deal of reliance on the Theory and Practice=
 of
> science, but the hopeful intentions of so many inventions can be quite
> buggered up in appliance.".split()
>
> How do I use the sort method?
>
> If I simply write l.sort() , it doesn't work...what do I need to add?
>
> Thanks a lot,
> Annika

1) l.sort() sorts the list 'l'.  sort() does not return a new, sorted lis=
t.
2) if you are unhappy with the order you get from sort() you can pass it =
a=20
function which takes two arguments, compares them and returns either -1, =
0,=20
or 1.  There is a builtin function call cmp() which is often used as a=20
building block.

def insensitive_cmp(left, right):
    return cmp(left.lower(), right.lower())

l.sort(insensitive_cmp)


From CWyglendowski@greenville.edu  Tue Oct  1 18:24:30 2002
From: CWyglendowski@greenville.edu (Christian Wyglendowski)
Date: Tue, 01 Oct 2002 12:24:30 -0500
Subject: [Tutor] Example Source Code
Message-ID: <sd99940d.037@gwprimary.greenville.edu>

This will probably be the first of many such replies, but check out =
www.uselesspython.com.  Lots of example code there.

>>> "Mr. Smiley" <tank_uddf@yahoo.com> 09/28/02 02:07PM >>>
Hello fellow Python Developers,

I am new to the Python language and have been studying
it extensively, but I have found that I learn better
when there is example source code out there. Do you
know of any web-sites who provide example source code.
I have tried searching in the various documentation on
the web-site and looked extensively on the Python
search engine but could not find anything. Thanks for
the help.



__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com=20

_______________________________________________
Tutor maillist  -  Tutor@python.org=20
http://mail.python.org/mailman/listinfo/tutor



From dyoo@hkn.eecs.berkeley.edu  Tue Oct  1 19:06:47 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 1 Oct 2002 11:06:47 -0700 (PDT)
Subject: [Tutor] help How do I use a program I built in linux
In-Reply-To: <F28udHLnW5H16AchVcq0000b26f@hotmail.com>
Message-ID: <Pine.LNX.4.44.0210011055080.32644-100000@hkn.eecs.berkeley.edu>


On Mon, 30 Sep 2002, Peter Dudleston wrote:

> I have decided to join the linux revolution and I need some help I have
> python2.2 pre-installed with this version of linux "mandrake" and I was
> wondering what do I type at the shell to run my programs do I need to
> make a new directory because no matter what I change the directory to I
> can't run my programs for example I have one called now which just tells
> you the time and I saved it as now.py and I can't get it to run no
> matter what it says that the command doesn't exist does anyone have
> anything they can tell me "keep in mind I'm a very newbie to this
> envirment" so if you could explain it in lame mans terms I would really
> appreciate it thanks for all you help everyone and talk to you all soon

Hi Danny (or Peter?),


Breathe --- you're going way too fast for me!  *grin* Forgive me; perhaps
I'm being just picky, but I really like punctuated sentences.  Please put
some breaks so we can pick out your main questions easily.


> I was wondering what do I type at the shell to run my programs

Try something like:

###
$ python [name_of_the_script.py]
###

at the shell prompt of your system.  For example, if we had a program
called 'hello.py', we can run it on a Linux system with the following
command:

###
$ python hello.py
###



> I have one called now which just tells you the time and I saved it as
> now.py
>
> I can't get it to run no matter what
>
> it says that the command doesn't exist

One thing that we've found is that natural language is vague, despite our
best intentions.  Paraphrasing what's happening is good, and it's often
more helpful to add to that description with a cut-and-paste of the exact
error message; even ugly error messages may provide clues that we can
tease out.

Can you show us exactly what you're typing at the prompt, and how your
system is responding?



From dyoo@hkn.eecs.berkeley.edu  Tue Oct  1 19:35:18 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 1 Oct 2002 11:35:18 -0700 (PDT)
Subject: [Tutor] (no subject)
In-Reply-To: <001c01c2685a$ff6e28b0$a242cbc7@softserv.attunity.co.il>
Message-ID: <Pine.LNX.4.44.0210011107040.32644-100000@hkn.eecs.berkeley.edu>


On Mon, 30 Sep 2002, Oren Levy wrote:

> I have the example of "spam.c" It complie & link well to dll (Im using
> MS-Visual studio 6) But I didn't understand how to use it ?,Where I need
> to put the files "spam.dll" and "spam.h"?

Hi Oren,

Just to confirm: what experience do you have with Python?  It sounds like
you're building Python C extensions: it's an advanced topic, so we just
want to make sure you know what you're getting into.  *grin* Are you a
newcomer to the language?


Once you've compiled a C module, you can move it over to a place where it
can be imported.  This is often in the 'lib/site-packages/' subdirectory
where Python's installed.  Afterwards, it should behave as if it were a
regular Python module.


Again, if you're not used to Python's module system yet, you may want to
hold off writing C extensions until Python modules are more familiar to
you.


Good luck!



From magnus@thinkware.se  Tue Oct  1 22:41:45 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue, 01 Oct 2002 23:41:45 +0200
Subject: [Tutor] download dialog-box
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C91B@mbtlipnt02.btlabs
 .bt.co.uk>
Message-ID: <5.1.0.14.0.20021001232457.0290f7c8@www.thinkware.se>

At 17:19 2002-10-01 +0100, alan.gauld@bt.com wrote:
>So what's the problem? Create an HTML file with links
>to the downloadable files.

But maybe he want's to feed the binary directly
from the script?

Then it's basically a matter of supplying the right
headers in the beginning, right? I'm not a big
expert in this...

Maybe there is something more easy to read than
http://www.cis.ohio-state.edu/cgi-bin/rfc/rfc2068.html ?

http://www.cs.tut.fi/~jkorpela/http.html ?

Either way, it's not very Python specific.

I think you should send something like:

content-type:application/octet-stream\r\n
content-lenght:44\r\n
\r\n
binarybinarybinarydlkj=F6sdlkfjs=F6dfkg=F6sdg=F6dsfl

Am I right?

On other words:

###
binary =3D open(filename, 'rb').read()
l =3D len(binary)
type =3D 'application/octet-stream'

fmt =3D "content-type:%s\r\ncontentlenght:%i\r\n\r\n%s"

sys.stdout.write(fmt % (type, l, binary)
###

Anything missing?


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From jpollack@socrates.Berkeley.EDU  Wed Oct  2 00:07:06 2002
From: jpollack@socrates.Berkeley.EDU (Joshua Pollack)
Date: Tue, 01 Oct 2002 16:07:06 -0700
Subject: [Tutor] variable initialization
Message-ID: <3D9A2A9A.5FD8B047@socrates.berkeley.edu>

Does anyone know if there's a way to initialize multiple variables in
one line( i.e.- a,b,c,d=0) or whatnot

Thanks!

Josh


-- 
Joshua Pollack
Graduate Student, Slatkin
Lab                                             
Deptartment of Integrative Biology
University of California-Berkeley 
jpollack@socrates.berkeley.edu


From shalehperry@attbi.com  Wed Oct  2 00:11:26 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue, 1 Oct 2002 16:11:26 -0700
Subject: [Tutor] variable initialization
In-Reply-To: <3D9A2A9A.5FD8B047@socrates.berkeley.edu>
References: <3D9A2A9A.5FD8B047@socrates.berkeley.edu>
Message-ID: <200210011611.26473.shalehperry@attbi.com>

On Tuesday 01 October 2002 16:07, Joshua Pollack wrote:
> Does anyone know if there's a way to initialize multiple variables in
> one line( i.e.- a,b,c,d=3D0) or whatnot
>
> Thanks!
>
> Josh


a, b, c =3D 0, 2, 4

a =3D b =3D c =3D 0

(one, two, three, four, five, six) =3D range(1, 7)


From jpollack@socrates.Berkeley.EDU  Wed Oct  2 00:38:17 2002
From: jpollack@socrates.Berkeley.EDU (Joshua Pollack)
Date: Tue, 01 Oct 2002 16:38:17 -0700
Subject: [Tutor] variable initialization
Message-ID: <3D9A31E9.1E40D1EC@socrates.berkeley.edu>

Hmm... one more question then.

Say I'm wanting to initialize a large number of variables to 0 or even
as lists.
For instance, if I wanted to initialize 100 different variables without
having to write out:
one=two=three...ninetynine=hundred=0 

Is there a way to do this with a range statement or something?


Thanks again,
Josh




-- 
Joshua Pollack
Graduate Student, Slatkin
Lab                                             
Deptartment of Integrative Biology
University of California-Berkeley 
jpollack@socrates.berkeley.edu


From shalehperry@attbi.com  Wed Oct  2 00:48:05 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue, 1 Oct 2002 16:48:05 -0700
Subject: [Tutor] variable initialization
In-Reply-To: <3D9A31E9.1E40D1EC@socrates.berkeley.edu>
References: <3D9A31E9.1E40D1EC@socrates.berkeley.edu>
Message-ID: <200210011648.05449.shalehperry@attbi.com>

On Tuesday 01 October 2002 16:38, Joshua Pollack wrote:
> Hmm... one more question then.
>
> Say I'm wanting to initialize a large number of variables to 0 or even
> as lists.
> For instance, if I wanted to initialize 100 different variables without
> having to write out:
> one=3Dtwo=3Dthree...ninetynine=3Dhundred=3D0
>
> Is there a way to do this with a range statement or something?
>
>
> Thanks again,
> Josh

I would first question your need for so many variables (-:  But moving on=
, if=20
thay are distinct variables you have to type them somewhere.

my_list =3D [0 for x in range(0,1000)] # a list of zeroes.

How about giving us a sample of what you are trying to do, or is this jus=
t=20
idle curiousity (not that curiousity is a bad thing)?


From dyoo@hkn.eecs.berkeley.edu  Wed Oct  2 01:31:59 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 1 Oct 2002 17:31:59 -0700 (PDT)
Subject: [Tutor] variable initialization
In-Reply-To: <3D9A31E9.1E40D1EC@socrates.berkeley.edu>
Message-ID: <Pine.LNX.4.44.0210011726010.16515-100000@hkn.eecs.berkeley.edu>


On Tue, 1 Oct 2002, Joshua Pollack wrote:

> Hmm... one more question then.
>
> Say I'm wanting to initialize a large number of variables to 0 or even
> as lists.  For instance, if I wanted to initialize 100 different
> variables without having to write out:

If the variables are related in some way --- that is, if they can be
treated as a "collection" or a "group" --- then a Python list may be a
good way to approach this.

Instead of making one hundred variables (which would be tedious!), we can
make one variable with one hundred "slots" or "indices":

###
mylist = []
for i in range(100):
    mylist.append(0)
print mylist[0]
print mylist[42]
print mylist[99]
###

Hmmm.  Since everything's initialized to zero, this is not that exciting.
*grin*

But I hope it makes the use clear: once we have our list, we can pick out
individual elements of it by using indicing '[]'.



From jtk@yahoo.com  Wed Oct  2 05:08:52 2002
From: jtk@yahoo.com (Jeff Kowalczyk)
Date: Wed, 2 Oct 2002 00:08:52 -0400
Subject: [Tutor] Using __import__ to access a local module attribute
Message-ID: <ands2n$6i2$1@main.gmane.org>

I'm trying to use __import__ to dynamically import a module in a customized
Zope Formulator python product, and thereby access a singleton instance attribute
of the primary class wtih a call to getattr. I can get it to work with
hardcoding the module name, but I don't see what I'm missing when I try to
use __import__. The code below is just an early version of a means to an
end, and I'm wide open to better ways accessing the instance attribute.
Metaprogramming babysteps, I guess...

The MyExtClassInstance attribute in MyExtModule.py that I'm trying to access
is defined like this:
MyExtClassInstance = MyExtClass()

just like the widget and validator formulator classes are. MyExtModule.py
is in the same product directory with my customized formulator filesystem
product, call it 'FormulatorMyExt'.

--- FieldRegistry.py ------------------------------------------------------
def initializeFieldForm(field_class, components=('widget','validator')):
    """ """
    from Form import BasicForm
    from DummyField import fields

    form = BasicForm()
    override_form = BasicForm()
    tales_form = BasicForm()
    for component in components:
        if component not in ('widget','validator'):
           # when the seq is ('widget','validator','myExtModule')
            import MyExtModule # This works ...
           # but what I intend is a working form of either of these next lines....
           # __import__(component.capitalize(), globals(), locals())
           #__import__(getattr(Products.FormulatorMyExt,component.capitalize()),
                                globals(), locals())
            setattr(field_class, component,
                       getattr(MyExtModule,component.capitalize()+'Instance'))

I get errors like:
NameError: global name 'Layout' is not defined (in the first case, and)
NameError: global name 'Products' is not defined (in the second case)

Does anyone see my mistakes here?

And obviously, I want to get that last line of hardcoded MyExtModule name
out of there, but it obfuscated the problem to add that here. I can do it
with a getattr call, I think, contingent on solving the former problem.

Thanks for any help with using __import__, including the from list, or
suggestion of a completely different way to do it as appropriate.








From dyoo@hkn.eecs.berkeley.edu  Wed Oct  2 05:59:43 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 1 Oct 2002 21:59:43 -0700 (PDT)
Subject: [Tutor] Does python has a default database system or not?
In-Reply-To: <Pine.GSO.4.44.0209251645190.12354-100000@mega>
Message-ID: <Pine.LNX.4.44.0210011535400.12646-100000@hkn.eecs.berkeley.edu>


On Wed, 25 Sep 2002, TIAGO DUARTE FELIX wrote:

>
> If yes which module is it?

Hi Tiago,


Can you explain a little more what you're looking for in a database
system?  Are you looking for a full ACID-compliant database, or something
simpler?  There are modules in the standard library that can handle the
DBM format:

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

and these should come standard with Python.


However, I'm not sure if this is what you're expecting as a database, as a
DBM is more of a persistent dictionary than a real database.  I don't
think other database modules come in by default, but they are third-party
modules that are widely available and fairly easy to install.

There is an object database for Python called ZODB:

    http://www.amk.ca/zodb/zodb-zeo.html

which is pretty sophisticated.  There's also a simple SQL-like database
called Gadfly:

    http://gadfly.sourceforge.net/gadfly.html


Bindings to several SQL databases can be found on the Python.org's
Database Topics page:

    http://python.org/topics/database/


If you tell us more about what you're planning to do for your application,
we can try to point you toward better resources.


Good luck!



From annika.scheffler@gmx.net  Wed Oct  2 09:48:25 2002
From: annika.scheffler@gmx.net (Annika Scheffler)
Date: Wed, 2 Oct 2002 10:48:25 +0200 (MEST)
Subject: [Tutor] (no subject)
Message-ID: <2413.1033548505@www21.gmx.net>

Hi Rob,

Thanks for your help! In fact, it does work that way for me, too. But when
writing a function like this:

def sortList(someList):
      

          return someList.sort()

print sortList("What have we here".split())

I get "none" as a result. Why's that?

Thanks,
Annika




Message: 3
From: "Rob" <rob@uselesspython.com>
To: "Python Tutor" <tutor@python.org>
Subject: RE: [Tutor] sort method
Date: Tue, 1 Oct 2002 11:39:36 -0500

>>> l = "what have we here".split()
>>> l
['what', 'have', 'we', 'here']
>>> l.sort()
>>> l
['have', 'here', 'we', 'what']
>>>

Works for me.

Rob

> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> Annika Scheffler
> Sent: Tuesday, October 01, 2002 11:24 AM
> To: tutor@python.org
> Subject: [Tutor] sort method
>
>
> Hi,
>
> I am quite new to Python and I need your help:
>
> Can you give me a very simple example of the list.sort method?
> For instance I would like to sort this list:
>
> l = "What have we here".split()
>
> How do I use the sort method?
>
> If I simply write l.sort() , it doesn't work...what do I need to add?
>
> Thanks a lot,
> Annika
>
>

-- 
Ravens fly in flights, but the egale flies
alone.

+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Günstige DSL- & Modem/ISDN-Tarife!



From alan.gauld@bt.com  Wed Oct  2 12:03:49 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 2 Oct 2002 12:03:49 +0100
Subject: [Tutor] variable initialization
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C91D@mbtlipnt02.btlabs.bt.co.uk>

> Say I'm wanting to initialize a large number of variables to 0 or even
> as lists.

> Is there a way to do this with a range statement or something?

No, because you still have 100 names(ie variables) that must be 
individually initialised.

But it would be extremely unusual to have that many variables. 
Normally you'd be using some kind of list or dictionary instead.
Lists or dictionaries can normally be initialised within loops.

Can you give us a clue as to what you expect to do with 100 
variables? Maybe we can suggest a better design solution?

Alan G.


From alan.gauld@bt.com  Wed Oct  2 12:11:59 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 2 Oct 2002 12:11:59 +0100
Subject: [Tutor] Does python has a default database system or not?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C91E@mbtlipnt02.btlabs.bt.co.uk>

> Subject: [Tutor] Does python has a default database system or not?
> If yes which module is it?

It has a standard way of accessing relational databases. 
Several implementations of that standard exist for different 
databases (ODBC, Oracle, Sybase, DB2, Interbase, MySQL etc).

The documentation is here:

http://www.python.org/topics/database/

There is even a Python database called Gadfly which can be 
found at the Zope project web site and is suitable for 
small size databases(a few thousand entries say). 

For very simple databases you can use the built in "shelve" module 
which simply makes a file look like a dictionary by using the
even lower level pickle module which is designed for simple object
persistence.

Hopefully one of these options will meet your needs,

Alan G.


From darnold02@sprynet.com  Wed Oct  2 12:15:07 2002
From: darnold02@sprynet.com (Don Arnold)
Date: Wed, 2 Oct 2002 06:15:07 -0500
Subject: [Tutor] (no subject)
References: <2413.1033548505@www21.gmx.net>
Message-ID: <00a101c26a04$fd4a17a0$84d1b241@defaultcomp>

----- Original Message -----
From: "Annika Scheffler" <annika.scheffler@gmx.net>
To: <tutor@python.org>
Sent: Wednesday, October 02, 2002 3:48 AM
Subject: [Tutor] (no subject)


> Hi Rob,
>
> Thanks for your help! In fact, it does work that way for me, too. But when
> writing a function like this:
>
> def sortList(someList):
>
>
>           return someList.sort()
>
> print sortList("What have we here".split())
>
> I get "none" as a result. Why's that?
>
> Thanks,
> Annika
>
>
<snip>

Hello. You get None because the sort() method modifies the list you give it.
It doesn't create a new list, so there really is nothing for it to return.
You'll want to return the list itself after you sort it. Also, since lists
are mutable, you may want to work with a copy of the list to leave your
original list intact:

>>> def sortList(someList):
    tempList = someList[:]
    tempList.sort()
    return tempList

>>> b = [4,3,2,1]
>>> a = sortList(b)
>>> print a
[1, 2, 3, 4]
>>> print b
[4, 3, 2, 1]
>>>

Hope that helps,
Don




From op73418@mail.telepac.pt  Wed Oct  2 12:23:55 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Wed, 2 Oct 2002 12:23:55 +0100
Subject: [Tutor] (no subject)
References: <2413.1033548505@www21.gmx.net>
Message-ID: <001d01c26a06$31e08160$35190dd5@violante>

----- Original Message -----
From: "Annika Scheffler" <annika.scheffler@gmx.net>

> Hi Rob,
>
> Thanks for your help! In fact, it does work that way for me, too. But when
> writing a function like this:
>
> def sortList(someList):
>
>
>           return someList.sort()
>
> print sortList("What have we here".split())
>
> I get "none" as a result. Why's that?
>
> Thanks,
> Annika
>

Look at the expression:

someList.sort()

Remember that all functions, methods, etc return *something* and sort()
returns None, so the above evaluates to None. The sort() method does an
in-place sort, so what you want is

someList.sort()
return someList

Hope it helps,
Gonçalo Rodrigues




From alan.gauld@bt.com  Wed Oct  2 12:14:42 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 2 Oct 2002 12:14:42 +0100
Subject: [Tutor] (no subject)
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C91F@mbtlipnt02.btlabs.bt.co.uk>

> <PRE>how can I learn it  fast

Assuming 'it' is Python then it depends on your 
previous programming experience.

If an absolute beginner go to the Newbies section 
of the Python web site.

If an experienced programmer in other languages go 
to the quick start section of the web site or just 
directly to the official tutor (it doesn't take that 
long and gives definitive descriptions).

The python web site is of course at:

http://www.python.org/

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


From magnus@thinkware.se  Wed Oct  2 14:52:16 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed, 02 Oct 2002 15:52:16 +0200
Subject: [Tutor] (no subject)
In-Reply-To: <2413.1033548505@www21.gmx.net>
Message-ID: <5.1.0.14.0.20021002154041.02b17998@www.thinkware.se>

At 10:48 2002-10-02 +0200, Annika Scheffler wrote:
>Hi Rob,
>
>Thanks for your help! In fact, it does work that way for me, too. But when
>writing a function like this:
>
>def sortList(someList):
>
>
>           return someList.sort()
>
>print sortList("What have we here".split())
>
>I get "none" as a result. Why's that?

Same reason as

a =3D someList.sort()
print a
None

The statement "return someList.sort()" means:
"Please python, would you return the return
value of the sort() operation on the someList
object to the calling function?"

.sort() changes the list it sorts. It doesn't
return any value. You need to return the sorted
list, not the non-existing return value of the
sort operation.

You need

def sortList(someList):
     someList.sort()
     return someList

Contrast this with

a =3D someList.index(5)

or

return someList.count('x')

In these cases we use list operations that actually
return a value we care about.

The reason why sort() and reverse() chages the list
instead of returning a sorted/reversed list, leaving
the original unchaged, is that the list might be very
big, and the return value will be equally big. This
might use up more memory than you care for.

If you need to keep the sorted list intact, you can
change your function to:

def sortList(someList):
     sorted =3D someList[:]
     sorted.sort()
     return sorted

Please note that the first version changes the
"original" list.

If you type

a =3D [1,2,3,4]
b =3D a

then both a and b will refer to the _same_ list.
Not two identical.

b.reverse()
print a
[4, 3, 2, 1]



--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From annika.scheffler@gmx.net  Wed Oct  2 18:04:41 2002
From: annika.scheffler@gmx.net (Annika Scheffler)
Date: Wed, 2 Oct 2002 19:04:41 +0200 (MEST)
Subject: [Tutor] sort() once more...
Message-ID: <16956.1033578281@www29.gmx.net>

Hi,

thanks for everyone for your help!
I'm afraid I have another question...:

For example, I have a list like this: l = "What Do we have here".split(). 
If I use the sort() method on this list I get:
['Do', 'What', 'have', 'here', 'we']
What I want as a result is this, though:

['Do', 'have', 'here', 'we', 'What']

In other words, I'd like the sort() method to ignore the first letter of
each word being lower or uppercase. How can I do that?

Thanks a lot,
Annika


-- 
Ravens fly in flights, but the egale flies
alone.

+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Günstige DSL- & Modem/ISDN-Tarife!



From shalehperry@attbi.com  Wed Oct  2 18:10:23 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Wed, 2 Oct 2002 10:10:23 -0700
Subject: [Tutor] sort() once more...
In-Reply-To: <16956.1033578281@www29.gmx.net>
References: <16956.1033578281@www29.gmx.net>
Message-ID: <200210021010.23913.shalehperry@attbi.com>

On Wednesday 02 October 2002 10:04, Annika Scheffler wrote:
> Hi,
>
> thanks for everyone for your help!
> I'm afraid I have another question...:
>
> For example, I have a list like this: l =3D "What Do we have here".spli=
t().
> If I use the sort() method on this list I get:
> ['Do', 'What', 'have', 'here', 'we']
> What I want as a result is this, though:
>
> ['Do', 'have', 'here', 'we', 'What']
>
> In other words, I'd like the sort() method to ignore the first letter o=
f
> each word being lower or uppercase. How can I do that?
>
> Thanks a lot,
> Annika

As I said in my first response:

if you are unhappy with the order you get from sort() you can pass it a=20
function which takes two arguments, compares them and returns either -1, =
0,=20
or 1.  There is a builtin function call cmp() which is often used as a=20
building block.

def insensitive_cmp(left, right):
    return cmp(left.lower(), right.lower())

l.sort(insensitive_cmp)

This does what you need here.  Or does it really matter that:

aBc is sorted differently from ABC?  If so you could just lower case the =
first=20
letter inside the function.


From wolf_binary@hotmail.com  Wed Oct  2 19:08:57 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Wed, 02 Oct 2002 13:08:57 -0500
Subject: [Tutor] binary trees/ linked lists
Message-ID: <F144PasSmz6UuEhjJ8u000004f3@hotmail.com>

Hi folks,

Is there anything like a linked list or binary tree that can be made in 
Python?
Thanks,

Cameron Stoner

_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com



From ATrautman@perryjudds.com  Wed Oct  2 19:18:38 2002
From: ATrautman@perryjudds.com (Alan Trautman)
Date: Wed, 2 Oct 2002 13:18:38 -0500
Subject: [Tutor] binary trees/ linked lists
Message-ID: <0BA95581EDA7D611841B00A0C9AD25DD2B5891@mail.pjinet.com>

Cameron,

The dictionary due to its speed really replaces the linked list. From what
I've seen it handles all the ugly parts for you. 

To make a linked list you need to encapsulate the next (left or right)
object within the root (declare it as a property) and then within each node
as you go. i.e... when you add a new node you instantiate the node and place
it in as a property of the parent object. Until the new node is needed you
instantiate it with a null value allowing all of the normal binary search
tree and list patterns. 

Unfortunately the only good examples of doing this aren't pythonic. Any good
Java objects book will cover this. In addition VB6 and Java pattern books
also apply here. I'm really trying to remember the title of my VB book that
covers this nicely Oh senility sets in early for some of us :)

Hope this helps, did you have anything specific in mind?

Alan

-----Original Message-----
From: Cameron Stoner [mailto:wolf_binary@hotmail.com]
Sent: Wednesday, October 02, 2002 1:09 PM
To: tutor@python.org
Subject: [Tutor] binary trees/ linked lists


Hi folks,

Is there anything like a linked list or binary tree that can be made in 
Python?
Thanks,

Cameron Stoner

_________________________________________________________________
Join the world's largest e-mail service with MSN Hotmail. 
http://www.hotmail.com


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


From dyoo@hkn.eecs.berkeley.edu  Wed Oct  2 19:20:58 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed, 2 Oct 2002 11:20:58 -0700 (PDT)
Subject: [Tutor] (no subject) (fwd)
Message-ID: <Pine.LNX.4.44.0210021109460.8687-100000@hkn.eecs.berkeley.edu>

Hi Oren,

I'm forwarding your message to the Tutor list; it's usually better to keep
the discussion on the mailing list, so that if any one of us gives a silly
answer, others can step in to make sure a satisfactory answer is given.


I think you may want to ask your question on comp.lang.python though
rather than Tutor; I'm not sure how many of us here have experience with
VMS.  The only resources I've been able to find on this is:

    http://www.pi-net.dyndns.org/docs/python_vms/genman/history.html

I haven't found anything newer than 1.52 for OpenVMS, but then, I'm not
familiar enough with the architecture.


I hope you can find what you're looking for!


---------- Forwarded message ----------
Date: Wed, 2 Oct 2002 08:45:23 +0300
From: Oren Levy <oren@softserv.attunity.co.il>
To: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] (no subject)

Re: [Tutor] (no subject)0.TNX a lot

1.I have experience of 2 years with python but It my first time with
python-extending

2.I already found the answer

3.It doesn't work because your example (spam.c) doesn't contain
"__declspec(dllexport)" before exported function "init..." (very popular
"copy - paste" bug :) )

4.Another question I want to use python on alpha-VMS,I already download
from ftp site VMS-version but It doesn't contain instructions,do u have
any newer python - version for VMS? how can I install it on alpha-VMS(I
think I need to recompile something), please answer me -it very necessary

tnx again
Oren


----- Original Message -----
  From: Danny Yoo
  To: Oren Levy
  Cc: tutor@python.org
  Sent: Tuesday, October 01, 2002 9:35 PM
  Subject: Re: [Tutor] (no subject)





  On Mon, 30 Sep 2002, Oren Levy wrote:

  > I have the example of "spam.c" It complie & link well to dll (Im using
  > MS-Visual studio 6) But I didn't understand how to use it ?,Where I need
  > to put the files "spam.dll" and "spam.h"?

  Hi Oren,

  Just to confirm: what experience do you have with Python?  It sounds like
  you're building Python C extensions: it's an advanced topic, so we just
  want to make sure you know what you're getting into.  *grin* Are you a
  newcomer to the language?



  Once you've compiled a C module, you can move it over to a place where it
  can be imported.  This is often in the 'lib/site-packages/' subdirectory
  where Python's installed.  Afterwards, it should behave as if it were a
  regular Python module.



  Again, if you're not used to Python's module system yet, you may want to
  hold off writing C extensions until Python modules are more familiar to
  you.



  Good luck!




From op73418@mail.telepac.pt  Wed Oct  2 19:55:32 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Wed, 2 Oct 2002 19:55:32 +0100
Subject: [Tutor] binary trees/ linked lists
References: <F144PasSmz6UuEhjJ8u000004f3@hotmail.com>
Message-ID: <002301c26a45$48a38980$35190dd5@violante>

----- Original Message -----
From: "Cameron Stoner" <wolf_binary@hotmail.com>


> Hi folks,
>
> Is there anything like a linked list or binary tree that can be made in
> Python?
> Thanks,
>
> Cameron Stoner
>

There are recipes for these either in ActiveState's Cookbook or in the
vaults of parnassus. I can send you also some modules (in pure Python) I
have coded for these types of containers.

With my best regards,
Gonçalo Rodrigues



From magnus@thinkware.se  Wed Oct  2 19:52:28 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed, 02 Oct 2002 20:52:28 +0200
Subject: Fwd: Re: [Tutor] sort()
Message-ID: <5.1.0.14.0.20021002180726.02b29e68@www.thinkware.se>

>From: Annika Scheffler <annika.scheffler@gmx.net>
>Subject: Re: [Tutor] sort()
>
>Hi,
>
>thanks for everyone for your help!
>I'm afraid I have another question...:
>
>For example, I have a list like this: l =3D "What Do we have here".split().
>If I use the sort() method on this list I get:
>['Do', 'What', 'have', 'here', 'we']
>What I want as a result is this, though:
>
>['Do', 'have', 'here', 'we', 'What']
>
>In other words, I'd like the sort() method to ignore the first letter of
>each word being lower or uppercase. How can I do that?

I think someone already answered that.

def caseIndependentSort(this, that):
     return cmp(this.lower(), that.lower())

l.sort(caseIndependentSort)




--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From wolf_binary@hotmail.com  Wed Oct  2 19:51:58 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Wed, 02 Oct 2002 13:51:58 -0500
Subject: [Tutor] linux book
Message-ID: <F197Ej9YUMLdo4qt6V90000ebe4@hotmail.com>


What would be a good Linux Book on the GUI?

Cameron Stoner

_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com



From i812@softhome.net  Wed Oct  2 20:19:39 2002
From: i812@softhome.net (Rob McGee)
Date: Wed, 2 Oct 2002 14:19:39 -0500
Subject: [Tutor] linux book
In-Reply-To: <F197Ej9YUMLdo4qt6V90000ebe4@hotmail.com>
References: <F197Ej9YUMLdo4qt6V90000ebe4@hotmail.com>
Message-ID: <20021002191939.GI2095@hal>

On Wed, Oct 02, 2002 at 01:51:58PM -0500, Cameron Stoner wrote:
> What would be a good Linux Book on the GUI?

Are you speaking of Python? If so, I don't know.

If not, I *still* don't know. :) There are *many* GUI's, not just one.
Your best bet is to ask users of your distro what they recommend. Also,
try on the various window managers (desktop environments) to see what
you like. Then seek a book on your GUI of choice.

Anyway, I'm not one for buying dead tree books. Everything I've learned
about GNU/Linux has come from included and online documentation. There
are numerous online books at tldp.org.

    Rob - /dev/rob0


From dyoo@hkn.eecs.berkeley.edu  Wed Oct  2 21:40:39 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed, 2 Oct 2002 13:40:39 -0700 (PDT)
Subject: [Tutor] linux book [on GUI's / anygui?]
In-Reply-To: <20021002191939.GI2095@hal>
Message-ID: <Pine.LNX.4.44.0210021328090.13850-100000@hkn.eecs.berkeley.edu>


On Wed, 2 Oct 2002, Rob McGee wrote:

> On Wed, Oct 02, 2002 at 01:51:58PM -0500, Cameron Stoner wrote:
> > What would be a good Linux Book on the GUI?
>
> Are you speaking of Python? If so, I don't know.
>
> If not, I *still* don't know. :) There are *many* GUI's, not just one.
> Your best bet is to ask users of your distro what they recommend. Also,
> try on the various window managers (desktop environments) to see what
> you like. Then seek a book on your GUI of choice.

People have written Python bindings for many of the major GUI toolkits on
Linux.  I've heard that PyGTK and PyQT are popular,

    PyGTK: http://www.daa.com.au/~james/pygtk/
    PyQT: http://www.riverbankcomputing.co.uk/pyqt/index.php

as well as wxPython:

    wxPython: http://www.wxpython.org/


What's really neat is that people have trying to write a unification
module, so that it shouldn't matter what GUI one is running on.  A few
people have been involved in writing an abstract layer on top of any GUI.
Not surprisingly, it's called AnyGUI:

    http://anygui.sourceforge.net

I think a few of the contributors of AnyGUI are known to pop up on Tutor
every so often.


Good luck to you!



From glingl@aon.at  Wed Oct  2 23:20:10 2002
From: glingl@aon.at (Gregor Lingl)
Date: Thu, 03 Oct 2002 00:20:10 +0200
Subject: [Tutor] linux book [on GUI's / anygui?]
References: <Pine.LNX.4.44.0210021328090.13850-100000@hkn.eecs.berkeley.edu>
Message-ID: <3D9B711A.3070506@aon.at>

Danny Yoo schrieb:

>What's really neat is that people have trying to write a unification
>module, so that it shouldn't matter what GUI one is running on.  A few
>people have been involved in writing an abstract layer on top of any GUI.
>Not surprisingly, it's called AnyGUI:
>
>    http://anygui.sourceforge.net
>
>  
>
There is even a book containing two chapters on AnyGUI, the one beeing 
an introduction
to the use of AnyGUIm the other one beeing a worked out example 
application using AnyGUI.

It's Practical Python by Magnus Lie Hetland (who is as far as I know the 
coordinator of the
AnyGUI-project)

Gregor

>I think a few of the contributors of AnyGUI are known to pop up on Tutor
>every so often.
>
>
>Good luck to you!
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>  
>






From glingl@aon.at  Wed Oct  2 23:24:46 2002
From: glingl@aon.at (Gregor Lingl)
Date: Thu, 03 Oct 2002 00:24:46 +0200
Subject: [Tutor] binary trees/ linked lists
References: <F144PasSmz6UuEhjJ8u000004f3@hotmail.com> <002301c26a45$48a38980$35190dd5@violante>
Message-ID: <3D9B722E.80306@aon.at>

Gonçalo Rodrigues schrieb:

>----- Original Message -----
>From: "Cameron Stoner" <wolf_binary@hotmail.com>
>
>
>  
>
>>Hi folks,
>>
>>Is there anything like a linked list or binary tree that can be made in
>>Python?
>>Thanks,
>>
>>Cameron Stoner
>>
>>    
>>
Have a look at:
http://www.ibiblio.org/obp/thinkCSpy/
Chapters 17 and 20
Gregor


>There are recipes for these either in ActiveState's Cookbook or in the
>vaults of parnassus. I can send you also some modules (in pure Python) I
>have coded for these types of containers.
>
>With my best regards,
>Gonçalo Rodrigues
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>  
>






From ironman7@tbaytel.net  Thu Oct  3 00:25:02 2002
From: ironman7@tbaytel.net (Brian Moorman)
Date: Wed, 2 Oct 2002 19:25:02 -0400
Subject: [Tutor] Making .py script into an .exe program.
Message-ID: <200210022324.g92NOAa167748@tbaytel.net>

I'm learning how to program in Python, and I'm also attempting to learn 
Tkinter as well.  I am writing a small fantasy hockey script, and I'd like to 
share it with my friends who use the Windows OS.  I am using Linux myself.

I realize I can just have them download the Python interpreter and Tkinter, 
but is there a way to create an .exe from my Python script simply?  If not, 
what other options are available to me, if any?  Thanks!

Brian Moorman


From dyoo@hkn.eecs.berkeley.edu  Thu Oct  3 02:55:07 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed, 2 Oct 2002 18:55:07 -0700 (PDT)
Subject: [Tutor] Making .py script into an .exe program.
In-Reply-To: <200210022324.g92NOAa167748@tbaytel.net>
Message-ID: <Pine.LNX.4.44.0210021852250.23766-100000@hkn.eecs.berkeley.edu>


On Wed, 2 Oct 2002, Brian Moorman wrote:

> I'm learning how to program in Python, and I'm also attempting to learn
> Tkinter as well.  I am writing a small fantasy hockey script, and I'd
> like to share it with my friends who use the Windows OS.  I am using
> Linux myself.
>
> I realize I can just have them download the Python interpreter and
> Tkinter, but is there a way to create an .exe from my Python script
> simply?  If not, what other options are available to me, if any?
> Thanks!

Hi Brian,

Yes, you can package your program into an EXE by using a program like the
py2exe utility:

    http://py2exe.sourceforge.net

It bundles a minimal Python runtime with your scripts; I'm not quite sure
how large the resulting binary is, but it's probably not too bad.



Best of wishes!



From shalabh@gdit.iiit.net  Thu Oct  3 05:44:30 2002
From: shalabh@gdit.iiit.net (shalabh@gdit.iiit.net)
Date: Thu, 3 Oct 2002 10:14:30 +0530 (IST)
Subject: [Tutor] Re: Tutor digest, Vol 1 #1969 - 9 msgs
In-Reply-To: <20021002160005.25991.99623.Mailman@mail.python.org>
Message-ID: <Pine.LNX.4.33.0210031008590.30544-100000@gdit.iiit.net>

Hi all,

I am new to python. Could u give me a little explanation about the 
following code :

class VirtualAttributes:
    __vdict = None
    __vdict_name = locals().keys()[0]
     
    def __init__(self):
        self.__dict__[self.__vdict_name] = {}
    
    def __getattr__(self, name):
        return self.__vdict[name]
    
    def __setattr__(self, name, value):
        self.__vdict[name] = value

Here it says :

self.__dict__[self.__vdict_name] = {}

should it be

self.__vdict__[self.__vdict_name] = {}

if not

what is the significance of __dict__.  if for initialising a dictionary 
why not named __vdict from which we are setting and and getting attributes 
and using as a dictionary.

Could u help.

Thanx,
Shalabh





From anthonypolis@hotmail.com  Thu Oct  3 05:56:29 2002
From: anthonypolis@hotmail.com (anthony polis)
Date: Thu, 03 Oct 2002 04:56:29 +0000
Subject: [Tutor] finding a non-letter?
Message-ID: <F48syWVLEFN03a5sqMa000007d0@hotmail.com>

hello,

I need to know if a string's first charcter is an integer. How would I do 
this? I already know how to access the first character of a string by using 
str[0], but how would test to see if it's a non-letter?

Thanks,
Anthony

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com



From shalehperry@attbi.com  Thu Oct  3 06:13:19 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Wed, 2 Oct 2002 22:13:19 -0700
Subject: [Tutor] finding a non-letter?
In-Reply-To: <F48syWVLEFN03a5sqMa000007d0@hotmail.com>
References: <F48syWVLEFN03a5sqMa000007d0@hotmail.com>
Message-ID: <200210022213.19062.shalehperry@attbi.com>

On Wednesday 02 October 2002 21:56, anthony polis wrote:
> hello,
>
> I need to know if a string's first charcter is an integer. How would I =
do
> this? I already know how to access the first character of a string by u=
sing
> str[0], but how would test to see if it's a non-letter?
>

import string

text =3D '1string'
if text[0] in string.digits:
    print "text's first character is a number"
else:
    print "or it is something else ...."

there is also the regex approach:

import re
text =3D '1string'
num_re =3D re.compile(r'^\d+')
if num_re.search(text):
    print "text begins with a number"


From dyoo@hkn.eecs.berkeley.edu  Thu Oct  3 08:08:35 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 3 Oct 2002 00:08:35 -0700 (PDT)
Subject: [Tutor] finding a non-letter?
In-Reply-To: <F48syWVLEFN03a5sqMa000007d0@hotmail.com>
Message-ID: <Pine.LNX.4.44.0210022343120.32303-100000@hkn.eecs.berkeley.edu>


On Thu, 3 Oct 2002, anthony polis wrote:

> I need to know if a string's first charcter is an integer. How would I
> do this?

Let's take a few concrete examples; let's look at strings whose first
characters look like numbers:

###
>>> words_starting_with_a_digit = [
...     "3v1l",
...     "4u",
...     "5\//33t"]
###


Because we're going to try writing something to check if a word starts
with a number, we have to do some negative tests too: we should think of
words that don't start with a number:

###
>>> words_starting_with_nondigit = [
...     "l33t",
...     "m3g4toky0.c0m"
...     ]
###

(Help!  I've been reading too much http://megatokyo.com.  Please forgive
me for the silly examples.  *grin*)



> I already know how to access the first character of a string by using
> str[0]
>
> but how would test to see if it's a non-letter?

What we can do is check, manually, if that character is either "0", or
"1", or "2", or...

###
def starts_with_a_digit(word):
    if word[0] == "0" or word[0] == "1" or word[0] == "2" or...
###

If we were determined enough to finish this function, it should work.
But we can do a lot to improve it.  One big way is to use the 'in'
operator.  Rather than build up that huge, bulky boring 'or' expression,
we can more simply check if some thing is "in" a collection:

###
def starts_with_a_digit(word):
    if word[0] in ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"):
        return 1
    return 0
###


And at least that fits on a few lines.  Does it work?

###
>>> for w in words_starting_with_a_digit + words_starting_with_nondigit:
...     print w, starts_with_a_digit(w)
...
3v1l 1
4u 1
5\//33t 1
l33t 0
m3g4toky0.c0m 0
###

Ok, yes, so we have what we were looking for.  Yah, we're done.



... but if we use a little more Python, we can write a better definition.
Let's keep going just for a little longer.  *grin*


Python treats strings as sequences too, so we can avoid constructing a
tuple, and instead act on the string "0123456789" directly:

###
def starts_with_a_digit(word):
    if word[0] in "0123456789":
        return 1
    return 0
###

The 'in' operator actually evaluates to either 1 or 0: it returns 1 if it
can find the element in the sequence, and 0 otherwise.


One other trick we can use is to avoid doing the 'if' altogther, and just
straight out use the result of 'in':

###
def starts_with_a_digit(word):
    return word[0] in "0123456789"
###


If we were still going at this beyond Uselessness, we can avoid typing out
that string of digits by borrowing a definition in the string module:

###
>>> string.digits
'0123456789'
>> def starts_with_a_digit(word):
...     return word[0] in string.digits
...
###



Best of wishes to you!



From magnus@thinkware.se  Thu Oct  3 09:18:03 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu, 03 Oct 2002 10:18:03 +0200
Subject: [Tutor] finding a non-letter?
In-Reply-To: <200210022213.19062.shalehperry@attbi.com>
References: <F48syWVLEFN03a5sqMa000007d0@hotmail.com>
 <F48syWVLEFN03a5sqMa000007d0@hotmail.com>
Message-ID: <5.1.0.14.0.20021003080545.029c6580@www.thinkware.se>

At 22:13 2002-10-02 -0700, Sean 'Shaleh' Perry wrote:
>import re
>text =3D '1string'
>num_re =3D re.compile(r'^\d+')
>if num_re.search(text):
>     print "text begins with a number"

or

import re
text =3D '1string'
num_re =3D re.compile(r'\d')
if num_re.match(text):
     print "text beins with a number"

Sean's version says:
Search through the string to see if you can find
the following: Start of string followed by one or
more numbers.

The second version says:
Look at the beginning of the string and see if
we find a digit.

See http://py-howto.sourceforge.net/regex/regex.html
and http://etext.lib.virginia.edu/helpsheets/regex.html
and http://gnosis.cx/publish/programming/regular_expressions.html


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From shalehperry@attbi.com  Thu Oct  3 09:20:05 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Thu, 3 Oct 2002 01:20:05 -0700
Subject: [Tutor] finding a non-letter?
In-Reply-To: <5.1.0.14.0.20021003080545.029c6580@www.thinkware.se>
References: <F48syWVLEFN03a5sqMa000007d0@hotmail.com> <5.1.0.14.0.20021003080545.029c6580@www.thinkware.se>
Message-ID: <200210030120.05273.shalehperry@attbi.com>

On Thursday 03 October 2002 01:18, Magnus Lycka wrote:
>
> Sean's version says:
> Search through the string to see if you can find
> the following: Start of string followed by one or
> more numbers.
>
> The second version says:
> Look at the beginning of the string and see if
> we find a digit.
>

I find that I get bitten by re.match so I always use search instead.  Tha=
nks=20
for the clarification Magnus.


From magnus@thinkware.se  Thu Oct  3 09:34:48 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu, 03 Oct 2002 10:34:48 +0200
Subject: [Tutor] binary trees/ linked lists
In-Reply-To: <002301c26a45$48a38980$35190dd5@violante>
References: <F144PasSmz6UuEhjJ8u000004f3@hotmail.com>
Message-ID: <5.1.0.14.0.20021003102239.029d5de0@www.thinkware.se>

>From: "Cameron Stoner" <wolf_binary@hotmail.com>
> > Is there anything like a linked list or binary tree that can be made in
> > Python?

The Zope Object Database (ZODB) comes with BTrees.

Not very useful if you want to understand algorithms
in Python--it's written in C, but useful if you need
a real BTree implementation for python. I.e. if you
have very big data sets that you need to search through
etc.

The python list type is more like a vector than like
a linked list.

Are you just trying to understand the concepts, or do
you think these structures would be useful for some
particular need of yours?


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From glingl@aon.at  Thu Oct  3 10:19:51 2002
From: glingl@aon.at (Gregor Lingl)
Date: Thu, 03 Oct 2002 11:19:51 +0200
Subject: [Tutor] execute file at startup
Message-ID: <3D9C0BB7.3070303@aon.at>

1. What means do I have to get
certain names from certain modules
imported automatically at startup of
     a) IDLE
     b) the commandline Python interpreter?

2. What means do I have to get a certain module
executed automatically at startup?


More specifically:
I'd like to have a specific function 
already defined (in the main namespace)
after startup, regardless of using IDLE
or the commandline interpreter.

How do I have to proceed?

Gregor









From magnus@thinkware.se  Thu Oct  3 11:25:09 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu, 03 Oct 2002 12:25:09 +0200
Subject: [Tutor] linux book
In-Reply-To: <F197Ej9YUMLdo4qt6V90000ebe4@hotmail.com>
Message-ID: <5.1.0.14.0.20021003121547.02a0d9f8@www.thinkware.se>

At 13:51 2002-10-02 -0500, Cameron Stoner wrote:
>What would be a good Linux Book on the GUI?

Which GUI?

There are only two dedicated python GUI books as
far as I know:
http://www.manning.com/Grayson/
Python and Tkinter Programming

http://www.opendocspublishing.com/
GUI Programming with Python: QT Edition

There is talk of a wxPython book, but it's not on
the radar yet I think.

Some other books discuss GUI:
Python Programming on Win 32 (good book!) discussess several
Programming Python, 2nd Edition discusses Tkinter
As someone mention a while ago, Magnus Lie-Hetlands
book covers AnyGUI.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From alan.gauld@bt.com  Thu Oct  3 11:32:24 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 3 Oct 2002 11:32:24 +0100
Subject: [Tutor] binary trees/ linked lists
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C924@mbtlipnt02.btlabs.bt.co.uk>

> Is there anything like a linked list

A Python list is like a linked list....

> binary tree 

You have to do that yourself. Either using a list or 
dictionary or by creating node classes...

Lutz describes the process in his book 
Programming Python (1st Ed.)

There's rarely any need for a true linked list in Python, 
since the built in list does it all for you however trees 
can be useful.

Some tree pseudocode:

class Node:
   def __init__(self,data,ltree=None,rtree=None)
      self.data = data
      self.ltree = ltree
      self.rtree = rtree

   def add(self,node):
      if cmp(node.data,self.data) <= 0: 
         if self.ltree: self.rtree.add(node)
         else self.ltree = node
	else:
         if self.ltree: self.ltree.add(node)
         else self.ltree = node      

   def find(self,data):
      if self.data == data: return self
      elif data <= self.data: 
           if self.rtree: return self.rtree.find(data)
           else: return None
      else:
           if self.ltree: return self.ltree.find(data)
           else: return None

root = Node(5)
root.add(Node(2))
root.add(Node(1))
root.add(Node(7))
print root.find(5)
print root.find(7)

Something like that...

Alan g.


From alan.gauld@bt.com  Thu Oct  3 11:37:03 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 3 Oct 2002 11:37:03 +0100
Subject: [Tutor] linux book
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C925@mbtlipnt02.btlabs.bt.co.uk>

> What would be a good Linux Book on the GUI?

Which GUI? And what do you want to know? 
How to program it or how top use it?

Generic X Windows? - The O'Reilly series is very comprehensive
with both programming and user guides.

GNOME/GT/K - There are a couple, I think Coriolis(sp?) do one
KDE/Qt - Wrox press do a couple

Then there are the other toolkits like wxWindows, Tk, 
Lesstiff, Interviews, etc etc.

Depends what you want.

Alan g.


From alan.gauld@bt.com  Thu Oct  3 11:42:35 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 3 Oct 2002 11:42:35 +0100
Subject: [Tutor] Making .py script into an .exe program.
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C926@mbtlipnt02.btlabs.bt.co.uk>

> share it with my friends who use the Windows OS.  I am using 
> Linux myself.
> 
> I realize I can just have them download the Python 
> interpreter and Tkinter, but is there a way to create 
> an .exe from my Python script 

Yes, you can use py2exe.
It simply bundles up the interoreter and other bits you 
need into a big exe file, but it looks like its a real 
exe to most users... Snag is you wind up with a lot of 
copies of python loaded if you do it often!


Or you can simply create a batch file that runs the python 
installer followed by copying your script into the library.

I prefer the second course personally since its easier to 
install subsequent programs. If they have a modern HP PC 
I believe python is already installed since HP are using 
python for their admin tools...

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


From alan.gauld@bt.com  Thu Oct  3 11:46:49 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 3 Oct 2002 11:46:49 +0100
Subject: [Tutor] finding a non-letter?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C928@mbtlipnt02.btlabs.bt.co.uk>

> if text[0] in string.digits:

OOPS! I said string.numbers, it is indeed string.digits...

sorry,

Alan G.


From alan.gauld@bt.com  Thu Oct  3 11:45:53 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 3 Oct 2002 11:45:53 +0100
Subject: [Tutor] finding a non-letter?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C927@mbtlipnt02.btlabs.bt.co.uk>

> str[0], but how would test to see if it's a non-letter?

import string
if str[0] not in string.letters: # do whatever


OR

if str[0] in string.numbers: # do it

the first tests any non letter(punctuation etc)the 
second is specifically for numbers.

try

dir(string)

to see the other predefined collections.

HTH

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


From faithless_nw@yahoo.com  Thu Oct  3 12:08:51 2002
From: faithless_nw@yahoo.com (Alexander Joukov)
Date: Thu, 3 Oct 2002 04:08:51 -0700 (PDT)
Subject: [Tutor] dll problem
Message-ID: <20021003110851.55320.qmail@web40807.mail.yahoo.com>

Hello!
i tried to solve the problem myself for a while now, i
guess the lack of knowlege and experience is obvious.
So i desperately need some help on the following:
i use python 2.2.1 for windows and Installer version
5, alpha 1. i have converted several scripts into
stand-alones no problem, but whenever i try to add
"--noconsole" option, the file is created, but when i
try to start it, i get fatal errors : "ERROR LOADING
PYTHON DLL." and then "c:\windows\temp\python22.dll"

Thanx

Alex


__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com


From fgranger@altern.org  Thu Oct  3 13:59:20 2002
From: fgranger@altern.org (Francois Granger)
Date: Thu, 03 Oct 2002 14:59:20 +0200
Subject: [Tutor] execute file at startup
In-Reply-To: <3D9C0BB7.3070303@aon.at>
Message-ID: <B9C20BC8.58069%fgranger@altern.org>

on 3/10/02 11:19, Gregor Lingl at glingl@aon.at wrote:

> More specifically:
> I'd like to have a specific function
> already defined (in the main namespace)
> after startup, regardless of using IDLE
> or the commandline interpreter.
>=20
> How do I have to proceed?

http://python.org/doc/current/tut/node4.html#SECTION004230000000000000000

--=20
Le courrier =E9lectronique 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://minilien.com/?IXZneLoID0




From magnus@thinkware.se  Thu Oct  3 16:21:19 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu, 03 Oct 2002 17:21:19 +0200
Subject: [Tutor] binary trees/ linked lists
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C924@mbtlipnt02.btlabs
 .bt.co.uk>
Message-ID: <5.1.0.14.0.20021003125836.029ef9f8@www.thinkware.se>

At 11:32 2002-10-03 +0100, alan.gauld@bt.com wrote:
> > Is there anything like a linked list
>
>A Python list is like a linked list....

Not really...

I'd say a python list is like a vector in C++
etc. It's not implemented as a linked list,
and it neither has the interface, nor the
timing characteristics you would expect from
a linked list.

In a linked list you reach a certain element
by traversal. Each element points to the next.
Lists can be double-linked (also having a
pointer to the previous), and then it might
be as fast to find the last element as the
first, but to find an element in the middle,
you need to walk through a lot of elements.

A vector finds each element, given it's index
as a simple offset from a base adress. Fetching
any element is equally fast.

In python, fetching any element from a list is
equally fast, regardless of position.

A linked list is, on the other hand, very fast
for inserting new elements anywhere. You just
have to change the pointers in the immediate
vicinity.

In a vector, it's quick to append an element to
the end, but if you insert it in the beginning,
you have to move all the other elements, which
is slow.

With a big python list, .append(0) is much, much
faster than .insert(0,0)



--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From alan.gauld@bt.com  Thu Oct  3 16:34:20 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 3 Oct 2002 16:34:20 +0100
Subject: [Tutor] binary trees/ linked lists
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C92E@mbtlipnt02.btlabs.bt.co.uk>

> >A Python list is like a linked list....
> 
> Not really...
> 
> I'd say a python list is like a vector in C++
> etc. It's not implemented as a linked list,
> and it neither has the interface, nor the
> timing characteristics you would expect from
> a linked list.

OK, I just meant that everywhere you use a linked 
list you could use a Python list! ie you can grow 
them dynamically, insert in the middle, find 
elements, traverse in either direction etc.

The internal implementation is something I encourage 
people not to think about. If I want to do that I 
can work in C++!! :-)

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


From dyoo@hkn.eecs.berkeley.edu  Thu Oct  3 20:11:17 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 3 Oct 2002 12:11:17 -0700 (PDT)
Subject: [Tutor] complex file parsing
In-Reply-To: <20020925011118.GA26676@isis.visi.com>
Message-ID: <Pine.LNX.4.44.0209242246420.14322-100000@hkn.eecs.berkeley.edu>


On Tue, 24 Sep 2002, Tim Wilson wrote:

> I'm wondering if some of the experts on this list have some advise
> regarding more complex parsing of files. Here's the scenario: I'm a
> Ph.D. student in eduation, specifically Instructional Systems and
> Technology. I'm taking a class right now where we are supposed to survey
> the literature in our field and find trends, summarize what sort of work
> is being done, etc. Being a geek I naturally gravitate toward automation
> for tasks like this. :-)

Hi Tim,

There's a project out there called 'pybliographer' that might be useful
for you:

    http://canvas.gnome.org:65348/pybliographer/

It looks like they canceled support for Endnote, though I haven't dug
deeply enough to find out why yet.


At an initial glance, it looks like regular expressions would be useful to
parse the records.  Has anyone replied back to you about using regular
expressions on your problem yet?



From magnus@thinkware.se  Thu Oct  3 20:54:12 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu, 03 Oct 2002 21:54:12 +0200
Subject: [Tutor] binary trees/ linked lists
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C92E@mbtlipnt02.btlabs
 .bt.co.uk>
Message-ID: <5.1.0.14.0.20021003212114.029db830@www.thinkware.se>

At 16:34 2002-10-03 +0100, alan.gauld@bt.com wrote:
>OK, I just meant that everywhere you use a linked
>list you could use a Python list! ie you can grow
>them dynamically, insert in the middle, find
>elements, traverse in either direction etc.
>
>The internal implementation is something I encourage
>people not to think about. If I want to do that I
>can work in C++!! :-)

Agreed!

The problem occurs if you have big lists and high
performance requirements. As I mentioned, they have
different sweet spots and bottle necks. In 99% of
the cases it doesn't matter, but sometimes there is
a huge difference in how Python lists behave compared
to a linked list. E.g.

 >>> from time import clock as t
 >>> def measure(f, n):
...     start =3D t()
...     for i in range(n): f()
...     return t() - start
...
 >>> def addFirst():
...     l.insert(0,0)
...
 >>> def addLast():
...     l.append(0)
...
 >>> l =3D range(1000)
 >>> measure(addFirst, 100)/measure(addLast, 100)
2.4258241758658317
 >>> l =3D range(10000)
 >>> measure(addFirst, 100)/measure(addLast, 100)
89.448554134709681
 >>> l =3D range(100000)
 >>> measure(addFirst, 100)/measure(addLast, 100)
469.85452162937037
 >>> l =3D range(1000000)
 >>> measure(addFirst, 100)/measure(addLast, 100)
4732.36800513662

For a real linked list, there would not be any
difference if we added an element in the beginning
or the end of the list.

On the other hand, it would take proportional to
the length of the list to find the right place
to insert data if we for instance want to insert
data in sorted order.

Then a BTree would be much better--and there are
(as I wrote) BTrees for Python in ZODB.

The algorithms themselves are really rather
uninteresting in real life. You never really
need a linked list unless someone tells you to
show a linked list.

You might need a stack, or a queue, or a priority
queue or a set. These are data collections with
various practical qualities. A linked list is really
just a means to achieving something like that.

Since deleting and adding in the "bottom" of a
python list is equally bad, a queue implemented
with a python list, while trivial to implement,
will scale badly. A linked list would be a better
basis for implementing a queue.

But who cares? Python has a queue module in its
standard lib...

import Queue
help(Queue)

While we'll probably make better software from
the start the more we know about technical details
and libraries, python programs are typically simple
to modify.

So, by all means, start out with a list whether
it's the optimal data type or not. Chances are good
that the bottleneck will be somewhere else, and if
you made your application more complex to avoid a
non-existent performance problem, you have just
wasted time and made software maintenance more
costly.

The trivial queue is built like this:

 >>> class Q(list):
...     def push(self, x):
...             self.insert(0, x)
...
 >>> q =3D Q()
 >>> q.push(3)
 >>> q.push('A')
 >>> q.push('Z')
 >>> print q
['Z', 'A', 3]
 >>> q.pop()
3
 >>> q.pop()
'A'
 >>> q.pop()
'Z'
 >>> q.pop()
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
IndexError: pop from empty list

This will work well for small queues/FIFOs. But as
you noticed in the benchmarking above, it will start
to get slow with many thousands of elements...


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From dyoo@hkn.eecs.berkeley.edu  Fri Oct  4 00:08:51 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 3 Oct 2002 16:08:51 -0700 (PDT)
Subject: [Tutor] help How do I use a program I built in linux (fwd)
Message-ID: <Pine.LNX.4.44.0210031552340.18829-100000@hkn.eecs.berkeley.edu>

Hi Danny,

Please send replies to tutor@python.org, and not me directly:  By sending
just to me, you may get a hasty or unreliable answer, without someone
jumping in to give correction.


But if you send to the Tutor@python.org address, other people can share
their knowledge with you.  At least, then, there's a checks-and-balances
thing going on that tries to ensure swift chastisement on inadequate
answers...  *grin*

I'll forward your message to Tutor for you.  I'll try taking a look at
your question when I have more time.

Sincerely,
Danny Yoo



---------- Forwarded message ----------
Date: Thu, 03 Oct 2002 16:27:34 -0600
From: Peter Dudleston <dandudle@msn.com>
To: dyoo@hkn.eecs.berkeley.edu
Subject: Re: [Tutor] help How do I use a program I built in linux

Hi Danny

I was wondering do all the files I save have to be in my home directory...
I figured out how to run the programs, but if I make a new directory for
my programs... I type the path of the file for example python begpython
now.py...  I try to run it like that in the shell and no error pops up but
it just goes to the next line how do I set up a pointer or something of
that nature... So I can run a program in a separate so my home directory
doesn't look so cluttered.... Thanks for all your help and hope to talk to
you soon.

Sincerely Danny D


>From: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
>To: Peter Dudleston <dandudle@msn.com>
>CC: Tutor <tutor@python.org>
>Subject: Re: [Tutor] help How do I use a program I built in linux
>Date: Tue, 1 Oct 2002 11:06:47 -0700 (PDT)
>
>
>
>On Mon, 30 Sep 2002, Peter Dudleston wrote:
>
> > I have decided to join the linux revolution and I need some help I have
> > python2.2 pre-installed with this version of linux "mandrake" and I was
> > wondering what do I type at the shell to run my programs do I need to
> > make a new directory because no matter what I change the directory to I
> > can't run my programs for example I have one called now which just tells
> > you the time and I saved it as now.py and I can't get it to run no
> > matter what it says that the command doesn't exist does anyone have
> > anything they can tell me "keep in mind I'm a very newbie to this
> > envirment" so if you could explain it in lame mans terms I would really
> > appreciate it thanks for all you help everyone and talk to you all soon
>
>Hi Danny (or Peter?),
>
>
>Breathe --- you're going way too fast for me!  *grin* Forgive me; perhaps
>I'm being just picky, but I really like punctuated sentences.  Please put
>some breaks so we can pick out your main questions easily.
>
>
> > I was wondering what do I type at the shell to run my programs
>
>Try something like:
>
>###
>$ python [name_of_the_script.py]
>###
>
>at the shell prompt of your system.  For example, if we had a program
>called 'hello.py', we can run it on a Linux system with the following
>command:
>
>###
>$ python hello.py
>###
>
>
>
> > I have one called now which just tells you the time and I saved it as
> > now.py
> >
> > I can't get it to run no matter what
> >
> > it says that the command doesn't exist
>
>One thing that we've found is that natural language is vague, despite our
>best intentions.  Paraphrasing what's happening is good, and it's often
>more helpful to add to that description with a cut-and-paste of the exact
>error message; even ugly error messages may provide clues that we can
>tease out.
>
>Can you show us exactly what you're typing at the prompt, and how your
>system is responding?




_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com




From kalle@lysator.liu.se  Fri Oct  4 00:58:44 2002
From: kalle@lysator.liu.se (Kalle Svensson)
Date: Fri, 4 Oct 2002 01:58:44 +0200
Subject: [Tutor] help How do I use a program I built in linux (fwd)
In-Reply-To: <Pine.LNX.4.44.0210031552340.18829-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.44.0210031552340.18829-100000@hkn.eecs.berkeley.edu>
Message-ID: <20021003235844.GC4363@i92.ryd.student.liu.se>

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

[Danny Dudleston]
> I was wondering do all the files I save have to be in my home directory...
> I figured out how to run the programs, but if I make a new directory for
> my programs... I type the path of the file for example python begpython
> now.py...  I try to run it like that in the shell and no error pops up but
> it just goes to the next line how do I set up a pointer or something of
> that nature... So I can run a program in a separate so my home directory
> doesn't look so cluttered.... Thanks for all your help and hope to talk to
> you soon.

If you could provide us with more information, like the contents of
now.py, the exact command you type to execute the program and the path
to the direcory where it is located, it would be easier to help you.

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/>

iD8DBQE9nNmedNeA1787sd0RAjW5AJ0coJPd+YLhStgqv7AeZPLyxlb6AwCgrfgG
P3CqhQ5k19aoDOhE0R8Q0MM=
=ydBV
-----END PGP SIGNATURE-----


From cmhowe@patriot.net  Fri Oct  4 09:02:40 2002
From: cmhowe@patriot.net (Charles M Howe)
Date: Fri, 04 Oct 2002 04:02:40 -0400
Subject: [Tutor] Python DNS Cache 0.1.0
Message-ID: <3D9D4B20.7C204585@patriot.net>

FWIW, there is an announcement on Freshmeat (freshmeat.net) for the
above. It says: "About: PyDNSCache is a thread-safe DNS cache module for
Python, for use with network daemins and any other applications that use
resolver functions for redundant hostnames." It is freeware.

Charles M Howe




From dyoo@hkn.eecs.berkeley.edu  Fri Oct  4 09:36:51 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 4 Oct 2002 01:36:51 -0700 (PDT)
Subject: [Tutor] help How do I use a program I built in linux (fwd)
In-Reply-To: <Pine.LNX.4.44.0210031552340.18829-100000@hkn.eecs.berkeley.edu>
Message-ID: <Pine.LNX.4.44.0210040115330.6632-100000@hkn.eecs.berkeley.edu>


> I was wondering do all the files I save have to be in my home directory...

Hi Danny,

Python programs can pretty much be located anywhere; as long as Linux
knows where to look for Python, it can run your programs.  Your question
is really more about how Linux works, so you might want to look through a
book on using Linux.

Let me give you a few links that might help: the Gentoo folks have a good
collection of tutorials here:

    http://gentoo.org/index-articles.html

and the Linux Documentation Project is also invaluable; they have several
different tutorials on understanding the Linux environment:

    http://www.tldp.org/

Finally, Eric Raymond has been writing a book called "The Art of Unix
Programming"  that tries to sum up the key points of understanding how
pieces fit together; it might be worth a look:

    http://www.tuxedo.org/~esr/writings/taoup/

Ok, enough links.  *grin*




Most of the main commands in Linux are located in a directory called
'/usr/bin/'.  These binaries are all collected in a single place, to make
it fairly convenient for Linux to find the right command whenever we enter
something at the shell.

If things are set up right, no matter where we are, Linux should know.
For example:

###
dyoo@coffeetable:~$ python
Python 2.2.1 (#2, Sep 13 2002, 23:25:07)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>


dyoo@coffeetable:~$ cd /tmp
dyoo@coffeetable:/tmp$ python
Python 2.2.1 (#2, Sep 13 2002, 23:25:07)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>


dyoo@coffeetable:/tmp$ cd /usr/bin
dyoo@coffeetable:/usr/bin$ ls -l python
lrwxrwxrwx    1 root     root            9 Sep 19 08:10 python ->
python2.2


dyoo@coffeetable:/usr/bin$ which python
/usr/bin/python
###

So anything in /usr/bin is immediately available to you, anywhere in your
directory structure, just as long as your setup is normal.



> I figured out how to run the programs, but if I make a new directory for
> my programs... I type the path of the file for example python begpython
> now.py...  I try to run it like that in the shell and no error pops up
> but it just goes to the next line

Can you cut and paste what you typed, and how the system responded?
That'll give us a better to as to what happened.  Also, please show us
what 'now.py' looks like.  Don't worry, we don't mind looking at source
code, just as long as it isn't too long.

It might seem like a lot of unnecessary cut-and-pasting, but we have good
reasons for asking for these details: we want to repeat the exact steps
that you're taking.  If we can't duplicate what you're running into on our
own machines, then we may tell you something completely bogus without
understanding your situation.  That's why we ask for so much.


> how do I set up a pointer or something of that nature... So I can run a
> program in a separate so my home directory doesn't look so cluttered....

Here's an concrete example of running Python programs in different
directories.  Let's say that I'm in my home directory, and that I have a
program called 'bobs_puzzle.py' that I can run:

###
dyoo@coffeetable:~$ cd ~

dyoo@coffeetable:~$ ls -l bobs_puzzle.py
-rw-r--r--    1 dyoo     dyoo         3358 Sep 22 01:28 bobs_puzzle.py

dyoo@coffeetable:~$ python bobs_puzzle.py
39662
###


If we move 'bobs_puzzle.py' off to another directory, we should still be
able to run it:

###
dyoo@coffeetable:~$ mkdir source_code

dyoo@coffeetable:~$ mv bobs_puzzle.py source_code/

dyoo@coffeetable:~$ ls -l bobs_puzzle.py
ls: bobs_puzzle.py: No such file or directory

dyoo@coffeetable:~$ ls -l source_code/bobs_puzzle.py
-rw-r--r--    1 dyoo     dyoo         3358 Sep 22 01:28
source_code/bobs_puzzle.py

dyoo@coffeetable:~$ python source_code/bobs_puzzle.py
39662

dyoo@coffeetable:~$ cd source_code/
dyoo@coffeetable:~/source_code$ python bobs_puzzle.py
39662
###

It shouldn't really matter where we are, just as long as we give Python
the right place where our program file lives.


Please feel free to ask more questions, but don't forget to tell us more
details.  Good luck!



From slime@vsnl.net  Thu Oct  3 16:47:51 2002
From: slime@vsnl.net (Prahlad Vaidyanathan)
Date: Thu, 3 Oct 2002 21:17:51 +0530
Subject: [Tutor] Re:  binary trees/ linked lists
In-Reply-To: <F144PasSmz6UuEhjJ8u000004f3@hotmail.com>
References: <F144PasSmz6UuEhjJ8u000004f3@hotmail.com>
Message-ID: <20021003154751.GA3072@localhost.localdomain>

Hi,

On Wed, 02 Oct 2002 Cameron Stoner spaked thusly :
> Hi folks,
> 
> Is there anything like a linked list or binary tree that can be made in 
> Python?
> Thanks,

    I've written a simple module that you might want to take a
look at :

    http://www.symonds.net/~prahladv/files/stack.py

HTH,

pv.
-- 
Prahlad Vaidyanathan  <http://www.symonds.net/~prahladv/>

If you think before you speak the other guy gets his joke in first.


From alan.gauld@bt.com  Fri Oct  4 17:14:26 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 4 Oct 2002 17:14:26 +0100
Subject: [Tutor] help How do I use a program I built in linux (fwd)
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C938@mbtlipnt02.btlabs.bt.co.uk>

> > I figured out how to run the programs, but if I make a new 
> > directory for my programs... I type the path of the file 
> > for example python begpythonnow.py...  

One thing about Unix(including Linux) is that you don't 
need the python at the front provided you start tyour 
script with the "shebang trick"

That means that you put the following magic line at the start:

#! /bin/env python
# rest of script foo.py here....

Save the file and change it to be executable:

$ chmod +x foo.py

And then you can run your file directly by just typing 

$ foo.py

( Or double clicking in a file explorer GUI application. )

You can still type

$ python <path to foo>/foo.py

if you want to but its easier to just type:

$<path to foo>/foo.py

HTH,

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


From wolf_binary@hotmail.com  Fri Oct  4 22:23:18 2002
From: wolf_binary@hotmail.com (CameronStoner)
Date: Fri, 4 Oct 2002 14:23:18 -0700
Subject: [Tutor] binary trees/ linked lists
Message-ID: <DAV30s9VarAqZT8ORFA0000aa3c@hotmail.com>

This is a multi-part message in MIME format.

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

>Python is often used in combination with other
>programming languages such as C++. The proportions
>might vary from writing all in Python except a
>routine that became a bottleneck until replaced
>with C++ code, to systems that are complete C++
>applications, with a Python interpreter embedded
>to provide a macro facility.

I have thought about doing this, but I have no idea really where you'd =
start
in embedding the interpreter into the game.  I would very much like to
pursue this idea, but thought it was to much to handle right now.

Thanks,

Cameron Stoner


------=_NextPart_000_003C_01C26BB1.95899380
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.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2><FONT face=3D"Times New Roman" =
size=3D3>&gt;Python is=20
often used in combination with other<BR>&gt;programming languages such =
as C++.=20
The proportions<BR>&gt;might vary from writing all in Python except=20
a<BR>&gt;routine that became a bottleneck until replaced<BR>&gt;with C++ =
code,=20
to systems that are complete C++<BR>&gt;applications, with a Python =
interpreter=20
embedded<BR>&gt;to provide a macro facility.<BR><BR>I have thought about =
doing=20
this, but I have no idea really where you'd start<BR>in embedding the=20
interpreter into the game.&nbsp; I would very much like to<BR>pursue =
this idea,=20
but thought it was to much to handle right =
now.<BR><BR>Thanks,<BR><BR>Cameron=20
Stoner</FONT><BR></FONT></DIV></BODY></HTML>

------=_NextPart_000_003C_01C26BB1.95899380--


From dyoo@hkn.eecs.berkeley.edu  Fri Oct  4 21:08:14 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 4 Oct 2002 13:08:14 -0700 (PDT)
Subject: [Tutor] A genomic sequence generator?
Message-ID: <Pine.LNX.4.44.0210031347450.18829-100000@hkn.eecs.berkeley.edu>

Hi everyone,

I just ran into an puzzle that I thought might be interesting to folks
here.  Here's the problem:


   """Genomic Sequence Generator:

      Given a pattern like AT<GC>A<TA>, produce the strings ATGAT, ATGAA,
      ATCAT, ATCAA.
   """

I shamelessly copied this from M-J. Dominus's hilarious talk on Conference
Presentation Judo:

    http://perl.plover.com/yak/judo/presentation/slide019.html)


This might be a nice puzzle for Useless Python.



From magnus@thinkware.se  Sat Oct  5 01:12:35 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat, 05 Oct 2002 02:12:35 +0200
Subject: [Tutor] A genomic sequence generator?
In-Reply-To: <Pine.LNX.4.44.0210031347450.18829-100000@hkn.eecs.berkeley
 .edu>
Message-ID: <5.1.0.14.0.20021005021107.029faec0@www.thinkware.se>

At 13:08 2002-10-04 -0700, Danny Yoo wrote:
>Hi everyone,
>
>I just ran into an puzzle that I thought might be interesting to folks
>here.  Here's the problem:
>
>
>    """Genomic Sequence Generator:
>
>       Given a pattern like AT<GC>A<TA>, produce the strings ATGAT, ATGAA,
>       ATCAT, ATCAA.
>    """
>
>I shamelessly copied this from M-J. Dominus's hilarious talk on Conference
>Presentation Judo:
>
>     http://perl.plover.com/yak/judo/presentation/slide019.html)
>
>
>This might be a nice puzzle for Useless Python.


# genomic.py

genom = "AT<GC>A<TA>"
result = []

def makeGenes(rest, soFar, result):
     if not rest:
         result.append("".join(soFar))
         return
     char = rest.pop(0)
     if char == '<':
         char = rest.pop(0)
         while char != '>':
             makeGenes(rest[rest.index('>')+1:], soFar+[char], result)
             char = rest.pop(0)
     else:
         makeGenes(rest[:], soFar+[char], result)

print makeGenes(list(genom), [], result)
for gene in result: print gene



-- 
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 reavey@nep.net  Sat Oct  5 09:04:37 2002
From: reavey@nep.net (reavey)
Date: 05 Oct 2002 04:04:37 -0400
Subject: [Tutor] if
Message-ID: <1033805083.27810.9.camel@localhost.localdomain>

>>>a = 11
>>>b = 11
>>>if a==b

get a syntax error , b as a string?

I have done a type(a) and type(b) both are int. class


I've tried different test operations <,>,!=
nothing works

the above is a simplified version of a program I found at
http://www.devshed.com/Server_Side/python/python101
part two of wishes were Pythons on page 9
Thanks
Mike Re-v




From rob@uselesspython.com  Sat Oct  5 13:46:06 2002
From: rob@uselesspython.com (Rob)
Date: Sat, 5 Oct 2002 07:46:06 -0500
Subject: [Tutor] if
In-Reply-To: <1033805083.27810.9.camel@localhost.localdomain>
Message-ID: <MPEOIFCOPCIHEDCLBLPBIEHNCHAA.rob@uselesspython.com>

>>> a = 11
>>> b = 11
>>> if a==b:
	print 'a==b'


a==b
>>>

I haven't seen the rest of your code, or your syntax error, but here's a
working model. Perhaps you left off the : at the end of the *if* statement.

Rob
http://uselesspython.com

> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> reavey
> Sent: Saturday, October 05, 2002 3:05 AM
> To: tutor@python.org
> Subject: [Tutor] if
>
>
> >>>a = 11
> >>>b = 11
> >>>if a==b
>
> get a syntax error , b as a string?
>
> I have done a type(a) and type(b) both are int. class
>
>
> I've tried different test operations <,>,!=
> nothing works
>
> the above is a simplified version of a program I found at
> http://www.devshed.com/Server_Side/python/python101
> part two of wishes were Pythons on page 9
> Thanks
> Mike Re-v
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>




From lbrannma@cablespeed.com  Sat Oct  5 17:30:59 2002
From: lbrannma@cablespeed.com (Lance)
Date: Sat, 5 Oct 2002 09:30:59 -0700
Subject: [Tutor] clearing screen?
Message-ID: <001201c26c8c$96749840$3212eb42@MYNEWBOX>

This is a multi-part message in MIME format.

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

Hi,

I run programs in Idle from an Edit window. What command can I use at =
the top of my program in the Edit window to clear the IDLE output =
screen?

Thanks in advance,
Lance
------=_NextPart_000_000F_01C26C51.E9FA4900
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>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I run programs in Idle from an Edit =
window. What=20
command can I use at the top of my program in the Edit window to clear=20
the&nbsp;IDLE output screen?</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>Lance</FONT></DIV></BODY></HTML>

------=_NextPart_000_000F_01C26C51.E9FA4900--




From Jmllr891@cs.com  Sat Oct  5 17:43:00 2002
From: Jmllr891@cs.com (Jmllr891@cs.com)
Date: Sat, 5 Oct 2002 12:43:00 EDT
Subject: [Tutor] need help with urllib
Message-ID: <a2.2cfda600.2ad07094@cs.com>

--part1_a2.2cfda600.2ad07094_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

I've recently been trying to write a script that will download images off the 
web for me (say a daily comic strip or something of that sort).

The script works perfectly fine, it downloads the image and produces no 
errors. But the image is always corrupt or something. No matter what I try to 
view it in (even a web browser) it can't be displayed.

This is my code (this one downloads the Python logo):
---------------------------------
import urllib

image = URLopener()
image.retrieve('http://www.python.org/pics/', 'pythonHi.gif')
---------------------------------

What could be wrong? My internet connection maybe?

--part1_a2.2cfda600.2ad07094_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

<HTML><FONT FACE=arial,helvetica><FONT  SIZE=2 FAMILY="FIXED" FACE="Courier New" LANG="0">I've recently been trying to write a script that will download images off the web for me (say a daily comic strip or something of that sort).<BR>
<BR>
The script works perfectly fine, it downloads the image and produces no errors. But the image is always corrupt or something. No matter what I try to view it in (even a web browser) it can't be displayed.<BR>
<BR>
This is my code (this one downloads the Python logo):<BR>
---------------------------------<BR>
import urllib<BR>
<BR>
image = URLopener()<BR>
image.retrieve('http://www.python.org/pics/', 'pythonHi.gif')<BR>
---------------------------------<BR>
<BR>
What could be wrong? My internet connection maybe?</FONT></HTML>

--part1_a2.2cfda600.2ad07094_boundary--


From Andrew <angelopoulos@csi.com>  Sat Oct  5 18:31:55 2002
From: Andrew <angelopoulos@csi.com> (Andrew)
Date: Sat, 5 Oct 2002 13:31:55 -0400
Subject: [Tutor] need help with urllib
In-Reply-To: <a2.2cfda600.2ad07094@cs.com>
References: <a2.2cfda600.2ad07094@cs.com>
Message-ID: <94101395830.20021005133155@csi.com>

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

Hi Jmllr891,

   New to python myself, been lurking here the past week... tried
what
   you tried without a problem from idle. The only difference I see
is
   that I explicitly list the file I wanted and gave it a new local
   name.

   import urllib
   loc = urllib.URLopener()
   loc.retrieve("http://i.dslr.net/avatars/418397.gif", "junk.gif")
   ('junk.gif', <mimetools.Message instance at 0x00F144B0>)

   It created the .gif without a problem in my python dir.

   When I tried it without the filename I got this:
   Traceback (most recent call last):
   File "<pyshell#14>", line 1, in ?
   lox.retrieve("http://i.dslr.net/avatars/", "418397.gif")
   File "D:\PYTHON22\lib\urllib.py", line 210, in retrieve
   fp = self.open(url, data)
   File "D:\PYTHON22\lib\urllib.py", line 178, in open
   return getattr(self, name)(url)
   File "D:\PYTHON22\lib\urllib.py", line 301, in open_http
   return self.http_error(url, fp, errcode, errmsg, headers)
   File "D:\PYTHON22\lib\urllib.py", line 318, in http_error
   return self.http_error_default(url, fp, errcode, errmsg, headers)
   File "D:\PYTHON22\lib\urllib.py", line 324, in http_error_default
   raise IOError, ('http error', errcode, errmsg, headers)
   IOError: ('http error', 404, 'Not Found', <mimetools.Message
instance at 0x01269F10>)

   You catching the exception and maybe doing something with it?

   (btw, me: Python 2.2, Win98 SE, Netscape7)

- -- Andrew
mailto:angelopoulos@csi.com


- --
Saturday, October 5, 2002, 12:43:00 PM, you wrote:


Jcc> I've recently been trying to write a script that will download
images off the
Jcc> web for me (say a daily comic strip or something of that sort).

Jcc> The script works perfectly fine, it downloads the image and
produces no
Jcc> errors. But the image is always corrupt or something. No matter
what I try to
Jcc> view it in (even a web browser) it can't be displayed.

Jcc> This is my code (this one downloads the Python logo):
Jcc> ---------------------------------
Jcc> import urllib

Jcc> image = URLopener()
Jcc> image.retrieve('http://www.python.org/pics/', 'pythonHi.gif')
Jcc> ---------------------------------

Jcc> What could be wrong? My internet connection maybe?

-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5i
Comment: It isn't so strange. You put your mail in envelopes, no?

iQA/AwUBPZ8iE8SLfgHZWt7tEQL09QCgi1mu7kEj/3l7ODulTOTrn8Ys3NIAoMVy
z+K6zRPTSbJRGuYBmUvFQfl+
=cmYF
-----END PGP SIGNATURE-----



From magnus@thinkware.se  Sat Oct  5 22:30:21 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat, 05 Oct 2002 23:30:21 +0200
Subject: [Tutor] clearing screen?
In-Reply-To: <001201c26c8c$96749840$3212eb42@MYNEWBOX>
Message-ID: <5.1.0.14.0.20021005232449.028f4f98@www.thinkware.se>

At 09:30 2002-10-05 -0700, Lance wrote:
>Hi,
>
>I run programs in Idle from an Edit window. What command can I use at the=
=20
>top of my program in the Edit window to clear the IDLE output screen?

I don't know if you can... The easy way
is to close the Python Shell window manually.
IDLE will then start a new window which is
empty.




--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Sat Oct  5 22:45:52 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat, 05 Oct 2002 23:45:52 +0200
Subject: [Tutor] need help with urllib
In-Reply-To: <a2.2cfda600.2ad07094@cs.com>
Message-ID: <5.1.0.14.0.20021005234043.0290ab18@www.thinkware.se>

At 12:43 2002-10-05 -0400, Jmllr891@cs.com wrote:
>I've recently been trying to write a script that will download images off 
>the web for me (say a daily comic strip or something of that sort).
>
>The script works perfectly fine, it downloads the image and produces no 
>errors. But the image is always corrupt or something. No matter what I try 
>to view it in (even a web browser) it can't be displayed.

Did you try renaming it to something.txt before opening it?

>This is my code (this one downloads the Python logo):

No, it doesn't. ;)

>import urllib
>
>image = URLopener()
>image.retrieve('http://www.python.org/pics/', 'pythonHi.gif')

Read The Fine Manual: URLopener.retrieve(url[,filename[...]])
Retrieves the content of url (a directory listing, or error
message in this case) and places it in file name.


-- 
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 Oct  5 23:31:03 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sun, 06 Oct 2002 00:31:03 +0200
Subject: [Tutor] A genomic sequence generator?
In-Reply-To: <5.1.0.14.0.20021005021107.029faec0@www.thinkware.se>
References: <Pine.LNX.4.44.0210031347450.18829-100000@hkn.eecs.berkeley .edu>
Message-ID: <5.1.0.14.0.20021006003022.029d57c0@www.thinkware.se>

Iterative version.

# genomic2.py

genom = "AT<GC>A<TA>"

def makeGenes(rest):
     results = [""]
     while rest:
         chunk, rest = rest.split('<',1)
         for i in range(len(results)):
             results[i] = results[i]+chunk
         variants, rest = rest.split('>',1)
         newResults = []
         for char in variants:
             for each in results:
                 newResults.append(each+char)
         results = newResults
     for each in results:
         print each

makeGenes(genom)



-- 
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 Oct  6 05:45:12 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat, 5 Oct 2002 21:45:12 -0700 (PDT)
Subject: [Tutor] A genomic sequence generator?
In-Reply-To: <5.1.0.14.0.20021006003022.029d57c0@www.thinkware.se>
Message-ID: <Pine.LNX.4.44.0210052138150.30561-100000@hkn.eecs.berkeley.edu>

Hi everyone,

I've written another way of doing the genomic sequence generator that
uses... well... generators.  *grin* But I'm a bit ashamed because I know
it's more complicated than it needs to be.  I wonder how to simplify it!


Here's it is:

######
"""An iterator and generator approach to the genomic sequence
generator described in:

    http://mail.python.org/pipermail/tutor/2002-October/017690.html

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

from __future__ import nested_scopes
from __future__ import generators

import re


def genomic_sequence_generator(sequence):
    """Given a sequence like "AT<GC>A<TA>", returns an iterator that
    produces all possible values where the bracketed values vary."""
    tokens = tokenize(sequence)
    generator = SingleIterator("")
    for t in tokens:
        if t.startswith('<'):
            generator = PairSummingIterator(generator,
                                            GroupIterator(t[1:-1]))
        else:
            generator = PairSummingIterator(generator,
                                            SingleIterator(t))
    return generator


######################################################################

def tokenize(sequence):
    """Given a string like "AT<GC>A<TA>", splits it into a list that
    splits off the group characters into ['AT', '<GC>', 'A', 'TA']."""
    return filter(identity, re.split('(<.+?>)', sequence))

def identity(x):
    """A simple identity function.  x -> x."""
    return x


######################################################################
class GroupIterator:
    """Given a group, returns an iterator that iteratively visits each
    element in the group."""
    def __init__(self, group):
        self.group = group
    def __iter__(self):
        return sequence_generator(self.group)

def sequence_generator(sequence):
    for x in sequence:
        yield x

def SingleIterator(single_thing):
    return GroupIterator([single_thing])
######################################################################

class PairSummingIterator:
    """Given two iterators p1 and p2, returns all possible sums
    between elements of p1 and p2.

    Warning: p1 and p2 have to be finite, or else we run into big
    problems.
    """
    def __init__(self, p1, p2):
        self.p1, self.p2 = p1, p2
    def __iter__(self):
        return pair_summing_generator(self.p1, self.p2)

def pair_summing_generator(p1, p2):
    for x in p1:
        for y in p2:
            yield x+y

######################################################################


if __name__ == '__main__':
    for solution in genomic_sequence_generator("AT<GC>A<TA>"):
        print solution
######



Hope this helps!



From idiot1@netzero.net  Sun Oct  6 05:41:54 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Sun, 06 Oct 2002 00:41:54 -0400
Subject: [Tutor] self installing, or lifting by one's own bootstraps.
Message-ID: <3D9FBF12.46DEE258@netzero.net>

I am writing a script.
Woo boy, there's news. alert the media, someone! ;-P

But wait; it's a sh/bourne shell script. :-O

It exists to install tinylist for you. Locates where the interpeter is, and
places that shebang on the first line of the scripts of the suite, builds your
config file, creates your first list, all that good stuff. Just answer a few
simple questions and it's done.

As soon as I eat the last cockroach. |-(

It's an interesting bootstrap problem- not knowing where python is living in J
Random User's box, and assuming rather minimal skills on the web master's part,
how do we get the thing in there, executing, installed, and nicely set up- real
simple and easy? Can't be written in python, as we MUST assume THE USER DOES NOT
KNOW WHERE IT IS OR HOW TO FIND IT. And automating the process of creating the
shebang and adding it to the incompleted script REALLY reduces typo errors by a
novice.

But all the FreeBSD world, and even linux, mounts the sh shell. So there's the
tool. But I have a minor problem, a for loop is barking at me.

for FILE in `ls -1 TL*.p`
        cat /tmp/python $FILE > ./$FILEy

it gets me some rather cryptic messages: (the first 3 lines are normal output to
the user.)
Item #6:
Add the interpeter shebang to each TLscript source file,
creating the final interpeted executable script.
./testscript: 66: Syntax error: word unexpected
ns#

Any shell script  mavens care to graciously give me a clue?

When complete, this will be coming with TL1.5.0, and is the major difference in
this version. Sorry windows fans, will have to devlop a batch file for you
later, probably call it V:1.5.5.


-- 

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
Unlimited Long Distance only $29.95/ month!
Sign Up Today! www.netzerolongdistance.com


From shalehperry@attbi.com  Sun Oct  6 06:10:49 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Sat, 5 Oct 2002 22:10:49 -0700
Subject: [Tutor] self installing, or lifting by one's own bootstraps.
In-Reply-To: <3D9FBF12.46DEE258@netzero.net>
References: <3D9FBF12.46DEE258@netzero.net>
Message-ID: <200210052210.49397.shalehperry@attbi.com>

On Saturday 05 October 2002 21:41, Kirk Bailey wrote:
> But all the FreeBSD world, and even linux, mounts the sh shell. So ther=
e's
> the tool. But I have a minor problem, a for loop is barking at me.
>
> for FILE in `ls -1 TL*.p`
>         cat /tmp/python $FILE > ./$FILEy
>
> it gets me some rather cryptic messages: (the first 3 lines are normal
> output to the user.)
> Item #6:
> Add the interpeter shebang to each TLscript source file,
> creating the final interpeted executable script.
> ./testscript: 66: Syntax error: word unexpected
> ns#
>
> Any shell script  mavens care to graciously give me a clue?
>

You know Kirk, it would not hurt you to read a tutorial (or man page) now=
 and=20
then (-:

for FILE in `ls -1 *`;
do
    echo ${FILE} # braces are for safer variable expansion
done

The shell is not Python, it has its own rules.

Also, a common idiom for generated files is to name the input foo.in.  So=
 in=20
your case you would have TLfoo.py.in --> TLfoo.py.


From Jmllr891@cs.com  Sun Oct  6 17:29:59 2002
From: Jmllr891@cs.com (Jmllr891@cs.com)
Date: Sun, 6 Oct 2002 12:29:59 EDT
Subject: [Tutor] Is it possible to get a list of files from a remote host?
Message-ID: <89.1f13eeda.2ad1bf07@cs.com>

--part1_89.1f13eeda.2ad1bf07_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

I just learned how to download files from a remote host using the urllib 
module. Now, is it at all possible to get a list of files that are on that 
remote host? Say, using the glob module?

--part1_89.1f13eeda.2ad1bf07_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

<HTML><FONT FACE=arial,helvetica><FONT  SIZE=2 FAMILY="SCRIPT" FACE="Papyrus" LANG="0">I just learned how to download files from a remote host using the urllib module. Now, is it at all possible to get a list of files that are on that remote host? Say, using the glob module?</FONT></HTML>

--part1_89.1f13eeda.2ad1bf07_boundary--


From alan.gauld@bt.com  Sun Oct  6 18:33:50 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 6 Oct 2002 18:33:50 +0100
Subject: [Tutor] clearing screen?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C939@mbtlipnt02.btlabs.bt.co.uk>

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_01C26D5E.8886BC40
Content-Type: text/plain;
	charset="iso-8859-1"

>  I run programs in Idle from an Edit window.  
>  What command can I use at the top of my program in the Edit window  
>  to clear the IDLE output screen? 
 
Yu can't really but you could try:
 
for i in range(50): print
 
As an approximation... 
 
Alan g

 


------_=_NextPart_001_01C26D5E.8886BC40
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 face=Arial><FONT size=2><SPAN class=980174017-06102002><FONT 
face="Courier New" color=#0000ff>&gt; &nbsp;</FONT></SPAN>I run programs in Idle 
from an Edit window.&nbsp;<SPAN class=980174017-06102002><FONT 
face="Courier New" color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=980174017-06102002><FONT 
face="Courier New" color=#0000ff>&gt; </FONT>&nbsp;</SPAN>What command can I use 
at the top of my program in the Edit window&nbsp;<SPAN 
class=980174017-06102002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=980174017-06102002><FONT 
face="Courier New" color=#0000ff>&gt; </FONT>&nbsp;</SPAN>to clear the&nbsp;IDLE 
output screen?<SPAN class=980174017-06102002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=980174017-06102002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=980174017-06102002><FONT 
face="Courier New" color=#0000ff>Yu can't really but you could 
try:</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=980174017-06102002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=980174017-06102002><FONT 
face="Courier New" color=#0000ff>for i in range(50): 
print</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=980174017-06102002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=980174017-06102002><FONT 
face="Courier New" color=#0000ff>As an 
approximation...</FONT>&nbsp;</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=980174017-06102002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=980174017-06102002>Alan g</SPAN></FONT></FONT></DIV>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV></BLOCKQUOTE></BODY></HTML>

------_=_NextPart_001_01C26D5E.8886BC40--


From magnus@thinkware.se  Sun Oct  6 19:03:16 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sun, 06 Oct 2002 20:03:16 +0200
Subject: [Tutor] Is it possible to get a list of files from a
 remote host?
In-Reply-To: <89.1f13eeda.2ad1bf07@cs.com>
Message-ID: <5.1.0.14.0.20021006194126.029c6030@www.thinkware.se>

At 12:29 2002-10-06 -0400, Jmllr891@cs.com wrote:
>I just learned how to download files from a remote host using the urllib 
>module. Now, is it at all possible to get a list of files that are on that 
>remote host? Say, using the glob module?

Hi,

There is no magic here. Basically, you can reach just
the same information with a program (python or something
else) as you reach with your browser (although the browser
does hide some details).

Didn't you follow my advice about the urlretrieve? ;) What
you *did* fetch in the code where you tried to fetch the
python logo was just what you ask for now: A directory
listing. Type http://www.python.org/pics/ and see for
yourself.

You get this as HTML and you won't get it unless the web
server is set up to give directory listings and lack a
default file (index.html etc) in that directory.

You aren't supposed to be able to roam around the
filesystem at will on all the web servers on the net.

If you want to mirror / download a whole web site, you will
have to write a program that follows all local hyperlinks
recursively, and hope that gets you all the pages you need.

I suggest you take a look in the Tools/webchecker directory of your
python installation. Try running websucker.py. Maybe it's something
like that you are looking for?


-- 
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 Oct  6 19:16:47 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sun, 06 Oct 2002 20:16:47 +0200
Subject: Fwd: RE: [Tutor] clearing screen?
Message-ID: <5.1.0.14.0.20021006201603.029ec148@www.thinkware.se>

Woops, I just sent this to Alan...

>At 18:33 2002-10-06 +0100, you wrote:
>> >  I run programs in Idle from an Edit window.
>> > What command can I use at the top of my program in the Edit window
>> > to clear the IDLE output screen?
>>
>>Yu can't really but you could try:
>>
>>for i in range(50): print
>>
>>As an approximation...
>
>In my experience, IDLE gets slow when you have written
>a lot of data in the shell window. And if you get a lot
>of data printed and use Ctrl-PgUp to get to the top of
>output, 50 empty lines is a poor approximation for a
>cleared screen...
>
>Is it impossible to make a program running inside IDLE
>to somehow be able to control IDLE?
>
>I mean, I run PyCrust from within an applications, and
>there I get access to the innards of my program, and
>I can manipulate objects in runtime.
>
>It should certainly be able to patch IDLE so that this
>gets possible. I think...
>
>On the other hand, one could argue that IDLE might not
>be the IDEAL tool to present large amounts of data to
>the user.
>
>The way out might be to create a new dialog with some
>suitable Tkinter widget, and to redirect stdout to that?



--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From Andrew <angelopoulos@csi.com>  Sun Oct  6 19:46:12 2002
From: Andrew <angelopoulos@csi.com> (Andrew)
Date: Sun, 6 Oct 2002 14:46:12 -0400
Subject: Re[2]: [Tutor] Is it possible to get a list of files from a  remote host?
In-Reply-To: <5.1.0.14.0.20021006194126.029c6030@www.thinkware.se>
References: <5.1.0.14.0.20021006194126.029c6030@www.thinkware.se>
Message-ID: <19267381172.20021006144612@csi.com>


I would think that if there are a bunch of "knowns" here... you know
the page, and know that it is a directory listing, know the format
and know what you are looking for a simple solution would be to get
and parse that page, id those strings/elements that you are
looking for (re module or find?) and then do something else with them
(retrieve them?). Know any HTML?

Assuming, like Magnus said, the Web server normally provides publicly
the information you are looking for (and he's right, if it is the
whole site you are looking for then websucker is kind of fun to play
with and  poke around in--at least this newbie is enjoying it).

- -- Andrew
mailto:angelopoulos@csi.com


- --
Sunday, October 6, 2002, 2:03:16 PM, you wrote:


ML> At 12:29 2002-10-06 -0400, Jmllr891@cs.com wrote:
>>I just learned how to download files from a remote host using the
>>urllib module. Now, is it at all possible to get a list of files
>>that are on that remote host? Say, using the glob module?

ML> Hi,

ML> There is no magic here. Basically, you can reach just
ML> the same information with a program (python or something
ML> else) as you reach with your browser (although the browser
ML> does hide some details).

ML> Didn't you follow my advice about the urlretrieve? ;) What
ML> you *did* fetch in the code where you tried to fetch the
ML> python logo was just what you ask for now: A directory
ML> listing. Type http://www.python.org/pics/ and see for
ML> yourself.

ML> You get this as HTML and you won't get it unless the web
ML> server is set up to give directory listings and lack a
ML> default file (index.html etc) in that directory.

ML> You aren't supposed to be able to roam around the
ML> filesystem at will on all the web servers on the net.

ML> If you want to mirror / download a whole web site, you will
ML> have to write a program that follows all local hyperlinks
ML> recursively, and hope that gets you all the pages you need.

ML> I suggest you take a look in the Tools/webchecker directory of
your
ML> python installation. Try running websucker.py. Maybe it's
something
ML> like that you are looking for?



From dyoo@hkn.eecs.berkeley.edu  Sun Oct  6 23:30:52 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 6 Oct 2002 15:30:52 -0700 (PDT)
Subject: [Tutor] A hacky indexer for Useless Python?
Message-ID: <Pine.LNX.4.44.0210061522550.18312-100000@hkn.eecs.berkeley.edu>

Hi Rob,

One of your challenges mentioned writing a small program to make it easier
to search Useless Python.  I've started doing a little HTML parsing of the
Useless Python pages, and came up with the following program: it reads
through all 16 pages of Useless, and tries to extract the program entries
from each page.

It's really rough code, but I hope it's useful for Useless.  Just don't
change Useless Python's format, ok?  *grin*


######
"""A small script to help index Useless Python.

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

import sgmllib
import urllib
import re


def main():
    code_pages = [("http://www.uselesspython.com/"
                   + "uselesspython%s.html" % index)
                  for index in range(1, 16+1)]  ## fixme, don't hardcode!
    entries = []
    for page in code_pages:
        print "processing page", page
        entries.extend(parse_entries(urllib.urlopen(page)))
    for e in entries:
        print e
        print



def parse_entries(source_file):
    parser = UselessParser()
    parser.feed(source_file.read())   ## perhaps we want to feed only a
bit at at a time
    return parser.getEntries()



class UselessParser(sgmllib.SGMLParser):
    def __init__(self):
        sgmllib.SGMLParser.__init__(self)
        self._entries = []
        self._tags = []
        self._newrow = []
        self._newtd = []


    def handle_data(self, data):
        if 'td' in self._tags:
            self._newtd.append(data)


    def unknown_starttag(self, tag, attrs):
        if tag == 'tr':
            self._newrow = []
        if tag == 'td':
            self._newtd = []
        if 'td' in self._tags:
            self._newtd.append(self.get_starttag_text())
        self._tags.append(tag)


    def unknown_endtag(self, tag):
        if tag in self._tags:
            while tag in self._tags:  # ugly hack; I need to use XMLParser
                self._tags.pop()
        if tag == 'tr' and self._hasGoodRow():
            self._addEntry()
        if tag == 'td':
            self._newrow.append(''.join(self._newtd))
        if 'td' in self._tags:
            self._newtd.append("</%s>" % tag)



    def getEntries(self):
        return self._entries

    def _hasGoodRow(self):
        return len(self._newrow) == 3

    def _addEntry(self):
        self._entries.append(UselessEntry(self._newrow[0],
                                          self._newrow[1],
                                          self._newrow[2]))




class UselessEntry:
    def __init__(self, url, submitter, description):
        self.url, self.submitter, self.description = \
                  url, submitter, description

    def __str__(self):
        return "source: %s\nsubmitter: %s\ndescription:%s" %\
               (self.url, self.submitter, self.description)



if __name__ == '__main__':
    main()
######


Best of wishes to you!



From idiot1@netzero.net  Mon Oct  7 07:34:01 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Mon, 07 Oct 2002 02:34:01 -0400
Subject: [Tutor] tinylist 1.5.0 available
Message-ID: <3DA12AD9.90F912F1@netzero.net>

Version 1.5.0 is now available. Major change is addition of a borne shell script
to
automate installing it.

http://www.tinylist.org/


-- 

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
Unlimited Long Distance only $29.95/ month!
Sign Up Today! www.netzerolongdistance.com


From nano@intermatik.co.id  Mon Oct  7 08:57:37 2002
From: nano@intermatik.co.id (nano)
Date: 07 Oct 2002 14:57:37 +0700
Subject: [Tutor] retrieving instances value
Message-ID: <1033960555.12725.46.camel@jrwd.internal.intermatik.com>

hi gurus,

i have this:

class Transaction:
	def __init__(self,name='',address='',age=''):
		self._name = name
		self._address = address
		self._age = age

# make a Transaction instance
obj = Transaction('my name', 'my address', 25)

how can i retrieve each 'obj' instance value without typing it one by
one manually (in case it have 100 instances)?

thanks in advance,

nano'



From James.Rocks@equant.com  Mon Oct  7 09:17:32 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Mon, 7 Oct 2002 09:17:32 +0100
Subject: [Tutor] 2 Import Or Not?
Message-ID: <OFF263A37C.C1DD7950-ON80256C4B.002D7350@equant.com>

Hi,

Currently I am using Python under Windows with the pythonwin extensions and
generally it's pretty good but I have a problem :-)

If I "import" a routine in the interactive window and it imports OK and I
subsequently edit the file I've imported then it doesn't register the
changes I've made. I'm using the pythonwin editor but I've checked and it
seems to be true in the normal python editor too ... I can't find any way
to "un-import" or override the import already in place and, so far, can
only resolve it by closing the session and re-running it which is a pain in
the bum.

Any ideas?

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From James.Rocks@equant.com  Mon Oct  7 11:36:36 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Mon, 7 Oct 2002 11:36:36 +0100
Subject: [Tutor] Underlining?
Message-ID: <OF4026A5B6.C40BB24A-ON80256C4B.003A3DF4@equant.com>

Hi,

I'm trying to create a report and auto-underline some of the stuff i.e. to
create a line of "equal signs" the same length as the server name. This is
how I'm trying to do it:

      import string
      sServer = "SERVER 1"
      string.translate(string.ljust("", len(sServer)), "=", " ")

It fails (naturally) on the basis that I need s 256 character string for
translation which is just a bit excessive for my needs :-)

Does anyone know of a more appropriate method or function for this

Cheers

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From James.Rocks@equant.com  Mon Oct  7 11:45:20 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Mon, 7 Oct 2002 11:45:20 +0100
Subject: [Tutor] Underlining?
Message-ID: <OF3994ECF5.C25432FE-ON80256C4B.003AEA62@equant.com>

OK,

Excuse me for being dumb ... but I just solved it. Inappropriate choice of
functions :-(

I should have used:

      string.replace(string.ljust("", len(sServer)), " ", "=")

Sorry :-)

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From op73418@mail.telepac.pt  Mon Oct  7 11:55:24 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Mon, 7 Oct 2002 11:55:24 +0100
Subject: [Tutor] 2 Import Or Not?
References: <OFF263A37C.C1DD7950-ON80256C4B.002D7350@equant.com>
Message-ID: <002b01c26df0$0ad2a1f0$1d190dd5@violante>

----- Original Message -----
From: <James.Rocks@equant.com>


> Hi,
>
> Currently I am using Python under Windows with the pythonwin extensions
and
> generally it's pretty good but I have a problem :-)
>
> If I "import" a routine in the interactive window and it imports OK and I
> subsequently edit the file I've imported then it doesn't register the
> changes I've made. I'm using the pythonwin editor but I've checked and it
> seems to be true in the normal python editor too ... I can't find any way
> to "un-import" or override the import already in place and, so far, can
> only resolve it by closing the session and re-running it which is a pain
in
> the bum.
>
> Any ideas?
>

Check the reload function. That is, use

reload(<mymodule>)

And it forces reimporting of the module. Note however, that your variables
will still reference the "old" mymodule.

Hope it helps,
Gonçalo Rodrigues



From rob@uselesspython.com  Mon Oct  7 12:05:32 2002
From: rob@uselesspython.com (Rob)
Date: Mon, 7 Oct 2002 06:05:32 -0500
Subject: [Tutor] Underlining?
In-Reply-To: <OF3994ECF5.C25432FE-ON80256C4B.003AEA62@equant.com>
Message-ID: <MPEOIFCOPCIHEDCLBLPBAEJGCHAA.rob@uselesspython.com>

It's great that you identified your own solution, but you don't need to
self-deprecate here.

Nobody wise enough to make good use of Python and the Tutor list can be
reasonably called "dumb". heh

Rob
http://uselesspython.com

> Excuse me for being dumb ... but I just solved it. Inappropriate choice of
> functions :-(
>
> I should have used:
>
>       string.replace(string.ljust("", len(sServer)), " ", "=")
>
> Sorry :-)
>




From faithless_nw@yahoo.com  Mon Oct  7 12:23:41 2002
From: faithless_nw@yahoo.com (Alexander Joukov)
Date: Mon, 7 Oct 2002 04:23:41 -0700 (PDT)
Subject: [Tutor] python executable
Message-ID: <20021007112341.25206.qmail@web40808.mail.yahoo.com>

 here i go again...
 i tried to solve the problem myself for a while now,
 but with no luck....
 So i desperately need some help on the following:
 i use python 2.2.1 for windows and Installer version
 5, alpha 1. i have converted several scripts into
 stand-alones no problem, but whenever i try to add
 "--noconsole" option, the file is created, but when
 i
 try to start it, i get fatal errors : "ERROR LOADING
 PYTHON DLL." and then "c:\windows\temp\python22.dll"
 
 Thanx
 
 Alex
 

__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com


From rob@uselesspython.com  Mon Oct  7 12:35:24 2002
From: rob@uselesspython.com (Rob)
Date: Mon, 7 Oct 2002 06:35:24 -0500
Subject: [Tutor] python executable
In-Reply-To: <20021007112341.25206.qmail@web40808.mail.yahoo.com>
Message-ID: <MPEOIFCOPCIHEDCLBLPBKEJGCHAA.rob@uselesspython.com>

Disclaimer: I haven't tried using Installer.

One thing to note is that alpha-release software is often buggy. So there
could be an issue there.

Do you have a file python22.dll in the c:\windows\temp\ folder?

Rob

>  here i go again...
>  i tried to solve the problem myself for a while now,
>  but with no luck....
>  So i desperately need some help on the following:
>  i use python 2.2.1 for windows and Installer version
>  5, alpha 1. i have converted several scripts into
>  stand-alones no problem, but whenever i try to add
>  "--noconsole" option, the file is created, but when
>  i
>  try to start it, i get fatal errors : "ERROR LOADING
>  PYTHON DLL." and then "c:\windows\temp\python22.dll"
>




From jeff@ccvcorp.com  Mon Oct  7 18:04:00 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Mon, 07 Oct 2002 10:04:00 -0700
Subject: [Tutor] Underlining?
References: <OF3994ECF5.C25432FE-ON80256C4B.003AEA62@equant.com>
Message-ID: <3DA1BE80.DDC4398@ccvcorp.com>


James.Rocks@equant.com wrote:

> I should have used:
>
>       string.replace(string.ljust("", len(sServer)), " ", "=")

It may be simpler to avoid the string module functions altogether.  Remember
that strings can also be multiplied, so this should probably work:

underline = "=" * len(sServer)

Jeff Shannon
Technician/Programmer
Credit International





From alan.gauld@bt.com  Mon Oct  7 17:30:43 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 7 Oct 2002 17:30:43 +0100
Subject: [Tutor] retrieving instances value
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C944@mbtlipnt02.btlabs.bt.co.uk>

> class Transaction:
> 	def __init__(self,name='',address='',age=''):
> 		self._name = name
> 		self._address = address
> 		self._age = age
> 
> # make a Transaction instance
> obj = Transaction('my name', 'my address', 25)
> 
> how can i retrieve each 'obj' instance value without typing it one by
> one manually (in case it have 100 instances)?

Store the instances in a list or dictionary.
Probably a dictionary keyed by name, or maybe even by 
the tuple of value.

So:

XnList = []
XnDict = {}
while 1:
  name = raw_input("NAME? ")
  addr = raw_input("ADDRESS? ")
  ag = raw_input("AGE? ")
  obj = Transaction(name,addr,age)
  XnDict[n] = obj
  # OR ... XnDict[(name,addr,age)] = obj
  # OR ... XnList.append(obj)

And access them with:

for x in XnDict.keys(): print XnDict[x].name

OR

for x in XnList: print x.name


HTH,

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


From alan.gauld@bt.com  Mon Oct  7 17:33:38 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 7 Oct 2002 17:33:38 +0100
Subject: [Tutor] 2 Import Or Not?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C945@mbtlipnt02.btlabs.bt.co.uk>

> subsequently edit the file I've imported then it doesn't register the
> changes I've made. 

try to "reload()" the module.

Note that reload only works if you imported the module, not if you 
imported names from within the module. 

ie

import foo           # this will reload ok
from foo import bar  # this won't reload ok

print foo.bar

reload(foo)

HTH,

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


From alan.gauld@bt.com  Mon Oct  7 17:36:11 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 7 Oct 2002 17:36:11 +0100
Subject: [Tutor] Underlining?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C946@mbtlipnt02.btlabs.bt.co.uk>

>       import string
>       sServer = "SERVER 1"
>       string.translate(string.ljust("", len(sServer)), "=", " ")
> 

uline = '=' * len(sServer)

Does that do what you want?

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


From tismer@tismer.com  Mon Oct  7 21:45:32 2002
From: tismer@tismer.com (Christian Tismer)
Date: Mon, 07 Oct 2002 13:45:32 -0700
Subject: [Tutor] Is there a file creator?
References: <Pine.LNX.4.33.0309060016440.6729-100000@bbetty.sugarking.dyndns.org>
Message-ID: <3DA1F26C.7010209@tismer.com>

Gus Tabares wrote:
> SA,
> 
> 	I think when you open a file in write mode, if the file doesn't
> already exists, it will be created, hence, it will start empty. Hope this
> helps...
> 
> 
> Gus
> 
> On Fri, 6 Sep 2002, S A wrote:
> 
> 
>>Is there a function or module that creates an empty file like the unix command "touch" does?

Well, a real equivalent of "touch" would have to set the
time stamp of an existing file to now, without changing
the file. Opening in write mode would clear it.
For that purpose, os.utime seems to be appropriate, since
it appears to work, whether the file is opened or not.

something like (not tested):

import os, time

def touch(path):
   if os.path.exists(path):
     t = time.time()
     os.utime(path, (t, t) )
   else:
     file(path, 'w').close()

ciao - chris

-- 
Christian Tismer             :^)   <mailto:tismer@tismer.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a     :    *Starship* http://starship.python.net/
14109 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34  home +49 30 802 86 56  pager +49 173 24 18 776
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?   http://www.stackless.com/




From Michael Montagne <montagne@boora.com>  Mon Oct  7 23:21:02 2002
From: Michael Montagne <montagne@boora.com> (Michael Montagne)
Date: Mon, 7 Oct 2002 15:21:02 -0700
Subject: [Tutor] Default printer in Windows
Message-ID: <20021007222102.GA11776@boora.com>

I'm trying to automate printing pdf files from zope.  I'm planning on
converting them to postscript and then copying them right to the
printer.  But I need the user's default printer.  Can it be retrieved by
python? 

-- 
  Michael Montagne  [montagne@boora.com]   503.226.1575 
--    


From idiot1@netzero.net  Tue Oct  8 05:27:32 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Tue, 08 Oct 2002 00:27:32 -0400
Subject: [Tutor] TINYLIST update
Message-ID: <3DA25EB4.A7AE6CFB@netzero.net>

oops. tinylist.1.5.1.tzar.gz is now available, as is tinylist151.zip. Sorry, had
to fix a typo.
http://www.tinylist.org/

-- 

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
Unlimited Long Distance only $29.95/ month!
Sign Up Today! www.netzerolongdistance.com


From goneil@scu.edu  Tue Oct  8 06:18:56 2002
From: goneil@scu.edu (Galen O'Neil)
Date: 07 Oct 2002 22:18:56 -0700
Subject: [Tutor] regexing and timing, seperatly
Message-ID: <1034054350.8743.38.camel@lucidia>

1.  I can't seem to find a simple tutorial or example on timing.  I want
an infinite loop but I don't want it to eat all my cpu time.  I've
looked at a few programs that use tkinter and root.mainloop() but I
can't imagine there aren't some other ways that don't involve tkinter. 
So if anybody knows where I can find a decent tutorial or has some
sample code, that would be great.

2.  I'm taking data from a telnet session (using telnetlib) but I can't
seem to do regexs on it.  Here's an example:

this result from this code:

print "***searching data, data at this moment contains***"
print data
import re
m = re.match("Player", data)
if m:
    print 'Match found: ', m.group()
else:
    print 'No match'
    

***searching data, data at this moment contains***


=======================[   God Wars : Rogue
Edition    ]=======================

                |

AVATARS        -|

Immortal    
0.45   (Ronin)                      Wolfe the
mortal

Login Timer  0.00   {Yellow Invoker}            
AutoKelvan tell me hi

Avatar       0.00   {=Rogue
Lemure=}             Shaddai the demonator

                |

MORTALS        -|

Mortal+      None
                              
InfuriaterSuEs

Mortal+      None
                               Lerdos the
mortal

                |

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

| Current | Players Visible :
5   | Arena Status : Challenge In Progress     
|

| Stats   | Most Players    :
21  | Player Kills : 4491 | Status
Kills : 2996 |

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



<7970 qp> <21000H 22166M
4000V>
No match


You may notice that the word player is in the string, but it still
returns no match.  Any ideas?

--Modig



From shalehperry@attbi.com  Tue Oct  8 06:24:31 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Mon, 7 Oct 2002 22:24:31 -0700
Subject: [Tutor] regexing and timing, seperatly
In-Reply-To: <1034054350.8743.38.camel@lucidia>
References: <1034054350.8743.38.camel@lucidia>
Message-ID: <200210072224.31681.shalehperry@attbi.com>

On Monday 07 October 2002 22:18, Galen O'Neil wrote:
> 1.  I can't seem to find a simple tutorial or example on timing.  I wan=
t
> an infinite loop but I don't want it to eat all my cpu time.  I've
> looked at a few programs that use tkinter and root.mainloop() but I
> can't imagine there aren't some other ways that don't involve tkinter.
> So if anybody knows where I can find a decent tutorial or has some
> sample code, that would be great.
>

this is not clear.  Are you trying to have a timer so that your program d=
oes=20
something on certain intervals?

> 2.  I'm taking data from a telnet session (using telnetlib) but I can't
> seem to do regexs on it.  Here's an example:
>
> this result from this code:
>
> print "***searching data, data at this moment contains***"
> print data
> import re
> m =3D re.match("Player", data)
> if m:
>     print 'Match found: ', m.group()
> else:
>     print 'No match'
>

you used re.match() which searches for the regex at the beginning of the=20
string.  It is basically for when the string is expected to exactly match=
 the=20
regex.  What you want is re.search, it is used the same way just a differ=
ent=20
function name.

words =3D string.split(sentence)
for word in words:
   if re.match(r"\w+"):
       print "I am a valid python variable name"

is the type of logic where match makes sense.  Basically think of match a=
s the=20
equivalent of always adding "^" to the front of your regex.


From goneil@scu.edu  Tue Oct  8 06:55:59 2002
From: goneil@scu.edu (Galen O'Neil)
Date: 07 Oct 2002 22:55:59 -0700
Subject: [Tutor] regexing and timing, seperatly
In-Reply-To: <200210072224.31681.shalehperry@attbi.com>
References: <1034054350.8743.38.camel@lucidia>
 <200210072224.31681.shalehperry@attbi.com>
Message-ID: <1034056569.8743.51.camel@lucidia>

1.  I can't seem to find a simple tutorial or example on timing.  I want
an infinite loop but I don't want it to eat all my cpu time.  I've
looked at a few programs that use tkinter and root.mainloop() but I
can't imagine there aren't some other ways that don't involve tkinter. 
So if anybody knows where I can find a decent tutorial or has some
sample code, that would be great.

> this is not clear.  Are you trying to have a timer so that your program does 
> something on certain intervals?

I want something like this that doesn't eat up all the cpu time.  So it
would either do it every x amount of time or, do it only when getdata()
would return new data.  I'm having a hard time expressing this exactly
because I don't know what options are available.

while 1:
	data = getdata()
	myfunction(data)



Also, thank you Sean 'Shaleh' Perry, I knew my problem with regexing was
something simple I was missing.





From James.Rocks@equant.com  Tue Oct  8 07:53:38 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Tue, 8 Oct 2002 07:53:38 +0100
Subject: [Tutor] Underlining?
Message-ID: <OFF8FF1D5D.2D4B787E-ON80256C4C.0025BDEB@equant.com>

Hi Jeff,

> underline = "=" * len(sServer)

Multiplying strings? Wow, I'd never have thought of that ... cool :-)

Yes it works ... thanks :-)

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From dylan.belsey@baesystems.com  Tue Oct  8 08:07:58 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Tue, 8 Oct 2002 16:37:58 +0930
Subject: [Tutor] Passing a value into an embedded python interpreter
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B98D2ACE@wtntex1.baea.com.au>

Hi Tutor list,
	I am attempting to embed the python interpreter into C++ code.  I
have successfully been able to create functions in C++ that can be called
from the embedded interpreted environment (with the use of SWIG).  However,
I can't see my way clearly on how I can pass (map) the value of a variable
in C++, to a variable in the python namespace.
	If anyone has dealt with this or has any ideas, your advice would be
much appreciated.  I have of course been perusing the doco on extending and
embedding Python and the initial possibilities on how to tackle this problem
seem to be quite convoluted (to me anyway).
	TIA,
		Dylan


From James.Rocks@equant.com  Tue Oct  8 08:02:34 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Tue, 8 Oct 2002 08:02:34 +0100
Subject: [Tutor] My First Python Program
Message-ID: <OF38F3BB39.3D8FDADE-ON80256C4C.00260C9E@equant.com>

Hi,

I have now successfully written my first Python program ... OK it's a
conversion from one I wrote in WinBatch (if you can genuinely call that
programming) but that was my work too. I have to say, despite the
disparaging noises from a couple of my programmer colleagues (one of whom
insists, in error, that OO can only be done in a visual development
environment) that I am quite impressed ... the program took some 12 minutes
to create a report in WinBatch and a mere 25 seconds in Python.

Obviously I want to improve that (it's a bit like tinkering with a car
engine at times) so I was wondering if there's anywhere we can present
small programs and say "tell me how I can make this better"?

Cheers

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From James.Rocks@equant.com  Tue Oct  8 08:35:59 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Tue, 8 Oct 2002 08:35:59 +0100
Subject: [Tutor] Continuously Updating A Display?
Message-ID: <OF7CCF7854.0EE49D84-ON80256C4C.0029B6AA@equant.com>

Hi,

I know how to create messages dialogs but how do I provide a running
information panel ... I want it to provide information but not to delay
program execution.

Thanks

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From lumbricus@gmx.net  Tue Oct  8 09:08:02 2002
From: lumbricus@gmx.net (lumbricus@gmx.net)
Date: Tue, 8 Oct 2002 10:08:02 +0200 (MEST)
Subject: [Tutor] retrieving instances value
References: <1033960555.12725.46.camel@jrwd.internal.intermatik.com>
Message-ID: <8254.1034064482@www59.gmx.net>

Hello!

[ snip ]

> how can i retrieve each 'obj' instance value without typing it one by
> one manually (in case it have 100 instances)?

>>> print obj.__dict__
 
> thanks in advance,
> 
> nano'

HTH, HAND
J"o!

-- 

-- 
Wir beschliessen etwas, stellen das dann in
den Raum und warten dann einige Zeit ab, was
passiert. Wenn es dann kein grosses Geschrei
gibt und keine Aufstaende, weil die meisten
gar nicht begreifen, was da beschlossen
wurde, dann machen wir weiter - Schritt fuer
Schritt, bis es kein Zurueck mehr gibt. 
   -- J-C Juncker

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



From mylene.reiners@cmg.com  Tue Oct  8 09:26:14 2002
From: mylene.reiners@cmg.com (Mylene Reiners)
Date: Tue, 8 Oct 2002 10:26:14 +0200
Subject: [Tutor] My First Python Program
Message-ID: <B569A4D2254ED2119FE500104BC1D5CD01A694F7@NL-EIN-MAIL01>

James,

Post your code on this list, and we will be happy to have a look

Mylene 

-----Original Message-----
From: James.Rocks@equant.com
To: tutor@python.org
Sent: 10/8/2002 9:02 AM
Subject: [Tutor] My First Python Program

Hi,

I have now successfully written my first Python program ... OK it's a
conversion from one I wrote in WinBatch (if you can genuinely call that
programming) but that was my work too. I have to say, despite the
disparaging noises from a couple of my programmer colleagues (one of
whom
insists, in error, that OO can only be done in a visual development
environment) that I am quite impressed ... the program took some 12
minutes
to create a report in WinBatch and a mere 25 seconds in Python.

Obviously I want to improve that (it's a bit like tinkering with a car
engine at times) so I was wondering if there's anywhere we can present
small programs and say "tell me how I can make this better"?

Cheers

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


From James.Rocks@equant.com  Tue Oct  8 10:33:25 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Tue, 8 Oct 2002 10:33:25 +0100
Subject: [Tutor] My First Python Program (Vey Large)!
Message-ID: <OF177D9962.08DADF9A-ON80256C4C.0034634E@equant.com>

Hi,

This is my first python program (my apologies, it isn't small) ... any
suggestions as to how I can improve it, speed it up or whatever? Comments
are often an issue with interpreted languages and I have a fair few of them
but ultimately they serve to make the program maintainable so I'd prefer to
keep them :-)

The program idea is simple ... using a datafile generated by a DOS batch
file on another machine the program produces a report of the number of
times the Citrix severs in our "farm" restart, downtime, availability etc.

The datafile, created by a DOS batch file that pings each server and
establishes whether they are "UP" or not based on PING response, will be a
large (say 5Mb) file something like this:

"SRVA17    "                     UP
09/30/102 13:26
"SRVA14    "                     UP
09/30/102 13:26
"SRVA15    "                     UP
09/30/102 13:26
"SRVA18    "                     UP
09/30/102 13:26
"SRVTSATL19"                     DOWN
09/30/102 13:26
"SRVTSGLA01"                     UP
09/30/102 13:27
"SRVA17    "                     UP
09/30/102 13:27
"SRVA14    "                     UP
09/30/102 13:27
"SRVA15    "                     UP
09/30/102 13:27
"SRVA18    "                     UP
09/30/102 13:27
"SRVTSATL19"                     DOWN
09/30/102 13:27
"SRVTSGLA01"                     UP

The next stage of my project will be to migrate this DOS program to python
(I checked the archives and it seems like people regularly ask how to
'ping' from within Linux) and only record changes of state but at present
that is what I got :-)

This is the main program, functions & temporary INI file follow:

#
# Program Name:  CTX Report (CTXREPT.PY)
# Last Updated: 7th October 2002
# Author:       James "Undead" Rocks
#
# A program designed to monitor and report on the state of the Equant
Citrix Server farm.
#

#
# Import standard & custom functions
#
import string, win32api
import jcrfunc, ctxfunc

#
# Program Constants
#
_TRUE_ = 1
_FALSE_ = 0

#
# Program Variables ('s' denotes 'string', 'i' denotes 'integer' and 'l'
denotes 'logical')
#
sSrvName = ""       # Temporary string to store server names
sSrvStatus = {}     # Array to contain current server event status
sSrvDownDate = {}   # Array to contain current server down date
sSrvDownTime = {}   # Array to contain current server down time
lStart = _TRUE_     # Report start flag
iSrvNumber = 0      # Number of servers so far found (integer)
sReptStart = ""     # Initialise Report Start Date & Time (string)
sReptEnd = ""       # Initialise Report End Date & Time (string)

#
# More Variables Used In Program
# ==============================
# sLine:        Raw line input from data file
# sEvents:      Array used to stored current event being analysed:
#                   [0] Date of server crash (UTC string)
#                   [1] Time of server crash (UTC string)
#                   [2] Server Name (string)
#                   [3] Server status ("UP"/"DOWN", string)
# sPDate:       Current event date (UTC string)
# sDownTime:      Time that server crashed (UTC string)
# sUpTime:      Time that server returned to service (UTC string)
# iDownTime:      Time server crashed (sec from year 2000, integer)
# iUpTime:      Time server returned to service  (sec from year 2000,
integer)
# iTimeOut:     Length of server outage  (seconds, integer)
# iRestarts:      Number of restarts for server (integer)
#

#
# Open raw data file for reading
#
fCTXLog = open ('c:\python22\ctxstat.log', 'r')

#
# Copy base INI file for update during program execution
#
win32api.CopyFile("c:\python22\ctxrept.new", "c:\python22\ctxrept.ini", 0)

#
# Loop endlessly (break handled internally)
#
while _TRUE_:
    #
    # Read in two lines of code, if it is empty then break
    #
    sLine = fCTXLog.readline() + fCTXLog.readline()
    if string.strip (sLine) == "":
        break

    #
    # separate data out of raw input
    #
    sEvents = ["20" + sLine [7:9] + ":" + sLine [0:2] + ":" + sLine [3:5],
sLine [10:15], string.strip(sLine [17:27])]

    #
    # Update CTXREPT.INI file with server details (if not already done) and
number of restarts.
    #
    if ctxfunc.readctxini(sEvents[2], "Found", "No") == "No":
        ctxfunc.writectxini(sEvents[2], "Found", "Yes")
        ctxfunc.writectxini(sEvents[2], "Restarts", 0)
        iSrvNumber = iSrvNumber + 1
        sSrvNumber = "Server " +
string.zfill(string.strip(str(iSrvNumber)), 3)
        ctxfunc.writectxini("Servers", sSrvNumber, sEvents[2])

    #
    # Create Time & Date Stamp ... write to CTXREPT.INI if report is
starting
    # Keep to record Report End at appropriate time.
    #
    sPDate = sEvents [0] + ":" + sEvents [1]+ ":00"
    if lStart == _TRUE_:
        sReptStart = sPDate
        lStart = _FALSE_

    #
    # Update event with server status
    #
    if sLine [49:50] == "U":
        sEvents.append ("UP")
    else:
        sEvents.append ("DOWN")

    #
    # Assign default server status of "UP" to server as found
    #
    if string.find (sSrvName, "[" + sEvents[2] + "]") < 0:
        sSrvName = sSrvName + "[" + sEvents [2] + "]"
        sSrvStatus [sEvents[2]] = "UP"

    #
    # If server staus changes then ...
    #
    if sSrvStatus[sEvents[2]] != sEvents [3]:
        sSrvStatus [sEvents[2]] = sEvents [3]
        if sEvents[3] == "DOWN":
            #
            # ... record server, time & date of 'DOWN'
            #
            sSrvDownDate [sEvents[2]] = sEvents [0]
            sSrvDownTime [sEvents[2]] = sEvents [1]
        else:
            #
            # ... record 'DOWN' & 'UP' Times in CTXREPT.INI file
            #
            sDownTime = sSrvDownDate [sEvents[2]] + ":" + sSrvDownTime
[sEvents[2]]
            sUpTime = sEvents [0] + ":" + sEvents [1]
            iDownTime = jcrfunc.time2sec(sDownTime + ":00")
            iUpTime = jcrfunc.time2sec(sUpTime + ":00")
            iTimeOut = iUpTime - iDownTime
            #
            # Only record data on servers that have been down in excess of
2 minutes.
            #
            if iTimeOut > 120:
                iRestarts = string.atoi(ctxfunc.readctxini(sEvents[2],
"Restarts", "0"))
                iRestarts = iRestarts + 1
                sEventNo = 'Event ' + string.zfill(str(iRestarts), 3)
                ctxfunc.writectxini(sEvents[2], sEventNo, sDownTime + " " +
sUpTime + " " + str(iTimeOut))
                ctxfunc.writectxini(sEvents[2], "Restarts", iRestarts)

#
# Record Report End Time & Date
#
sReptEnd = sPDate

#
# Close raw data file
#
fCTXLog.close ()

#
# Open File For Report Writing
#
fCTXRept = open ("c:\python22\ctxrept.log", "w")

#
# Calculate report duration and write report header
#
iReptTime = jcrfunc.time2sec(sReptEnd) - jcrfunc.time2sec(sReptStart)
sJReptStart = jcrfunc.date2jul(sReptStart)
sJReptEnd = jcrfunc.date2jul(sReptEnd)
sJReptTime = jcrfunc.sec2jul (iReptTime)
fCTXRept.write ("Citrix Server Report\n====================")
fCTXRept.write ("\nReport Start:\t" + sJReptStart)
fCTXRept.write ("\nReport End:\t" + sJReptEnd)
fCTXRept.write ("\nReport Time:\t" + sJReptTime + " (" + str(iReptTime) + "
sec)\n\n")

#
# Step through servers (crude 'FOR' loop)
#
iCount = 0
while iCount < iSrvNumber:
    #
    # Increment loop counter, find relevant server and output its name
(underlined)
    #
    iCount = iCount + 1
    sSrvNumber = "Server " + string.zfill(string.strip(str(iCount)), 3)
    sServer = ctxfunc.readctxini("Servers", sSrvNumber, "N/A")
    fCTXRept.write (sServer + "\n" + "="  * len(sServer))

    #
    # If a server has restarted at any point write the details, otherwise
assume 100% availability
    #
    fDownTime = 0.0
    iRestarts = ctxfunc.readctxini(sServer, "Restarts", 0)
    if iRestarts > 0:
        iEvent = 0
        while iEvent < iRestarts:
            iEvent = iEvent + 1
            sEventNo = ctxfunc.readctxini(sServer, "Event " +
string.zfill(string.strip(str(iEvent)), 3), "N/A")
            fEventTime = sEventNo [34:]
            fDownTime = fDownTime + string.atoi(fEventTime)

        fCTXRept.write ("\nRestarts:\t" + str(iRestarts))
        fCTXRept.write ("\nDown Time:\t" + jcrfunc.sec2jul (int(fDownTime))
+ " (" + str(int(fDownTime)) +" sec)")
        fCTXRept.write ("\nAverage D/T:\t" + jcrfunc.sec2jul
(int(fDownTime/iRestarts)) + " (" + str(int(fDownTime/iRestarts)) +" sec)")
        fCTXRept.write ("\nAvailability:\t" + str(round(100 -
((fDownTime/iReptTime) * 100), 2)) + "%")
        print int(fDownTime/iRestarts), "Average D/T:\t" + jcrfunc.sec2jul
(int(fDownTime/iRestarts)) + " (" + str(int(fDownTime/iRestarts+1)) +"
sec)"

    else:
        fCTXRept.write ("\nRestarts:\tNone")
        fCTXRept.write ("\nDown Time:\tNone")
        fCTXRept.write ("\nAverage D/T:\tN/A")
        fCTXRept.write ("\nAvailability:\t100%")

    fCTXRept.write ("\nComments:\t\n\n")

#
# Finish Report
#
fCTXRept.close()


*** Support Module JCRFUNC ****

#
# Module Name:  JCR Functions
# Last Updated: 4th April 2002
# Author:       James "Undead" Rocks
#

#
# Function: Time To Seconds (time2sec)
# Date:     4th April 2002
# Author:   James "Undead" Rocks
# *** Comments ***
# Requires 1 argument, a date in UTC (string) format i.e.
"YYYY:MM:DD:HH:MM:SS"
# Returns the time in seconds
#
def time2sec (sUTCTime):
    import string

    iYear = string.atoi(sUTCTime [0:4])
    iMonth = string.atoi(sUTCTime [5:7])
    iDay = string.atoi(sUTCTime [8:10])
    iHour = string.atoi(sUTCTime [11:13])
    iMinute = string.atoi(sUTCTime [14:16])
    iSSec = string.atoi(sUTCTime [17:19])
    iTmp31 = 2678400
    iTmp30 = 2592000

    if iYear == 2004:
        iTmpFeb = 2505600
    else:
        iTmpFeb = 2419200

    if iMonth == 1:
        iMtSec = 0
    elif iMonth == 2:
        iMtSec = iTmp31
    elif iMonth == 3:
        iMtSec = iTmp31 + iTmpFeb
    elif iMonth == 4:
        iMtSec = (iTmp31 * 2) + iTmpFeb
    elif iMonth == 5:
        iMtSec = (iTmp31 * 2) + iTmp30 + iTmpFeb
    elif iMonth == 6:
        iMtSec = (iTmp31 * 3) + iTmp30 + iTmpFeb
    elif iMonth == 7:
        iMtSec = (iTmp31 * 3) + (iTmp30 * 2) + iTmpFeb
    elif iMonth == 8:
        iMtSec = (iTmp31 * 4) + (iTmp30 * 2) + iTmpFeb
    elif iMonth == 9:
        iMtSec = (iTmp31 * 5) + (iTmp30 * 2) + iTmpFeb
    elif iMonth == 10:
        iMtSec = (iTmp31 * 5) + (iTmp30 * 3) + iTmpFeb
    elif iMonth == 11:
        iMtSec = (iTmp31 * 6) + (iTmp30 * 3) + iTmpFeb
    else:
        iMtSec = (iTmp31 * 6) + (iTmp30 * 4) + iTmpFeb

    iYSec = (iYear - 2001) * 31536000
    iDSec = iDay * 86400
    iHSec = iHour * 3600
    iMnSec = iMinute * 60

    iSeconds = iYSec + iMtSec + iDSec + iHSec + iMnSec + iSSec

    return iSeconds


#
# Function:
# Date:     4th April 2002
# Author:   James "Undead" Rocks
# *** Comments ***
#
def date2jul (sUTCTime):
    import string
    #
    # Extract Time Components
    #
    iYear = string.atoi(sUTCTime [0:4])
    iMonth = string.atoi(sUTCTime [5:7])
    iDay = string.atoi(sUTCTime [8:10])
    iHour = string.atoi(sUTCTime [11:13])
    iMinute = string.atoi(sUTCTime [14:16])
    iSSec = string.atoi(sUTCTime [17:19])

    if iDay == 1 or iDay == 21 or iDay == 31:
        sDay = str(iDay) + "st"
    elif iDay == 2 or iDay == 22:
        sDay = str(iDay) + "nd"
    elif iDay == 3 or iDay == 23:
        sDay = str(iDay) + "rd"
    else:
        sDay = str(iDay) + "th"

    sMonths = ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December']
    sMonth = sMonths[iMonth - 1]
    sJulian = string.zfill(iHour, 2) + ":" + string.zfill(iMinute, 2) + ",
" + sDay + " " + sMonth + ", " + str(iYear)

    return sJulian

#
# Function:
# Date:     4th April 2002
# Author:   James "Undead" Rocks
# *** Comments ***
#
def sec2jul (iSeconds):
    iDays = iSeconds/86400
    iHours = (iSeconds - (iDays * 86400))/3600
    iMinutes = (iSeconds - (iDays * 86400) - (iHours * 3600))/60
    iSeconds = iSeconds - (iDays * 86400) - (iHours * 3600) - (iMinutes *
60)

    sDays = str(iDays) + " day" + iif(iDays == 1, "", "s")
    sHours = str(iHours) + " hour" + iif(iHours == 1, "", "s")
    sMinutes = str(iMinutes) + " minute" + iif(iMinutes == 1, "", "s")
    sSeconds = str(iSeconds) + " second" + iif(iSeconds == 1, "", "s")

    if iDays > 0:
        sTime = sDays + ", " + sHours + ", " + sMinutes
    elif iHours > 0:
        sTime = sHours + ", " + sMinutes
    elif iMinutes > 0:
        sTime = sMinutes
    else:
        sTime = "Less than 1 minute"

    return sTime

#
# Function:
# Date:     4th April 2002
# Author:   James "Undead" Rocks
# *** Comments ***
#
def iif(iCondition, vTrue, vFalse):
    if iCondition:
        return vTrue
    else:
        return vFalse


*** Support Module CTXFUNC ****

#
# Module Name:  CTX Support Functions
# Last Updated: 4th April 2002
# Author:       James "Undead" Rocks
#

#
# Function: Read The CTX INI file (readctxini)
# Date:     4th April 2002
# Author:   James "Undead" Rocks
# *** Comments ***
# Queries the CTX INI (Windows only) file to return the specified value.
# Two arguments passed: Section Name & Key Name
# Returns:  value or an "N/A" if not found.
#
def readctxini (sSection, sKey, vDefault):
    import win32api

    sReturn = win32api.GetProfileVal(sSection, sKey , vDefault, "c:
\python22\ctxrept.ini")
    return sReturn


#
# Function: Write To The CTX INI file (writectxini)
# Date:     4th April 2002
# Author:   James "Undead" Rocks
# *** Comments ***
# Updates the CTX INI (Windows only) with the specified value
# updating Section & Ket as neccessary.
# Three arguments passed: Section Name, Key Name & Value
#
def writectxini (sSection, sKey, sValue):
    import win32api

    win32api.WriteProfileVal(sSection, sKey, sValue, "c:
\python22\ctxrept.ini")

*** Intermediate INI file ***

#
# Tempoary Variable Storage
#

[Servers]
Server 001=SRVA17
Server 002=SRVA14
Server 003=SRVA15
Server 004=SRVA18
Server 005= SRVA SATL19
Server 006= SRVA SGLA01

[SRVA17]
Description = SRVA17 (LONF01): Citrix ICA Master
Restarts =0
Found =Yes

[SRVA14]
Description = SRVA14: Atlas Application Server
Restarts =3
Found =Yes
Event 001=2002:10:01:18:21 2002:10:01:18:29 480
Event 002=2002:10:03:14:11 2002:10:03:14:24 780
Event 003=2002:10:04:13:25 2002:10:04:13:31 360

[SRVA15]
Description = SRVA15: Atlas Application Server
Restarts =8
Found =Yes
Event 001=2002:09:30:18:11 2002:09:30:18:24 780
Event 002=2002:10:01:12:56 2002:10:01:13:02 360
Event 003=2002:10:01:13:37 2002:10:01:13:44 420
Event 004=2002:10:01:15:09 2002:10:01:15:22 780
Event 005=2002:10:02:08:56 2002:10:02:09:09 780
Event 006=2002:10:02:10:31 2002:10:02:10:38 420
Event 007=2002:10:02:13:15 2002:10:02:15:22 7620
Event 008=2002:10:04:18:00 2002:10:04:18:07 420

[SRVA18]
Description = SRVA18: Atlas Application Server
Restarts =0
Found =Yes

[SRVASATL19]
Description = SRVA SATL19 (SRVA19): Atlas Application Server
Restarts =7
Found =Yes
Event 001=2002:09:30:13:26 2002:09:30:13:35 540
Event 002=2002:09:30:18:09 2002:09:30:18:16 420
Event 003=2002:10:01:15:48 2002:10:01:15:56 480
Event 004=2002:10:01:17:25 2002:10:02:10:07 60120
Event 005=2002:10:02:13:08 2002:10:02:13:16 480
Event 006=2002:10:04:10:50 2002:10:04:11:05 900
Event 007=2002:10:04:17:26 2002:10:04:17:40 840

[SRVASGLA01]
Description = SRVA SGLA01: GLA Application Server
Restarts =0
Found =Yes

Again my apologies for the size!

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From alan.gauld@bt.com  Tue Oct  8 10:47:35 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 8 Oct 2002 10:47:35 +0100
Subject: [Tutor] Default printer in Windows
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C948@mbtlipnt02.btlabs.bt.co.uk>

> I'm trying to automate printing pdf files from zope.  I'm planning on
> converting them to postscript and then copying them right to the
> printer.  But I need the user's default printer.  Can it be 
> retrieved by python? 

What platform?

If it's Unix then it might be defined in the PRINTER environment 
variable - although this is far from universal.

If it's Windoze then just printing to the PRN or LPT ports 
should work provided the printer is a real postscript printer
(if the postscvript processing is done in a device driver 
the raw data approach may not work!).

There are also things you can do with the registry but thats 
starting to get into using the WSH COM object model or Win32API 
which may lead to its own problems within a Zope architecture.

BTW which printer are you printing on? The client browser end 
or the Zope server end? It makes a big difference! The above 
all assumes the server end, if its the client things just got 
a whole heap more complex!

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



From alan.gauld@bt.com  Tue Oct  8 10:49:55 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 8 Oct 2002 10:49:55 +0100
Subject: [Tutor] regexing and timing, seperatly
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C949@mbtlipnt02.btlabs.bt.co.uk>

> an infinite loop but I don't want it to eat all my cpu time.  

Check out the select function....

> m = re.match("Player", data)

m = re.search((....)

match only finds the re at the start of the string.
A very common gotcha when using re...

Alan G.


From alan.gauld@bt.com  Tue Oct  8 10:53:27 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 8 Oct 2002 10:53:27 +0100
Subject: [Tutor] My First Python Program
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C94A@mbtlipnt02.btlabs.bt.co.uk>

> Obviously I want to improve that (it's a bit like tinkering with a car
> engine at times) so I was wondering if there's anywhere we can present
> small programs and say "tell me how I can make this better"?

Sure if they really are small - say ~100 lines or so?

But first why not play with the Python profiler and see 
where the time is being spent. That might give you some 
clues as to whjoch bits of your code need tightening up...

Alan g.


From James.Rocks@equant.com  Tue Oct  8 10:55:12 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Tue, 8 Oct 2002 10:55:12 +0100
Subject: [Tutor] What Is Python Based On?
Message-ID: <OF89EB4920.04CFCBEB-ON80256C4C.00365310@equant.com>

Hi,

I was just looking into Kylix & RAD etc. (in LinuxFormat, Nov 2002) and it
mentions that Delphi is a development of Pascal and that led me to wonder
what language (if any) is historically behind Python? Does anyone know?

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ
Phone:             0207-5226856
Fax:                   0207-5126087
Mobile Phone:     07771-767405
http://www.equant.com

This e-mail (including any attachments) is confidential and may be legally
privileged.  If you are not an intended recipient or an authorized
representative of an intended recipient, you are prohibited from using,
copying or distributing the information in this e-mail or its attachments.
If you have received this e-mail in error, please notify the sender
immediately by return e-mail and delete all copies of this message and any
attachments.  Thank you.



From alan.gauld@bt.com  Tue Oct  8 10:57:58 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 8 Oct 2002 10:57:58 +0100
Subject: [Tutor] Continuously Updating A Display?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C94B@mbtlipnt02.btlabs.bt.co.uk>

> I know how to create messages dialogs but how do I provide a running
> information panel ... I want it to provide information but 
> not to delay program execution.

Normally I'd do that with a label widget and just update the text 
from various points in my program. 


class TkinterApp(Frame):
   def __init__(self):
      self.MsgBrd = Label(self)
      self.MsgBoard.pack()
      # etc
   def another(self):
      # do some stuff
      self.MsgBrd['text'] = "I'm doing another thing!"
      # do some more

TkinterApp().mainloop()


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


From James.Rocks@equant.com  Tue Oct  8 10:57:31 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Tue, 8 Oct 2002 10:57:31 +0100
Subject: [Tutor] My First Python Program
Message-ID: <OF2D21F30C.A5F8A578-ON80256C4C.003690D0@equant.com>

> Sure if they really are small - say ~100 lines or so?

Oops! Sorry about that (I already posted and it's a bit big)!

> But first why not play with the Python profiler and see
> where the time is being spent. That might give you some
> clues as to whjoch bits of your code need tightening up...

Where's the Python profiler then?

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From schalla@vasoftware.com  Tue Oct  8 16:46:17 2002
From: schalla@vasoftware.com (schalla)
Date: Tue, 08 Oct 2002 15:46:17 +0000
Subject: [Tutor] Python with Clearcase
Message-ID: <3DA2FDC9.1040206@vasoftware.com>

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

Hi fellow Pythoners,

Im new to Python. Im working on a project in which i want to start a 
python file when any action (add, delete or update files) happens in the 
Clearcase repository.
what i want is the following:
 
1) The python file should start a trigger and the trigger should execute 
another python file.
2) The second python file should get the commit message, version and the 
person who updated the page into the repository.

It would be gr8 if anyone tell me how to go abt that, or if anyone 
worked on something similar a piece of code would be of great help.

Thanks a lot in advance

Schalla


--------------050301060509070204060008
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, Arial, sans-serif" size="-1">Hi fellow Pythoners,<br>
<br>
Im new to Python. Im working on a project in which i want to start a python
file when any action (add, delete or update files) happens in the Clearcase
repository.<br>
what i want is the following:<br>
&nbsp;<br>
1) The python file should start a trigger and the trigger should execute
another python file.<br>
2) The second python file should get the commit message, version and the
person who updated the page into the repository.<br>
<br>
It would be gr8 if anyone tell me how to go abt that, or if anyone worked
on something similar a piece of code would be of great help.<br>
<br>
Thanks a lot in advance<br>
<br>
Schalla<br>
<br>
</font>
</body>
</html>

--------------050301060509070204060008--



From James.Rocks@equant.com  Tue Oct  8 11:23:33 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Tue, 8 Oct 2002 11:23:33 +0100
Subject: [Tutor] Continuously Updating A Display?
Message-ID: <OFCA538749.F944B95D-ON80256C4C.0038EB8B@equant.com>

Hi Alan,

> TkinterApp().mainloop()
> Does that help?

Am I correct in thinking that that is Linux only, not Windows? Currently I
am working in Windows, I haven't yet got round to figuring how to develop
Python stuff on Linux yet ... I'm working on it though :-)

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From alan.gauld@bt.com  Tue Oct  8 11:37:10 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 8 Oct 2002 11:37:10 +0100
Subject: [Tutor] My First Python Program (Vey Large)!
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C94C@mbtlipnt02.btlabs.bt.co.uk>

> Comments are often an issue with interpreted languages 

Not significant with Python which compiles the code before running it.
The compile stage may take marginally longer but its no big deal.


However I'll strip out many of them below for brevity!

> # Program Variables ('s' denotes 'string', 'i' denotes 
> 'integer' and 'l' denotes 'logical')

Be aware that python variables are all object references so
the naming convention could be misleading since there is 
nothing to stop you reassigning (even accidentally) an 
integer to a string etc...

> sSrvName = ""       # Temporary string to store server names
> sSrvStatus = {}     # Array to contain current server event status
> sSrvDownDate = {}   # Array to contain current server down date
> sSrvDownTime = {}   # Array to contain current server down time

These are actually dictionaries not arrays, that could be 
significant later...

> lStart = _TRUE_     # Report start flag
> iSrvNumber = 0      # Number of servers so far found (integer)
> sReptStart = ""     # Initialise Report Start Date & Time (string)
> sReptEnd = ""       # Initialise Report End Date & Time (string)

This is crying out for a server class but we can ignore that for now!

> fCTXLog = open ('c:\python22\ctxstat.log', 'r')

Probably not a good idea to store the log file in the python directory 
tree, better to set up a dedicated folder for it somewhere...

> while _TRUE_:
>     sLine = fCTXLog.readline() + fCTXLog.readline()
>     if string.strip (sLine) == "":
>         break

You don't need the string module for strip, its now a method of 
string objects... since you use strip later assign to a variable:

sLine = sLine.strip()

>     sEvents = ["20" + sLine [7:9] + ":" + sLine [0:2] + ":" + 
> sLine [3:5],
> sLine [10:15], string.strip(sLine [17:27])]

string addition is inefficient coz it creates multiple intermediate strings,

you might get a speed up using string formatting instead:

sEvents = "20%s:%s:%s%s%s" %
(sLine[7:9],sLine[0:2],sLine[3:5],sline10:15],sLine17:25])

>     if ctxfunc.readctxini(sEvents[2], "Found", "No") == "No":
>         ctxfunc.writectxini(sEvents[2], "Found", "Yes")
>         ctxfunc.writectxini(sEvents[2], "Restarts", 0)
>         iSrvNumber = iSrvNumber + 1
>         sSrvNumber = "Server " +
> string.zfill(string.strip(str(iSrvNumber)), 3)

Try string formatting again:

          sSrvNumber = "Server%d" % iSrvNumber

>     sPDate = sEvents [0] + ":" + sEvents [1]+ ":00"

Hmm, always 2:0:00... I assume this will get changed at some point?


>     if lStart == _TRUE_:
>         sReptStart = sPDate
>         lStart = _FALSE_

>     if sLine [49:50] == "U":

One char so just use sLine[49] - indexing is cheaper than slicing....

>         sEvents.append ("UP")
>     else:
>         sEvents.append ("DOWN")

>     if string.find (sSrvName, "[" + sEvents[2] + "]") < 0:
>         sSrvName = sSrvName + "[" + sEvents [2] + "]"

You do the string creation twice so assign to a temp var:

     str = "[" + sEvents [2] + "]"
     if string.find (sSrvName, str) < 0:
         sSrvName = sSrvName + str

saves all that multiple string creation stuff being done more than once

>         sSrvStatus [sEvents[2]] = "UP"

>     if sSrvStatus[sEvents[2]] != sEvents [3]:
>         sSrvStatus [sEvents[2]] = sEvents [3]
>         if sEvents[3] == "DOWN":

This isn't quite so bad but you still do the indexing multiple 
times, temp variables are better.

index = sEvents[2]
condition = sEvents[3]

if sSrvStatus[index] != condition
     sSrvStatus[index] = condition
     if condition == "DOWN":
   
>                 iRestarts = iRestarts + 1
>                 sEventNo = 'Event ' + string.zfill(str(iRestarts), 3)

Use string formatting again.

> iReptTime = jcrfunc.time2sec(sReptEnd) - jcrfunc.time2sec(sReptStart)

Not sure what the jcrfunc stuff does but you might be better using 
the standard python time module?

> fCTXRept.write ("Citrix Server Report\n====================")
> fCTXRept.write ("\nReport Start:\t" + sJReptStart)
> fCTXRept.write ("\nReport End:\t" + sJReptEnd)
> fCTXRept.write ("\nReport Time:\t" + sJReptTime + " (" + 

Probably better to use triple quoted strings and formatting here then 
write the string in one go...

str = """    # The newline will be included but makes for neater code
layout...
Citrix Server Report
====================
Report Start:\t%s
Report End:\t%s
Report Time:\t%s (%d sec)

""" % (sJReptStart, sJReptEnd, sJReptTime)

fCTXRept.write(str)

Oops, I've run out of time(a teleconference calls)... 
but hopefully some general principles there.

Someone else will add more I guess.

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


From magnus@thinkware.se  Tue Oct  8 14:38:41 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue, 08 Oct 2002 15:38:41 +0200
Subject: [Tutor] Python with Clearcase
In-Reply-To: <3DA2FDC9.1040206@vasoftware.com>
Message-ID: <5.1.0.14.0.20021008152536.0310a9b8@www.thinkware.se>

At 15:46 2002-10-08 +0000, schalla wrote:
>Hi fellow Pythoners,
>
>Im new to Python. Im working on a project in which i want to start a=20
>python file when any action (add, delete or update files) happens in the=20
>Clearcase repository.
>what i want is the following:
>
>1) The python file should start a trigger and the trigger should execute=20
>another python file.

Huh? Surely a ClearCase event starts the trigger? If you
want to run clearcase commands from python, that's no big issue.
E.g.

---
import os
os.system('cleartool ci myfile.c')
---

That's the basic concept. If you need to do things based on
stdout/stderr instead you need some more code. See the use
of popen4 in mktrig.py (follow linkbelow).

>2) The second python file should get the commit message, version and the=20
>person who updated the page into the repository.
>
>It would be gr8 if anyone tell me how to go abt that, or if anyone worked=
=20
>on something similar a piece of code would be of great help.

I have some example code that registers triggers
and use python scripts to implement triggers as
well. They don't really do anything useful. They
where written as demonstrations for a course. See
http://www.thinkware.se/cgi-bin/thinki.cgi/PythonClearCase



--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From schalla@vasoftware.com  Tue Oct  8 20:58:57 2002
From: schalla@vasoftware.com (schalla)
Date: Tue, 08 Oct 2002 19:58:57 +0000
Subject: [Tutor] Python with Clearcase
References: <5.1.0.14.0.20021008152536.0310a9b8@www.thinkware.se>
Message-ID: <3DA33901.9090009@vasoftware.com>

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

Thanks Magnus,

Thanks for the sample code. I got an insight of how to go abt it.
The code is very helpful.
will get in touch  :)


Warm Regards

Schalla

Magnus Lycka wrote:

> At 15:46 2002-10-08 +0000, schalla wrote:
>
>> Hi fellow Pythoners,
>>
>> Im new to Python. Im working on a project in which i want to start a 
>> python file when any action (add, delete or update files) happens in 
>> the Clearcase repository.
>> what i want is the following:
>>
>> 1) The python file should start a trigger and the trigger should 
>> execute another python file.
>
>
> Huh? Surely a ClearCase event starts the trigger? If you
> want to run clearcase commands from python, that's no big issue.
> E.g.
>
> ---
> import os
> os.system('cleartool ci myfile.c')
> ---
>
> That's the basic concept. If you need to do things based on
> stdout/stderr instead you need some more code. See the use
> of popen4 in mktrig.py (follow linkbelow).
>
>> 2) The second python file should get the commit message, version and 
>> the person who updated the page into the repository.
>>
>> It would be gr8 if anyone tell me how to go abt that, or if anyone 
>> worked on something similar a piece of code would be of great help.
>
>
> I have some example code that registers triggers
> and use python scripts to implement triggers as
> well. They don't really do anything useful. They
> where written as demonstrations for a course. See
> http://www.thinkware.se/cgi-bin/thinki.cgi/PythonClearCase
>
>
>


--------------030501040305080608090204
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 size="-1"><font face="Helvetica, Arial, sans-serif">Thanks Magnus,<br>
<br>
Thanks for the sample code. I got an insight of how to go abt it.<br>
The code is very helpful. <br>
will get in touch &nbsp;:)<br>
<br>
<br>
Warm Regards<br>
<br>
Schalla</font></font><br>
<br>
Magnus Lycka wrote:<br>
<blockquote type="cite"
 cite="mid5.1.0.14.0.20021008152536.0310a9b8@www.thinkware.se">At 15:46 2002-10-08
+0000, schalla wrote: <br>
  <blockquote type="cite">Hi fellow Pythoners, <br>
 <br>
Im new to Python. Im working on a project in which i want to start a  python
file when any action (add, delete or update files) happens in the  Clearcase
repository. <br>
what i want is the following: <br>
 <br>
1) The python file should start a trigger and the trigger should execute
 another python file. <br>
  </blockquote>
 <br>
Huh? Surely a ClearCase event starts the trigger? If you <br>
want to run clearcase commands from python, that's no big issue. <br>
E.g. <br>
 <br>
--- <br>
import os <br>
os.system('cleartool ci myfile.c') <br>
--- <br>
 <br>
That's the basic concept. If you need to do things based on <br>
stdout/stderr instead you need some more code. See the use <br>
of popen4 in mktrig.py (follow linkbelow). <br>
 <br>
  <blockquote type="cite">2) The second python file should get the commit
message, version and the  person who updated the page into the repository. 
    <br>
 <br>
It would be gr8 if anyone tell me how to go abt that, or if anyone worked
 on something similar a piece of code would be of great help. <br>
  </blockquote>
 <br>
I have some example code that registers triggers <br>
and use python scripts to implement triggers as <br>
well. They don't really do anything useful. They <br>
where written as demonstrations for a course. See <br>
<a class="moz-txt-link-freetext" href="http://www.thinkware.se/cgi-bin/thinki.cgi/PythonClearCase">http://www.thinkware.se/cgi-bin/thinki.cgi/PythonClearCase</a> <br>
 <br>
 <br>
 <br>
</blockquote>
<br>
</body>
</html>

--------------030501040305080608090204--



From rlegge@tc3net.com  Tue Oct  8 16:11:38 2002
From: rlegge@tc3net.com (Ray Leggett)
Date: Tue, 8 Oct 2002 11:11:38 -0400
Subject: [Tutor] capturing os.system() output
Message-ID: <200210081511.g98FBFu8011774@tc3net.com>

All right, I know this is probably very basic, but how would I capture the 
output of an os.system() call, instead of having it print to standard output 
immediately? 


From annika.scheffler@gmx.net  Tue Oct  8 17:17:14 2002
From: annika.scheffler@gmx.net (Annika Scheffler)
Date: Tue, 8 Oct 2002 18:17:14 +0200 (MEST)
Subject: [Tutor] regular Expressions
Message-ID: <32701.1034093834@www55.gmx.net>

Hi all!

I have a problem with regular Expressions. I want to loop through each word
in a file and find that word and the next 25 characters in another file.

I tried it like that:

import re

for eW in sortedFile:
     mat = re.search(eW, "...........................", readFile)

I also tried that one:

import re

for eW in sortedFile:
    mat = re.search("eW.................", readFile)

I know the second version is NOT what I want. I don't actually search the
characters "eW", eW is a variable that stands for eachWord in the file.
But the first version doesn't work either. Why not?
And what is the proper way to do it?

Thanks a lot,

Annika

-- 
Ravens fly in flights, but the egale flies
alone.

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



From alan.gauld@bt.com  Tue Oct  8 17:17:56 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 8 Oct 2002 17:17:56 +0100
Subject: [Tutor] My First Python Program
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C955@mbtlipnt02.btlabs.bt.co.uk>

> Where's the Python profiler then?

In the profile module. Read the docs for info on how to use it.

Output looks like:

>>> profile.run("foo()")
...output here....
         3 function calls in 1.007 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.024    0.024    0.024    0.024 <stdin>:1(foo)
        1    0.000    0.000    0.024    0.024 <string>:1(?)
        1    0.983    0.983    1.007    1.007 profile:0(foo())
        0    0.000             0.000          profile:0(profiler)

HTH,

Alan G.


From shalehperry@attbi.com  Tue Oct  8 17:24:31 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue, 8 Oct 2002 09:24:31 -0700
Subject: [Tutor] regular Expressions
In-Reply-To: <32701.1034093834@www55.gmx.net>
References: <32701.1034093834@www55.gmx.net>
Message-ID: <200210080924.31282.shalehperry@attbi.com>

On Tuesday 08 October 2002 09:17, Annika Scheffler wrote:
>
> I know the second version is NOT what I want. I don't actually search t=
he
> characters "eW", eW is a variable that stands for eachWord in the file.
> But the first version doesn't work either. Why not?
> And what is the proper way to do it?
>

The regular expression documentation in the Python docs (and on the websi=
te)=20
should be quite helpful here.  Also, consider going to the bookstore and =
look=20
up O'Reilly and associates "Mastering Regular Expressions".  Yes it does =
talk=20
about Perl and other languages for the most part.  But the language of=20
regular expressions is fairly similar in most languages because everyone =
has=20
standardized on perl 5 regexs.


From Michael Montagne <montagne@boora.com>  Tue Oct  8 17:27:38 2002
From: Michael Montagne <montagne@boora.com> (Michael Montagne)
Date: Tue, 8 Oct 2002 09:27:38 -0700
Subject: [Tutor] Default printer in Windows
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C948@mbtlipnt02.btlabs.bt.co.uk>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C948@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20021008162738.GA22979@boora.com>

>On 08/10/02, from the brain of alan.gauld@bt.com tumbled:

> > I'm trying to automate printing pdf files from zope.  I'm planning on
> > converting them to postscript and then copying them right to the
> > printer.  But I need the user's default printer.  Can it be 
> > retrieved by python? 
> 
> What platform?
> 
> If it's Unix then it might be defined in the PRINTER environment 
> variable - although this is far from universal.
> 
> If it's Windoze then just printing to the PRN or LPT ports 
> should work provided the printer is a real postscript printer
> (if the postscvript processing is done in a device driver 
> the raw data approach may not work!).
> 
> There are also things you can do with the registry but thats 
> starting to get into using the WSH COM object model or Win32API 
> which may lead to its own problems within a Zope architecture.
> 
> BTW which printer are you printing on? The client browser end 
> or the Zope server end? It makes a big difference! The above 
> all assumes the server end, if its the client things just got 
> a whole heap more complex!
> 
> Alan g.
> Author of the 'Learning to Program' web site
> http://www.freenetpages.co.uk/hp/alan.gauld

It's Windoze and I'm trying to print to a printer defined on the client
machine.  My latest approach is to use this:
os.system('"c:\program files\Adobe\Acrobat 5.0\Acrobat\Acrobat.exe /p /h
e:\\mjm\\bor.pdf"')
to print a file named e:\\mjm\\bor.pdf".
It will only work if everyone's Acrobat.exe is in the same place, but
perhaps I can try a couple of different locations.  All I need is to get
the filename from zope and, in theory, it should print on the default
printer for the machine that Acobat is installed (the  client).
Untested but I hope it works cause the alternatives seem very complex.

-- 
  Michael Montagne  [montagne@boora.com]   503.226.1575 
--    


From alan.gauld@bt.com  Tue Oct  8 17:22:30 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 8 Oct 2002 17:22:30 +0100
Subject: [Tutor] Continuously Updating A Display?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C957@mbtlipnt02.btlabs.bt.co.uk>

> > TkinterApp().mainloop()
> > Does that help?
> 
> Am I correct in thinking that that is Linux only, not 
> Windows? 

Nope, its standard Tkinter.
Assuming thats what you are using for the GUI...

It might be worth checking the GIUI page on my web tutor
if you haven't used Tkinter before... Also the bigger 
tutor from the Python web site Tkinter section.

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


From alan.gauld@bt.com  Tue Oct  8 17:20:38 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 8 Oct 2002 17:20:38 +0100
Subject: [Tutor] Python with Clearcase
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C956@mbtlipnt02.btlabs.bt.co.uk>

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_01C26EE6.A35475B0
Content-Type: text/plain;
	charset="iso-8859-1"

>  Im new to Python. Im working on a project in which i want to start a
python file  
>  when any action (add, delete or update files) happens in the Clearcase
repository. 
 
What platform? Unix or NT?
 
It will make a significant difference! If on Unix I'd recommend sticking to
shell 
scripts for this job, but on NT python might be better bet....
 
At least your version control should be good! :-)
 
Green with envy and using Continuus,
 
Alan g.
 

------_=_NextPart_001_01C26EE6.A35475B0
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">
<TITLE></TITLE>

<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face="Helvetica, Arial, sans-serif"><FONT size=2><SPAN 
class=210352616-08102002><FONT face="Courier New" color=#0000ff>&gt; 
&nbsp;</FONT></SPAN>Im new to Python. Im working on a project in which i want to 
start a python file&nbsp;<SPAN class=210352616-08102002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face="Helvetica, Arial, sans-serif"><FONT size=2><SPAN 
class=210352616-08102002><FONT face="Courier New" color=#0000ff>&gt; 
</FONT>&nbsp;</SPAN>when any action (add, delete or update files) happens in the 
Clearcase repository.<SPAN class=210352616-08102002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face="Helvetica, Arial, sans-serif"><FONT size=2><SPAN 
class=210352616-08102002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face="Helvetica, Arial, sans-serif"><FONT size=2><SPAN 
class=210352616-08102002>What platform? Unix or NT?</SPAN></FONT></FONT></DIV>
<DIV><FONT face="Helvetica, Arial, sans-serif"><FONT size=2><SPAN 
class=210352616-08102002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face="Helvetica, Arial, sans-serif"><FONT size=2><SPAN 
class=210352616-08102002>It will make a significant difference! If on Unix I'd 
recommend sticking to shell </SPAN></FONT></FONT></DIV>
<DIV><FONT face="Helvetica, Arial, sans-serif"><FONT size=2><SPAN 
class=210352616-08102002>scripts for this job, but on NT python might be better 
bet....</SPAN></FONT></FONT></DIV>
<DIV><FONT face="Helvetica, Arial, sans-serif"><FONT size=2><SPAN 
class=210352616-08102002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face="Helvetica, Arial, sans-serif"><FONT size=2><SPAN 
class=210352616-08102002>At least your version control should be good! 
:-)</SPAN></FONT></FONT></DIV>
<DIV><FONT face="Helvetica, Arial, sans-serif"><FONT size=2><SPAN 
class=210352616-08102002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face="Helvetica, Arial, sans-serif"><FONT size=2><SPAN 
class=210352616-08102002>Green with envy and using 
Continuus,</SPAN></FONT></FONT></DIV>
<DIV><FONT face="Helvetica, Arial, sans-serif"><FONT size=2><SPAN 
class=210352616-08102002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face="Helvetica, Arial, sans-serif"><FONT size=2><SPAN 
class=210352616-08102002>Alan g.</SPAN></FONT></FONT></DIV>
<DIV><FONT face="Helvetica, Arial, sans-serif"><FONT size=2><FONT 
face="Courier New" color=#0000ff></FONT>&nbsp;</DIV></FONT></FONT></BODY></HTML>

------_=_NextPart_001_01C26EE6.A35475B0--


From alan.gauld@bt.com  Tue Oct  8 17:08:36 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 8 Oct 2002 17:08:36 +0100
Subject: [Tutor] What Is Python Based On?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C954@mbtlipnt02.btlabs.bt.co.uk>

> I was just looking into Kylix & RAD etc. 

It's good. If you need a compiled solution it's one of, if 
not *the* best.  :-)

> mentions that Delphi is a development of Pascal 

Actually of Object Pascal as developed for the Apple Mac.

> me to wonder what language (if any) is historically behind Python? 

Read the history on the web site.
The most immediate ancestor is ABC but in reality theres not 
that much similarity, I'd say C and Pascval both had influences 
too. And I know several folks who think Python looks a lot 
like Lisp... I wouldn't argue either!

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


From alan.gauld@bt.com  Tue Oct  8 17:24:53 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 8 Oct 2002 17:24:53 +0100
Subject: [Tutor] capturing os.system() output
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C958@mbtlipnt02.btlabs.bt.co.uk>

> All right, I know this is probably very basic, but how would 
> I capture the output of an os.system() call, instead of having 
> it print to standard output immediately? 

Use os.popen instead

There are several variants woith subtle differences, read the 
docs to pick the right one. I usually use popen2() 
- for reasons which escape me! :-)

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


From karthik@james.hut.fi  Tue Oct  8 19:17:34 2002
From: karthik@james.hut.fi (Karthikesh Raju)
Date: Tue, 8 Oct 2002 21:17:34 +0300
Subject: [Tutor] Help with Configparser/and classes
In-Reply-To: <20021008160006.10114.85591.Mailman@mail.python.org>
Message-ID: <Pine.SGI.4.21.0210082103100.1457788-100000@james.hut.fi>

Hi All,

Thankx to Danny Yoo and all for the previous answer. Now i am struck with
another one:

i am writing a class called communicate. Something like this:

class Communicate:
    """ This is the main communicate class : there will be more
    """

    def __init__(self):
        """This should hopefully read a file and set self's parameters
        """
        self.C = 10
        self.K = 6
        self.N = 8
        self.Na = 3
        self.L = 4
        self.modulation = "QPSK"


1. Shown is just one method in the class. Now there are lot of self
 variables (i understand they are something like private variables). Now i
 want to have an .ini file, so that i call something like this in the
  __init__ module :

def __init__(self, fileName):
    file = open(fileName, 'r')
    self = something(file)

and all the self's variables are set. i want the ini file to be the
interface between the class and the outside world. Some one suggested
ConfigParser , couldnt get an idea of what it is and how to use it..

2. Is this method of having all the data in self variables good.The size
of some of these 'self' could be very high 40000x40000 complex. Should i
create local variables in the methods (i need a lot of variables, but
their def life is too small .....)

for example one of the method could be:

def generateNoise(self):
        """ Generates AWGN
        """
        power = Numeric.sqrt(RandomArray.random()*10)
        Noise = Numeric.zeros(....)
        Noise.real = Random ......
        Noise.imag = RandomArray....

(Boared to type the whole thing that is why there are ......'s )

Any way power is a local variable, which i guess dies after
generateNoise() method is called in the object. Am i right..
Can i have variables like 'power'

3. Thirdly, i want an easy method like '.mat' that exists in matlab. Can i
use pickle (cPickle or Numeric.pickle) to store all the variables that i
want. These matrices could be 40000x40000 entries long. Assuming that all
the variables are in 'self' should i write an assignment module before
pickling them  (in case pickle is the right way to store these variables)

def writeToFile(self):
    Na = self.Na
    x =  self.x
    pickle the variables Na, x

Thankx in advance and in anticipation,

karthik 

PS: slowly moving from Matlab to Python, hence these stupid doubts

-----------------------------------------------------------------------
Karthikesh Raju,		    email: karthik@james.hut.fi		
Researcher,			    http://www.cis.hut.fi/karthik
Helsinki University of Technology,  Tel: +358-9-451 5389
Laboratory of Comp. & Info. Sc.,    Fax: +358-9-451 3277
Department of Computer Sc.,
P.O Box 5400, FIN 02015 HUT,
Espoo, FINLAND
-----------------------------------------------------------------------




From dfinner@Kollsman.com  Tue Oct  8 19:55:31 2002
From: dfinner@Kollsman.com (dfinner@Kollsman.com)
Date: Tue, 8 Oct 2002 14:55:31 -0400
Subject: [Tutor] Default printer in Windows
Message-ID: <85256C4C.0067F613.00@Notes.kollsman.com>


I'm new to Python, but have spent some time playing with printer assignments in
Lotus Notes.  If this helps, great.  If Python has some extra magic it can do,
even better!

The printer belongs to the OS so anything you want to do with various printer
settings has to be done through the Windows API; finding and setting default
printers, switching between landscape and portrait, etc.

There are several API sites that provide useful information about these
functions along with some pointers at a Notes discussion forum for things like
switching orientation and selecting printers.  From what little I have seen
about the Python Win32 stuff, you should be able to adopt much of this code into
the Python environment.

Caveat - there was a ton of discussion about accessing printers as a function of
the OS.  Win 9x was a no brainer, WinNT/2000/etc. had issues associated with the
login rights of the person on the workstation.  The consensus was that printer
stuff (on WinNT/2000) belonged to the admin account and was, therefore,
unavailable to the login person.  A recent addition to this thread seemed to
indicate this wasn't necessarily true.  I'm not sure how it's all playing out,
just a word of caution.

Hope this helps.

Doug

Windows API and VB Reference:
http://www.vbapi.com/index.html
http://www.allapi.net/
http://freevbcode.com/default.asp
http://www.mvps.org/vbnet/
http://www.vb-world.net/
http://msdn.microsoft.com/library/default.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vb98/html/vbidxkeycodeconstants.asp

 (VB Constants)

Printer Orientation:
http://www.notes.net/46dom.nsf/8fcda5a283f280b2852565590071d8af/c96d8f6be24082b98525693a0045e7a9!OpenDocument
http://www.notes.net/46dom.nsf/8fcda5a283f280b2852565590071d8af/88a79bd38a4fb8748525693b00411460!OpenDocument
http://209.180.19.180/pub/jordan/   (current code by the developer)
http://www.notes.net/sandbox.nsf/ecc552f1ab6e46e4852568a90055c4cd/b376f26b8cbd9f1b8525694d004e24c3?OpenDocument
http://www.notes.net/46dom.nsf/DateAllThreadedweb/b94b0b2454de749285256b66005e053d?OpenDocument

(why NT/2K is a problem)
http://www-10.lotus.com/ldd/46dom.nsf/ShowMyTopicsAllFlatweb/cb1c2b82362d531980256c2a0059f3c8?OpenDocument

(maybe NT/2K is not a problem)

Printer Selection:
http://www.notes.net/46dom.nsf/434e319a66960d8385256857005cd97b/3CA7A2FDFDC519F1852567BA004B3253?OpenDocument
http://web6.notes.net/46dom.nsf/434e319a66960d8385256857005cd97b/BE12FD60BA537B2C852568C00007B383?OpenDocument




From Andrew <angelopoulos@csi.com>  Tue Oct  8 23:54:33 2002
From: Andrew <angelopoulos@csi.com> (Andrew)
Date: Tue, 8 Oct 2002 18:54:33 -0400
Subject: Re[2]: [Tutor] Default printer in Windows
In-Reply-To: <20021008162738.GA22979@boora.com>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C948@mbtlipnt02.btlabs.bt.co.uk>
 <20021008162738.GA22979@boora.com>
Message-ID: <1338735091.20021008185433@csi.com>

MM> It's Windoze and I'm trying to print to a printer defined on the client
MM> machine.  My latest approach is to use this:
MM> os.system('"c:\program files\Adobe\Acrobat 5.0\Acrobat\Acrobat.exe /p /h
MM> e:\\mjm\\bor.pdf"')
MM> to print a file named e:\\mjm\\bor.pdf".
MM> It will only work if everyone's Acrobat.exe is in the same place, but
MM> perhaps I can try a couple of different locations.  All I need is to get
MM> the filename from zope and, in theory, it should print on the default
MM> printer for the machine that Acobat is installed (the  client).
MM> Untested but I hope it works cause the alternatives seem very complex.


Hi Michael,

I'm not a Python expert, and there might be a better way, but why not
prompt them to find Adobe for you the first time? You can then store/pickle that
information?

-- Andrew                            
mailto:angelopoulos@csi.com
-- 



From magnus@thinkware.se  Wed Oct  9 00:12:55 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed, 09 Oct 2002 01:12:55 +0200
Subject: [Tutor] What Is Python Based On?
In-Reply-To: <OF89EB4920.04CFCBEB-ON80256C4C.00365310@equant.com>
Message-ID: <5.1.0.14.0.20021009010135.0324dbc8@www.thinkware.se>

At 10:55 2002-10-08 +0100, James.Rocks@equant.com wrote:
>what language (if any) is historically behind Python? Does anyone know?

Python is more original than Delphi/Kylix which is
a kind of Pascal.

The main inspirations were ABC and Modula-3. Guido had some
summer job at Digital and worked with Modula-3 at the place
where it was developed. He worked with the development of
ABC in Amsterdam, in Andrew Tannenbaum's Amoeba project.

The perhaps most noticable python element: That indentation
determines block structure is a ABC feature.

The parts of Python that aren't coded in Python are
coded in C, and this shines through in places. For
instance "import time, math" will give you two modules
that are basically thin wrappers over std C libraries.

There are some syntac elements that are C-like, for
instance = for assignment and == for equality, but
it's certainly not a C look-alike like Java and C#.

Some functional elements have been borrowed from Lisp
(map, reduce, filter, lambda) and recently list
comprehension was borrowed from Haskell.

You can find some examples of code written in all these
languages at http://99-bottles-of-beer.ls-la.net/ so
you can compare...


-- 
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 abarker@xminc.com  Wed Oct  9 03:03:36 2002
From: abarker@xminc.com (Anthony Barker)
Date: Tue, 08 Oct 2002 22:03:36 -0400
Subject: [Tutor] What Is Python Based On?
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C954@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <3DA38E78.8070500@xminc.com>

alan.gauld@bt.com wrote:
>>I was just looking into Kylix & RAD etc. 
> 
> 
> It's good. If you need a compiled solution it's one of, if 
> not *the* best.  :-)

I think that QT is close in terms of speed of development.
It is free for Linux, uses more the more standard C++, and classes map 
somewhat closely to MFC

+++ it has python bindings

http://www.opendocspublishing.com/pyqt/

For database stuff Delphi/Kylix is probably more mature although
QT 3 has some some stuff - and trolltech is very actively
developing it.


Python has nice a fairly nice C interface
Python for speed of development and you can recode
slower stuff in c.

Also you can look at blackadder (I haven't tried it):

http://www.thekompany.com/products/blackadder/

Also many people use wxPython...

Anthony




From dylan.belsey@baesystems.com  Wed Oct  9 00:41:54 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Wed, 9 Oct 2002 09:11:54 +0930
Subject: [Tutor] Continuously Updating A Display?
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B98D2ACF@wtntex1.baea.com.au>

Alternatively, try the "after" method on widgets.  This creates a callback
to a user defined function after a preset period of time.  Note: Only
referring to Tkinter at the moment.

-----Original Message-----
From: alan.gauld@bt.com [mailto:alan.gauld@bt.com]
Sent: Tuesday, 8 October 2002 19:58
To: James.Rocks@equant.com; tutor@python.org
Subject: RE: [Tutor] Continuously Updating A Display?


> I know how to create messages dialogs but how do I provide a running
> information panel ... I want it to provide information but 
> not to delay program execution.

Normally I'd do that with a label widget and just update the text 
from various points in my program. 


class TkinterApp(Frame):
   def __init__(self):
      self.MsgBrd = Label(self)
      self.MsgBoard.pack()
      # etc
   def another(self):
      # do some stuff
      self.MsgBrd['text'] = "I'm doing another thing!"
      # do some more

TkinterApp().mainloop()


Does that help?
     
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


From dylan.belsey@baesystems.com  Wed Oct  9 02:49:48 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Wed, 9 Oct 2002 11:19:48 +0930
Subject: [Tutor] Passing a value into an embedded python interpreter
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B98D2AD0@wtntex1.baea.com.au>

	FYI. To answer my own question and for anyone else who is
interested....the simple solution is to use sprintf() and create a command
string, with the variable I want to pass in, as a parameter in the string.
	Then use PyRun_SimpleString(command_string) to pass it into the
interpreter.  The command string looks something like: "Python_variable =
45675218" (arbitrary number used here).
	PyRun_SimpleString lives in Python.h.  I can't claim ownership of
this solution.  It was adapted from an example in Chapter 17, Embedding and
Extending Python with C/C++, page 639, Professional Linux Programming - Neil
Matthew and Richard Stones et al., Wrox Press Ltd, 2000.
	

-----Original Message-----
From: BELSEY, Dylan [mailto:dylan.belsey@baesystems.com]
Sent: Tuesday, 8 October 2002 17:08
To: 'tutor@python.org'
Subject: [Tutor] Passing a value into an embedded python interpreter


Hi Tutor list,
	I am attempting to embed the python interpreter into C++ code.  I
have successfully been able to create functions in C++ that can be called
from the embedded interpreted environment (with the use of SWIG).  However,
I can't see my way clearly on how I can pass (map) the value of a variable
in C++, to a variable in the python namespace.
	If anyone has dealt with this or has any ideas, your advice would be
much appreciated.  I have of course been perusing the doco on extending and
embedding Python and the initial possibilities on how to tackle this problem
seem to be quite convoluted (to me anyway).
	TIA,
		Dylan

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


From yaya@ntlworld.com  Wed Oct  9 04:13:26 2002
From: yaya@ntlworld.com (Phil Watson)
Date: Wed, 9 Oct 2002 04:13:26 +0100
Subject: [Tutor] Please Remove me from the mailing list!
Message-ID: <000c01c26f41$d59f4ee0$c5c90350@sn010966720387>

This is a multi-part message in MIME format.

------=_NextPart_000_0009_01C26F4A.3733F450
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


------=_NextPart_000_0009_01C26F4A.3733F450
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>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0009_01C26F4A.3733F450--




From goneil@scu.edu  Wed Oct  9 07:41:21 2002
From: goneil@scu.edu (Galen O'Neil)
Date: 08 Oct 2002 23:41:21 -0700
Subject: [Tutor] xml.sax error
Message-ID: <1034145694.4008.26.camel@lucidia>

Dear Pythoners,
	I'm begginging to work with xml.sax,and my interpretation of the error
message I got would be that there is some sort of problem with the
module.  But I doubt that is the actual answer, as I was using on the
most basic functionality.  
	The code I'm running is almost directly from a HOWTO @
(http://pyxml.sourceforge.net/topics/howto/node12.html). Am I doing
something wrong?  Take a look and let me know what you see.
Thanks,
Galen

I run this code:

if __name__ == '__main__':
	#Create a parser
	parser = make_parser()
	
	#Create the handler
	dh = ReadAccounts(accounts)
	
	#Tell the parser to use my f'in handler yo
	parser.setContentHandler(dh)
	
	#open the file
	file = open("autokelvan.xml", "r")
	
	#Parse the input
	parser.parse(file)

I get this output:

>python -u xmlin.py
Traceback (most recent call last):
  File "xmlin.py", line 83, in ?
    parser.parse(file)
  File "/usr/lib/python2.2/site-packages/_xmlplus/sax/expatreader.py",
line 107, in parse
    self.reset()
  File "/usr/lib/python2.2/site-packages/_xmlplus/sax/expatreader.py",
line 236, in reset
    self._parser = expat.ParserCreate(intern = self._interning)
TypeError: 'intern' is an invalid keyword argument for this function
>Exit code: 256





From Jmllr891@cs.com  Wed Oct  9 10:27:35 2002
From: Jmllr891@cs.com (Jmllr891@cs.com)
Date: Wed, 9 Oct 2002 05:27:35 EDT
Subject: [Tutor] Windows Standalone Icon?
Message-ID: <167.155483d3.2ad55087@cs.com>

--part1_167.155483d3.2ad55087_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

I've been turning my Python scripts into Windows standalone executables (.exe 
files) so my friends can use them too. I have a few icons that I have 
designed that I would like to use for my programs, but I can't use anything 
besides the default Python icon.

I've heard that it is possible to change the icon if you are running Windows 
NT or 2000, but I'm running Windows ME. So, is there something I can change 
in my setup script to allow me to use custom icons or am I stuck?

--part1_167.155483d3.2ad55087_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've been turning my Python scripts into Windows standalone executables (.exe files) so my friends can use them too. I have a few icons that I have designed that I would like to use for my programs, but I can't use anything besides the default Python icon.<BR>
<BR>
I've heard that it is possible to change the icon if you are running Windows NT or 2000, but I'm running Windows ME. So, is there something I can change in my setup script to allow me to use custom icons or am I stuck?</FONT></HTML>

--part1_167.155483d3.2ad55087_boundary--


From alan.gauld@bt.com  Wed Oct  9 15:42:56 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 9 Oct 2002 15:42:56 +0100
Subject: [Tutor] Default printer in Windows
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C95C@mbtlipnt02.btlabs.bt.co.uk>

> It's Windoze and I'm trying to print to a printer defined on 
> the client machine.  My latest approach is to use this:
> os.system('"c:\program files\Adobe\Acrobat 

What if your clients are using Macs? Or Linux?
Or a different browser that won't run Pytho - Opera say?
Or AOL or Mozilla, or a text browser like lynx?

You have no control over the client on a web site (normally, 
intranet might occasionally be different!). The best bet is 
normally to just present an HTML page that easy for the 
client user to print manually IME.

> the filename from zope and, in theory, it should print on the default
> printer for the machine that Acobat is installed (the  client).

How are you getting the python code to run on the client? Have 
they all got the WSH python extensions installed?
I wasn't waware that Zope could do anything client side...


> Untested but I hope it works cause the alternatives seem very complex.

Unfortunately you are correct.

Alan G


From alan.gauld@bt.com  Wed Oct  9 15:52:59 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 9 Oct 2002 15:52:59 +0100
Subject: [Tutor] What Is Python Based On?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C95D@mbtlipnt02.btlabs.bt.co.uk>

> > It's good. If you need a compiled solution it's one of, if 
> > not *the* best.  :-)
> 
> I think that QT is close in terms of speed of development.

QT is a class library but Kylix is an IDE so theres not 
much comparison. Kylix GUI classes are the QT ones licensed 
by Borland from Troll and wrapped to mimic the CLX classes 
on Windows.

But it is the IDE/Compiler I was talking about. The compiled 
code is faster than GNU g++ and faster to write than C++.

Its not as fast as Python for development time but thats
no good if you really need a compiled solution...


> It is free for Linux, uses more the more standard C++, 

Kylix is free in its most basic form, and uses Object Pascal...

> classes map somewhat closely to MFC

Kylix is code compatible with Delphi for windoze...

If getting paid for writing the code I'd rather use Kylix. 
If doing it for free I'd probably go with Qt or GT/k

Alan g.


From dfinner@Kollsman.com  Wed Oct  9 16:12:35 2002
From: dfinner@Kollsman.com (dfinner@Kollsman.com)
Date: Wed, 9 Oct 2002 11:12:35 -0400
Subject: [Tutor] Watch folder code - follow up question
Message-ID: <85256C4D.00538CBF.00@Notes.kollsman.com>


Thanks to Lei, I've tried building the first bit of the skeleton to watch a
folder.

import win32api
pathName = 'c:\\IDFIles'
bSubDirs = False
filter = FILE_NOTIFY_CHANGE_FILE_NAME
chgHandle = win32api.FindFirstChangeNotification(pathName, bSubDirs , filter )
print chgHandle

Generates the following:
Traceback (most recent call last):
  File "C:\Python22\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
 line 301, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Python22\Lib\DFScripts\DirWatcher.py", line 4, in ?
    filter = 0 #FILE_NOTIFY_CHANGE_FILE_NAME
NameError: name 'FILE_NOTIFY_CHANGE_FILE_NAME' is not defined

Per the help in Win32API, filter is an int variable.  If I substitue an integer
(1 or 2 for instance), for filter, I get back a chgHandle value.

I've poked around the web at various Win API sites and have not found anything
that converts the filter into an integer.  Any idea what
FILE_NOTIFY_CHANGE_FILE_NAME is as an integer???

TIA

Doug


BTW - I found this while looking around.  I'll probably try to convert this into
some Python-esque code.

http://www.codeproject.com/file/directorychangewatcher.asp




From James.Alexander.McCarney@Cognicase.com  Wed Oct  9 21:06:23 2002
From: James.Alexander.McCarney@Cognicase.com (McCarney, James Alexander)
Date: Wed, 9 Oct 2002 16:06:23 -0400
Subject: [Tutor] pseudo code --- search for <> tags
Message-ID: <23FD7B1A77E8D211BCB900001D108C02023FCA4B@camelot>

Hi list,

I want to search for all files in a folder/subfolder and output to a
textfile.

OS: Windows 2000
Py Version: 2.2.1

Here are the steps I think my script should take:

Accept the folder name and wildcard file search; if folder doesn't exist
tell me. If there are no files of the type for which I am searching tell me.

Ask me the name of the file to which I want to save the info.

Locate the folder.

Locate the files.

Open files for reading

Report the name and location of the file and put it in front of the returned
info.

Take whatever begins with '<' and ends with '/>'

Open a file for writing.

Put the '<' ... '/>' in the file

Save the file.

###pseudo code start
def TagFinger():
    """Finds mark-up, and prints it to a text file."""
    #imports
    import sys, string, os, os.path
    #welcome
    print "Welcome to TagFinger!"
    print ""
    folder=raw_input("Please type the name of the folder you wish to search:
") #this does not work ... Here is the error
"""
Traceback (most recent call last):
  File "<pyshell#16>", line 1, in ?
    folder
NameError: name 'folder' is not defined
"""

I would have thought if I entered (for example) "c:\*.*", when I type >>>
folder I would have gotten the input stored in folder.

Can anyone please tell me where to start? I thank you all for your help.


From magnus@thinkware.se  Wed Oct  9 21:47:12 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed, 09 Oct 2002 22:47:12 +0200
Subject: [Tutor] pseudo code --- search for <> tags
In-Reply-To: <23FD7B1A77E8D211BCB900001D108C02023FCA4B@camelot>
Message-ID: <5.1.0.14.0.20021009223143.032902a0@www.thinkware.se>

At 16:06 2002-10-09 -0400, McCarney, James Alexander wrote:
>I want to search for all files in a folder/subfolder and output to a
>textfile.

If you want to recursively work through subdirectories,
you should have a look at os.path.walk.

>Locate the folder.

os.chdir(...)

>Locate the files.

glob.glob('*.xxx')

>Open files for reading

f =3D file(filename, 'rt')
text =3D f.read()

>Report the name and location of the file and put it in front of the=
 returned
>info.

Have a look at the os.path module to get things
portable.

>Take whatever begins with '<' and ends with '/>'

I'm not quite sure what you intend here. What would
you want from "XXX<asd>12123123<asd/>XXX"?
a) <asd>12123123<asd/>
or
b) <asd/>
?

import re
re.findall(r"(<.+?/>)",text)    # case a
re.findall(r"(<[^>]+?/>)",text) # case b

Actually, to make case a handle line breaks in tags you need

pat =3D re.compile(r"(<.+?/>)",re.DOTALL)
pat.findall(text)

I'll let you figure out the rest.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From dandudle@msn.com  Wed Oct  9 14:51:49 2002
From: dandudle@msn.com (Peter Dudleston)
Date: Wed, 09 Oct 2002 07:51:49 -0600
Subject: [Tutor] Help  Return's are confusing me
Message-ID: <F18hsP3K0n3uEwiYrYK00000177@hotmail.com>

Help
Hello everyone

I know that return's return the function or at least I thought that if I 
have some like this

def julian_leap(y):
    if (y%4) == 0:
     return 1
return 0

what is the 1 returning and what is the 0 returning thanks for all the help

Sincelely Danny D



_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com



From python <python@inkedmn.net>  Wed Oct  9 22:59:43 2002
From: python <python@inkedmn.net> (python)
Date: Wed, 9 Oct 2002 14:59:43 -0700
Subject: [Tutor] Help  Return's are confusing me
In-Reply-To: <F18hsP3K0n3uEwiYrYK00000177@hotmail.com>
References: <F18hsP3K0n3uEwiYrYK00000177@hotmail.com>
Message-ID: <103509210907.20021009145943@inkedmn.net>

peter,

ok, it works like this...

in the example you posted, there are two return statements.  it might
have been better written like this:

def julian_leap(y):
     if (y%4) == 0:
        return 1  #is returned if the conditional is true
     else:
        return 0  #is returned if the conditional is false


it'd look something like this:

>>> def julian_leap(y):
...     if (y % 4) == 0:
...             return "yes"
...     else:
...             return "no"
...
>>> julian_leap(4)
'yes'
>>> julian_leap(7)
'no'


make sense?

brett



From glingl@aon.at  Thu Oct 10 00:12:38 2002
From: glingl@aon.at (Gregor Lingl)
Date: Thu, 10 Oct 2002 01:12:38 +0200
Subject: [Tutor] Help  Return's are confusing me
References: <F18hsP3K0n3uEwiYrYK00000177@hotmail.com> <103509210907.20021009145943@inkedmn.net>
Message-ID: <3DA4B7E6.1050509@aon.at>

python schrieb:

>peter,
>
>ok, it works like this...
>
>in the example you posted, there are two return statements.  it might
>have been better written like this:
>
>def julian_leap(y):
>     if (y%4) == 0:
>        return 1  #is returned if the conditional is true
>     else:
>        return 0  #is returned if the conditional is false
>
>  
>

Why not:

def julian_leap(y):
    return y%4 == 0

Regards, Gregor




From darnold02@sprynet.com  Thu Oct 10 00:43:41 2002
From: darnold02@sprynet.com (Don Arnold)
Date: Wed, 9 Oct 2002 18:43:41 -0500
Subject: [Tutor] Help  Return's are confusing me
References: <F18hsP3K0n3uEwiYrYK00000177@hotmail.com> <103509210907.20021009145943@inkedmn.net> <3DA4B7E6.1050509@aon.at>
Message-ID: <006c01c26fed$bb865330$c111ba3f@defaultcomp>

----- Original Message -----
From: "Gregor Lingl" <glingl@aon.at>
To: "python" <python@inkedmn.net>
Cc: "Peter Dudleston" <dandudle@msn.com>; <tutor@python.org>
Sent: Wednesday, October 09, 2002 6:12 PM
Subject: Re: [Tutor] Help Return's are confusing me


> python schrieb:
>
> >peter,
> >
> >ok, it works like this...
> >
> >in the example you posted, there are two return statements.  it might
> >have been better written like this:
> >
> >def julian_leap(y):
> >     if (y%4) == 0:
> >        return 1  #is returned if the conditional is true
> >     else:
> >        return 0  #is returned if the conditional is false
> >
> >
> >
>
> Why not:
>
> def julian_leap(y):
>     return y%4 == 0
>
> Regards, Gregor
>
>

because it's wrong? ; )  a year divisible by 100 isn't a leap year unless
it's divisible by 400. so:

def julian_leap(y):
    return (y % 4 == 0 and y % 100 != 0) or (y % 400 == 0)

Don



From glingl@aon.at  Thu Oct 10 00:54:33 2002
From: glingl@aon.at (Gregor Lingl)
Date: Thu, 10 Oct 2002 01:54:33 +0200
Subject: [Tutor] Help  Return's are confusing me
References: <F18hsP3K0n3uEwiYrYK00000177@hotmail.com> <103509210907.20021009145943@inkedmn.net> <3DA4B7E6.1050509@aon.at> <006c01c26fed$bb865330$c111ba3f@defaultcomp>
Message-ID: <3DA4C1B9.2030407@aon.at>

Don Arnold schrieb:

>----- Original Message -----
>From: "Gregor Lingl" <glingl@aon.at>
>To: "python" <python@inkedmn.net>
>Cc: "Peter Dudleston" <dandudle@msn.com>; <tutor@python.org>
>Sent: Wednesday, October 09, 2002 6:12 PM
>Subject: Re: [Tutor] Help Return's are confusing me
>
>
>  
>
>>python schrieb:
>>
>>    
>>
>>>peter,
>>>
>>>ok, it works like this...
>>>
>>>in the example you posted, there are two return statements.  it might
>>>have been better written like this:
>>>
>>>def julian_leap(y):
>>>    if (y%4) == 0:
>>>       return 1  #is returned if the conditional is true
>>>    else:
>>>       return 0  #is returned if the conditional is false
>>>
>>>
>>>
>>>      
>>>
>>Why not:
>>
>>def julian_leap(y):
>>    return y%4 == 0
>>
>>Regards, Gregor
>>
>>
>>    
>>
>
>because it's wrong? ; )  a year divisible by 100 isn't a leap year unless
>it's divisible by 400. so:
>
>def julian_leap(y):
>    return (y % 4 == 0 and y % 100 != 0) or (y % 400 == 0)
>
>Don
>
>
>  
>
Isn't this gregorian_leap?
Gregor  ;-)


>  
>






From magnus@thinkware.se  Thu Oct 10 01:05:08 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu, 10 Oct 2002 02:05:08 +0200
Subject: [Tutor] Help  Return's are confusing me
In-Reply-To: <006c01c26fed$bb865330$c111ba3f@defaultcomp>
References: <F18hsP3K0n3uEwiYrYK00000177@hotmail.com>
 <103509210907.20021009145943@inkedmn.net>
 <3DA4B7E6.1050509@aon.at>
Message-ID: <5.1.0.14.0.20021010020410.032a8690@www.thinkware.se>

At 18:43 2002-10-09 -0500, Don Arnold wrote:
>because it's wrong? ; )  a year divisible by 100 isn't a leap year unless
>it's divisible by 400. so:

Don, I think you are confusing Julian and Gregorian calendars.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Thu Oct 10 01:03:52 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu, 10 Oct 2002 02:03:52 +0200
Subject: [Tutor] Help  Return's are confusing me
In-Reply-To: <F18hsP3K0n3uEwiYrYK00000177@hotmail.com>
Message-ID: <5.1.0.14.0.20021010014442.032a68d8@www.thinkware.se>

At 07:51 2002-10-09 -0600, Peter Dudleston wrote:
>I know that return's return the function or at least I thought that if I=20
>have some like this

The return statement is used to return a value to
the caller of the function. For instance, this can
be the result of a calculation:

def pythagoras(a, b):
     import math
     return math.sqrt(a*a+b*b)

print pythagoras(3,4)
5.0


>def julian_leap(y):
>    if (y%4) =3D=3D 0:
>     return 1
>return 0
>
>what is the 1 returning and what is the 0 returning thanks for all the help

Typically, 1 is used to indicate "true" and 0 is
used to indicate "false" in Python. To be a little
more precise, numeric 0 and empty things indicate
false. E.g.

if []: never gets here
elif "": nor here
elif 0.0: nor here
else: always here

To be even more precise, see Python Language Reference
section 5.10 and section 3.3.1 (__nonzero__).

In the case above, julian_leap could be used like this:

y =3D input('Year please: ')
assert type(y) =3D=3D type(0)

print "Hello, I'd like to tell you that", y, "is",

if not julian_leap(y):
     print "not",

print "a Julian leap year."


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From darnold02@sprynet.com  Thu Oct 10 02:05:08 2002
From: darnold02@sprynet.com (Don Arnold)
Date: Wed, 9 Oct 2002 20:05:08 -0500
Subject: [Tutor] Help  Return's are confusing me
References: <F18hsP3K0n3uEwiYrYK00000177@hotmail.com> <103509210907.20021009145943@inkedmn.net> <3DA4B7E6.1050509@aon.at> <006c01c26fed$bb865330$c111ba3f@defaultcomp> <3DA4C1B9.2030407@aon.at>
Message-ID: <008601c26ff9$1c208bb0$c111ba3f@defaultcomp>

----- Original Message -----
From: "Gregor Lingl" <glingl@aon.at>
To: "Don Arnold" <darnold02@sprynet.com>
Cc: "python" <python@inkedmn.net>; "Peter Dudleston" <dandudle@msn.com>;
<tutor@python.org>
Sent: Wednesday, October 09, 2002 6:54 PM
Subject: Re: [Tutor] Help Return's are confusing me


> Don Arnold schrieb:
>
> >----- Original Message -----
> >From: "Gregor Lingl" <glingl@aon.at>
> >To: "python" <python@inkedmn.net>
> >Cc: "Peter Dudleston" <dandudle@msn.com>; <tutor@python.org>
> >Sent: Wednesday, October 09, 2002 6:12 PM
> >Subject: Re: [Tutor] Help Return's are confusing me
> >
> >
> >
> >
> >>python schrieb:
> >>
> >>
> >>
> >>>peter,
> >>>
> >>>ok, it works like this...
> >>>
> >>>in the example you posted, there are two return statements.  it might
> >>>have been better written like this:
> >>>
> >>>def julian_leap(y):
> >>>    if (y%4) == 0:
> >>>       return 1  #is returned if the conditional is true
> >>>    else:
> >>>       return 0  #is returned if the conditional is false
> >>>
> >>>
> >>>
> >>>
> >>>
> >>Why not:
> >>
> >>def julian_leap(y):
> >>    return y%4 == 0
> >>
> >>Regards, Gregor
> >>
> >>
> >>
> >>
> >
> >because it's wrong? ; )  a year divisible by 100 isn't a leap year unless
> >it's divisible by 400. so:
> >
> >def julian_leap(y):
> >    return (y % 4 == 0 and y % 100 != 0) or (y % 400 == 0)
> >
> >Don
> >
> >
> >
> >
> Isn't this gregorian_leap?
> Gregor  ;-)
>

it most certainly is. will anybody volunteer to help me get this egg off my
face? : )

Don




From nano@intermatik.co.id  Thu Oct 10 02:55:58 2002
From: nano@intermatik.co.id (nano)
Date: 10 Oct 2002 08:55:58 +0700
Subject: [Tutor] variables into a dictionary
Message-ID: <1034214976.4366.4.camel@jrwd.internal.intermatik.com>

hello pythoners,
i have some variables here:
one = 1
three = 4
six = 6

how can i assign those vars into a dictionary
numbers={'one':one,'three':three,'six':six}

that would be all for now,
TIA

nano'





From udigom@dandy.net  Thu Oct 10 05:25:31 2002
From: udigom@dandy.net (udigom)
Date: Thu, 10 Oct 2002 00:25:31 -0400
Subject: [Tutor] newbie "sound" question
Message-ID: <000b01c27015$12b3e9c0$2f891c42@dandy.net>

Hi all! Thanks for allowing me to join, lurk, and learn.

I am very new to python, and I have dl'ed the proper files and have had some
basic experience with IDLE, etc.

I am curious-- I have duplicated the hello world.py, and some other
exercises-- Is it possible to create sounds in .py files? If so, could one
of you kind people provide me with a simple basic source code so that I can
learn from it?

I thank you in advance !

udi





From goneil@scu.edu  Thu Oct 10 07:02:16 2002
From: goneil@scu.edu (Galen O'Neil)
Date: 09 Oct 2002 23:02:16 -0700
Subject: [Tutor] newbie "sound" question
In-Reply-To: <000b01c27015$12b3e9c0$2f891c42@dandy.net>
References: <000b01c27015$12b3e9c0$2f891c42@dandy.net>
Message-ID: <1034229751.4548.10.camel@lucidia>

On Wed, 2002-10-09 at 21:25, udigom wrote:
> Hi all! Thanks for allowing me to join, lurk, and learn.
> 
> I am very new to python, and I have dl'ed the proper files and have had some
> basic experience with IDLE, etc.
> 
> I am curious-- I have duplicated the hello world.py, and some other
> exercises-- Is it possible to create sounds in .py files? If so, could one
> of you kind people provide me with a simple basic source code so that I can
> learn from it?


If you want to play sounds then you should check out pygame.
www.pygame.org

Make sure you get the examples, there is one called sound.py that is
pretty simple.

#load the sound    
file = os.path.join('data', 'secosmic_lo.wav')
sound = mixer.Sound(file)


#start playing
print 'Playing Sound...'
channel = sound.play()


#poll until finished
while channel.get_busy(): #still playing
    print '  ...still going...'
    time.wait(1000)
print '...Finished'





From j.ezequiel@spitech.com  Thu Oct 10 08:31:56 2002
From: j.ezequiel@spitech.com (Justin Ezequiel)
Date: Thu, 10 Oct 2002 15:31:56 +0800
Subject: [Tutor] RE: Watch folder code - follow up question
Message-ID: <01C27072.2DED3C20@pc7486>

FILE_NOTIFY_CHANGE_FILE_NAME = 1

Message: 7
From: dfinner@Kollsman.com
To: tutor@python.org
Date: Wed, 9 Oct 2002 11:12:35 -0400
Subject: [Tutor] Watch folder code - follow up question



Thanks to Lei, I've tried building the first bit of the skeleton to watch a
folder.

import win32api
pathName = 'c:\\IDFIles'
bSubDirs = False
filter = FILE_NOTIFY_CHANGE_FILE_NAME
chgHandle = win32api.FindFirstChangeNotification(pathName, bSubDirs , filter )
print chgHandle

Generates the following:
Traceback (most recent call last):
  File "C:\Python22\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
 line 301, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Python22\Lib\DFScripts\DirWatcher.py", line 4, in ?
    filter = 0 #FILE_NOTIFY_CHANGE_FILE_NAME
NameError: name 'FILE_NOTIFY_CHANGE_FILE_NAME' is not defined

Per the help in Win32API, filter is an int variable.  If I substitue an integer
(1 or 2 for instance), for filter, I get back a chgHandle value.

I've poked around the web at various Win API sites and have not found anything
that converts the filter into an integer.  Any idea what
FILE_NOTIFY_CHANGE_FILE_NAME is as an integer???

TIA

Doug


BTW - I found this while looking around.  I'll probably try to convert this into
some Python-esque code.

http://www.codeproject.com/file/directorychangewatcher.asp




From magnus@thinkware.se  Thu Oct 10 10:29:46 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu, 10 Oct 2002 11:29:46 +0200
Subject: [Tutor] newbie "sound" question
In-Reply-To: <000b01c27015$12b3e9c0$2f891c42@dandy.net>
Message-ID: <5.1.0.14.0.20021010110324.04b18830@www.thinkware.se>

At 00:25 2002-10-10 -0400, udigom wrote:
>I am curious-- I have duplicated the hello world.py, and some other
>exercises-- Is it possible to create sounds in .py files? If so, could one
>of you kind people provide me with a simple basic source code so that I can
>learn from it?

To PLAY sound the simplest thing is to use the
winsound module if you are using Windows. (I think
this is what the other respondent wrote about also.)

To CREATE sounds... I don't know. Strange that it
doesn't pop up more often. I did that on my old C64
almost 20 years ago, and it was fairly simple then!

I'm pretty sure the mechanics will vary depending on
platform. I don't know of any generic Python interface
for that. Have a look at http://www.vex.net/parnassus/



--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From valdas.jonikas@if.lt  Thu Oct 10 13:33:22 2002
From: valdas.jonikas@if.lt (Valdas Jonikas)
Date: Thu, 10 Oct 2002 13:33:22 +0100
Subject: [Tutor] Frames height and width
Message-ID: <20021010112954.B700620F40@hermes.if.lt>

SGkgYWxsLA0KDQpTb21lIHRyb3VibGVzIHdpdGggZnJhbWVzIGhlaWdodCBhbmQgd2lkdGggOikN
CkEgcGllY2Ugb2YgY29kZToNCg0KZjEgPSBGcmFtZShyb290LCB3aWR0aD0zMDApDQpmMS5wYWNr
KCkNCmYyID0gRnJhbWUoZjEsIHdpZHRoPTUwKQ0KZjIucGFjayhzaWRlPUxFRlQpDQpmMyA9IEZy
YW1lKGYxLCB3aWR0aD01MCkNCmYzLnBhY2soc2lkZT1SSUdIVCkNCg0KQWZ0ZXIgcnVubmluZyBh
IHByb2dyYW0sIHdpZHRoIG9mIGYxIHJlZHVjZXMNCnRvIHBsYWNlIGYyIGFuZCBmMyB3aWR0aHMu
DQpJcyBpdCBwb3NzaWJsZSB0byBtYWtlIHdpZHRoIG9mIGYxIGZpeGVkLCBpLmUuIDMwMD8NCg0K
VGhhbmtzLA0KVmFsZGFzDQo=



From alan.gauld@bt.com  Thu Oct 10 13:59:47 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 10 Oct 2002 13:59:47 +0100
Subject: [Tutor] xml.sax error
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C960@mbtlipnt02.btlabs.bt.co.uk>

> 	The code I'm running is almost directly from a HOWTO @
> (http://pyxml.sourceforge.net/topics/howto/node12.html). Am I doing
> something wrong?  Take a look and let me know what you see.

I'm no expert in this area as I've done nothing with sax.

BUT, The error actually smells to me of an incompatibility 
between the python code and the underlying library version.

It might be worth posting the versions you are using of
python
sax
expat 
etc

But, like I say, I'm guessing!

Alan g.

> >python -u xmlin.py
> Traceback (most recent call last):
>   File "xmlin.py", line 83, in ?
>     parser.parse(file)
>   File "/usr/lib/python2.2/site-packages/_xmlplus/sax/expatreader.py",
> line 107, in parse
>     self.reset()
>   File "/usr/lib/python2.2/site-packages/_xmlplus/sax/expatreader.py",
> line 236, in reset
>     self._parser = expat.ParserCreate(intern = self._interning)
> TypeError: 'intern' is an invalid keyword argument for this function
> >Exit code: 256


From alan.gauld@bt.com  Thu Oct 10 14:01:51 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 10 Oct 2002 14:01:51 +0100
Subject: [Tutor] Windows Standalone Icon?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C961@mbtlipnt02.btlabs.bt.co.uk>

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_01C2705D.333D9AE0
Content-Type: text/plain;
	charset="iso-8859-1"

 >  I've been turning my Python scripts into Windows standalone executables
(.exe files)  
 >   ... , but I can't use anything besides the default Python icon.
 
In any windows 9.x/NT version you can create a shortcut to the file.
Then right click the shortcut and click Change Icon....
 
You can do this from WSH too but its messy....
 
Alan g.
 

------_=_NextPart_001_01C2705D.333D9AE0
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><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=590210813-10102002><FONT face="Courier New" 
color=#0000ff>&nbsp;&gt; &nbsp;</FONT></SPAN>I've been turning my Python scripts 
into Windows standalone executables (.exe files)&nbsp;<SPAN 
class=590210813-10102002><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><FONT face="Courier New"><FONT color=#0000ff><SPAN 
class=590210813-10102002>&nbsp;&gt;&nbsp;&nbsp;</SPAN><SPAN 
class=590210813-10102002>&nbsp;...&nbsp;</SPAN></FONT></FONT>, but I can't use 
anything besides the default Python icon.<BR><SPAN 
class=590210813-10102002><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=590210813-10102002><FONT face="Courier New" color=#0000ff>In 
any windows 9.x/NT&nbsp;version you can create a shortcut to the 
file.</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=590210813-10102002><FONT face="Courier New" 
color=#0000ff>Then right click the shortcut and click Change 
Icon....</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=590210813-10102002></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=590210813-10102002><FONT face="Courier New" color=#0000ff>You 
can do this from WSH too but its 
messy....</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=590210813-10102002></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN class=590210813-10102002><FONT face="Courier New" 
color=#0000ff>Alan g.</FONT></SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=arial,helvetica><FONT lang=0 face=Arial FAMILY="SANSSERIF"><FONT 
size=2><SPAN 
class=590210813-10102002>&nbsp;</SPAN></FONT></FONT></FONT></DIV></BODY></HTML>

------_=_NextPart_001_01C2705D.333D9AE0--


From alan.gauld@bt.com  Thu Oct 10 14:13:24 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 10 Oct 2002 14:13:24 +0100
Subject: [Tutor] pseudo code --- search for <> tags
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C963@mbtlipnt02.btlabs.bt.co.uk>

> ###pseudo code start
> def TagFinger():
>     """Finds mark-up, and prints it to a text file."""
>     #imports
>     import sys, string, os, os.path
>     #welcome
>     print "Welcome to TagFinger!"
>     print ""
>     folder=raw_input("Please type the name of the folder you 
> wish to search:
> ") #this does not work ... Here is the error

folder is defined as a local variable inside your function.

To access it outside the function you need to returnm it:

      return folder

then you can use it thusly:

>>> folder = TagFinger()
gfgfhvghjg
>>> folder
'gfgfhvghjg'

For more on namespaces and scope seee my tutor 
topic 'Whats in a name?'

HTH,

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


From alan.gauld@bt.com  Thu Oct 10 14:20:20 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 10 Oct 2002 14:20:20 +0100
Subject: [Tutor] variables into a dictionary
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C964@mbtlipnt02.btlabs.bt.co.uk>

> hello pythoners,
> i have some variables here:
> one = 1
> three = 4
> six = 6
> 
> how can i assign those vars into a dictionary
> numbers={'one':one,'three':three,'six':six}

Erm, I'm not sure what you mean. The line above does assign 
them to a dictionary!

Do you mean one by one? Like;

numbers['one'] = one

Or do you mean assign values to the dictionary instead of 
variables? If so thats what you are doing.

print numbers['one'] #--> prints 1

If not can you expand a little on what you want?

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


From abarker@xminc.com  Thu Oct 10 15:16:12 2002
From: abarker@xminc.com (Anthony Barker)
Date: Thu, 10 Oct 2002 10:16:12 -0400 (EDT)
Subject: [Tutor] Mozilla as a Development Environment
Message-ID: <12458.198.96.180.245.1034259372.squirrel@www.xminc.com>

>What do you think of mozilla as a dev environment (pyXUL?).
>
>Didn't know it was one, I thought it was a browser engine!
>A search on google for pyXUL didn't throw anything up...

Sorry that was pyXPCOM from ActiveState

http://aspn.activestate.com/ASPN/Downloads/Komodo/PyXPCOM/

XPCOM is a Mozilla COM copy.
pyXPCOM is used by activestate in their komodo product

I got quite excited after working through the XUL planet
tutorial(http://www.xulplanet.com/). Mozilla seperates the layout from the
application from the content - and makes it all network accessable.

eg
http://www.xulplanet.com/tutorials/xultu/examples/findfile/findfile-persist.xul
(need mozilla to view).

There is a project to make it viewable in Java as well as Flash.

Anthony




From James.Rocks@equant.com  Thu Oct 10 14:58:19 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Thu, 10 Oct 2002 14:58:19 +0100
Subject: [Tutor] My First Python Program (Vey Large)!
Message-ID: <OF6E27E9DE.EACAE828-ON80256C4E.004CA715@equant.com>

Hi Alan,

> Oops, I've run out of time(a teleconference calls)...
> but hopefully some general principles there.

Thanks for that ... I've modified my program based upon what you said :-)

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From James.Rocks@equant.com  Thu Oct 10 15:02:13 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Thu, 10 Oct 2002 15:02:13 +0100
Subject: [Tutor] Runing an external command?
Message-ID: <OFFFF40E66.1068528B-ON80256C4E.004CC0A9@equant.com>

Hi,

I want to "ping" a server within my program.

My intention, initially at least, is to "shell out" and call the DOS ping
program to do this ... eventualy I will attempt to rewite the C program
source that someone mentioned in the archives.

So my question is how do I run an external program and does the program
wait until that program has finished execution or does it just carry on
regardless?

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From Jmllr891@cs.com  Thu Oct 10 15:40:17 2002
From: Jmllr891@cs.com (Jmllr891@cs.com)
Date: Thu, 10 Oct 2002 10:40:17 EDT
Subject: [Tutor] Windows Standalone Icon?
Message-ID: <153.159f348b.2ad6eb51@cs.com>

--part1_153.159f348b.2ad6eb51_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

OK, a couple of people gave me resources to stuff about distutils and py2exe 
already. But the sources they gave me are the exact places where it tells me 
that I can only change my .exe icon when I run the build process under 
Windows NT or 2000.

Does anyone know of a tweak or something I can use?

--part1_153.159f348b.2ad6eb51_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">OK, a couple of people gave me resources to stuff about distutils and py2exe already. But the sources they gave me are the exact places where it tells me that I can only change my .exe icon when I run the build process under Windows NT or 2000.<BR>
<BR>
Does anyone know of a tweak or something I can use?</FONT></HTML>

--part1_153.159f348b.2ad6eb51_boundary--


From alan.gauld@bt.com  Thu Oct 10 17:13:48 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 10 Oct 2002 17:13:48 +0100
Subject: [Tutor] Runing an external command?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C968@mbtlipnt02.btlabs.bt.co.uk>

> My intention, initially at least, is to "shell out" and call 
> the DOS ping
> So my question is how do I run an external program and does 
> the program wait until that program has finished execution 

os.system()

OR 

os.popen()

Basically the second allows you to read the output of the 
program - which might be handy for a ping!
Read the os module docs for the details.

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


From kojo@hal-pc.org  Thu Oct 10 18:40:40 2002
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Thu, 10 Oct 2002 12:40:40 -0500
Subject: [Tutor] extramural papers in python??
In-Reply-To: <20020101003555.57c5e2f8.thomi@thomi.imail.net.nz>
Message-ID: <web-22775075@mail.hal-pc.org>

Runs a paper using python?  I'm not sure I understand the 
question.  If you're looking for papers ABOUT python, or 
FEATURING python, I know there's a Master's Thesis at 
Texas A&M that compares Python, Java and C++.  If that 
will help, send me an email and I'll get the citation for 
you later this evening.

On Tue, 1 Jan 2002 00:35:55 +1300
  Thomi Richards <thomi@thomi.imail.net.nz> wrote:
>
>can anyone recommend a university which runs a 
>programming paper, using
>python?? I'm looking to take one or more papers 
>extramuraly, to complete
>my degree.
>
>thanks.
>
>-- 
>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

****************************
Kojo Idrissa
kojo@hal-pc.org

http://www.hal-pc.org/~kojo
****************************


From magnus@thinkware.se  Thu Oct 10 21:14:05 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu, 10 Oct 2002 22:14:05 +0200
Subject: [Tutor] Runing an external command?
In-Reply-To: <OFFFF40E66.1068528B-ON80256C4E.004CC0A9@equant.com>
Message-ID: <5.1.0.14.0.20021010221000.032abd58@www.thinkware.se>

At 15:02 2002-10-10 +0100, James.Rocks@equant.com wrote:
>So my question is how do I run an external program and does the program
>wait until that program has finished execution or does it just carry on
>regardless?

host =3D 'www.python.org'
os.system('ping %s" % host)

Will wait for the ping to finish.

Obviously, if you want the output, your program
must wait:

resultList =3D os.popen('ping %s' % host).readlines()

If you don't want your program to wait, you should
run the following.
Windows: os.system('start ping %s" % host)
Unix:    os.system('ping %s &" % host)


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Thu Oct 10 21:24:37 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu, 10 Oct 2002 22:24:37 +0200
Subject: [Tutor] variables into a dictionary
In-Reply-To: <1034214976.4366.4.camel@jrwd.internal.intermatik.com>
Message-ID: <5.1.0.14.0.20021010221417.032caea0@www.thinkware.se>

At 08:55 2002-10-10 +0700, nano wrote:
>hello pythoners,
>i have some variables here:
>one =3D 1
>three =3D 4
>six =3D 6
>
>how can i assign those vars into a dictionary
>numbers=3D{'one':one,'three':three,'six':six}

You already have! :)

print locals()

locals contain more though. If you assign them all
in a row, I guess you could copy locals() before and
after, and use the difference.

before =3D locals().copy()
one =3D 2
three =3D 4
...
after =3D locals().copy()

myVars =3D {}
before_items =3D before.items()
for item in after.items():
     # Besides one, three, etc, the 'before' dict will be in 'after'
     if item[0] =3D 'before': continue
     if item not in before_items():
         myVars[item[0]] =3D item[1]


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Thu Oct 10 21:38:40 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu, 10 Oct 2002 22:38:40 +0200
Subject: [Tutor] Mozilla as a Development Environment
In-Reply-To: <12458.198.96.180.245.1034259372.squirrel@www.xminc.com>
Message-ID: <5.1.0.14.0.20021010223507.032cfab8@www.thinkware.se>

I'm evaluating Komodo right now. It's too slow
to be usable on AMD Duron 700 / 256MB / Win2000.
Besides being slow, it uses 40MB of RAM with a tiny
file open.

I don't know if Mozilla or ActiveState is to blame
here, but I sure won't pay money for Komodo.

PythonWin is MUCH better.

At 10:16 2002-10-10 -0400, you wrote:
> >What do you think of mozilla as a dev environment (pyXUL?).
> >
> >Didn't know it was one, I thought it was a browser engine!
> >A search on google for pyXUL didn't throw anything up...
>
>Sorry that was pyXPCOM from ActiveState
>
>http://aspn.activestate.com/ASPN/Downloads/Komodo/PyXPCOM/
>
>XPCOM is a Mozilla COM copy.
>pyXPCOM is used by activestate in their komodo product
>
>I got quite excited after working through the XUL planet
>tutorial(http://www.xulplanet.com/). Mozilla seperates the layout from the
>application from the content - and makes it all network accessable.
>
>eg
>http://www.xulplanet.com/tutorials/xultu/examples/findfile/findfile-persist=
.xul
>(need mozilla to view).
>
>There is a project to make it viewable in Java as well as Flash.
>
>Anthony
>
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From glenbar@gte.net  Thu Oct 10 22:44:42 2002
From: glenbar@gte.net (Glen Barnett)
Date: Thu, 10 Oct 2002 14:44:42 -0700
Subject: [Tutor] Exchanging window data
Message-ID: <002901c270a6$3f1c5a60$d018153f@gb>

I'm writing a script to use any number of windows and I'm interested in
exchanging data among them. In the sample I have here the main window passes
a method name "hitCntl" and a variable name "self.messag" to the new windows
when they are created using the class Frm1. When a button is pressed a
message is added to the variable and the method is called. Is this the
proper technique? What other ways are there?  I noticed if I use
self.messag=[] in  "hitCntl" instead of self.messag.pop(0) to clear it then
the messages no longer work even though the name is the same.

Thanks
Glen

#
from Tkinter import *
class Frm1:
   def __init__(self,frame,mess,note,name):
            self.name1=name
            self.message=mess
            self.note1=note
            self.bb=Button(frame,text="Hello",command=self.b2c)
            self.bb.pack()
   def b2c(self):
        self.message.append(self.note1)
            self.name1()

class MAIN1:
   def __init__(self,frame):
        self.messag=[]
            for x in range(25):
                        w2=Toplevel()
                        tm= "Hello from %d" %x
                        Frm1(w2,self.messag,tm,self.hitCntl)
   def hitCntl(self):
            print "Redirected"
            print self.messag
            self.messag.pop(0)

if __name__ =="__main__":
   root=Tk()
   cf=MAIN1(root)
   root.mainloop()



From James.Alexander.McCarney@Cognicase.com  Thu Oct 10 23:40:17 2002
From: James.Alexander.McCarney@Cognicase.com (McCarney, James Alexander)
Date: Thu, 10 Oct 2002 18:40:17 -0400
Subject: [Tutor] file.readlines() error
Message-ID: <23FD7B1A77E8D211BCB900001D108C02023FCA55@camelot>

Hi list,

Thanks for your answers yesterday. I am making some progress...

This is my code, that runs fine up to rtfile=file.readlines()
It wants a byte size for my file. How can I pass one in programatically?

See underneath the code for the error...


def tagfinger():
    """Finds mark-up, and prints it to a text file."""
    #imports
    import sys, string, os, os.path, glob, re
    #welcome
    print "Welcome to TagFinger!"
    print ""
    path_in=raw_input("Please type the pathname where you wish to search: ")
    print "The pathname you have chosen is: ",path_in
    print ""
    from os import chdir
    chdir(path_in)
    print "You are now in path: ",path_in
    print "We found the follwing...",glob.glob("*")
    list1=glob.glob("*")
    print ""
    answer=raw_input("Which file's tags do you wish to extract? ")
    print "You chose",answer
    for answer in list1:
        list1.pop()
    print "...Opening...",answer
    rtfile=file(answer, 'r')
    print '...Reading...',answer
    rtfile=file.readlines()  ### <<<------ Error because I cannot pass in
the byte size!

Traceback (most recent call last):
  File "<pyshell#119>", line 1, in ?
    tagfinger()
  File "C:\Documents and Settings\jamccarn\Desktop\tagfinger.py", line 24,
in tagfinger
    rtfile=file.readlines()
TypeError: descriptor 'readlines' of 'file' object needs an argument



From dylan.belsey@baesystems.com  Thu Oct 10 23:50:25 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Fri, 11 Oct 2002 08:20:25 +0930
Subject: [Tutor] file.readlines() error
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B98D2AD8@wtntex1.baea.com.au>

	At a quick glance, you may want to replace rtfile=file.readlines()
with lines=rtfile.readlines().  That is to say that you may be using the
wrong object for the readlines() call.


-----Original Message-----
From: McCarney, James Alexander
[mailto:James.Alexander.McCarney@Cognicase.com]
Sent: Friday, 11 October 2002 08:40
To: 'tutor@python.org'
Subject: [Tutor] file.readlines() error


Hi list,

Thanks for your answers yesterday. I am making some progress...

This is my code, that runs fine up to rtfile=file.readlines()
It wants a byte size for my file. How can I pass one in programatically?

See underneath the code for the error...


def tagfinger():
    """Finds mark-up, and prints it to a text file."""
    #imports
    import sys, string, os, os.path, glob, re
    #welcome
    print "Welcome to TagFinger!"
    print ""
    path_in=raw_input("Please type the pathname where you wish to search: ")
    print "The pathname you have chosen is: ",path_in
    print ""
    from os import chdir
    chdir(path_in)
    print "You are now in path: ",path_in
    print "We found the follwing...",glob.glob("*")
    list1=glob.glob("*")
    print ""
    answer=raw_input("Which file's tags do you wish to extract? ")
    print "You chose",answer
    for answer in list1:
        list1.pop()
    print "...Opening...",answer
    rtfile=file(answer, 'r')
    print '...Reading...',answer
    rtfile=file.readlines()  ### <<<------ Error because I cannot pass in
the byte size!

Traceback (most recent call last):
  File "<pyshell#119>", line 1, in ?
    tagfinger()
  File "C:\Documents and Settings\jamccarn\Desktop\tagfinger.py", line 24,
in tagfinger
    rtfile=file.readlines()
TypeError: descriptor 'readlines' of 'file' object needs an argument


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


From magnus@thinkware.se  Thu Oct 10 23:58:04 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri, 11 Oct 2002 00:58:04 +0200
Subject: [Tutor] Exchanging window data
In-Reply-To: <002901c270a6$3f1c5a60$d018153f@gb>
Message-ID: <5.1.0.14.0.20021011004242.04b1a0e0@www.thinkware.se>

At 14:44 2002-10-10 -0700, Glen Barnett wrote:
>I'm writing a script to use any number of windows and I'm interested in
>exchanging data among them.

You can use a number of different ways to exchange data. In
a wxPython application I'm using the Publish/Subscribe
or Observer pattern.

The central handler for this looks like this:
(It's more or less directly from the GoF book,
but uses Alex Martelli's Borg pattern.)

# Publish-Subscribe pattern (alias Observer)
class Publisher:
     __shared_state =3D {'observers' : {},  'message' : {}}
     def __init__(self):
         self.__dict__ =3D self.__shared_state
     def attach(self, observer, event):
         if not self.observers.has_key(event):
             self.observers[event] =3D []
         if observer not in self.observers[event]:=20
self.observers[event].append(observer)
     def detach(self, observer, event):
         try: self.observers[event].remove(observer)
         except (KeyError, ValueError), e:
             print e
     def notify(self, event):
         try:
             for o in self.observers[event]:
                 o.update(event)
         except KeyError:
             pass
     def getMessage(self, event):
         try:
             return self.message[event]
         except:
             m =3D "Tried to get message for nonexisting event %s" % event
             print m
             return m
     def setMessage(self, event, message):
         self.message[event] =3D message
         self.notify(event)

A class that is listening to a kind of event (this has
nothing to do with GUI events) needs to call the attach()
method of the Publisher, and it must have a update()
method which is called to notify the sunscriber of the
event. On notification, it might call getMessage().

The class that is sending the information will call the
SetMessage method.

So, to be a subscriber (or observer)...

class X:
     def __init__(self,...):
         ...
         Publisher().attach(self, 'QUOTES')
         ...
     def __del__(self):
         Publisher().detach(self, 'QUOTES')
     def update(self, event):
         # Handle an observation
         msg =3D Publisher().GetMessage(event)
         ...

And the class sending the message...

class Y:
     def xyz(self, ...):
         ...
         Publisher().SetMessage('QUOTES', 'MSFT $0.55')
         ...

I'm using strings here, but both events and messages could
be arbitrary objects, as long as the sender and rceiver
agrees. I often use classes as events.



--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From James.Alexander.McCarney@Cognicase.com  Fri Oct 11 00:55:52 2002
From: James.Alexander.McCarney@Cognicase.com (McCarney, James Alexander)
Date: Thu, 10 Oct 2002 19:55:52 -0400
Subject: [Tutor] recursion in script with re module
Message-ID: <23FD7B1A77E8D211BCB900001D108C02023FCA57@camelot>

Ok list,
Thank you for your hints and answers... Now I have the text file display to
my screen, but what I want -- as Magnus helpfully pointed out -- is
recursion. So I have imported re.

I read the docs -- or tried to! ;-) -- and I looked at the recursion how-to
-- and I am starting to get perl hives. ;-)

Anyway, now that the file is opened in the script... I tried to implement
Magnus's suggestions. What I want is everything between the < > signs. 

So re.findall(r"(<[^>]+?/>)",alllines) should work. But it doesn't because
it is a list instead of a string. Can I pop eveything out of a list at once?
Or--as I seem to recall in the tutorial--is it a one by one thing?

Here is the error:

Traceback (most recent call last):
  File "<pyshell#134>", line 1, in ?
    tagfinger()
  File "C:\Documents and Settings\jamccarn\Desktop\tagfinger.py", line 26,
in tagfinger
    out_tags=re.findall(r"(<[^>]+?/>)",alllines)
  File "C:\Python22\lib\sre.py", line 166, in findall
    return _compile(pattern, 0).findall(string)
TypeError: expected string or buffer

Here is the code:

def tagfinger():
    """Finds mark-up, and prints it to a text file."""
    #imports
    import sys, string, os, os.path, glob, re
    #welcome
    print "Welcome to TagFinger!"
    print ""
    path_in=raw_input("Please type the pathname where you wish to search: ")
    print "The pathname you have chosen is: ",path_in
    print ""
    from os import chdir
    chdir(path_in)
    print "You are now in path: ",path_in
    print "We found the follwing...",glob.glob("*")
    list1=glob.glob("*")
    print ""
    answer=raw_input("Which file's tags do you wish to extract? ")
    print "You chose",answer
    for answer in list1:
        list1.pop()
    print "...Opening...",answer
    rtfile=file(answer, 'r')
    print '...Reading...',answer
    alllines=rtfile.readlines()
    print alllines
    out_tags=re.findall(r"(<[^>]+?/>)",alllines)
    print out_tags


From magnus@thinkware.se  Fri Oct 11 01:33:08 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri, 11 Oct 2002 02:33:08 +0200
Subject: [Tutor] recursion in script with re module
In-Reply-To: <23FD7B1A77E8D211BCB900001D108C02023FCA57@camelot>
Message-ID: <5.1.0.14.0.20021011022612.0317b768@www.thinkware.se>

At 19:55 2002-10-10 -0400, McCarney, James Alexander wrote:
>Thank you for your hints and answers... Now I have the text file display to
>my screen, but what I want -- as Magnus helpfully pointed out -- is
>recursion. So I have imported re.

I think you mean regular expressions. Recursion is something
entirely different. (Another rainy day...)

>So re.findall(r"(<[^>]+?/>)",alllines) should work. But it doesn't because
>it is a list instead of a string. Can I pop eveything out of a list at=
 once?

You can use .read() instead of .readlines(), and it will become
one big string. Or "".join(alllines) to make it into one big string
after reading the lines (if you want the lines for something else).

Note that alllines will have line endings in the end of all lines.
If you want to get rid of that before joining (making is one big
line) you could do:

"".join([line.rstrip() for line in alllines])



--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From j.ezequiel@spitech.com  Fri Oct 11 03:40:51 2002
From: j.ezequiel@spitech.com (Justin Ezequiel)
Date: Fri, 11 Oct 2002 10:40:51 +0800
Subject: [Tutor] RE: Watch folder code - follow up question
Message-ID: <01C27112.AE4C9640@pc7486>

Doug,

I guess I should have told you where I got the value
I have Visual Basic installed on my machine and it comes with the 'API Text Viewer'
Among others, It has a list of constants

a Google search on FILE_NOTIFY_CHANGE_FILE_NAME also turned up this link

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20242914.html



Thanks to Lei, I've tried building the first bit of the skeleton to watch a
folder.

import win32api
pathName = 'c:\\IDFIles'
bSubDirs = False
filter = FILE_NOTIFY_CHANGE_FILE_NAME
chgHandle = win32api.FindFirstChangeNotification(pathName, bSubDirs , filter )
print chgHandle

Generates the following:
Traceback (most recent call last):
  File "C:\Python22\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
 line 301, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Python22\Lib\DFScripts\DirWatcher.py", line 4, in ?
    filter = 0 #FILE_NOTIFY_CHANGE_FILE_NAME
NameError: name 'FILE_NOTIFY_CHANGE_FILE_NAME' is not defined

Per the help in Win32API, filter is an int variable.  If I substitue an integer
(1 or 2 for instance), for filter, I get back a chgHandle value.

I've poked around the web at various Win API sites and have not found anything
that converts the filter into an integer.  Any idea what
FILE_NOTIFY_CHANGE_FILE_NAME is as an integer???

TIA

Doug


BTW - I found this while looking around.  I'll probably try to convert this into
some Python-esque code.

http://www.codeproject.com/file/directorychangewatcher.asp



From goneil@scu.edu  Fri Oct 11 06:01:29 2002
From: goneil@scu.edu (Galen O'Neil)
Date: 10 Oct 2002 22:01:29 -0700
Subject: [Tutor] xml.sax error
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C960@mbtlipnt02.btlabs.bt.co.uk>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C960@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <1034312499.3976.2.camel@lucidia>

I'm looking for the versions on these packages and I've become slightly
confused.  Sax is actually xml.sax and there are many things that come
up with 'pydoc -k expat.'  How are these packaged, or how can I find out
how they are packaged?  I ask so that I can look up the version number
for the big packages and not all the individual components.
  And what is the best way to find version numbers on these things,
pydoc, looking in the files?

--Galen


On Thu, 2002-10-10 at 05:59, alan.gauld@bt.com wrote:
> > 	The code I'm running is almost directly from a HOWTO @
> > (http://pyxml.sourceforge.net/topics/howto/node12.html). Am I doing
> > something wrong?  Take a look and let me know what you see.
> 
> I'm no expert in this area as I've done nothing with sax.
> 
> BUT, The error actually smells to me of an incompatibility 
> between the python code and the underlying library version.
> 
> It might be worth posting the versions you are using of
> python
> sax
> expat 
> etc
> 
> But, like I say, I'm guessing!
> 
> Alan g.
> 
> > >python -u xmlin.py
> > Traceback (most recent call last):
> >   File "xmlin.py", line 83, in ?
> >     parser.parse(file)
> >   File "/usr/lib/python2.2/site-packages/_xmlplus/sax/expatreader.py",
> > line 107, in parse
> >     self.reset()
> >   File "/usr/lib/python2.2/site-packages/_xmlplus/sax/expatreader.py",
> > line 236, in reset
> >     self._parser = expat.ParserCreate(intern = self._interning)
> > TypeError: 'intern' is an invalid keyword argument for this function
> > >Exit code: 256
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor




From James.Rocks@equant.com  Fri Oct 11 07:44:40 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Fri, 11 Oct 2002 07:44:40 +0100
Subject: [Tutor] My First Python Program (Vey Large)!
Message-ID: <OFBCA376A9.794C41B0-ON80256C4F.002494DB@equant.com>

Hi Alan,

> And the real question is.... did it speed it up in any
> worthwhile way?

Yes (25 seconds) but it was only taking some 30 seconds anyway (which
sounds small but still about 20% faster).  Obviously I'm looking to improve
that (if only to find out just how fast it can be) ... I'll let you know if
I suceed.

The real pay off is (will be) in what you've effectively taught me and in
any future (more time consuming) programs I suspect.

Thanks :-)

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From James.Rocks@equant.com  Fri Oct 11 08:46:21 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Fri, 11 Oct 2002 08:46:21 +0100
Subject: [Tutor] Switch or Select?
Message-ID: <OF1AF73DBA.EAD5B799-ON80256C4F.002A810D@equant.com>

Hi,

Just curious ... is there any kind of switch or select statement in Python?
I know there is if/elif/else but a switch/case/else/break style control
structure would be quite handy :-)

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From James.Rocks@equant.com  Fri Oct 11 08:49:37 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Fri, 11 Oct 2002 08:49:37 +0100
Subject: [Tutor] Running an external command?
Message-ID: <OF374258C5.97C4BBED-ON80256C4F.002ABD66@equant.com>

Hi Magnus, Hi Alan,

Alan:
> os.system()
> OR
> os.popen()
> Basically the second allows you to read the output of the
> program - which might be handy for a ping!
> Read the os module docs for the details.

Magnus:
> host = 'www.python.org'
> os.system('ping %s" % host)
> Will wait for the ping to finish.
> Obviously, if you want the output, your program
> must wait:
> resultList = os.popen('ping %s' % host).readlines()
> If you don't want your program to wait, you should
> run the following.
> Windows: os.system('start ping %s" % host)
> Unix:    os.system('ping %s &" % host)

Brilliant (exactly what I wanted) ... thanks to both of you :-)

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From alan.gauld@bt.com  Fri Oct 11 08:59:10 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 11 Oct 2002 08:59:10 +0100
Subject: [Tutor] file.readlines() error
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C96A@mbtlipnt02.btlabs.bt.co.uk>

> See underneath the code for the error...
> 
> def tagfinger():
>     import sys, string, os, os.path, glob, re
....
>     print "The pathname you have chosen is: ",path_in
>     print ""
>     from os import chdir


Warning this is ILLEGAL CODE in Python.
You are not supposed to use fom X import Y inside a function.
In Python 2.x it will spit out a warning or evben an error.
But even in previous versions it is an error.

See the python idioms paper in the topics section of 
the python web site....

>     rtfile=file(answer, 'r')
>     print '...Reading...',answer
>     rtfile=file.readlines()  ### <<<------ Error because I 

It looks like you are getting some kind of conflict between
the os and builtin file handling functions. This might be 
a bad result of the from/import above. Try taking out 
(or moving it to global level) the from/import and see 
what happens.

> TypeError: descriptor 'readlines' of 'file' object needs an argument

My theory is based on the word 'descriptor'...

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


From nano@intermatik.co.id  Fri Oct 11 10:13:02 2002
From: nano@intermatik.co.id (nano)
Date: 11 Oct 2002 16:13:02 +0700
Subject: [Tutor] variables into a dictionary
In-Reply-To: <1034214976.4366.4.camel@jrwd.internal.intermatik.com>
References: <1034214976.4366.4.camel@jrwd.internal.intermatik.com>
Message-ID: <1034327596.4491.12.camel@jrwd.internal.intermatik.com>

thanks to all your help,
i'm sorry if i can't explain my problem clearly. but Magnus' mail have
solved my problem. i just know that there is an object named 'locals'.
that's just all what i need.
thanks again,

nano'

On Thu, 2002-10-10 at 08:55, nano wrote:
> hello pythoners,
> i have some variables here:
> one = 1
> three = 4
> six = 6
> 
> how can i assign those vars into a dictionary
> numbers={'one':one,'three':three,'six':six}
> 
> that would be all for now,
> TIA
> 
> nano'
> 
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 




From arodrigo@genasys.com  Fri Oct 11 11:34:15 2002
From: arodrigo@genasys.com (Amaya Rodrigo Sastre)
Date: Fri, 11 Oct 2002 12:34:15 +0200
Subject: [Tutor] File copying
Message-ID: <20021011103415.GC10553@onix>

--ew6BAiZeqk4r7MaW
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Dear Tutors,

I am trying to copy files around, but I only see doc on how to move
them. 

Any hints?

My script is attached.

-- 
Amaya M. Rodrigo Sastre       Genasys II Spain, S.A.U. 
MLS Sysadmin                    Ventura de la Vega, 5. 
Phone: +34.91.3649100              28014 Madrid. Spain 

--ew6BAiZeqk4r7MaW
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="copy_files.py"

#!/usr/bin/python

from normalDate import ND
import os  
import sys

today = ND()
yesterday = today - 1

today_all = today.formatAmaya()
yesterday_all = yesterday.formatAmaya()

today_day  = today.formatAmayaDay()
yesterday_day = yesterday.formatAmayaDay()

today_month  = today.formatAmayaMonth()
yesterday_month = yesterday.formatAmayaMonth()

def my_dir_name(yesterday_day):
	#return "day_%s" % (yesterday_day)
	my_dir = "day_" + yesterday_day
	return my_dir
	
def make_my_dir(yesterday_day):
	for i in xrange(1,4,1):
		j = str(i)
   		my_dir = my_dir_name(yesterday_day) + "/" + j 
		#print my_dir
		makedirs(my_dir)

def my_log_name(yesterday_all):
	for i in xrange(1,4,1):
		print "stdout.log.%s.gpphost%s" % (yesterday_all, i)

my_dir_name(yesterday_day)
my_log_name(yesterday_all)
make_my_dir(yesterday_day)


--ew6BAiZeqk4r7MaW
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="normalDate.py"

#!/usr/bin/env python
# normalDate.py - version 1.2 - 2002/02/19
# Author: Jeff Bauer, Rubicon Research - jbauer@rubic.com
# License: Same as Python 2.1 or later

import time
from types import IntType, ListType, StringType, TupleType

_bigBangScalar = -4345732  # based on (-9999, 1, 1) BC/BCE minimum
_bigCrunchScalar = 2958463  # based on (9999,12,31) AD/CE maximum
_daysInMonthNormal = [31,28,31,30,31,30,31,31,30,31,30,31]
_daysInMonthLeapYear = [31,29,31,30,31,30,31,31,30,31,30,31]
_dayOfWeekName = ['Monday', 'Tuesday', 'Wednesday', 'Thursday',
                  'Friday', 'Saturday', 'Sunday']
_monthName = ['January', 'February', 'March', 'April', 'May', 'June',
              'July','August','September','October','November','December']

class NormalDateException(Exception):
    """Exception class for NormalDate"""
    pass

class NormalDate:
    """
    NormalDate is a specialized class to handle dates without
    all the excess baggage (time zones, daylight savings, leap
    seconds, etc.) of other date structures.  The minimalist
    strategy greatly simplifies its implementation and use.

    Internally, NormalDate is stored as an integer with values
    in a discontinuous range of -99990101 to 99991231.  The
    integer value is used principally for storage and to simplify
    the user interface.  Internal calculations are performed by
    a scalar based on Jan 1, 1900.

    Valid NormalDate ranges include (-9999,1,1) B.C.E. through
    (9999,12,31) C.E./A.D.

    1.2 - Bugfix for Python2.2, which changed localtime's type
          to time.struct_time rather than a tuple.  Thanks to
          Paul Weimer for reporting this problem.  Added some,
          but not all, of Robin Becker's ideas he incorporated
          into ReportLab's version of normalDate.
    1.1 - Added exception in setNormalDate for bad integer;
          range() returns a list of normalDates rather than
          a list of integers.
    1.0 - No changes, except the version number.  After 3 years of use
            by various parties I think we can consider it stable.
    0.8 - added Prof. Stephen Walton's suggestion for a range method 
            - module author resisted the temptation to use lambda <0.5 wink>
    0.7 - added Dan Winkler's suggestions for __add__, __sub__ methods
    0.6 - modifications suggested by Kevin Digweed to fix:
            - dayOfWeek, dayOfWeekAbbrev, clone methods
            - permit NormalDate to be a better behaved superclass
    0.5 - minor tweaking
    0.4 - added methods __cmp__, __hash__
        - added Epoch variable, scoped to the module
        - added setDay, setMonth, setYear methods
    0.3 - minor touch-ups
    0.2 - fixed bug for certain B.C.E leap years
        - added Jim Fulton's suggestions for short alias class name =ND
          and __getstate__, __setstate__ methods

    Special thanks for ideas and suggestions:  
        Jim Fulton
        Kevin Digweed
        Paul Weimer
        Robin Becker
        Roedy Green
        Stephen Walton
    """
    def __init__(self, normalDate=None):
        """
        Accept 1 of 4 values to initialize a NormalDate:
            1. None - creates a NormalDate for the current day
            2. integer in yyyymmdd format
            3. string in yyyymmdd format
            4. tuple in (yyyy, mm, dd) - localtime/gmtime can also be used
        """
        if normalDate is None:
            self.setNormalDate(time.localtime(time.time()))
        else:
            self.setNormalDate(normalDate)

    def add(self, days):
        """add days to date; use negative integers to subtract"""
        if not type(days) is IntType:
            raise NormalDateException( \
                'add method parameter must be integer type')
        self.normalize(self.scalar() + days)

    def __add__(self, days):
        """add integer to normalDate and return a new, calculated value"""
        if not type(days) is IntType:
            raise NormalDateException( \
                '__add__ parameter must be integer type')
        cloned = self.clone()
        cloned.add(days)
        return cloned

    def clone(self):
        """return a cloned instance of this normalDate"""
        return self.__class__(self.normalDate)

    def __cmp__(self, target):
        if target is None: 
            return 1
        elif not hasattr(target, 'normalDate'):
            return 1
        else:
            return cmp(self.normalDate, target.normalDate)

    def day(self):
        """return the day as integer 1-31"""
        return int(repr(self.normalDate)[-2:])

    def dayOfWeek(self):
        """return integer representing day of week, Mon=0, Tue=1, etc."""
        return apply(dayOfWeek, self.toTuple())

    def dayOfWeekAbbrev(self):
        """return day of week abbreviation for current date: Mon, Tue, etc."""
        return _dayOfWeekName[self.dayOfWeek()][:3]

    def dayOfWeekName(self):
        """return day of week name for current date: Monday, Tuesday, etc."""
        return _dayOfWeekName[self.dayOfWeek()]

    def dayOfYear(self):
        """day of year"""
        if self.isLeapYear():
            daysByMonth = _daysInMonthLeapYear
        else:
            daysByMonth = _daysInMonthNormal
        priorMonthDays = 0
        for m in xrange(self.month() - 1):
            priorMonthDays = priorMonthDays + daysByMonth[m]
        return self.day() + priorMonthDays

    def daysBetweenDates(self, normalDate):
        """
        return value may be negative, since calculation is 
        self.scalar() - arg
        """
        if type(normalDate) is _NormalDateType:
            return self.scalar() - normalDate.scalar()
        else:
            return self.scalar() - NormalDate(normalDate).scalar()

    def daysInMonth(self, month):
        """returns last day of the month as integer 28-31"""
        if self.isLeapYear():
            return _daysInMonthLeapYear[month - 1]
        else:
            return _daysInMonthNormal[month - 1]

    def equals(self, target):
        if type(target) is _NormalDateType:
            if target is None:
                return self.normalDate is None
            else:
                return self.normalDate == target.normalDate
        else:
            return 0

    def endOfMonth(self):
        """returns (cloned) last day of month"""
        return self.__class__(self.__repr__()[-8:-2] + \
                              str(self.lastDayOfMonth()))

    def firstDayOfMonth(self):
        """returns (cloned) first day of month"""
        return self.__class__(self.__repr__()[-8:-2] + "01")
    
    def formatAmaya(self):
        """return date as Amaya likes it: YYYY/MM/DD"""
        d = self.__repr__()
	return "%s-%s-%s" % (d[-8:-4], d[-4:-2], d[-2:])

    def formatAmayaDay(self):
        """return date as Amaya likes it: DD"""
        d = self.__repr__()
        return "%s" % d[-2:]

    def formatAmayaMonth(self):
        """return date as Amaya likes it: MM"""
        d = self.__repr__()
        return "%s" % d[-4:-2]

    def formatUS(self):
        """return date as string in common US format: MM/DD/YY"""
        d = self.__repr__()
        return "%s%s/%s" % (d[-4:-2], d[-2:], d[-6:-4])

    def formatUSCentury(self):
        """return date as string in 4-digit year US format: MM/DD/YYYY"""
        d = self.__repr__()
        return "%s/%s/%s" % (d[-4:-2], d[-2:], d[-8:-4])

    def __getstate__(self):
        """minimize persistent storage requirements"""
        return self.normalDate

    def __hash__(self):
        return hash(self.normalDate)

    def __int__(self):
        return self.normalDate

    def isLeapYear(self):
        """
        determine if specified year is leap year, returning true (1) or 
        false (0)
        """
        return isLeapYear(self.year())

    def _isValidNormalDate(self, normalDate):
        """checks for date validity in [-]yyyymmdd format"""
        if type(normalDate) is not IntType:
            return 0
        if len(repr(normalDate)) > 9:
            return 0
        if normalDate < 0:
            dateStr = "%09d" % normalDate
        else:
            dateStr = "%08d" % normalDate
        if len(dateStr) < 8:
            return 0
        elif len(dateStr) == 9:
            if (dateStr[0] != '-' and dateStr[0] != '+'):
                return 0
        year = int(dateStr[:-4])
        if year < -9999 or year > 9999 or year == 0:
            return 0    # note: zero (0) is not a valid year
        month = int(dateStr[-4:-2])
        if month < 1 or month > 12:
            return 0
        if isLeapYear(year):
            maxDay = _daysInMonthLeapYear[month - 1]
        else:
            maxDay = _daysInMonthNormal[month - 1]
        day = int(dateStr[-2:])
        if day < 1 or day > maxDay:
            return 0
        if year == 1582 and month == 10 and day > 4 and day < 15:
            return 0  # special case of 10 days dropped: Oct 5-14, 1582
        return 1

    def lastDayOfMonth(self):
        """returns last day of the month as integer 28-31"""
        if self.isLeapYear():
            return _daysInMonthLeapYear[self.month() - 1]
        else:
            return _daysInMonthNormal[self.month() - 1]

    def localeFormat(self):
        """override this method to use your preferred locale format"""
        return self.formatUS()

    def month(self):
        """returns month as integer 1-12"""
        return int(repr(self.normalDate)[-4:-2])

    def monthAbbrev(self):
        """returns month as a 3-character abbreviation, i.e. Jan, Feb, etc."""
        return _monthName[self.month() - 1][:3]

    def monthName(self):
        """returns month name, i.e. January, February, etc."""
        return _monthName[self.month() - 1]

    def normalize(self, scalar):
        """convert scalar to normalDate"""
        if scalar < _bigBangScalar:
            msg = "normalize(%d): scalar below minimum" % \
                  _bigBangScalar
            raise NormalDateException(msg)
        if scalar > _bigCrunchScalar:
            msg = "normalize(%d): scalar exceeds maximum" % \
                  _bigCrunchScalar
            raise NormalDateException(msg)
        from math import floor
        if scalar >= -115860:
            year = 1600 + int(floor((scalar + 109573) / 365.2425))
        elif scalar >= -693597:
            year = 4 + int(floor((scalar + 692502) / 365.2425))
        else:
            year = -4 + int(floor((scalar + 695058) / 365.2425))
        days = scalar - firstDayOfYear(year) + 1
        if days <= 0:
            year = year - 1
            days = scalar - firstDayOfYear(year) + 1
        daysInYear = 365
        if isLeapYear(year):
            daysInYear = daysInYear + 1
        if days > daysInYear:
            year = year + 1
            days = scalar - firstDayOfYear(year) + 1
        # add 10 days if between Oct 15, 1582 and Dec 31, 1582
        if (scalar >= -115860 and scalar <= -115783):
            days = days + 10
        if isLeapYear(year):
            daysByMonth = _daysInMonthLeapYear
        else:
            daysByMonth = _daysInMonthNormal
        dc = 0; month = 12
        for m in xrange(len(daysByMonth)):
            dc = dc + daysByMonth[m]
            if dc >= days:
                month = m + 1
                break
        # add up the days in prior months
        priorMonthDays = 0
        for m in xrange(month - 1):
            priorMonthDays = priorMonthDays + daysByMonth[m]
        day = days - priorMonthDays
        self.setNormalDate((year, month, day))

	def __radd__(self,days):
		"""for completeness"""
		return self.__add__(days)

    def range(self, days):
        """Return a range of normalDates as a list.  Parameter
        may be an int or normalDate."""
        if type(days) is not IntType:
            days = days - self  # if not int, assume arg is normalDate type
        r = []
        for i in range(days):
            r.append(self + i)
        return r

    def __repr__(self):
        """print format: [-]yyyymmdd"""
        # Note: When disassembling a NormalDate string, be sure to
        # count from the right, i.e. epochMonth = int(`Epoch`[-4:-2]),
        # or the slice won't work for dates B.C.
        if self.normalDate < 0:
            return "%09d" % self.normalDate
        else:
            return "%08d" % self.normalDate

	def __rsub__(self, v):
		if type(v) is IntType:
			return NormalDate(v) - self
		else:
			return v.scalar() - self.scalar()

    def scalar(self):
        """days since baseline date: Jan 1, 1900"""
        (year, month, day) = self.toTuple()
        days = firstDayOfYear(year) + day - 1
        if self.isLeapYear():
            for m in xrange(month - 1):
                days = days + _daysInMonthLeapYear[m]
        else:
            for m in xrange(month - 1):
                days = days + _daysInMonthNormal[m]
        if year == 1582:
            if month > 10 or (month == 10 and day > 4):
                days = days - 10
        return days

    def setDay(self, day):
        """set the day of the month"""
        maxDay = self.lastDayOfMonth()
        if day < 1 or day > maxDay:
            msg = "day is outside of range 1 to %d" % maxDay
            raise NormalDateException(msg)
        (y, m, d) = self.toTuple()
        self.setNormalDate((y, m, day))

    def setMonth(self, month):
        """set the month [1-12]"""
        if month < 1 or month > 12:
            raise NormalDateException('month is outside range 1 to 12')
        (y, m, d) = self.toTuple()
        self.setNormalDate((y, month, d))

    def setNormalDate(self, normalDate):
        """
        accepts date as scalar string/integer (yyyymmdd) or tuple 
        (year, month, day, ...)"""
        _type = type(normalDate)
        if _type is IntType:
            self.normalDate = normalDate
        elif _type is StringType:
            try:
                self.normalDate = int(normalDate)
            except ValueError:
                raise NormalDateException("Bad integer: '%s'" % normalDate)
        elif _type in (TupleType, ListType) or _type is _TimeType:
            self.normalDate = int("%04d%02d%02d" % normalDate[:3])
        elif _type is _NormalDateType:
            self.normalDate = normalDate.normalDate
        if not self._isValidNormalDate(self.normalDate):
            msg = "unable to setNormalDate(%s)" % `normalDate`
            raise NormalDateException(msg)

    def setYear(self, year):
        if year == 0:
            raise NormalDateException('cannot set year to zero')
        elif year < -9999:
            raise NormalDateException('year cannot be less than -9999')
        elif year > 9999:
            raise NormalDateException('year cannot be greater than 9999')
        (y, m, d) = self.toTuple()
        self.setNormalDate((year, m, d))

    __setstate__ = setNormalDate

    def __sub__(self, v):
        if type(v) is IntType:
            return self.__add__(-v)
        return self.scalar() - v.scalar()

    def toTuple(self):
        """return date as (year, month, day) tuple"""
        return (self.year(), self.month(), self.day())

    def year(self):
        """return year in yyyy format, negative values indicate B.C."""
        return int(repr(self.normalDate)[:-4])

#################  Utility functions  #################

def bigBang():
    """return lower boundary as a NormalDate"""
    return NormalDate((-9999, 1, 1))

def bigCrunch():
    """return upper boundary as a NormalDate"""
    return NormalDate((9999, 12, 31))

def dayOfWeek(y, m, d):
    """return integer representing day of week, Mon=0, Tue=1, etc."""
    if m == 1 or m == 2:
        m = m + 12
        y = y - 1
    return (d + 2*m + 3*(m+1)/5 + y + y/4 - y/100 + y/400) % 7

def firstDayOfYear(year):
    """number of days to the first of the year, relative to Jan 1, 1900"""
    if type(year) is not IntType:
        msg = "firstDayOfYear() expected integer, got %s" % type(year)
        raise NormalDateException(msg)
    if year == 0:
        raise NormalDateException('first day of year cannot be zero (0)')
    elif year < 0:  # BCE calculation
        firstDay = (year * 365) + int((year - 1) / 4) - 693596
    else:           # CE calculation
        leapAdjust = int((year + 3) / 4)
        if year > 1600:
            leapAdjust = leapAdjust - int((year + 99 - 1600) / 100) + \
                         int((year + 399 - 1600) / 400)
        firstDay = year * 365 + leapAdjust - 693963
        if year > 1582:
            firstDay = firstDay - 10
    return firstDay

def isLeapYear(year):
    """determine if specified year is leap year, returns Python boolean"""
    if year < 1600:
        if year % 4:
            return 0
        else:
            return 1
    elif year % 4 != 0:
        return 0
    elif year % 100 != 0:
        return 1
    elif year % 400 != 0:
        return 0
    else:
        return 1

ND=NormalDate
Epoch=bigBang()
_NormalDateType = type(Epoch)
_TimeType = type(time.localtime(time.time()))

if __name__ == '__main__':
    today = ND()
    print "NormalDate test:"
    print "  Today (%s) is: %s %s" % \
          (today, today.dayOfWeekAbbrev(), today.localeFormat())
    yesterday = today - 1
    print "  Yesterday was: %s %s" % \
          (yesterday.dayOfWeekAbbrev(), yesterday.localeFormat())
    tomorrow = today + 1
    print "  Tomorrow will be: %s %s" % \
          (tomorrow.dayOfWeekAbbrev(), tomorrow.localeFormat())
    print "  Days between tomorrow and yesterday: %d" % \
          (tomorrow - yesterday)

--ew6BAiZeqk4r7MaW--


From lbrannma@cablespeed.com  Fri Oct 11 13:21:38 2002
From: lbrannma@cablespeed.com (Lance)
Date: Fri, 11 Oct 2002 05:21:38 -0700
Subject: [Tutor] Reading Excel
Message-ID: <001801c27120$bf876990$3212eb42@MYNEWBOX>

This is a multi-part message in MIME format.

------=_NextPart_000_0015_01C270E6.130D1A50
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi All,

How might I read an Excel file using Python?

Thanks in advance.
Lance
------=_NextPart_000_0015_01C270E6.130D1A50
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>Hi All,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>How might I read an Excel file using=20
Python?</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>Lance</FONT></DIV></BODY></HTML>

------=_NextPart_000_0015_01C270E6.130D1A50--




From alan.gauld@bt.com  Fri Oct 11 12:59:36 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 11 Oct 2002 12:59:36 +0100
Subject: FW: [Tutor] Continuously Updating A Display?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C96E@mbtlipnt02.btlabs.bt.co.uk>

James meant this discussion for the list so here is my 
reply to his question...

Alan G.

 -----Original Message-----

 > So, as per your web page, I type in: top = Tk() and the 
 > first thing I notice is that it doesn't do this at all:
 > 
 > "This creates the top level widget in our widget heirarchy. 
 > All other widgets will be created as children of this. 
 > Notice that a new blank window has appeared 
 
 Are you doing it at the DOS prompt. And have you checked the 
 task bar - it has a habit of appearing behind the current window!
 
 Tkinter and IDLE don't mix well coz IDLE is itself written 
 in Tkinter.... it gets confused over which mainloop is 
 running etc.
 
 > I imagine this is a Windows/Tkinter issue and maybe 
 > I have to use the win32api API instead 
 
 No, not at all, my tutor was written for PC users (de facto 
 the majority) and should work as is. (I am actually running 
 Win 98SE at work and Windows XP Home at home - I also have 
 a Linux box and an Apple iBook laptop at home which I use 
 to test for compatibility across platforms... it should 
 work on all of them!)
 
 Also do you get any error messages? Or just no window?
 
 Alan G. 


From James.Rocks@equant.com  Fri Oct 11 13:16:17 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Fri, 11 Oct 2002 13:16:17 +0100
Subject: [Tutor] Testing For EOF?
Message-ID: <OFF85F4556.13DD6277-ON80256C4F.00406769@equant.com>

Hi,

Does anyone know an easy way to test for the end of a file?

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ
Phone:             0207-5226856
Fax:                   0207-5126087
Mobile Phone:     07771-767405
http://www.equant.com

This e-mail (including any attachments) is confidential and may be legally
privileged.  If you are not an intended recipient or an authorized
representative of an intended recipient, you are prohibited from using,
copying or distributing the information in this e-mail or its attachments.
If you have received this e-mail in error, please notify the sender
immediately by return e-mail and delete all copies of this message and any
attachments.  Thank you.



From James.Rocks@equant.com  Fri Oct 11 13:29:15 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Fri, 11 Oct 2002 13:29:15 +0100
Subject: [Tutor] Continuously Updating A Display?
Message-ID: <OFF7F2F1B2.B432D0FD-ON80256C4F.00448CD9@equant.com>

Hi Alan,

Sorry about replying to you and not the list last time :-(

> > So, as per your web page, I type in: top = Tk() and the first thing I
> > notice is that it doesn't do this at all:
> >
> > "This creates the top level widget in our widget heirarchy. All other
> > widgets will be created as children of this. Notice that a
> > new blank window has appeared
> Are you doing it at the DOS prompt. And have you checked the
> task bar - it has a habit of appearing behind the current window!

No ... I've checked visually and in Task Manager ... nothing appears.

> Tkinter and IDLE don't mix well coz IDLE is itself written
> in Tkinter.... it gets confused over which mainloop is
> running etc.

However this got me thinking ... I'm using Marc Hammond's windows
extensions and his Pythonwin editor, so I checked, realised that IDLE was
the more normal editor and tried there and ... it works! Must be something
different about Pythonwin.

> > I imagine this is a Windows/Tkinter issue and maybe I have to use the
> > win32api API instead
> No not at all, my tutor was written for PC users (de facto
> the majority) and should work as is. (I am actually running
> Win 98SE at work and Windows XP Home at home - I also have
> a Linux box and an Apple iBook laptop at home which I use
> to test for compatibility across platforms...)

OK ... seems it's a Pythonwin issue.

> Also do you get any error messages? Or just no window?

It was no Window ... I guess I should mail Marc Hammond and let him know as
I gather this is a fairly common thing to try?

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From arodrigo@genasys.com  Fri Oct 11 13:47:26 2002
From: arodrigo@genasys.com (Amaya Rodrigo Sastre)
Date: Fri, 11 Oct 2002 14:47:26 +0200
Subject: [Tutor] File copying
In-Reply-To: <HPEBIMANNCHHDMDBGCHHAEDHDGAA.hernan@orgmf.com.ar>
References: <HPEBIMANNCHHDMDBGCHHAEDHDGAA.hernan@orgmf.com.ar>
Message-ID: <20021011124726.GD10553@onix>

Hernan Martinez Foffani dijo:
> import shutil
> shutil.copyfile(src, dest)

I can't believe it was so *simple*. I don't seem to be any good at
finding the right python module.

Thanks for saving me some struggling with popen :-)

-- 
Amaya M. Rodrigo Sastre       Genasys II Spain, S.A.U. 
MLS Sysadmin                    Ventura de la Vega, 5. 
Phone: +34.91.3649100              28014 Madrid. Spain 


From alan.gauld@bt.com  Fri Oct 11 14:20:44 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 11 Oct 2002 14:20:44 +0100
Subject: [Tutor] Switch or Select?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C970@mbtlipnt02.btlabs.bt.co.uk>

> Just curious ... is there any kind of switch or select 
> statement in Python?

Nope.

> I know there is if/elif/else but a switch/case/else/break 
> style control structure would be quite handy :-)

if/elif is all you get. Its not too bad.

If you have a long case structure its usually better 
to use a dictionary:

def f1():....
def f2():....
def f3():....
etc....

cases = {test1:f1, test2:f2,test3:f3,....etc}

if test in cases.keys():
   result = cases[test]()
else: raise CaseError

That'll be faster too.
The only snag is that you have a lot of very small functions 
to write. If thats a problem you might be able to use lambdas,
however they are restricted to expressions!:

cases={test1: lambda : sqrt(foo),
       test2: lambda : pow(foo,3),
       test3: lambda : foo % 1,...}

if test in cases.keys():
   result = cases[test]()
else: raise CaseError

personally, I'd probably just use if/elif ;-)

Alan g.


From alan.gauld@bt.com  Fri Oct 11 14:25:41 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 11 Oct 2002 14:25:41 +0100
Subject: [Tutor] extramural papers in python??
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C971@mbtlipnt02.btlabs.bt.co.uk>

> I'm looking for a single paper which teaches programming (first year),
> which uses python as its reference language. My local college uses
> pascal (yuck yuck), and then delphi. 

If you actually want to become a full time professional 
programmer Pascal and Delphi are pretty good choices. 
They will force you into adopting good habits that will
be useful in any future languages you use. I still use 
Delphi when I need to produce a compiled Windoze program.

However if you just want to learn to program for occasional 
or personal use then Python is much easier, thats why 
I wrote my tutor in it :-)

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


From bwinton@latte.ca  Fri Oct 11 14:30:07 2002
From: bwinton@latte.ca (Blake Winton)
Date: Fri, 11 Oct 2002 09:30:07 -0400
Subject: [Tutor] Switch or Select?
In-Reply-To: <OF1AF73DBA.EAD5B799-ON80256C4F.002A810D@equant.com>
References: <OF1AF73DBA.EAD5B799-ON80256C4F.002A810D@equant.com>
Message-ID: <20021011133007.GB19509@latte.ca>

* James.Rocks@equant.com <James.Rocks@equant.com> [021011 03:50]:
> Hi,
> 
> Just curious ... is there any kind of switch or select statement in Python?
> I know there is if/elif/else but a switch/case/else/break style control
> structure would be quite handy :-)

Yes, there is.  The standard way to write it in Python is:
x = 3
if x == 1:
    pass
elif x == 2:
    pass
elif x == 3:
    pass
else
    pass

(Okay, so there really isn't one.  But I am kind of wondering
 why you think a switch statement is more useful than the if/elif?)

Oh, and I should probably mention that the other way to mimic a
switch statement looks something like this:
def handleOne():
    pass
def handleTwo():
    pass
def handleThree():
    pass
def handleDefault():
    pass
switch = { 1:handleOne, 2:handleTwo, 3:handleThree }

x = 3
function = handleDefault
if switch.has_key( x ):
    function = switch[x]

function()

(This is a very powerful technique, by the way.  Even if you don't
 use it now, you should keep it in the back of your mind...)

Later,
Blake.
-- 
  9:25am  up 5 days, 16:35,  1 user,  load average: 0.00, 0.00, 0.00


From hernan@orgmf.com.ar  Fri Oct 11 14:30:40 2002
From: hernan@orgmf.com.ar (Hernan Martinez Foffani)
Date: Fri, 11 Oct 2002 15:30:40 +0200
Subject: [Tutor] Switch or Select?
In-Reply-To: <20021011121601.22226.27475.Mailman@mail.python.org>
Message-ID: <HPEBIMANNCHHDMDBGCHHKEDHDGAA.hernan@orgmf.com.ar>

[James.Rocks@equant.com]
> Just curious ... is there any kind of switch or select statement in
> Python? I know there is if/elif/else but a switch/case/else/break
> style control structure would be quite handy :-)

In general you can do it with a chain of elif.
If you want to dispatch code based on a scalar value, a dictionary
of functions may be a better aproach.
The only case (pun intended) were a switch construct may help is
when evaluating ranges.  It was considered before but there were
not consensus on syntax and semantics.

Regards,
-Hernan




From alan.gauld@bt.com  Fri Oct 11 14:29:14 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 11 Oct 2002 14:29:14 +0100
Subject: [Tutor] File copying
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C972@mbtlipnt02.btlabs.bt.co.uk>

> I am trying to copy files around, but I only see doc on how to move
> them. 
> 
> Any hints?

shutil module, copyfile function...

Not obvious I agree.

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


From alan.gauld@bt.com  Fri Oct 11 14:32:07 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 11 Oct 2002 14:32:07 +0100
Subject: [Tutor] Reading Excel
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C973@mbtlipnt02.btlabs.bt.co.uk>

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_01C2712A.98391C80
Content-Type: text/plain;
	charset="iso-8859-1"

 >  How might I read an Excel file using Python? 
 
You need Mark Hammonds win32 extensions.
 
They allow access to the Microsoft COM libraries 
and thence to Excel. He includes some very short examples in the
documentation.
 
Follow the links from the Python web site. Alternatively get 
the ActiveState version of Python with them ready bundled.
 
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_01C2712A.98391C80
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 face=Arial><FONT size=2><SPAN class=260183813-11102002><FONT 
face="Courier New" color=#0000ff>&nbsp;&gt; &nbsp;</FONT></SPAN>How might I read 
an Excel file using Python?<SPAN class=260183813-11102002><FONT 
face="Courier New" color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=260183813-11102002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=260183813-11102002><FONT 
face="Courier New" color=#0000ff>You need Mark Hammonds win32 
extensions.</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=260183813-11102002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=260183813-11102002><FONT 
face="Courier New" color=#0000ff>They allow access to the Microsoft COM 
libraries</FONT>&nbsp;</SPAN></FONT></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=260183813-11102002>and thence to Excel. He includes some very short 
examples in the documentation.</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=260183813-11102002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=260183813-11102002>Follow the links from the Python web site. 
Alternatively get </SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=260183813-11102002>the ActiveState version of Python with them ready 
bundled.</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=260183813-11102002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=260183813-11102002>
<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_01C2712A.98391C80--


From fok@mcrane.co.uk  Fri Oct 11 14:47:10 2002
From: fok@mcrane.co.uk (Finbarr O'Keeffe)
Date: Fri, 11 Oct 2002 14:47:10 +0100
Subject: [Tutor] Reading Excel
In-Reply-To: <20021011121601.22226.27475.Mailman@mail.python.org>
Message-ID: <0be401c2712c$b2f49bb0$32001fac@fok>

 -----Original Message-----
Message: 7
From: "Lance" <lbrannma@cablespeed.com>
To: "Tutor" <tutor@python.org>
Date: Fri, 11 Oct 2002 05:21:38 -0700
Subject: [Tutor] Reading Excel

Hi All,

How might I read an Excel file using Python?

Thanks in advance.
Lance

Lance you could try the following code as a start. I would recommend Mark
Hammond & andy robinsons book "python programming on win32" which gives a
good introduction into this subject area:-

from win32com.client import Dispatch
from win32com.client import constants
app=Dispatch("Excel.Application")
app.Visible=1
app.Workbooks.Add()
app.Sheets(1).Cells(1,1).Value=str('sample cell data')


Regards

finbarr



From James.Alexander.McCarney@Cognicase.com  Fri Oct 11 19:15:28 2002
From: James.Alexander.McCarney@Cognicase.com (McCarney, James Alexander)
Date: Fri, 11 Oct 2002 14:15:28 -0400
Subject: [Tutor] re module and looping
Message-ID: <23FD7B1A77E8D211BCB900001D108C02023FCA58@camelot>

Hi list. Thank you for your tips and advice thus far. Success on compiling
the re objects; success on getting a return.

If you could advise me on the following, I would appreciate it...
I get only one tag <HTML> when I run the following. here is the re
code


    #tricky re stuff
    p=re.compile(r"(<.*?>)",re.DOTALL)
    m=p.match(alllines)
    if m:
        print "Match found: ",m.group() #<<<------Returns only ONE tag
    else:
        print "No match found."
    
How can I keep looping till the end, and keep getting all the < ... > and
the < /... > tags?

The code as it is now. Btw Alan thanks for the imports tip.

#imports
import sys, string, os, os.path, glob, re

def tagfinger():
    """Finds mark-up, and prints it to a text file."""
    #welcome
    print "Welcome to TagFinger!"
    print ""
    path_in=raw_input("Please type the pathname where you wish to search: ")
    print "The pathname you have chosen is: ",path_in
    print ""
    from os import chdir
    chdir(path_in)
    print "You are now in path: ",path_in
    print "We found the follwing...",glob.glob("*")
    list1=glob.glob("*")
    print ""
    answer=raw_input("Which file's tags do you wish to extract? ")
    print "You chose",answer
    for answer in list1:
        list1.pop()
    print ""
    print "...Opening...",answer
    rtfile=file(answer, 'r')
    print '...Reading...',answer
    print ""
    alllines=rtfile.read()
    print alllines

    #tricky re stuff
    p=re.compile(r"(<.*?>)",re.DOTALL)
    m=p.match(alllines)
    if m:
        print "Match found: ",m.group()
    else:
        print "No match found."
    


From charlie@begeistert.org  Fri Oct 11 19:21:21 2002
From: charlie@begeistert.org (Charlie Clark)
Date: Fri, 11 Oct 2002 20:21:21 +0200
Subject: [Tutor] Re: case/switch, etc.
In-Reply-To: <20021011160005.27475.99591.Mailman@mail.python.org>
Message-ID: <DC42NHQP64YTJDJH9IH765YHGIHXRDB.3da716a1@gormenghast>

Alan wrote:

That'll be faster too.
The only snag is that you have a lot of very small functions
to write. If thats a problem you might be able to use lambdas,
however they are restricted to expressions!:

cases={test1: lambda : sqrt(foo),
       test2: lambda : pow(foo,3),
       test3: lambda : foo % 1,...}

if test in cases.keys():
   result = cases[test]()
else: raise CaseError

personally, I'd probably just use if/elif ;-)

***
never having worked with case/switch, etc. I'm not sure when you would like to use it but I think it 
should also be mentioned that apart from if/elif you can also use try/except combinations instead for 
fine-grained control and powerful return values, etc. 

try:
	do_something()
except MyError:
       do_something_else()

Charlie




From magnus@thinkware.se  Fri Oct 11 19:45:37 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri, 11 Oct 2002 20:45:37 +0200
Subject: [Tutor] re module and looping
In-Reply-To: <23FD7B1A77E8D211BCB900001D108C02023FCA58@camelot>
Message-ID: <5.1.0.14.0.20021011204138.02fdb570@www.thinkware.se>

At 14:15 2002-10-11 -0400, McCarney, James Alexander wrote:
>Hi list. Thank you for your tips and advice thus far. Success on compiling
>the re objects; success on getting a return.
>
>If you could advise me on the following, I would appreciate it...
>I get only one tag <HTML> when I run the following. here is the re
>code
>
>
>     #tricky re stuff
>     p=3Dre.compile(r"(<.*?>)",re.DOTALL)
>     m=3Dp.match(alllines)
>     if m:
>         print "Match found: ",m.group() #<<<------Returns only ONE tag
>     else:
>         print "No match found."
>
>How can I keep looping till the end, and keep getting all the < ... > and
>the < /... > tags?

Read the library manual. First of all, read about the
difference between match and search. Then forget that ;)
and use findall instead.

Match allways matches from the start of the string.
Seach matches the first found occurence from a given
point. (You hardly ever use match, but you could use
search in a loop.) Findall returns a list of found
patterns, but not as match objects. Try and see.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Fri Oct 11 19:50:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri, 11 Oct 2002 20:50:02 +0200
Subject: [Tutor] Re: case/switch, etc.
In-Reply-To: <DC42NHQP64YTJDJH9IH765YHGIHXRDB.3da716a1@gormenghast>
References: <20021011160005.27475.99591.Mailman@mail.python.org>
Message-ID: <5.1.0.14.0.20021011204608.0316c380@www.thinkware.se>

There are also simpler cases where
dicts are an obvious choice:

switch x
case xx
    a =3D 1
case yy
    a =3D 2
etc...

Here you can simply do:

a =3D {xx:1, yy:2 ...}[x]

All in all, I find python much more powerful.

Another (semi-related issue) is how you
can use 'and' and 'or' instead of 'if' or
a C construct like "a?x:y"


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From James.Alexander.McCarney@Cognicase.com  Fri Oct 11 20:30:47 2002
From: James.Alexander.McCarney@Cognicase.com (McCarney, James Alexander)
Date: Fri, 11 Oct 2002 15:30:47 -0400
Subject: [Tutor] re module and looping
Message-ID: <23FD7B1A77E8D211BCB900001D108C02023FCA59@camelot>

Magnus wrote:

"Read the library manual. First of all, read about the
difference between match and search. Then forget that ;)
and use findall instead."


Absolutely brilliant! ;-) Thanks Magnus...

One glitch, however, is this. The code caught everything, except for these
two tags:
<!--
and
-->

Which is where a script goes in the HTML...

I would have thought

    p=re.compile(r"(<.*?>)",re.DOTALL)
    m=re.findall(r"(<.*?>)",alllines)

would have returned everything, including <!-- and -->


I am reading the re How-to by Andrew Kuchling. Btw, I will read re, reread
re, and re-reread re, because text-processing is a big part of what I need
to do.

Cheers! Who knows, maybe a nice script for the useless Python site.


From jeff@ccvcorp.com  Fri Oct 11 20:33:08 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Fri, 11 Oct 2002 12:33:08 -0700
Subject: [Tutor] Watch folder code - follow up question
References: <85256C4D.00538CBF.00@Notes.kollsman.com>
Message-ID: <3DA72774.BD061764@ccvcorp.com>


dfinner@Kollsman.com wrote:

> I've poked around the web at various Win API sites and have not found anything
> that converts the filter into an integer.  Any idea what
> FILE_NOTIFY_CHANGE_FILE_NAME is as an integer???

There's a win32con module that defines most of the Win API constants:

>>> import win32con
>>> win32con.FILE_NOTIFY_CHANGE_FILE_NAME
1
>>>

Hope that helps...

Jeff Shannon
Technician/Programmer
Credit International




From shalehperry@attbi.com  Fri Oct 11 21:34:22 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Fri, 11 Oct 2002 13:34:22 -0700
Subject: [Tutor] re module and looping
In-Reply-To: <23FD7B1A77E8D211BCB900001D108C02023FCA59@camelot>
References: <23FD7B1A77E8D211BCB900001D108C02023FCA59@camelot>
Message-ID: <200210111334.22537.shalehperry@attbi.com>

On Friday 11 October 2002 12:30, McCarney, James Alexander wrote:
> Magnus wrote:
>
> "Read the library manual. First of all, read about the
> difference between match and search. Then forget that ;)
> and use findall instead."
>
>
> Absolutely brilliant! ;-) Thanks Magnus...
>
> One glitch, however, is this. The code caught everything, except for th=
ese
> two tags:
> <!--
> and
> -->
>
> Which is where a script goes in the HTML...
>
> I would have thought
>
>     p=3Dre.compile(r"(<.*?>)",re.DOTALL)
>     m=3Dre.findall(r"(<.*?>)",alllines)
>
> would have returned everything, including <!-- and -->
>

it should *IF* the open and close is on the same line.

<fngvjkfvhdzifsndfsjik> will match

<fvjhfhsihsdfhzs
>

won't (the greater than sign is on the next line).


From lbrannma@cablespeed.com  Sat Oct 12 00:16:34 2002
From: lbrannma@cablespeed.com (Lance)
Date: Fri, 11 Oct 2002 16:16:34 -0700
Subject: [Tutor] Reading Excel
References: <0be401c2712c$b2f49bb0$32001fac@fok>
Message-ID: <005501c2717c$3df44fe0$3212eb42@MYNEWBOX>

Thanks everyone for the Win32 advice. This is a tremendous list.

Lance

----- Original Message ----- 
From: "Finbarr O'Keeffe" <fok@mcrane.co.uk>
To: <tutor@python.org>
Sent: Friday, October 11, 2002 6:47 AM
Subject: RE: [Tutor] Reading Excel


> -----Original Message-----
> Message: 7
> From: "Lance" <lbrannma@cablespeed.com>
> To: "Tutor" <tutor@python.org>
> Date: Fri, 11 Oct 2002 05:21:38 -0700
> Subject: [Tutor] Reading Excel
> 
> Hi All,
> 
> How might I read an Excel file using Python?
> 
> Thanks in advance.
> Lance
> 
> Lance you could try the following code as a start. I would recommend Mark
> Hammond & andy robinsons book "python programming on win32" which gives a
> good introduction into this subject area:-
> 
> from win32com.client import Dispatch
> from win32com.client import constants
> app=Dispatch("Excel.Application")
> app.Visible=1
> app.Workbooks.Add()
> app.Sheets(1).Cells(1,1).Value=str('sample cell data')
> 
> 
> Regards
> 
> finbarr
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
> 



From thomi@thomi.imail.net.nz  Sat Oct 12 00:40:55 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Sat, 12 Oct 2002 12:40:55 +1300
Subject: [Tutor] extramural papers in python??
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C971@mbtlipnt02.btlabs.bt.co.uk>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C971@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20021012124055.587f26fd.thomi@thomi.imail.net.nz>

I a;;ready know a bit ofg pascal, and even more C. I know the basics of
python, but i just wanted to do something which i would find
interesting... I have no idea where this degree is going to take me, so
anything is useful...


On Fri, 11 Oct 2002 14:25:41 +0100 Thus said alan.gauld@bt.com:

> > I'm looking for a single paper which teaches programming (first
> > year), which uses python as its reference language. My local college
> > uses pascal (yuck yuck), and then delphi. 
> 
> If you actually want to become a full time professional 
> programmer Pascal and Delphi are pretty good choices. 
> They will force you into adopting good habits that will
> be useful in any future languages you use. I still use 
> Delphi when I need to produce a compiled Windoze program.
> 
> However if you just want to learn to program for occasional 
> or personal use then Python is much easier, thats why 
> I wrote my tutor in it :-)
> 
> 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


-- 
Thomi Richards
thomi@imail.net.nz
http://thomi.imail.net.nz/
Thomi Richards,
thomi@imail.net.nz


From emile@fenx.com  Sat Oct 12 08:14:27 2002
From: emile@fenx.com (Emile van Sebille)
Date: Sat, 12 Oct 2002 00:14:27 -0700
Subject: [Tutor] Re: Testing For EOF?
References: <OFF85F4556.13DD6277-ON80256C4F.00406769@equant.com>
Message-ID: <ao8i24$hf8$1@main.gmane.org>

<James.Rocks@equant.com> asks:
> Does anyone know an easy way to test for the end of a file?
> 

while 1:
    rec = filehandle.read()
    if not rec: break

HTH,
 
--

Emile van Sebille
emile@fenx.com

---------





From goneil@scu.edu  Sat Oct 12 08:42:31 2002
From: goneil@scu.edu (Galen O'Neil)
Date: 12 Oct 2002 00:42:31 -0700
Subject: [Tutor] removing items from a list
Message-ID: <1034408564.3911.12.camel@lucidia>

Dear listreaders,
I want to remove items from a list that have content that matches my
data.  I can think of a few ways to do this, but none that seem as
simple as it should be.

This doesn't work, I'm not sure why.  Mabye item isn't a refence to the
list item, but just has the same value.

for item in list:
	if item == data: del item

This works, its ok, but still seems like there should be something
cleaner if not faster.
i=0
for item in list:
	if item == data:
		del list[i]
	i=i+1


This seems inefficient:

i=0
for item in list:
	if not item == data:
		newlist[i] = item
		i = i + 1
list = newlist

--Galen



From goneil@scu.edu  Sat Oct 12 11:07:43 2002
From: goneil@scu.edu (Galen O'Neil)
Date: 12 Oct 2002 03:07:43 -0700
Subject: [Tutor] Handling telnet disconnection, while loop
Message-ID: <1034417273.4022.19.camel@lucidia>

while telnetopen and loop:
	try:
		dostuff()
	except:
		close()

close()


This is the code I'm working with, essentially.  I have a few questions.
1. I declared loop as a global variable, and I change it to 0 inside of
a function like this.

def stoplooping():
	loop =0

Contrary to my expectations, this doesn't stop the loop.  Any thoughts?

2. I want my program to run continuously until it is disconnected from
the telnet server (a MUD if your interested) then save some data.  The
best I've come up with is this try: except: setup, but I don't like it
much.  It hides some debugging data from me, when the dostuff() function
fails it doesn't give me debug info, it just fails the try.  And, this
just seems sloppy.  Any more thoughts?

Thanks in advance,
--Galen



From yduppen@xs4all.nl  Sat Oct 12 11:43:59 2002
From: yduppen@xs4all.nl (Yigal Duppen)
Date: Sat, 12 Oct 2002 12:43:59 +0200
Subject: [Tutor] Handling telnet disconnection, while loop
In-Reply-To: <1034417273.4022.19.camel@lucidia>
References: <1034417273.4022.19.camel@lucidia>
Message-ID: <200210121244.01703.yduppen@xs4all.nl>

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

> 1. I declared loop as a global variable, and I change it to 0 inside of
> a function like this.
>
> def stoplooping():
> 	loop =0
>
> Contrary to my expectations, this doesn't stop the loop.  Any thoughts?

Yup. This is a well-known issue. What happens here is that the interpreter 
assumes that your assigning 0 to the *local* variable loop; the fact that 
this variable happens to shadow (hide) the *global* variable with the same 
name is not the interpreter's problem.

You therefore must *explicitly* tell the interpreter that loop is a global 
variable, like this:

>>> def local_stop():
...     loop = 0
...
>>> def global_stop():
...     global loop
...     loop = 0
...
>>> loop = 1
>>> print loop
1
>>> local_stop()
>>> print loop
1
>>> global_stop()
>>> print loop
0


> 2. I want my program to run continuously until it is disconnected from
> the telnet server (a MUD if your interested) then save some data.  The
> best I've come up with is this try: except: setup, but I don't like it
> much.  It hides some debugging data from me, when the dostuff() function
> fails it doesn't give me debug info, it just fails the try.  And, this
> just seems sloppy.  Any more thoughts?

You can use the traceback module:
>>> import traceback
>>> try:
...     raise Exception("Something happened!")
... except:
...     traceback.print_exc()
...
Traceback (most recent call last):
  File "<stdin>", line 2, in ?
Exception: Something happened!

The print_exc function can also take an arbitrary file object as argument, 
allowing you to write the error to e.g. a logfile.

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

iD8DBQE9p/zxLsKMuCf5EdwRAgGUAKCy/nOepMmN/jrs0qSHOcM0p3yDBgCgyAct
tgAC02lsFm1U9VX73VmNq/0=
=4sre
-----END PGP SIGNATURE-----



From yduppen@xs4all.nl  Sat Oct 12 11:50:46 2002
From: yduppen@xs4all.nl (Yigal Duppen)
Date: Sat, 12 Oct 2002 12:50:46 +0200
Subject: [Tutor] removing items from a list
In-Reply-To: <1034408564.3911.12.camel@lucidia>
References: <1034408564.3911.12.camel@lucidia>
Message-ID: <200210121250.46170.yduppen@xs4all.nl>

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

On Saturday 12 October 2002 09:42, Galen O'Neil wrote:
> Dear listreaders,
> I want to remove items from a list that have content that matches my
> data.  I can think of a few ways to do this, but none that seem as
> simple as it should be.

Simplest solution:
>>> item = "a"
>>> l = ["a", "b", "c"]
>>> l.remove(item)
>>> l
['b', 'c']

Note: remove will only remove the *first* value from the list

> This doesn't work, I'm not sure why.  Mabye item isn't a refence to the
> list item, but just has the same value.
>
> for item in list:
> 	if item == data: del item

Some notes:
1. Never use a built-in name such as list (or dict, or file, or...) for a 
variable. That's asking for trouble :)

2. What happens is this:
example:
>>> item = "a"			# The value "a" is given the name 'item'
>>> l = ["a", "b", "c"]		# A new object is created which contains "a", "b" and
					# "c". This new object gets the name 'l'
>>> del item			# The name 'item' is removed. The value it refers to is 
					# *not* removed!

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

iD8DBQE9p/6GLsKMuCf5EdwRAhHjAJ92BlRQ7BMc+v5Y8oVFgbtV7fcN0QCaAnkx
0GjUvRwmBY7NnFOoU+9sDQE=
=x7UY
-----END PGP SIGNATURE-----



From James.Rocks@equant.com  Sat Oct 12 13:52:12 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Sat, 12 Oct 2002 13:52:12 +0100
Subject: [Tutor] Re: case/switch, etc.
Message-ID: <OF1A38F9B3.32D99B1B-ON80256C50.00465AD5@equant.com>

Hi Magnus (& all in this thread)

> All in all, I find python much more powerful.

I'm sure you're right but you have to understand that I don't know that yet
coz I've only just started with it ... so far though I'm pretty impressed :
-)

In (some) other languages SWITCH/CASE has been touted as an advance on what
there was before ... that in mind I thought python might reasonably be
expected to feature it. I accept that there are many ways to skin a cat and
what I knew before is/was not neccessarily the best :-)

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From lbrannma@cablespeed.com  Sat Oct 12 14:29:44 2002
From: lbrannma@cablespeed.com (Lance)
Date: Sat, 12 Oct 2002 06:29:44 -0700
Subject: [Tutor] First app - design questions
Message-ID: <000e01c271f3$6d3d22f0$3212eb42@MYNEWBOX>

This is a multi-part message in MIME format.

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

Hi All,

I want to write an app that will summarize the contents of all .py files =
in a tree view. The top level of the tree would be folders containing =
the .py files. The next level would be the name of each file. The third =
level would be the procedures in each file. The main window of the tree =
view (e.g. the right window in Windows Explorer) would, for a given =
file, list the procedures and their __doc__ line(s).=20

Any design suggestions would be appreciated. I imagine I would have to =
control for different OS's (e.g. a tree view in Windows would no doubt =
be different from a Linux tree view).

Thanks,
Lance
------=_NextPart_000_000B_01C271B8.C0BFC670
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>Hi All,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I want to write an app that will =
summarize the=20
contents of all .py files in a tree view. The top level of the tree =
would be=20
folders containing the .py files. The next level would be the name of =
each file.=20
The third level would be the procedures in each file. The main window of =
the=20
tree view (e.g. the right window in Windows Explorer) would, for a given =
file,=20
list the procedures and their __doc__ line(s). </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Any design suggestions would be =
appreciated. I=20
imagine I would have to control for different OS's (e.g. a tree view in =
Windows=20
would no doubt be different from a Linux tree view).</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Lance</FONT></DIV></BODY></HTML>

------=_NextPart_000_000B_01C271B8.C0BFC670--




From op73418@mail.telepac.pt  Sat Oct 12 14:40:33 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Sat, 12 Oct 2002 14:40:33 +0100
Subject: [Tutor] removing items from a list
References: <1034408564.3911.12.camel@lucidia>
Message-ID: <002e01c271f4$f03095b0$6f100dd5@violante>

> Dear listreaders,
> I want to remove items from a list that have content that matches my
> data.  I can think of a few ways to do this, but none that seem as
> simple as it should be.
>
> This doesn't work, I'm not sure why.  Mabye item isn't a refence to the
> list item, but just has the same value.
>
> for item in list:
> if item == data: del item
>
> This works, its ok, but still seems like there should be something
> cleaner if not faster.
> i=0
> for item in list:
> if item == data:
> del list[i]
> i=i+1
>
>
> This seems inefficient:
>
> i=0
> for item in list:
> if not item == data:
> newlist[i] = item
> i = i + 1
> list = newlist
>
> --Galen

Removing an item from the list is always somewhat inefficient. You have to
linearly search the list, then remove the item, both O(N) operations (I am
being a little sloppy - I know). If your framework affords it, just stuff
your items in a dictionary as keys (in particular they have to be hashable).
In this way, testing equality and removing is essentialy independent of the
size of the dictionary.

If you must absolutely go with a list then use the remove method.

Hope it helps,
Gonçalo Rodrigues



From reavey@nep.net  Sat Oct 12 13:31:00 2002
From: reavey@nep.net (reavey)
Date: 12 Oct 2002 08:31:00 -0400
Subject: [Tutor] recursion program
Message-ID: <1034425861.4105.15.camel@localhost.localdomain>

I ran into this beauty in How to think like a computer scientist chapter
4
def countdown(n):
	if n == 0:
		print "BLASTOFF!"
	else:
		print n
	countdown(n-1)
indentation is probably wrong, I use idle and let it do the work

question:
I would like to call a sound effect say from
/usr/share/sounds/KDE_Beep_Lightning.wav when n == 0
How?
I would also like the countdown to be in real time, how?

TIA
mike Reavey





From francois.granger@free.fr  Sat Oct 12 17:43:29 2002
From: francois.granger@free.fr (=?iso-8859-1?Q?Fran=E7ois?= Granger)
Date: Sat, 12 Oct 2002 18:43:29 +0200
Subject: [Tutor] First app - design questions
In-Reply-To: <000e01c271f3$6d3d22f0$3212eb42@MYNEWBOX>
References: <000e01c271f3$6d3d22f0$3212eb42@MYNEWBOX>
Message-ID: <a05100338b9ce0171cec0@[192.168.1.11]>

At 6:29 -0700 on 12/10/02, in message [Tutor] First app - design 
questions, Lance wrote:
>Hi All,
>
>I want to write an app that will summarize the contents of all .py 
>files in a tree view. The top level of the tree would be folders 
>containing the .py files. The next level would be the name of each 
>file. The third level would be the procedures in each file. The main 
>window of the tree view (e.g. the right window in Windows Explorer) 
>would, for a given file, list the procedures and their __doc__ 
>line(s).

Have a look to pydoc in ths lib folder. It does already most of what you want.


-- 
Le courrier électronique 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://minilien.com/?IXZneLoID0 - 
http://marc.herbert.free.fr/mail/


From Andrew <angelopoulos@csi.com>  Sat Oct 12 18:42:54 2002
From: Andrew <angelopoulos@csi.com> (Andrew)
Date: Sat, 12 Oct 2002 13:42:54 -0400
Subject: [Tutor] Jython
In-Reply-To: <a05100338b9ce0171cec0@[192\.168\.1\.11]>
References: <000e01c271f3$6d3d22f0$3212eb42@MYNEWBOX>
 <a05100338b9ce0171cec0@[192.168.1.11]>
Message-ID: <4454298235.20021012134254@csi.com>

Hi All,

I've been busy going through Python's core modules and learning its
syntax wondering if I should rewrite a mod or two for my own greedy
needs and having lots of fun... Now I find out that they are building
something at work which will incorporate IBM's BSF (Bean Scripting
Framework) which adds Perl, Jython, ASP, netrexx, Rhino, etc. hooks
into the product line. 

So, I've got a couple of questions:

I've looked over Jython and am beginning to wonder: How much python is
really there (maybe a pared down os module), but it seems to me all
the interesting things and modules that are in Python are "missing" in
Jython.. e.g., I would have to use mostly Java (or so it seems) to
create an SMTP client connection to somewhere... which leaves me
wondering where the efficiency is? Strikes me as easier to do it all
in Java instead of wondering where I've gone wrong with a mixed
language approach (just thinking, I haven't tried it yet). Any
comments or insight?

My second question is: Is Jython still being developed and supported?
the last official release was nearly a year ago (12/01)?

Andrew



From terjeja@hotmail.com  Sat Oct 12 19:04:13 2002
From: terjeja@hotmail.com (Terje Johan Abrahamsen)
Date: Sat, 12 Oct 2002 18:04:13 +0000
Subject: [Tutor] RE module
Message-ID: <F81cHbb7i8st0LIKEKc0000feaf@hotmail.com>

Hello,

    I am playing around with the RE module. But there is one thing I would 
like to do, which I am not able to. I would like to search thru and find all 
filenames in a text. For example, all words exceeded by .exe. I guess I must 
find everything in front until it comes to a special character or space.

For example 'this is the text \\&*98and some 
more$53#start.exe*934more%4\\text.exe7['

Is it possible to get out 'start.exe' and 'text.exe' out of this?

Thanks in advance


_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com



From idiot1@netzero.net  Sun Oct 13 06:12:08 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Sun, 13 Oct 2002 01:12:08 -0400
Subject: [Tutor] update, and the I get to eat some crow department
Message-ID: <3DA900A8.2AF70EED@netzero.net>

OH WELL...

ever improved something to discover you DEproved it? Well, I had to go back and
correct a couple of typos that effected the custom welcome/farewell message
processing, and a cApitAlizaTIOn error that messed up the replyto address for
the confirmation  messages. The new and corrected tinylist.1.5.2.tzr.gp is on
the site, with autoinstaller, and I updated it so now it works with .in files as
source instead of .p files, which appears to be the standard. Trying also to
make the documentation clearer, so I can THROW OUT some of the earlier docs
which say less, voluminously.

And again, permissions in un*x are probably worth a  monthly knowledge lecture
in any un*x relevant forum. I installed TL in a domain I own to test the update-
and it bombed. I looked at my other 2 installs, changed permissions on the new
one to conform, and it worked. This seems to be the simplest way o trip over
your own feet in the world, permissions do.

Pass the catsup please. (munch munch...)

-- 

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
Unlimited Long Distance only $29.95/ month!
Sign Up Today! www.netzerolongdistance.com


From idiot1@netzero.net  Mon Oct 14 03:12:42 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Sun, 13 Oct 2002 22:12:42 -0400
Subject: [Tutor] test- this thing thinks I just subscribed?!??
Message-ID: <3DAA281A.9831F9F1@netzero.net>

interesting. I just got a welcome message from the tutor list server, and no
traffic on the list for a day. odd.

-- 

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
Unlimited Long Distance only $29.95/ month!
Sign Up Today! www.netzerolongdistance.com


From rob@uselesspython.com  Mon Oct 14 04:50:09 2002
From: rob@uselesspython.com (Rob)
Date: Sun, 13 Oct 2002 22:50:09 -0500
Subject: [Tutor] test- this thing thinks I just subscribed?!??
In-Reply-To: <3DAA281A.9831F9F1@netzero.net>
Message-ID: <MPEOIFCOPCIHEDCLBLPBKEBGCIAA.rob@uselesspython.com>

Once in a while I receive a message from the Tutor List server addressing me
as a new subscriber.

Rob

>
> interesting. I just got a welcome message from the tutor list
> server, and no
> traffic on the list for a day. odd.




From alan.gauld@bt.com  Mon Oct 14 11:40:52 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 14 Oct 2002 11:40:52 +0100
Subject: [Tutor] re module and looping
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C97E@mbtlipnt02.btlabs.bt.co.uk>

> If you could advise me on the following, I would appreciate it...
> I get only one tag <HTML> when I run the following. here is the re
> code
> 
> 
>     #tricky re stuff
>     p=re.compile(r"(<.*?>)",re.DOTALL)
>     m=p.match(alllines)

This isn't directly related to the question but it occurs 
to me that one caveat with this code is how it handles 
nested tags. For example script sections can have tags 
within strings or even use <,> in their mathematical 
sense and thus confuse the search. Also sometimes people 
comment out sections of a page temporarily, leaving the 
tags in place.

Mostly it will work OK but there may well be some 
strangenesses... 

Alan G.


From alan.gauld@bt.com  Mon Oct 14 12:15:17 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 14 Oct 2002 12:15:17 +0100
Subject: [Tutor] removing items from a list
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C97F@mbtlipnt02.btlabs.bt.co.uk>

> This doesn't work, I'm not sure why.  Mabye item isn't a 
> refence to the list item, but just has the same value.
> 
> for item in list:
> 	if item == data: del item

This deletes item but the list still has a reference to it.
ie item no longer points at the object but the list does!

> This works, its ok, but still seems like there should be something
> cleaner if not faster.

Actually it doesn't quite work!

> i=0
> for item in list:
> 	if item == data:
> 		del list[i]
> 	i=i+1

Two adjacent items that equal data will only result in 
one being deleted:

a
b <---- item
b
c

becomes

a
b
c <----- item after an iteration of the loop with item = b.

You really need to use a while loop to do this manually:

i = 0
while i < len(list):
   if list[i] == data: del list[i]
   else: i += 1


A better solution is to use the filter() function or a list 
comprehension

list = filter(lambda x: x != data, list)

list = [item for item in list if item != data]

filter is designed to filter out items that match the test 
function. comprehensions are designed to look a little 
like set notation in math....

Be aware that the performance may not be much better than 
the loops, but they look nicer...

HTH,

Alan G.


From James.Rocks@equant.com  Mon Oct 14 12:21:44 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Mon, 14 Oct 2002 12:21:44 +0100
Subject: [Tutor] Stopping A Program
Message-ID: <OFC0A82EF9.632F0430-ON80256C52.003E48F4@equant.com>

Hi,

Once a python program is running I don't seem to be able to stop it ... I
have to shut down (forcefully) the IDE (IDLE or Pythonwin). Is there an
easy way to stop a python program?

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ
Phone:             0207-5226856
Fax:                   0207-5126087
Mobile Phone:     07771-767405
http://www.equant.com

This e-mail (including any attachments) is confidential and may be legally
privileged.  If you are not an intended recipient or an authorized
representative of an intended recipient, you are prohibited from using,
copying or distributing the information in this e-mail or its attachments.
If you have received this e-mail in error, please notify the sender
immediately by return e-mail and delete all copies of this message and any
attachments.  Thank you.



From alan.gauld@bt.com  Mon Oct 14 12:22:20 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 14 Oct 2002 12:22:20 +0100
Subject: [Tutor] First app - design questions
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C980@mbtlipnt02.btlabs.bt.co.uk>

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_01C27373.F640F280
Content-Type: text/plain;
	charset="iso-8859-1"

 >  I want to write an app that will summarize the contents of all .py files
in a tree view.  
 
Interesting excercise. I think either Pythonwin or IDLE has a similar
facility 
built in, but I can't remember which,. nor indeed if I'm getting confused
with 
something else - Delphi and several Java IDEs do this....
 
>  Any design suggestions would be appreciated. I imagine I would have to  
>  control for different OS's (e.g. a tree view in Windows would no doubt be

>  different from a Linux tree view). 
 
Not if you use any of the cross platform GUIS - thats why they are cross
platform!
 
I'd recommend wxPython for this one...
 
http://www.wxpython.org/ <http://www.wxpython.org/> 
 
Alan g

------_=_NextPart_001_01C27373.F640F280
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 face=Arial><FONT size=2><SPAN class=240122611-14102002><FONT 
face="Courier New" color=#0000ff>&nbsp;&gt; &nbsp;</FONT></SPAN>I want to write 
an app that will summarize the contents of all .py files in a tree 
view.&nbsp;<SPAN class=240122611-14102002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=240122611-14102002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=240122611-14102002>Interesting 
excercise. I think either Pythonwin or IDLE has a similar facility 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=240122611-14102002>built in, but 
I can't remember which,. nor indeed if I'm getting confused with 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=240122611-14102002>something else 
- Delphi and several Java IDEs do this....</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=240122611-14102002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=240122611-14102002><FONT 
face="Courier New" color=#0000ff>&gt; &nbsp;</FONT></SPAN>Any design suggestions 
would be appreciated. I imagine I would have to&nbsp;<SPAN 
class=240122611-14102002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=240122611-14102002><FONT 
face="Courier New" color=#0000ff>&gt; </FONT>&nbsp;</SPAN>control for different 
OS's (e.g. a tree view in Windows would no doubt be&nbsp;<SPAN 
class=240122611-14102002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=240122611-14102002><FONT 
face="Courier New" color=#0000ff>&gt; </FONT>&nbsp;</SPAN>different from a Linux 
tree view).<SPAN class=240122611-14102002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=240122611-14102002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=240122611-14102002>Not if you use any 
of the cross platform GUIS - thats why they are cross 
platform!</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=240122611-14102002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=240122611-14102002>I'd recommend 
wxPython for this one...</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=240122611-14102002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=240122611-14102002><A 
href="http://www.wxpython.org/">http://www.wxpython.org/</A></SPAN></FONT></DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=240122611-14102002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=240122611-14102002>Alan g</SPAN></FONT></DIV></BODY></HTML>

------_=_NextPart_001_01C27373.F640F280--


From alan.gauld@bt.com  Mon Oct 14 12:29:47 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 14 Oct 2002 12:29:47 +0100
Subject: [Tutor] RE module
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C981@mbtlipnt02.btlabs.bt.co.uk>

> For example 'this is the text \\&*98and some 
> more$53#start.exe*934more%4\\text.exe7['
> 
> Is it possible to get out 'start.exe' and 'text.exe' out of this?

Probably not, unless there is some kind of special character 
just before the name.

You can search for the .exe but when you try to work out what 
the first part of the name is you must work back looking for 
the first non valid filename character.  But since spaces etc 
are valid filename chars its impoossible to know where the 
name starts and stops. Unless you know in advance what the 
possible filenames are (in which case just search to see which 
are present - easier!) I think you are beaten.

Alan G


From jpaish@freenet.edmonton.ab.ca  Mon Oct 14 13:08:19 2002
From: jpaish@freenet.edmonton.ab.ca (Joseph Paish)
Date: Mon, 14 Oct 2002 06:08:19 -0600
Subject: [Tutor] assigning types(?) to list elements
Message-ID: <0210140608190B.01006@localhost.localdomain>

i'm not sure what the correct terminology for what i am trying to do is, so 
i'll just describe it the best i can.

# code follows

file_handle = open ('/path/to/datafile.txt', 'r')
    
for each_line in file_handle.readlines() :
        each_line = each_line.rstrip() # strip off carriage return
        temp1, temp2, temp3, temp4, temp5, temp6 = string.split(each_line)
    
        # a sample record is : 'abc 123.45 74 98 234.56 345.67'
 
        # temp1 is a string so it doesn't need any conversion
        # but i do need to convert the others so i can do calculations with   
        #    them

        temp2  = float(temp2)
        temp3  = int(temp3)
        temp4  = int(temp4)
        temp5 = float(temp5)
        temp6 = float(temp6)

# end code

is there an easier way to assign a type to each of the variables so that i 
can do calculations with them.  the way it is now, if i don't do any 
conversion and add a number to any of temp2 thru temp6, i end up with a 
concatenated string.

i guess i am asking if there is another way to make each of the variables the 
correct type without doing it one variable at a time the way it is now.

there are a lot more than just the six variables i am using for this example, 
so one line of code for each variable would get very long.

a pointer to documentation would be very helpful so that i can understand any 
suggestions for doing what i am trying to do.  of course, an example of the 
correct way to do it wouldn't be turned down :-)

thanks

joe
 


From Blake.Garretson@dana.com  Mon Oct 14 14:30:02 2002
From: Blake.Garretson@dana.com (Blake.Garretson@dana.com)
Date: Mon, 14 Oct 2002 09:30:02 -0400
Subject: [Tutor] while else, for else
Message-ID: <OF952FCB68.81E4E22E-ON85256C52.0048E794@dana.com>

I have been using Python for 3+ years now, and I have yet to see regular
use of the "while else" or "for else" constructs.  I personally *never* use
them, and unless I haven't read enough source code from other people, I
haven't seen evidence that anybody else uses them very often either.

If you look in books like "Learning Python" or "Programming Python", you
can certainly find examples of how they can be used, but they never seem
necessary.  You can always get by with loops and normal if statments (and
some flags).

To me, it seems like they make the code more confusing and less readable,
so I don't use them.  So my question is, am I missing something?  Are there
situations that "while/for else" provide the only way to implement an
algorithm?  In other words, would I ever *have* to use it in order to do
something?  Moreover, are there common applications that maybe I *should*
be using this construct?  Are there any Python idioms that use loop elses?

Thanks,
-Blake Garretson




From James.Rocks@Equant.com  Mon Oct 14 14:49:21 2002
From: James.Rocks@Equant.com (James.Rocks@Equant.com)
Date: Mon, 14 Oct 2002 14:49:21 +0100
Subject: [Tutor] Stopping A Program
Message-ID: <OF55C6F236.D655CEB6-ON80256C52.004BABD0@equant.com>

Hi Thomi,

> are you using linux or windows?? It sounds liek you're using linux,
> but it can't rtell for sure.

Windows at present ... still trying to suss building Debian 33.0 Linux
which, to a Windows oriented individual like me, is completely alien to
install.

> I'm assuming that you have tried CTRL+D under
> linux, and (i think) CTRL + z under windows??

Neither appears to work I'm afraid :-(

> type "exit" at the prompt, and see what it says...

I can't reach the interactive window at all as that is where I am running
the program from.

Thanks anyway ...

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ
Phone:             0207-5226856
Fax:                   0207-5126087
Mobile Phone:     07771-767405
http://www.equant.com

This e-mail (including any attachments) is confidential and may be legally
privileged.  If you are not an intended recipient or an authorized
representative of an intended recipient, you are prohibited from using,
copying or distributing the information in this e-mail or its attachments.
If you have received this e-mail in error, please notify the sender
immediately by return e-mail and delete all copies of this message and any
attachments.  Thank you.



From op73418@mail.telepac.pt  Mon Oct 14 15:00:12 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Mon, 14 Oct 2002 15:00:12 +0100
Subject: [Tutor] assigning types(?) to list elements
References: <0210140608190B.01006@localhost.localdomain>
Message-ID: <000901c2738a$03a39b10$9e170dd5@violante>

From: "Joseph Paish" <jpaish@freenet.edmonton.ab.ca>

> i'm not sure what the correct terminology for what i am trying to do is,
so
> i'll just describe it the best i can.
>
> # code follows
>
> file_handle = open ('/path/to/datafile.txt', 'r')
>
> for each_line in file_handle.readlines() :
>         each_line = each_line.rstrip() # strip off carriage return
>         temp1, temp2, temp3, temp4, temp5, temp6 = string.split(each_line)
>
>         # a sample record is : 'abc 123.45 74 98 234.56 345.67'
>
>         # temp1 is a string so it doesn't need any conversion
>         # but i do need to convert the others so i can do calculations
with
>         #    them
>
>         temp2  = float(temp2)
>         temp3  = int(temp3)
>         temp4  = int(temp4)
>         temp5 = float(temp5)
>         temp6 = float(temp6)
>
> # end code
>
> is there an easier way to assign a type to each of the variables so that i
> can do calculations with them.  the way it is now, if i don't do any
> conversion and add a number to any of temp2 thru temp6, i end up with a
> concatenated string.
>
> i guess i am asking if there is another way to make each of the variables
the
> correct type without doing it one variable at a time the way it is now.
>
> there are a lot more than just the six variables i am using for this
example,
> so one line of code for each variable would get very long.
>
> a pointer to documentation would be very helpful so that i can understand
any
> suggestions for doing what i am trying to do.  of course, an example of
the
> correct way to do it wouldn't be turned down :-)
>
> thanks
>
> joe
>

With python 2.2 onward you can use

temp.__class__

to fetch the class of the temp object. It needs 2.2 because I believe that
with 2.1 and earlier builtin types have no __class__ attribute - although I
am not sure, and I have no way to test it.

Hope it helped,
Gonçalo Rodrigues




From shalehperry@attbi.com  Mon Oct 14 15:52:03 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Mon, 14 Oct 2002 07:52:03 -0700
Subject: [Tutor] while else, for else
In-Reply-To: <OF952FCB68.81E4E22E-ON85256C52.0048E794@dana.com>
References: <OF952FCB68.81E4E22E-ON85256C52.0048E794@dana.com>
Message-ID: <200210140752.03253.shalehperry@attbi.com>

On Monday 14 October 2002 06:30, Blake.Garretson@dana.com wrote:
> I have been using Python for 3+ years now, and I have yet to see regula=
r
> use of the "while else" or "for else" constructs.  I personally *never*=
 use
> them, and unless I haven't read enough source code from other people, I
> haven't seen evidence that anybody else uses them very often either.
>
> If you look in books like "Learning Python" or "Programming Python", yo=
u
> can certainly find examples of how they can be used, but they never see=
m
> necessary.  You can always get by with loops and normal if statments (a=
nd
> some flags).
>
> To me, it seems like they make the code more confusing and less readabl=
e,
> so I don't use them.  So my question is, am I missing something?  Are t=
here
> situations that "while/for else" provide the only way to implement an
> algorithm?  In other words, would I ever *have* to use it in order to d=
o
> something?  Moreover, are there common applications that maybe I *shoul=
d*
> be using this construct?  Are there any Python idioms that use loop els=
es?
>

Thney are definately not required because as you say you can always use a=
n if=20
right after the loop.

I believe the biggest reason that this construct is used less often is th=
at it=20
is python specific and many people code in both Python and some other=20
language(s).  These programmers most likely also came to Python as a seco=
nd=20
(or more) language.  So constructs like for..else are less likely to occu=
r to=20
them.  I would expect to see their usage higher from a person who learned=
=20
Python earlier.

As to when to use them think about it like this.  If your code is logical=
ly an=20
if..else statement but the if logic has to occur within a loop, then an e=
lse=20
makes sense.

while (not to end of line):
    if this word is the right one:
        store =3D word
        break
else:
    never found the word so store a backup word in its place

hope that helps.


From alan.gauld@bt.com  Mon Oct 14 17:07:23 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 14 Oct 2002 17:07:23 +0100
Subject: [Tutor] Stopping A Program
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C984@mbtlipnt02.btlabs.bt.co.uk>

> Once a python program is running I don't seem to be able to 
> stop it ... 

raise SystemExit

or

import sys
sys.exit()

The latter gives the option of returning an error code to 
the external environment:

sys.exit(2)

Note that these will all be caught by IDLE but when running 
the program as a standalone script will exit back to the OS.

BTW This is covered in the very first hands-on topic in my 
online tutor... :-)

HTH,

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


From alan.gauld@bt.com  Mon Oct 14 17:22:10 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 14 Oct 2002 17:22:10 +0100
Subject: [Tutor] while else, for else
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C986@mbtlipnt02.btlabs.bt.co.uk>

> I have been using Python for 3+ years now, and I have yet to 
> see regular use of the "while else" or "for else" constructs.  

I confess that in the same period I've used while/else once 
and for/else not at all...

Alan G.


From alan.gauld@bt.com  Mon Oct 14 17:20:46 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 14 Oct 2002 17:20:46 +0100
Subject: [Tutor] assigning types(?) to list elements
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C985@mbtlipnt02.btlabs.bt.co.uk>

WARNING: Untested code!

> for each_line in file_handle.readlines() :
>         each_line = each_line.rstrip() # strip off carriage return
>         temp1, temp2, temp3, temp4, temp5, temp6 = 
>                                            string.split(each_line)
          vals = string.split(each_line)
          types = [float,int,float,float]
          for i in range(2,len(types)):
            vals[i] = types[i](vals[i])  # convert types
          temp1,temp2,temp3,temp4,temp5 = vals # assign to vars


Not wonderful, I suspect there is a better pythonic way to do it, 
but it is at least extensible...

Is that any better?

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


From mongo57a@comcast.net  Mon Oct 14 19:19:33 2002
From: mongo57a@comcast.net (andy surany)
Date: Mon, 14 Oct 2002 14:19:33 -0400
Subject: [Tutor] Binding the mouse to a list using Tk.
Message-ID: <003201c273ae$3f0fd0a0$2502a8c0@emily.ewndsr01.nj.comcast.net>

This is a multi-part message in MIME format.

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

Hi all!

What I want to do is use a button to capture the position/value of the

selected item in a scrolled list. So the user selects the item in the list

with a single click of the left mouse button and then clicks a button.

Should be easy - I'm just not getting it......



I'm using Tkinter. I Created a class (ScrolledList) for a scrolled list which works fine. Created

another class (aaaaa) which populates the list - and it works fine. Created

a handler under ScrolledList (handleList) which should trap the results of

the bind (makeWidgets). Right now, all I'm trying to do is just print out

the value (just testing..) - but my logic is incorrect (actually, I think

that the logic may be correct - it's just in the wrong place...).

Here is a synopsis of the code. The "...." is non-relevant code which I have removed for simplification.



class ScrolledList(Frame):

    def __init__(self, options, parent=None):

        ........

        self.makeWidgets(options)

    def handleList(self, event):

        index = self.listbox.curselection()

        label = self.listbox.get(index)

        print "label is ", label

    def makeWidgets(self, options):

        ........

        list.bind('<Button-1>', self.handleList) 

Class aaaaa

    def update_strategy_code(self):

        ..........

        ScrolledList(options)

        Button(self, text='Update',

        command=self.edit_strategy_code).pack(side=LEFT)

    def edit_strategy_code(self):

        label=self.listbox.get(ACTIVE)

        print 'info2=',label

 TIA!

Andy (mongo57a@comcast.net)


--Boundary_(ID_rP+Enm3/pQR2u7Cqxy1VAQ)
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><FONT face=Arial size=2>
<P>Hi all!</P>
<P>What I want to do is use a button to capture the position/value of the</P>
<P>selected item in a scrolled list. So the user selects the item in the 
list</P>
<P>with a single click of the left mouse button and then clicks a button.</P>
<P>Should be easy - I'm just not getting it......</P>
<P>&nbsp;</P>
<P>I'm using Tkinter. I Created a class (ScrolledList) for a scrolled list which 
works fine. Created</P>
<P>another class (aaaaa) which populates the list - and it works fine. 
Created</P>
<P>a handler under ScrolledList (handleList) which should trap the results 
of</P>
<P>the bind (makeWidgets). Right now, all I'm trying to do is just print out</P>
<P>the value (just testing..) - but my logic is incorrect (actually, I think</P>
<P>that the logic may be correct - it's just in the wrong place...).</P>
<P>Here is a synopsis of the code. The "...." is non-relevant code which I have 
removed for simplification.</P>
<P>&nbsp;</P>
<P>class ScrolledList(Frame):</P>
<P>&nbsp;&nbsp;&nbsp; def __init__(self, options, parent=None):</P>
<P>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ........</P>
<P>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; self.makeWidgets(options)</P>
<P>&nbsp;&nbsp;&nbsp; def handleList(self, event):</P>
<P>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; index = self.listbox.curselection()</P>
<P>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; label = self.listbox.get(index)</P>
<P>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print "label is ", label</P>
<P>&nbsp;&nbsp;&nbsp; def makeWidgets(self, options):</P>
<P>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ........</P>
<P>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; list.bind('&lt;Button-1&gt;', 
self.handleList) </P>
<P>Class aaaaa</P>
<P>&nbsp;&nbsp;&nbsp; def update_strategy_code(self):</P>
<P>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ..........</P>
<P>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ScrolledList(options)</P>
<P>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Button(self, text='Update',</P>
<P>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
command=self.edit_strategy_code).pack(side=LEFT)</P>
<P>&nbsp;&nbsp;&nbsp; def edit_strategy_code(self):</P>
<P>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; label=self.listbox.get(ACTIVE)</P>
<P>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print 'info2=',label</P>
<P>&nbsp;TIA!</P>
<P>Andy (mongo57a@comcast.net)</P></FONT></FONT></DIV></BODY></HTML>

--Boundary_(ID_rP+Enm3/pQR2u7Cqxy1VAQ)--


From Michael.Baker@IGT.com  Thu Oct 10 17:13:45 2002
From: Michael.Baker@IGT.com (Baker.Michael)
Date: Thu, 10 Oct 2002 09:13:45 -0700
Subject: [Tutor] RE: Tutor digest, Vol 1 #1981 - 7 msgs
Message-ID: <5A021171E87BD411AF7700508B6940D00347C807@anchorgaming.anchorgaming.com>

this is how i would do it:

import os
command = 'ping %s'
ip = '192.168.44.40'

os.system(command % ip)

#--

from the docs for the os module (v 2.0):

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. 

enjoy,

Michael Baker



>To: tutor@python.org
>From: James.Rocks@equant.com
>Date: Thu, 10 Oct 2002 15:02:13 +0100
>Subject: [Tutor] Runing an external command?

>Hi,

>I want to "ping" a server within my program.

>My intention, initially at least, is to "shell out" and call the DOS ping
>program to do this ... eventualy I will attempt to rewite the C program
>source that someone mentioned in the archives.

>So my question is how do I run an external program and does the program
>wait until that program has finished execution or does it just carry on
>regardless?




From franois.granger@free.fr  Mon Oct 14 14:24:53 2002
From: franois.granger@free.fr (Fran=?ISO-8859-1?B?5w==?=ois Granger)
Date: Mon, 14 Oct 2002 15:24:53 +0200
Subject: [Tutor] assigning types(?) to list elements
In-Reply-To: <0210140608190B.01006@localhost.localdomain>
Message-ID: <B9D09245.58D58%franois.granger@free.fr>

on 14/10/02 14:08, Joseph Paish at jpaish@freenet.edmonton.ab.ca wrote:

> file_handle = open ('/path/to/datafile.txt', 'r')
>   
> for each_line in file_handle.readlines() :
>       each_line = each_line.rstrip() # strip off carriage return
>       temp1, temp2, temp3, temp4, temp5, temp6 = string.split(each_line)
>       temp2  = float(temp2)
>       temp3  = int(temp3)
>       temp4  = int(temp4)
>       temp5 = float(temp5)
>       temp6 = float(temp6)

This seems to do what you want:

typeslist = [str,float,int,int,float,float]

test = 'abc 123.45 74 98 234.56 345.67'
temp = test.split()
# a sample record is : 'abc 123.45 74 98 234.56 345.67'
result = []
for i in range(len(temp)):
    result.append(typeslist[i](temp[i]))
pass
-- 
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 magnusk2@telia.com  Mon Oct 14 20:58:58 2002
From: magnusk2@telia.com (Magnus Käck)
Date: Mon, 14 Oct 2002 21:58:58 +0200
Subject: [Tutor] editable_enters
Message-ID: <20021014215858.20a06f2c.magnusk2@telia.com>

Hi all,

I'm trying to use the function editable_enters, but I'm having no luck.

...
self.gtop = libglade.GladeXML("prename.glade", "prename")
...
self.gtop.editable_enters(self.namn);
...


Any tips, what is needed to use this function?

Magnus


From jeff@ccvcorp.com  Mon Oct 14 21:07:25 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Mon, 14 Oct 2002 13:07:25 -0700
Subject: [Tutor] assigning types(?) to list elements
References: <0210140608190B.01006@localhost.localdomain>
Message-ID: <3DAB23FD.802A7DDA@ccvcorp.com>

Joseph Paish wrote:

> i guess i am asking if there is another way to make each of the variables the
> correct type without doing it one variable at a time the way it is now.

If you have control over the data file, you may want to consider reading and
writing it in binary format using the struct module.  That will let you create a
string specifying a sequence of types that will be used for each record (line).
See the docs on struct for more info, and then come back here with specific
questions.

If you're getting the data file from somewhere else, and can't control its
format, then your options are a little weaker.  Best bet then (provided that each
line is known to be the same) is probably to apply a list of types, as suggested
by previous respondents.

Jeff Shannon
Technician/Programmer
Credit International




From scot@possum.in-berlin.de  Mon Oct 14 08:54:18 2002
From: scot@possum.in-berlin.de (Scot W. Stevenson)
Date: Mon, 14 Oct 2002 09:54:18 +0200
Subject: [Tutor] Parsing a primitive line of logic
Message-ID: <200210140954.18896.scot@possum.in-berlin.de>

Hello there, 

I'm trying to write a little piece that will let people search for keywords 
in, say, a text, so that given "Mary had a little lamb" they can write a 
query such as "Mary & lamb" and get "true", or "Mary & ! cow" and get 
true, too. 

The following code works, but somehow I'm not sure if it the right way to 
doit, first of all because it contains the eval(), which makes me as 
nervous as using exec(), and second because it seems like I'm wasting 
computer power be setting up the whole string for evaluation even if say 
the first term is negative. 

This can't be a new problem, in fact, I'm sure this is Programming 101. Any 
suggestions on what could be done better?

Thank you, 
Y, Scot

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

teststr = """This is one of those strings that has lots of animals in them:
    cat, dog, pig, mouse, emu, frog, and gopher. There are animals missing,
    but you'll have to find out which ones"""
    
parsedict = {'&' : 'and',
             '|' : 'or', 
             '!' : 'not',
             '(' : '(',
             ')' : ')'}

inputstring = ''
while inputstring != 'quit':
    inputstring = raw_input('Give me a search string please: ')
    words = inputstring.split()
    parselist = []

    for token in words:
        try:
            converted = parsedict[token]
        except KeyError:
            if token[0] == '"' and token[-1] == '"':
                token = token[1:-1]
            converted = teststr.count(token)
        parselist.append(str(converted))

    evalstring = ' '.join(parselist)
    if eval(evalstring):
        print '%s is true' % inputstring
    else:
        print '%s is false' % inputstring

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

-- 
   Scot W. Stevenson wrote me on Monday, 14. Oct 2002 in Zepernick, Germany   
       on his happy little Linux system that has been up for 323 hours        
        and has a CPU that is falling asleep at a system load of 0.00.        



From dylan.belsey@baesystems.com  Tue Oct 15 00:02:37 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Tue, 15 Oct 2002 08:32:37 +0930
Subject: [Tutor] Binding the mouse to a list using Tk.
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B98D2ADD@wtntex1.baea.com.au>

    Only had a brief look at your problem, but I believe that the Tkinter
widgets Listbox and ScrolledListBox may be what you need (and save you quite
a bit of time).  You can use the Listbox methods from within the
ScrolledListbox object as well.  You could then possibly associate a
function with your button which gets the currently selected item.
getcurselection() returns the text while the curselection() will return the
index.
    A lot of this is quite similar to what your code has proposed but using
the built-in widgets and their functions may shed some light on an easier
solution.
 
    HTH,
        Dylan
 

-----Original Message-----
From: andy surany [mailto:mongo57a@comcast.net]
Sent: Tuesday, 15 October 2002 04:20
To: tutor@python.org
Subject: [Tutor] Binding the mouse to a list using Tk.


Hi all!

What I want to do is use a button to capture the position/value of the

selected item in a scrolled list. So the user selects the item in the list

with a single click of the left mouse button and then clicks a button.

Should be easy - I'm just not getting it......

 

I'm using Tkinter. I Created a class (ScrolledList) for a scrolled list
which works fine. Created

another class (aaaaa) which populates the list - and it works fine. Created

a handler under ScrolledList (handleList) which should trap the results of

the bind (makeWidgets). Right now, all I'm trying to do is just print out

the value (just testing..) - but my logic is incorrect (actually, I think

that the logic may be correct - it's just in the wrong place...).

Here is a synopsis of the code. The "...." is non-relevant code which I have
removed for simplification.

 

class ScrolledList(Frame):

    def __init__(self, options, parent=None):

        ........

        self.makeWidgets(options)

    def handleList(self, event):

        index = self.listbox.curselection()

        label = self.listbox.get(index)

        print "label is ", label

    def makeWidgets(self, options):

        ........

        list.bind('<Button-1>', self.handleList) 

Class aaaaa

    def update_strategy_code(self):

        ..........

        ScrolledList(options)

        Button(self, text='Update',

        command=self.edit_strategy_code).pack(side=LEFT)

    def edit_strategy_code(self):

        label=self.listbox.get(ACTIVE)

        print 'info2=',label

 TIA!

Andy (mongo57a@comcast.net)



From reavey@nep.net  Mon Oct 14 20:13:47 2002
From: reavey@nep.net (reavey)
Date: 14 Oct 2002 15:13:47 -0400
Subject: [Tutor] recommendation sought
Message-ID: <1034622828.21703.7.camel@localhost.localdomain>

the best all around python book.  I'm particularly

interested in using python as a pic module programmer.


I'd like to let Santa know!!

TIA
MIke Reavey



From dyoo@hkn.eecs.berkeley.edu  Tue Oct 15 02:52:16 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 14 Oct 2002 18:52:16 -0700 (PDT)
Subject: [Tutor] I will be gone for a while
Message-ID: <Pine.LNX.4.44.0210141846530.3521-100000@hkn.eecs.berkeley.edu>

Hi everyone,


I'm going to be a submerged from Tutor for a while.  I'm trying to finish
a few projects that have been on the back burner for a long time now; I
want to keep them from burning.


I hate saying bye for a second time; it's like I'm calling wolf or
something!  I'll be back in a few weeks; I can't keep myself way for long
periods of time.  *grin*


Best of wishes to everyone!



From mongo57a@comcast.net  Tue Oct 15 04:49:56 2002
From: mongo57a@comcast.net (andy surany)
Date: Mon, 14 Oct 2002 23:49:56 -0400
Subject: [Tutor] Binding the mouse to a list using Tk.
Message-ID: <006501c273fd$ed73bae0$2502a8c0@emily.ewndsr01.nj.comcast.net>

Thanks Dylan. I am using the listbox methods. And everything works. If I put
the list.bind in the same method that calls the scrolled list, I even get a
response when I move the cursor to list selection (listbox.cursorselection).
The problem is that I need the selected list item to be independent of the
mouse (mouse is depressing a button which gets the original highlighted list
item). It's almost like I'm losing context.

I haven't looked at getcurselection - which I will do now. I still think
that my logic is correct - but I haven't placed it in the correct spot.

Regards,

Andy
-----Original Message-----
From: BELSEY, Dylan <dylan.belsey@baesystems.com>
To: tutor@python.org <tutor@python.org>
Date: Monday, October 14, 2002 6:59 PM
Subject: RE: [Tutor] Binding the mouse to a list using Tk.


>    Only had a brief look at your problem, but I believe that the Tkinter
>widgets Listbox and ScrolledListBox may be what you need (and save you
quite
>a bit of time).  You can use the Listbox methods from within the
>ScrolledListbox object as well.  You could then possibly associate a
>function with your button which gets the currently selected item.
>getcurselection() returns the text while the curselection() will return the
>index.
>    A lot of this is quite similar to what your code has proposed but using
>the built-in widgets and their functions may shed some light on an easier
>solution.
>
>    HTH,
>        Dylan
>
>
>-----Original Message-----
>From: andy surany [mailto:mongo57a@comcast.net]
>Sent: Tuesday, 15 October 2002 04:20
>To: tutor@python.org
>Subject: [Tutor] Binding the mouse to a list using Tk.
>
>
>Hi all!
>
>What I want to do is use a button to capture the position/value of the
>
>selected item in a scrolled list. So the user selects the item in the list
>
>with a single click of the left mouse button and then clicks a button.
>
>Should be easy - I'm just not getting it......
>
>
>
>I'm using Tkinter. I Created a class (ScrolledList) for a scrolled list
>which works fine. Created
>
>another class (aaaaa) which populates the list - and it works fine. Created
>
>a handler under ScrolledList (handleList) which should trap the results of
>
>the bind (makeWidgets). Right now, all I'm trying to do is just print out
>
>the value (just testing..) - but my logic is incorrect (actually, I think
>
>that the logic may be correct - it's just in the wrong place...).
>
>Here is a synopsis of the code. The "...." is non-relevant code which I
have
>removed for simplification.
>
>
>
>class ScrolledList(Frame):
>
>    def __init__(self, options, parent=None):
>
>        ........
>
>        self.makeWidgets(options)
>
>    def handleList(self, event):
>
>        index = self.listbox.curselection()
>
>        label = self.listbox.get(index)
>
>        print "label is ", label
>
>    def makeWidgets(self, options):
>
>        ........
>
>        list.bind('<Button-1>', self.handleList)
>
>Class aaaaa
>
>    def update_strategy_code(self):
>
>        ..........
>
>        ScrolledList(options)
>
>        Button(self, text='Update',
>
>        command=self.edit_strategy_code).pack(side=LEFT)
>
>    def edit_strategy_code(self):
>
>        label=self.listbox.get(ACTIVE)
>
>        print 'info2=',label
>
> TIA!
>
>Andy (mongo57a@comcast.net)
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor



From dylan.belsey@baesystems.com  Tue Oct 15 05:49:55 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Tue, 15 Oct 2002 14:19:55 +0930
Subject: [Tutor] Binding the mouse to a list using Tk.
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B98D2ADF@wtntex1.baea.com.au>

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_000_01C27406.4EB02E30
Content-Type: text/plain;
	charset="iso-8859-1"

Hi Andy,
	In the interest of code sharing, I have attached a file which I
believe contains some of the operations that you are looking to perform.  It
is a cut down version of a class I wrote for the current system I am working
on.  In its original form it obtains signals from a data server and displays
them ready for selection.  The user then selects signals from the left-hand
box, presses the appropriate button ('->') and the signal appears in the
selected signals box, on the right hand side.  This window was to aid the
user in selecting specific signals for monitoring.  I have kept the relevant
functionality in the file.
	I am currently running this under WinNT.  I have also made the file
self running, so all you have to do is get a DOS prompt in the directory
where you have saved it and then type "example.py" or "python example.py".
	Two windows will appear.  Just ignore the first one (but don't close
it until you are finished), for this exercise.  It is the root window, which
is important/necessary, but I have chosen not to use it here.
	So anyway, run it and experiment with it and then take a look at the
code, from which I hope you can get some ideas and help.
	If you have any questions, please feel free to ask.

	HTH,
		Dylan


PS: By the ways Tutors, if you see any glaring deficiencies, problems, etc.
in the code pls. feel free to comment.  However, I'm not too interested in a
code review at this point in time :)




-----Original Message-----
From: andy surany [mailto:mongo57a@comcast.net]
Sent: Tuesday, 15 October 2002 13:50
To: BELSEY, Dylan; tutor@python.org
Subject: Re: [Tutor] Binding the mouse to a list using Tk.


Thanks Dylan. I am using the listbox methods. And everything works. If I put
the list.bind in the same method that calls the scrolled list, I even get a
response when I move the cursor to list selection (listbox.cursorselection).
The problem is that I need the selected list item to be independent of the
mouse (mouse is depressing a button which gets the original highlighted list
item). It's almost like I'm losing context.

I haven't looked at getcurselection - which I will do now. I still think
that my logic is correct - but I haven't placed it in the correct spot.

Regards,

Andy
-----Original Message-----
From: BELSEY, Dylan <dylan.belsey@baesystems.com>
To: tutor@python.org <tutor@python.org>
Date: Monday, October 14, 2002 6:59 PM
Subject: RE: [Tutor] Binding the mouse to a list using Tk.


>    Only had a brief look at your problem, but I believe that the Tkinter
>widgets Listbox and ScrolledListBox may be what you need (and save you
quite
>a bit of time).  You can use the Listbox methods from within the
>ScrolledListbox object as well.  You could then possibly associate a
>function with your button which gets the currently selected item.
>getcurselection() returns the text while the curselection() will return the
>index.
>    A lot of this is quite similar to what your code has proposed but using
>the built-in widgets and their functions may shed some light on an easier
>solution.
>
>    HTH,
>        Dylan
>
>
>-----Original Message-----
>From: andy surany [mailto:mongo57a@comcast.net]
>Sent: Tuesday, 15 October 2002 04:20
>To: tutor@python.org
>Subject: [Tutor] Binding the mouse to a list using Tk.
>
>
>Hi all!
>
>What I want to do is use a button to capture the position/value of the
>
>selected item in a scrolled list. So the user selects the item in the list
>
>with a single click of the left mouse button and then clicks a button.
>
>Should be easy - I'm just not getting it......
>
>
>
>I'm using Tkinter. I Created a class (ScrolledList) for a scrolled list
>which works fine. Created
>
>another class (aaaaa) which populates the list - and it works fine. Created
>
>a handler under ScrolledList (handleList) which should trap the results of
>
>the bind (makeWidgets). Right now, all I'm trying to do is just print out
>
>the value (just testing..) - but my logic is incorrect (actually, I think
>
>that the logic may be correct - it's just in the wrong place...).
>
>Here is a synopsis of the code. The "...." is non-relevant code which I
have
>removed for simplification.
>
>
>
>class ScrolledList(Frame):
>
>    def __init__(self, options, parent=None):
>
>        ........
>
>        self.makeWidgets(options)
>
>    def handleList(self, event):
>
>        index = self.listbox.curselection()
>
>        label = self.listbox.get(index)
>
>        print "label is ", label
>
>    def makeWidgets(self, options):
>
>        ........
>
>        list.bind('<Button-1>', self.handleList)
>
>Class aaaaa
>
>    def update_strategy_code(self):
>
>        ..........
>
>        ScrolledList(options)
>
>        Button(self, text='Update',
>
>        command=self.edit_strategy_code).pack(side=LEFT)
>
>    def edit_strategy_code(self):
>
>        label=self.listbox.get(ACTIVE)
>
>        print 'info2=',label
>
> TIA!
>
>Andy (mongo57a@comcast.net)
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor


------_=_NextPart_000_01C27406.4EB02E30
Content-Type: application/octet-stream;
	name="example.py"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="example.py"


# Import main GUI modules.
from Tkinter import *
import Pmw

# Constants.
LISTBOX_WIDTH =3D              50          # Width of the listbox.


class SignalSelectWindow:
    def __init__(self, ParentWindow):

        # Initialise list to store selected indices locally.
        self.LocalList =3D []

        # Create the window and give it a title.
        self.Select =3D Toplevel(ParentWindow)
        self.Select.title("Monitor Signals Panel")
       =20
        # Create a frame within the window to hold signal boxes.
        self.f0 =3D Frame(self.Select)
       =20
        # Initialise the tuple to hold signal names for displaying in =
the ListBox.
        self.CurrentDisplayTuple =3D ("Signal1", "Signal2", "Signal3", =
"Signal4")
       =20
        # Create a dictionary where the keys are the signal names and =
the
        # values are the index as they appear in the =
CompleteSignalList.
        self.AllSignalsDict =3D {}

        # Populate the dictionary.
        listCounter =3D 0
        for element in self.CurrentDisplayTuple:
            self.AllSignalsDict[element] =3D listCounter

            # Increment the counter.
            listCounter =3D listCounter + 1
           =20
        # Create a LHS box containing all the available signals.
        self.box1 =3D Pmw.ScrolledListBox(self.f0, =
listbox_selectmode=3DEXTENDED,
                listbox_bd=3D3,
                items=3Dself.CurrentDisplayTuple,
                labelpos=3DN, label_text=3D'Available Signals:', =
label_font=3D(('MS', 'Sans', 'Serif'), '8', "bold underline"),
                listbox_width=3DLISTBOX_WIDTH)=20
        self.box1.pack(fill=3DBOTH, expand=3DYES, side=3DLEFT, =
padx=3D5, pady=3D5)
       =20
        # A frame to hold all of the selection buttons.
        self.f1 =3D Frame(self.f0)

        # A spacing frame.
        self.fSpace =3D Frame(self.f1, height=3D100)
        self.fSpace.pack(side=3DTOP, fill=3DBOTH, expand=3DYES)

        # Frame for the select and deselect buttons.
        self.f2 =3D Frame(self.f1)

        # Button creation.
        self.bDeselect =3D Button(self.f2, text=3D'<-', =
command=3Dself.RemoveSelectedSig)
        self.bDeselect.pack(expand=3DYES, side=3DBOTTOM, pady=3D2)
        self.bSelect =3D Button(self.f2, text=3D'->', =
command=3Dself.AddSelectedSig)
        self.bSelect.pack(expand=3DYES, side=3DBOTTOM, pady=3D2)
       =20
        self.f2.pack(side=3DTOP, fill=3DBOTH, expand=3DYES, pady=3D4)

        # Pack the main button frame.
        self.f1.pack(side=3DLEFT, fill=3DBOTH, expand=3DYES)
       =20
        # RHS box for the selected signal names.
        self.box2 =3D Pmw.ScrolledListBox(self.f0, =
listbox_selectmode=3DEXTENDED,
                listbox_bd=3D3,
                labelpos=3DN, label_text=3D'Selected Signals:', =
label_font=3D(('MS', 'Sans', 'Serif'), '8', "bold underline"),
                listbox_width=3DLISTBOX_WIDTH)=20
        self.box2.pack(fill=3DBOTH, expand=3DYES, side=3DLEFT, =
padx=3D5, pady=3D5)

        # Pack the signal boxes frame.
        self.f0.pack(side=3DTOP, fill=3DBOTH, expand=3DYES)

        return


    # Called when the '->' button is pressed.  Adds the selected =
signals in the left
    # box to the local index list and appends the name to the RHS box.
    # INPUT: None.
    # OUTPUT: None.
    def AddSelectedSig(self):
        # Get the text of the selected signals and convert to a list.
        SelectedSigsText =3D list(self.box1.getcurselection())

        # Do nothing if there are no signals selected.
        if SelectedSigsText =3D=3D []:
            return
       =20
        for signalName in SelectedSigsText:
            # Obtain the index of the signal.
            index =3D self.AllSignalsDict.get(signalName)

            if index !=3D None and index not in self.LocalList:
                # Add to local index list.
                self.LocalList.append(index)

                # Add the signal name to the end of the display in the =
RHS box.
                self.box2.insert(END, signalName)

        return


    # Called when the '<-' button is pressed.  Removes the selected =
signals in the left
    # box from the local index list and removes the name to the RHS =
box.
    # INPUT: None.
    # OUTPUT: None.
    def RemoveSelectedSig(self):
        # Capture the index's of the selected signals from the RHS box =
and convert
        # to a list.  Returns a list of strings.
        SelectedSigsIndices =3D list(self.box2.curselection())

        # Do nothing if there are no signals selected.
        if SelectedSigsIndices =3D=3D []:
            pass
        else:
            # For removing elements from a list, must reverse the order =
to H->L
            # to avoid indexation errors as the list reduces in size.
            SelectedSigsIndices.reverse()

           =20
            for indexStr in SelectedSigsIndices:
                # Convert to an integer.
                indexInt =3D int(indexStr)
               =20
                # Get the element that we want to remove from =
LocalList.
                removeElement =3D self.LocalList[indexInt]

                # Remove the element.
                self.LocalList.remove(removeElement)

                # Remove the signal from the display.
                self.box2.delete(indexInt)

        return

  =20
#  End of class: SignalSelectWindow.


if __name__ =3D=3D '__main__':
    root =3D Tk()
    sl =3D SignalSelectWindow(root)
    root.mainloop()

------_=_NextPart_000_01C27406.4EB02E30--


From magnus@thinkware.se  Tue Oct 15 09:42:27 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue, 15 Oct 2002 10:42:27 +0200
Subject: [Tutor] re module and looping
In-Reply-To: <23FD7B1A77E8D211BCB900001D108C02023FCA59@camelot>
Message-ID: <5.1.0.14.0.20021015104123.02afd008@www.thinkware.se>

At 15:30 2002-10-11 -0400, McCarney, James Alexander wrote:
>I would have thought
>
>     p=3Dre.compile(r"(<.*?>)",re.DOTALL)
>     m=3Dre.findall(r"(<.*?>)",alllines)

Why don't you use your compiled pattern (the
one using re.DOTALL):

m=3Dp.findall(alllines)


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From James.Rocks@equant.com  Tue Oct 15 09:44:09 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Tue, 15 Oct 2002 09:44:09 +0100
Subject: [Tutor] Stopping A Program
Message-ID: <OF59D5C8F6.031B28DB-ON80256C53.002FF675@equant.com>

Hi Alan,

> raise SystemExit
> or
> import sys
> sys.exit()
> The latter gives the option of returning an error code to
> the external environment:
> sys.exit(2)
> Note that these will all be caught by IDLE but when running
> the program as a standalone script will exit back to the OS.
> BTW This is covered in the very first hands-on topic in my
> online tutor... :-)

I think you misunderstood (or my expression was bad) ... I mean when a long
program is running how do you terminate it. In windows at least I cannot
access the immediate window so how do I force a running program to stop if
there is no code to stop it or it gets stuck in a loop that I hadn't
intended?

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From magnus@thinkware.se  Tue Oct 15 09:59:55 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue, 15 Oct 2002 10:59:55 +0200
Subject: [Tutor] Re: case/switch, etc.
In-Reply-To: <OF1A38F9B3.32D99B1B-ON80256C50.00465AD5@equant.com>
Message-ID: <5.1.0.14.0.20021015104519.02b01cf8@www.thinkware.se>

At 13:52 2002-10-12 +0100, James.Rocks@equant.com wrote:
>In (some) other languages SWITCH/CASE has been touted as an advance on what
>there was before ... that in mind I thought python might reasonably be
>expected to feature it.

Python tries to avoid redundant features.
If you want a lot of redundant features
(and the confusion that follows) go for
Perl or PHP.

The power in Python does not stem from
an extensive feature list, but from its
simplicity.

The richness in Python is in its standard
library, and in its data types. The syntax
is deliberately simple.

Sure, switches are slightly shorter than
if-elif-else for the cases where they fit.
But why have a special syntax for a subset
of the situations covered by if-elif-else?

Besides, with Python's completely consistent
indentation, it would not be so simple to
make switches look pretty. Look at how ugly
and inconsistently indentation is used for
switches in C programs.

It's like C's for-loop, which is a mutated form
of a clean iterations loop as they look in Pascal,
Fortran etc, to just a more compact, syntactic
variation of a while loop.

It doesn't really add any new feature, just a
short-form for a special case.

When I first saw it, I thought it was a very
cool feature, but then I've seen a mistakes
and confusion in using it, and Python's for
loop really adds something which the while
loop doesn't do in a simple way.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From thomi@thomi.imail.net.nz  Tue Oct 15 09:59:24 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Tue, 15 Oct 2002 21:59:24 +1300
Subject: [Tutor] Stopping A Program
In-Reply-To: <OF59D5C8F6.031B28DB-ON80256C53.002FF675@equant.com>
References: <OF59D5C8F6.031B28DB-ON80256C53.002FF675@equant.com>
Message-ID: <20021015215924.11c12bc1.thomi@thomi.imail.net.nz>

ummmmm CTRL+ALT+DELETE??

yeah, i know it's ugly, but then again, isn't windows?


On Tue, 15 Oct 2002 09:44:09 +0100 Thus said James.Rocks@equant.com:

> Hi Alan,
> 
> > raise SystemExit
> > or
> > import sys
> > sys.exit()
> > The latter gives the option of returning an error code to
> > the external environment:
> > sys.exit(2)
> > Note that these will all be caught by IDLE but when running
> > the program as a standalone script will exit back to the OS.
> > BTW This is covered in the very first hands-on topic in my
> > online tutor... :-)
> 
> I think you misunderstood (or my expression was bad) ... I mean when a
> long program is running how do you terminate it. In windows at least I
> cannot access the immediate window so how do I force a running program
> to stop if there is no code to stop it or it gets stuck in a loop that
> I hadn't intended?
> 
> James
> 
> James C. Rocks
> Equant
> Archway House
> Canary Wharf
> London E14 9SZ
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


-- 
Thomi Richards
thomi@imail.net.nz
http://thomi.imail.net.nz/
Thomi Richards,
thomi@imail.net.nz


From magnus@thinkware.se  Tue Oct 15 10:14:45 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue, 15 Oct 2002 11:14:45 +0200
Subject: [Tutor] Jython
In-Reply-To: <4454298235.20021012134254@csi.com>
References: <a05100338b9ce0171cec0@[192\.168\.1\.11]>
 <000e01c271f3$6d3d22f0$3212eb42@MYNEWBOX>
 <a05100338b9ce0171cec0@[192.168.1.11]>
Message-ID: <5.1.0.14.0.20021015111138.02b1b1f8@www.thinkware.se>

At 13:42 2002-10-12 -0400, Andrew wrote:
>I've looked over Jython and am beginning to wonder: How much python is
>really there (maybe a pared down os module), but it seems to me all
>the interesting things and modules that are in Python are "missing" in
>Jython.. e.g., I would have to use mostly Java (or so it seems) to
>create an SMTP client connection to somewhere...

It seems you didn't even try?

>which leaves me
>wondering where the efficiency is? Strikes me as easier to do it all
>in Java instead of wondering where I've gone wrong with a mixed
>language approach (just thinking, I haven't tried it yet). Any
>comments or insight?

Jython 2.1 on java1.4.0 (JIT: null)
Type "copyright", "credits" or "license" for more information.
 >>> import smtplib
 >>> s =3D smtplib.SMTP('mail.XXX.se')
 >>> s.close()
 >>> import poplib
 >>> s =3D poplib.POP3('mail.XXX.se')

Python modules seem to behave as usual.

If you'd rather code in Java, please do so.


>My second question is: Is Jython still being developed and supported?
>the last official release was nearly a year ago (12/01)?

It doesn't seem to be anyones top priority, but
if you check the sourceforge project, you'll
see a fairly high activity rating, and CVS
checkins last week at least.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Tue Oct 15 10:20:15 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue, 15 Oct 2002 11:20:15 +0200
Subject: [Tutor] Stopping A Program
In-Reply-To: <OFC0A82EF9.632F0430-ON80256C52.003E48F4@equant.com>
Message-ID: <5.1.0.14.0.20021015111849.02ae3080@www.thinkware.se>

At 12:21 2002-10-14 +0100, James.Rocks@equant.com wrote:
>Hi,
>
>Once a python program is running I don't seem to be able to stop it ... I
>have to shut down (forcefully) the IDE (IDLE or Pythonwin). Is there an
>easy way to stop a python program?

With PythonWin, right-click on the snake in the lower
right corner on your screen (next to the clock). Select
"Break into running code".


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Tue Oct 15 10:30:34 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue, 15 Oct 2002 11:30:34 +0200
Subject: [Tutor] RE module
In-Reply-To: <F81cHbb7i8st0LIKEKc0000feaf@hotmail.com>
Message-ID: <5.1.0.14.0.20021015112154.02b240e0@www.thinkware.se>

At 18:04 2002-10-12 +0000, Terje Johan Abrahamsen wrote:
>For example 'this is the text \\&*98and some=20
>more$53#start.exe*934more%4\\text.exe7['
>
>Is it possible to get out 'start.exe' and 'text.exe' out of this?

 >>> import re
 >>> t =3D 'this is the text \\&*98and some=20
more$53#start.exe*934more%4\\text.exe7['
 >>> re.findall(r'\w+\.exe',t)
['start.exe', 'text.exe']

This works with most exe file names that worked in DOS...
To find most old-fashioned DOS 8.3 filenames, do:

 >>> t =3D 'this is the text \\&*98and some=20
more$53#start.exe*934more%4\\text.exe7 t123.com['
 >>> re.findall(r'[\w]{1,8}\.\w\w\w',t)
['start.exe', 'text.exe', 't123.com']

But...

 >>> t =3D 'this is the text \\&*98and some more$53#a.com bcdef~1.exe'
 >>> re.findall(r'[\w]{1,8}\.\w\w\w',t)
['a.com', '1.exe']
 >>> re.findall(r'[\w~]{1,8}\.\w\w\w',t)
['a.com', 'bcdef~1.exe']

I'm not sure exactly what characters are allowed in Windows
filenames, but if your file is made so that the filenames
can be found manually in a consistent way, I'm pretty sure
you can find them with re.

As Alan said, Windows filenames can include spaces an other junk,
so it might be difficult to see what's patr of a filenamn, and what
is not, regardless of how you parse.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Tue Oct 15 10:39:47 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue, 15 Oct 2002 11:39:47 +0200
Subject: [Tutor] assigning types(?) to list elements
In-Reply-To: <B9D09245.58D58%franois.granger@free.fr>
References: <0210140608190B.01006@localhost.localdomain>
Message-ID: <5.1.0.14.0.20021015113233.02ae2e50@www.thinkware.se>

At 15:24 2002-10-14 +0200, Fran=E7ois Granger wrote:
>on 14/10/02 14:08, Joseph Paish at jpaish@freenet.edmonton.ab.ca wrote:
>
> > file_handle =3D open ('/path/to/datafile.txt', 'r')
> >
> > for each_line in file_handle.readlines() :
> >       each_line =3D each_line.rstrip() # strip off carriage return
> >       temp1, temp2, temp3, temp4, temp5, temp6 =3D=
 string.split(each_line)
> >       temp2  =3D float(temp2)
> >       temp3  =3D int(temp3)
> >       temp4  =3D int(temp4)
> >       temp5 =3D float(temp5)
> >       temp6 =3D float(temp6)
>
>This seems to do what you want:
>
>typeslist =3D [str,float,int,int,float,float]
>
>test =3D 'abc 123.45 74 98 234.56 345.67'
>temp =3D test.split()
># a sample record is : 'abc 123.45 74 98 234.56 345.67'
>result =3D []
>for i in range(len(temp)):
>     result.append(typeslist[i](temp[i]))

With a current python installation you can do
(untested):

typeslist =3D [str,float,int,int,float,float]
for each_line in file('/path/to/datafile.txt', 'r'):
     # Split will remove the trailing \n
     values =3D [Type(Value) for (Type, Value) in
               zip(typeslist, each_line.split())]
     ...whatever...


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Tue Oct 15 11:07:00 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue, 15 Oct 2002 12:07:00 +0200
Subject: [Tutor] while else, for else
In-Reply-To: <OF952FCB68.81E4E22E-ON85256C52.0048E794@dana.com>
Message-ID: <5.1.0.14.0.20021015114143.02ae23a8@www.thinkware.se>

At 09:30 2002-10-14 -0400, Blake.Garretson@dana.com wrote:
>I have been using Python for 3+ years now, and I have yet to see regular
>use of the "while else" or "for else" constructs.  I personally *never* use
>them, and unless I haven't read enough source code from other people, I
>haven't seen evidence that anybody else uses them very often either.

I use them now and then. It's a bit like
try...except in cases where you know that
you should break out of the loop if all
goes as expected:

Like this excerpt from a large program:

         for c in condIndex.findByMainName(name):
             if c.system =3D=3D system:
                 imp =3D c
                 break
         else:
             noObject =3D NothingObject(system)
             imp =3D Condition(name, 'C', noObject, system, '')

If I find a Condition 'c' with a given name belonging
to a given system, I use that. Otherwise, I make a new
Condition (with a dummy Object).

Without for...else I would have done:

         imp =3D None
         for c in condIndex.findByMainName(name):
             if c.system =3D=3D system:
                 imp =3D c
                 break
         if imp is None:
             noObject =3D NothingObject(system)
             imp =3D Condition(name, 'C', noObject, system, '')

Just one more line of code, but once you get used
to the concept of for/while...else, the first version
is much easier to read. It reads more like prose, with
a better flow and less surprise. Why should I do 'imp=3DNone'
if I never really wan't imp to be None? Besides, I assume
this will be more bytecode. The if-test has to be made.
for/while...else might provide some performance improvement.

A little further down:

         row =3D 0
         for f in self.getCatalog(Function):
             if f =3D=3D function and self.getProcessMatrixRow(f, row):
                 # We found a row to copy
                 break
             row +=3D 1
         else:
             return
         procRow =3D self.getProcessMatrix()[row]
         for col in range(len(procRow)):
             code =3D procRow[col][0]
             self.changeProcessMatrix(row, col, code)

Since the function ended here, it might as well have been:

         row =3D 0
         for f in self.getCatalog(Function):
             if f =3D=3D function and self.getProcessMatrixRow(f, row):
                 # We found a row to copy
                 procRow =3D self.getProcessMatrix()[row]
                 for col in range(len(procRow)):
                     code =3D procRow[col][0]
                     self.changeProcessMatrix(row, col, code)
                     return
             row +=3D 1

Perhaps the second is better? It's just a matter
of style. I found it simpler when I wrote it to see
it as a two step process: First find the row, and
then process it. The first version emphasizes this
separation, and also leads to less indentation. Not
a huge win in this case, but I guess I just wrote it
like I did because I thought of it like two separate
steps. Also, the second versions seems to suggest
that there is a nested loop here, and that's not
really the case, since the inner loop will only run
once.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Tue Oct 15 11:17:54 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue, 15 Oct 2002 12:17:54 +0200
Subject: [Tutor] recommendation sought
In-Reply-To: <1034622828.21703.7.camel@localhost.localdomain>
Message-ID: <5.1.0.14.0.20021015120953.02b1c670@www.thinkware.se>

At 15:13 2002-10-14 -0400, reavey wrote:
>the best all around python book.  I'm particularly
>
>interested in using python as a pic module programmer.

This is very difficult to say.

First, different people like different styles of books,
and depending on what they know before, different levels
of content might be relevant.

I haven't seen any books talking about really technical
subjects like what you look for here, but I suppose the
pic module is on a serial port? What platform do you use?
I think there is some non-standard python module for
working with serial ports in Windows and Linux, but I
doubt that any book covers that.

Obviously we don't know what you intend for your pic
module programmer.
On one end you might intend to write your pic machine
code in notepad and write code that reads text, convert
it to numbers an dump it on the pic module.
On the other end you might have intended a full featured
pic IDE, with a pretty GUI etc. It's not the same book
you are looking for... :)

Have a look at the book reviews:
http://www.python.org/cgi-bin/moinmoin/PythonBooks


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From thomi@thomi.imail.net.nz  Tue Oct 15 12:21:16 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Wed, 16 Oct 2002 00:21:16 +1300
Subject: [Tutor] help with PIL
Message-ID: <20021016002116.56511b21.thomi@thomi.imail.net.nz>

ok, question:

could someone please show me a small script to open a file called
map.bmp (which is a color bitmap file), and do the following things:

-> work out what the RGB value is for any given pixel in the file
-> work out how many pixels high and wide the file is
-> change the RGB values for any one given pixel..


thanks in advance. i fond that learning by practical example is soooo
much easier than wading through manuals which talk about things which
you don't want to know :-)

-- 
The software required Win95 or better, so I installed Linux.
Thomi Richards,
thomi@imail.net.nz


From James.Rocks@equant.com  Tue Oct 15 12:34:03 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Tue, 15 Oct 2002 12:34:03 +0100
Subject: [Tutor] Anyone recommend an IDE?
Message-ID: <OF61D3D22C.F7F683CD-ON80256C53.003F4C6E@equant.com>

Hi,

On Windows I use Pythonwin ... can anyone recommend an IDE I can use for
Python development on Linux (which I am trying to switch over to)? Cost
being a critical issue (and me not being that much of a programmer ... I
just tinker mainly) I would rather it was a freebie :-)

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From alan.gauld@bt.com  Tue Oct 15 12:18:04 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 15 Oct 2002 12:18:04 +0100
Subject: [Tutor] Binding the mouse to a list using Tk.
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C98A@mbtlipnt02.btlabs.bt.co.uk>

> I'm using Tkinter. I Created a class (ScrolledList) for 
> a scrolled list which works fine. 

So you get the message printed when you click on an item?
If so then it might be a good idea to have a state variable 
to store the current selection?

another class (aaaaa) which populates the list - and it works fine. 

the bind (makeWidgets). Right now, all I'm trying to do is just print out
the value (just testing..) - but my logic is incorrect 

So the print isn't working? I'm not sure what exactly is happening 
here.

class ScrolledList(Frame):
    def handleList(self, event):
        index = self.listbox.curselection()
        label = self.listbox.get(index)
        print "label is ", label
    def makeWidgets(self, options):
        ........
        list.bind('<Button-1>', self.handleList) 

You dont show the listbox being created,but I assume its 
a standard Tk Listbox control? And that you pass the same 
parent as the Scrolled Listbox? (BTW Its conventional 
to have the parent parameter as the first one after self....)

Class aaaaa
    def update_strategy_code(self):
        ..........
        ScrolledList(options)
        Button(self, text='Update',
        command=self.edit_strategy_code).pack(side=LEFT)

This confuses me too. You are creating a Button with parent 
of self yet the aaaaa class has no parent parameter(thats shown...)
Also you are creating the ScrolledList class with a parent of 
None - this is likely to lead to some very strange behaviour!


    def edit_strategy_code(self):
        label=self.listbox.get(ACTIVE)

Which listbox is this? Its not the one in your ScrolledList, 
thats for sure. It was just a local object in update_strategy...
Or maybe its now an orphaned control parented on None?

I really don't see how this is supposed to work?
Which is the parent form - I assume aaaaa? If so create the 
sub controls(ScrolledList) as children of self and assign 
them to instance variables for easy access. Its a much 
more conbventional and maintainable way of working. This 
seems to rely on a tad too much magic for my liking!

OTOH I'm maybe just confused and missing something obvious.

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


From emile@fenx.com  Tue Oct 15 14:25:35 2002
From: emile@fenx.com (Emile van Sebille)
Date: Tue, 15 Oct 2002 06:25:35 -0700
Subject: [Tutor] Re: help with PIL
References: <20021016002116.56511b21.thomi@thomi.imail.net.nz>
Message-ID: <aoh4se$c9o$1@main.gmane.org>

Thomi Richards:
> could someone please show me a small script to open a file called
> map.bmp (which is a color bitmap file), and do the following things:
>
> -> work out what the RGB value is for any given pixel in the file
> -> work out how many pixels high and wide the file is
> -> change the RGB values for any one given pixel..
>
>
> thanks in advance. i fond that learning by practical example is soooo
> much easier than wading through manuals which talk about things which
> you don't want to know :-)
>

You really should take a look at PIL's tutorial.  IIRC, it teaches by
example and answers these questions.

--

Emile van Sebille
emile@fenx.com

---------





From magnus@thinkware.se  Tue Oct 15 14:45:51 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue, 15 Oct 2002 15:45:51 +0200
Subject: [Tutor] Anyone recommend an IDE?
In-Reply-To: <OF61D3D22C.F7F683CD-ON80256C53.003F4C6E@equant.com>
Message-ID: <5.1.0.14.0.20021015154118.02b336d8@www.thinkware.se>

At 12:34 2002-10-15 +0100, James.Rocks@equant.com wrote:
>Hi,
>
>On Windows I use Pythonwin ... can anyone recommend an IDE I can use for
>Python development on Linux (which I am trying to switch over to)? Cost
>being a critical issue (and me not being that much of a programmer ... I
>just tinker mainly) I would rather it was a freebie :-)

IDLE Fork, http://idlefork.sourceforge.net/ , is starting to
become useful, and as far as I know, it works equally well
under Windows and Linux.

The linux way would be to use emacs or vi. Both have Python
support of different kind. See
http://www.python.org/cgi-bin/moinmoin/DevelopmentTools


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From kojo@hal-pc.org  Tue Oct 15 14:42:22 2002
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Tue, 15 Oct 2002 08:42:22 -0500
Subject: [Tutor] Anyone recommend an IDE?
In-Reply-To: <OF61D3D22C.F7F683CD-ON80256C53.003F4C6E@equant.com>
Message-ID: <web-23255754@mail.hal-pc.org>

Sorry, didn't reply to the list.

My suggestion was IDLE, the IDE that comes with Python. 
 It runs anywhere Python does and it's free when you buy 
Python...
:-)

On Tue, 15 Oct 2002 12:34:03 +0100
  James.Rocks@equant.com wrote:
]Hi,
]
]On Windows I use Pythonwin ... can anyone recommend an 
]IDE I can use for
]Python development on Linux (which I am trying to switch 
]over to)? Cost
]being a critical issue (and me not being that much of a 
]programmer ... I
]just tinker mainly) I would rather it was a freebie :-)
]
]James
]
]James C. Rocks
]Equant
]Archway House
]Canary Wharf
]London E14 9SZ
]
]
]_______________________________________________
]Tutor maillist  -  Tutor@python.org
]http://mail.python.org/mailman/listinfo/tutor

****************************
Kojo Idrissa
kojo@hal-pc.org

http://www.hal-pc.org/~kojo
****************************


From alan.gauld@bt.com  Tue Oct 15 14:57:14 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 15 Oct 2002 14:57:14 +0100
Subject: [Tutor] Stopping A Program
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C98D@mbtlipnt02.btlabs.bt.co.uk>

> > raise SystemExit
> > or
> > import sys
> > sys.exit()

> I think you misunderstood (or my expression was bad) ... I 
> mean when a long program is running how do you terminate it. 

Uh, OK I misunderstood.

CTRL-C should work....unless you've caught the exception 
somewhere. Personally I wouldn't run any long term process 
from IDLE I'd crank upm a DOS box for that...

Alan G.


From alan.gauld@bt.com  Tue Oct 15 15:05:26 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 15 Oct 2002 15:05:26 +0100
Subject: [Tutor] Anyone recommend an IDE?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C98E@mbtlipnt02.btlabs.bt.co.uk>

> On Windows I use Pythonwin ... can anyone recommend an IDE I 
> can use for Python development on Linux 

IDLE?

Thats why its part of the distro, it works on most platforms...

There are others but none that offer anything significantly 
better than IDLE IMHO unless you want to pay for them.

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


From ATrautman@perryjudds.com  Tue Oct 15 15:38:08 2002
From: ATrautman@perryjudds.com (Alan Trautman)
Date: Tue, 15 Oct 2002 09:38:08 -0500
Subject: [Tutor] Anyone recommend an IDE?
Message-ID: <0BA95581EDA7D611841B00A0C9AD25DD2B58AA@mail.pjinet.com>

I really like the official IDLE fork from source forge. It seems to handle
exits and errors more gracefully and open its own interactive window to run
the processes/programs/scripts than the standard IDLE.

Alan

-----Original Message-----
From: James.Rocks@equant.com [mailto:James.Rocks@equant.com]
Sent: Tuesday, October 15, 2002 6:34 AM
To: tutor@python.org
Subject: [Tutor] Anyone recommend an IDE?


Hi,

On Windows I use Pythonwin ... can anyone recommend an IDE I can use for
Python development on Linux (which I am trying to switch over to)? Cost
being a critical issue (and me not being that much of a programmer ... I
just tinker mainly) I would rather it was a freebie :-)

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


From James.Rocks@equant.com  Tue Oct 15 14:42:58 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Tue, 15 Oct 2002 14:42:58 +0100
Subject: [Tutor] Anyone recommend an IDE?
Message-ID: <OFD8B3BF78.F7E9510F-ON80256C53.004AF89E@equant.com>

> IDLE?
> Thats why its part of the distro, it works on most platforms...
> There are others but none that offer anything significantly
> better than IDLE IMHO unless you want to pay for them.

Agreed it works but it's so ... ugly ... and boring and ... well ... yuk! I
mean hey I actually like things that look nice ...

It's a shame boa-constructor doesn't work ... that's free, works on *nix &
win and looks real cool! Have to wait for release 0.1.1!

Ah well ... thanks for your views guys!

J.

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From lbergman@abi.tconline.net  Tue Oct 15 16:11:33 2002
From: lbergman@abi.tconline.net (Lewis Bergman)
Date: Tue, 15 Oct 2002 10:11:33 -0500
Subject: [Tutor] os.rename type error
Message-ID: <200210150920.50002.lbergman@[nospam]abi.tconline.net>

I know this should be readily apparent due to the fact that python tells me 
what is wrong. I just can't seem to figure out why.

Here is the offending bit of code minus the irrelevant parts:
---------------------------------------------------
conf = "/root/domains.to.scan.conf"
back = "/root/domains.to.scan.conf.old"

import string, getopt, sys, os

def main(conf = conf, back = back, domains = domains):

	def read(conf = conf, back = back):
		"""Read the conf file in, make a backup, blank the original."""
		print conf, back
		conf = open(conf, 'r')
		temp = conf.readlines()
		conf.close()
		os.rename(conf, back)
		conf = open(conf, 'w')
		return conf, temp
-----------------------------------------------------------
When I call the function I get this:

Traceback (most recent call last):
  File "./dom2scan.py", line 86, in ?
    main()
  File "./dom2scan.py", line 56, in main
    add(string.lower(args[i]))
  File "./dom2scan.py", line 34, in add
    conf, temp = read()
  File "./dom2scan.py", line 24, in read
    os.rename(conf, back)
TypeError: coercing to Unicode: need string or buffer, file found

You can see that I am using strings in both the source and destination 
arguemnents for os.rename. Does this mean I have to convert them to Unicode 
first? I guess that would be part of the string module. The reference library 
didn't say anything about that. The source and destination files are on the 
same filesystem on a linux box. The destination does not exist and I am root 
anyway.

Any clues would be appreciated.
-- 
Lewis Bergman
Texas Communications
4309 Maple St.
Abilene, TX 79602-8044
915-695-6962 ext 115



From mongo57a@comcast.net  Tue Oct 15 18:08:03 2002
From: mongo57a@comcast.net (andy surany)
Date: Tue, 15 Oct 2002 13:08:03 -0400
Subject: [Tutor] Binding the mouse to a list using Tk.
Message-ID: <003901c2746d$6c3ba260$2502a8c0@emily.ewndsr01.nj.comcast.net>

Ok, this got me a lot closer! But I'm still slightly off. Thanks for the
example Dylan. I stayed with Tk instead of Pmw based on the amount of code
already developed - and because the functions tended to work the same way.
But I used the "example" logic.

So now I am using:

    label = list(self.listbox.curselection())

and it looks pretty good! Except: label is the previous selection - not the
current. I am always behind by 1 (previous selection is item 2 from the
list, current is item 4, label="2").

Here are the 2 methods. As I indicated, "label" is always one behind the
current position; however, label1 is correct.

   def handleList(self, event):
        label=list(self.listbox.curselection())
        print "label is ", label

    def makeWidgets(self, options):
        sbar = Scrollbar(self)
        list = Listbox(self, relief=SUNKEN, selectmode=EXTENDED)
        sbar.config(command=list.yview)                   # xlink sbar and
list
        list.config(yscrollcommand=sbar.set)              # move one moves
other
        sbar.pack(side=RIGHT, fill=Y)                     # pack first=clip
last
        list.pack(side=LEFT, expand=YES, fill=BOTH)       # list clipped
first
        pos = 0

        for label in options:
          list.insert(pos, label)
          pos = pos+1

        list.bind('<Button-1>', self.handleList)          # set event
handler
        self.listbox = list
        label1=self.listbox.get(ACTIVE)
        print 'info=',label1


-----Original Message-----
From: BELSEY, Dylan <dylan.belsey@baesystems.com>
To: 'andy surany' <mongo57a@comcast.net>; tutor@python.org
<tutor@python.org>
Date: Tuesday, October 15, 2002 12:47 AM
Subject: RE: [Tutor] Binding the mouse to a list using Tk.


>Hi Andy,
> In the interest of code sharing, I have attached a file which I
>believe contains some of the operations that you are looking to perform.
It
>is a cut down version of a class I wrote for the current system I am
working
>on.  In its original form it obtains signals from a data server and
displays
>them ready for selection.  The user then selects signals from the left-hand
>box, presses the appropriate button ('->') and the signal appears in the
>selected signals box, on the right hand side.  This window was to aid the
>user in selecting specific signals for monitoring.  I have kept the
relevant
>functionality in the file.
> I am currently running this under WinNT.  I have also made the file
>self running, so all you have to do is get a DOS prompt in the directory
>where you have saved it and then type "example.py" or "python example.py".
> Two windows will appear.  Just ignore the first one (but don't close
>it until you are finished), for this exercise.  It is the root window,
which
>is important/necessary, but I have chosen not to use it here.
> So anyway, run it and experiment with it and then take a look at the
>code, from which I hope you can get some ideas and help.
> If you have any questions, please feel free to ask.
>
> HTH,
> Dylan
>
>
>PS: By the ways Tutors, if you see any glaring deficiencies, problems, etc.
>in the code pls. feel free to comment.  However, I'm not too interested in
a
>code review at this point in time :)
>
>
>
>
>-----Original Message-----
>From: andy surany [mailto:mongo57a@comcast.net]
>Sent: Tuesday, 15 October 2002 13:50
>To: BELSEY, Dylan; tutor@python.org
>Subject: Re: [Tutor] Binding the mouse to a list using Tk.
>
>
>Thanks Dylan. I am using the listbox methods. And everything works. If I
put
>the list.bind in the same method that calls the scrolled list, I even get a
>response when I move the cursor to list selection
(listbox.cursorselection).
>The problem is that I need the selected list item to be independent of the
>mouse (mouse is depressing a button which gets the original highlighted
list
>item). It's almost like I'm losing context.
>
>I haven't looked at getcurselection - which I will do now. I still think
>that my logic is correct - but I haven't placed it in the correct spot.
>
>Regards,
>
>Andy
>-----Original Message-----
>From: BELSEY, Dylan <dylan.belsey@baesystems.com>
>To: tutor@python.org <tutor@python.org>
>Date: Monday, October 14, 2002 6:59 PM
>Subject: RE: [Tutor] Binding the mouse to a list using Tk.
>
>
>>    Only had a brief look at your problem, but I believe that the Tkinter
>>widgets Listbox and ScrolledListBox may be what you need (and save you
>quite
>>a bit of time).  You can use the Listbox methods from within the
>>ScrolledListbox object as well.  You could then possibly associate a
>>function with your button which gets the currently selected item.
>>getcurselection() returns the text while the curselection() will return
the
>>index.
>>    A lot of this is quite similar to what your code has proposed but
using
>>the built-in widgets and their functions may shed some light on an easier
>>solution.
>>
>>    HTH,
>>        Dylan
>>
>>
>>-----Original Message-----
>>From: andy surany [mailto:mongo57a@comcast.net]
>>Sent: Tuesday, 15 October 2002 04:20
>>To: tutor@python.org
>>Subject: [Tutor] Binding the mouse to a list using Tk.
>>
>>
>>Hi all!
>>
>>What I want to do is use a button to capture the position/value of the
>>
>>selected item in a scrolled list. So the user selects the item in the list
>>
>>with a single click of the left mouse button and then clicks a button.
>>
>>Should be easy - I'm just not getting it......
>>
>>
>>
>>I'm using Tkinter. I Created a class (ScrolledList) for a scrolled list
>>which works fine. Created
>>
>>another class (aaaaa) which populates the list - and it works fine.
Created
>>
>>a handler under ScrolledList (handleList) which should trap the results of
>>
>>the bind (makeWidgets). Right now, all I'm trying to do is just print out
>>
>>the value (just testing..) - but my logic is incorrect (actually, I think
>>
>>that the logic may be correct - it's just in the wrong place...).
>>
>>Here is a synopsis of the code. The "...." is non-relevant code which I
>have
>>removed for simplification.
>>
>>
>>
>>class ScrolledList(Frame):
>>
>>    def __init__(self, options, parent=None):
>>
>>        ........
>>
>>        self.makeWidgets(options)
>>
>>    def handleList(self, event):
>>
>>        index = self.listbox.curselection()
>>
>>        label = self.listbox.get(index)
>>
>>        print "label is ", label
>>
>>    def makeWidgets(self, options):
>>
>>        ........
>>
>>        list.bind('<Button-1>', self.handleList)
>>
>>Class aaaaa
>>
>>    def update_strategy_code(self):
>>
>>        ..........
>>
>>        ScrolledList(options)
>>
>>        Button(self, text='Update',
>>
>>        command=self.edit_strategy_code).pack(side=LEFT)
>>
>>    def edit_strategy_code(self):
>>
>>        label=self.listbox.get(ACTIVE)
>>
>>        print 'info2=',label
>>
>> TIA!
>>
>>Andy (mongo57a@comcast.net)
>>
>>
>>_______________________________________________
>>Tutor maillist  -  Tutor@python.org
>>http://mail.python.org/mailman/listinfo/tutor
>
>



From jeff@ccvcorp.com  Tue Oct 15 17:43:18 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Tue, 15 Oct 2002 09:43:18 -0700
Subject: [Tutor] os.rename type error
References: <200210150920.50002.lbergman@[nospam]abi.tconline.net>
Message-ID: <3DAC45A6.5DBF246F@ccvcorp.com>


Lewis Bergman wrote:

> I know this should be readily apparent due to the fact that python tells me
> what is wrong. I just can't seem to figure out why.
> [....]
>         def read(conf = conf, back = back):
>                 """Read the conf file in, make a backup, blank the original."""
>                 print conf, back
>                 conf = open(conf, 'r')

Here's your problem.  You have a string conf, which you use to open the file... and
then store the open file in conf as well.  When you later give conf to os.rename(),
you're passing it the open file, not the string containing the filename.  Use a
different name for you open file variable, and all should be well.

Jeff Shannon
Technician/Programmer
Credit International







From magnus@thinkware.se  Tue Oct 15 18:45:14 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue, 15 Oct 2002 19:45:14 +0200
Subject: [Tutor] Anyone recommend an IDE?
In-Reply-To: <OFD8B3BF78.F7E9510F-ON80256C53.004AF89E@equant.com>
Message-ID: <5.1.0.14.0.20021015193707.02ad7290@www.thinkware.se>

At 14:42 2002-10-15 +0100, James.Rocks@equant.com wrote:
>Agreed it works but it's so ... ugly ... and boring and ... well ... yuk! I
>mean hey I actually like things that look nice ...
>
>It's a shame boa-constructor doesn't work ... that's free, works on *nix &
>win and looks real cool! Have to wait for release 0.1.1!

Well, if ugly or working is the choise... :)

Did you check
http://www.python.org/cgi-bin/moinmoin/DevelopmentTools ?
There are 2 relevant links from that page.

There are more than 20 editors for unix mentioned. Many
people swear by SciTE. WingIDE is also popular. It's free
for open source development, and the lite version costs
$35.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From aicolburn@yahoo.com  Tue Oct 15 21:32:49 2002
From: aicolburn@yahoo.com (Alan Colburn)
Date: Tue, 15 Oct 2002 13:32:49 -0700
Subject: [Tutor] methods within a class
Message-ID: <001701c2748a$07698560$cae68b86@fo5132>

Hi all--

Can you help me distinguish between these two simple programs? They differ
only in terms of statements I highlighted via commenting.  [If indentation
doesn't look right on your screen, just ignore...]

This one works fine:

****************************************************************************
*****
from Tkinter import *
root=Tk()

class Program(Frame):
 def __init__(self):
  Frame.__init__(self)
  self.pack()
  self.entry1=Entry(self)
  self.entry1.bind('<Key-Return>', self.gettext)
  self.entry1.pack(side=TOP, fill=X)
#   self.printText()

 def gettext(self, event):
  global text
  text=self.entry1.get()
  self.printText()

 def printText(self):
  print "The value of the variable text is: ", text

if __name__=="__main__":
 app=Program()
 app.mainloop()
****************************************************************************
*****

On the other hand, this one does not:

****************************************************************************
*****
from Tkinter import *
root=Tk()

class Program(Frame):
 def __init__(self):
  Frame.__init__(self)
  self.pack()
  self.entry1=Entry(self)
  self.entry1.bind('<Key-Return>', self.gettext)
  self.entry1.pack(side=TOP, fill=X)
  self.printText()

 def gettext(self, event):
  global text
  text=self.entry1.get()
 #  self.printText()

 def printText(self):
  print "The value of the variable text is: ", text

if __name__=="__main__":
 app=Program()
 app.mainloop()

I know the answer will be relatively simple; I just need a little lesson on
methods and classes I guess.

Thanks, as always, for your help. -- Alan C.

p.s. Scot (in Berlin) -- you may recognize parts of this small program from
a response you were kind enough to send me last summer :-)



From magnus@thinkware.se  Tue Oct 15 22:27:47 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue, 15 Oct 2002 23:27:47 +0200
Subject: [Tutor] methods within a class
In-Reply-To: <001701c2748a$07698560$cae68b86@fo5132>
Message-ID: <5.1.0.14.0.20021015231436.02afeb70@www.thinkware.se>

At 13:32 2002-10-15 -0700, Alan Colburn wrote:
>Hi all--
>
>Can you help me distinguish between these two simple programs? They differ
>only in terms of statements I highlighted via commenting.  [If indentation
>doesn't look right on your screen, just ignore...]

The Program.__init__ method will be called when you
do "app = Program()".

At this time the global variable "text" doesn't exist,
since you haven't called the gettext method get. You
*bind* gettext to an event here, but you don't call it
until the even loop handles such an event, and that's
certainly not in the middle of your __init__. Thus the
second version will fail when __init__ calls printText().

In the first version, you only call printText() after you
define global text in gettext(), so there you are safe.

An advice: Don't use globals. Certainly not in a case like
this. Either pass the text as a parameter, or make it a
member of your class. I can't imagine what you intended
in version 2, where you print the result of an event (gettext)
before you have had any possibility whatsoever to catch the
event. But if you wan't your code to be more robust, you could
do an initialization in Program.__init__ such as "self.text=''".

>This one works fine:
>
>****************************************************************************
>*****
>from Tkinter import *
>root=Tk()
>
>class Program(Frame):
>  def __init__(self):
>   Frame.__init__(self)
>   self.pack()
>   self.entry1=Entry(self)
>   self.entry1.bind('<Key-Return>', self.gettext)
>   self.entry1.pack(side=TOP, fill=X)
>#   self.printText()
>
>  def gettext(self, event):
>   global text
>   text=self.entry1.get()
>   self.printText()
>
>  def printText(self):
>   print "The value of the variable text is: ", text
>
>if __name__=="__main__":
>  app=Program()
>  app.mainloop()
>****************************************************************************
>*****
>
>On the other hand, this one does not:
>
>****************************************************************************
>*****
>from Tkinter import *
>root=Tk()
>
>class Program(Frame):
>  def __init__(self):
>   Frame.__init__(self)
>   self.pack()
>   self.entry1=Entry(self)
>   self.entry1.bind('<Key-Return>', self.gettext)
>   self.entry1.pack(side=TOP, fill=X)
>   self.printText()
>
>  def gettext(self, event):
>   global text
>   text=self.entry1.get()
>  #  self.printText()
>
>  def printText(self):
>   print "The value of the variable text is: ", text
>
>if __name__=="__main__":
>  app=Program()
>  app.mainloop()
>
>I know the answer will be relatively simple; I just need a little lesson on
>methods and classes I guess.
>
>Thanks, as always, for your help. -- Alan C.
>
>p.s. Scot (in Berlin) -- you may recognize parts of this small program from
>a response you were kind enough to send me last summer :-)
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

-- 
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 Abenz419@aol.com  Tue Oct 15 21:22:00 2002
From: Abenz419@aol.com (Abenz419@aol.com)
Date: Tue, 15 Oct 2002 16:22:00 EDT
Subject: [Tutor] looking for an interpreter
Message-ID: <16.27350833.2addd2e8@aol.com>

<PRE>i need an intrerpreter and i dont knwo where to find one.  i'm trying to 
learn python and i downloaded python2.2.2.  so if you could give me a little 
more info about it and about findind an interpreter it would be appreciated. 
thanks.


From magnus@thinkware.se  Tue Oct 15 23:53:33 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed, 16 Oct 2002 00:53:33 +0200
Subject: [Tutor] looking for an interpreter
In-Reply-To: <16.27350833.2addd2e8@aol.com>
Message-ID: <5.1.0.14.0.20021016004739.00b11de8@www.thinkware.se>

At 16:22 2002-10-15 -0400, Abenz419@aol.com wrote:
>i need an intrerpreter and i dont knwo where to find one.  i'm trying to
>learn python and i downloaded python2.2.2.  so if you could give me a=
 little
>more info about it and about findind an interpreter it would be=
 appreciated.
>thanks.

The Python interpreter is certainly included in python...

What OS are we talking about? If you are running windows,
it's called python.exe, and you can either run it
interactively, or you can execute python-scripts with
it. Typically that happens if you double-click on a file
with endings .py, .pyw, pyc or .pyo.

In Unix/Linux, type python at the prompt, or run a script
which uses the normal #! trick.

These are the platform I work with.

You can also use GUI wrappers for the interpreter, such
as IDLE, which is probably also included in what you got.
(idle.py or idle.pyw in Windows.)


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From thomi@thomi.imail.net.nz  Tue Oct 15 23:46:26 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Wed, 16 Oct 2002 11:46:26 +1300
Subject: [Tutor] Re: help with PIL
In-Reply-To: <aoh4se$c9o$1@main.gmane.org>
References: <20021016002116.56511b21.thomi@thomi.imail.net.nz>
 <aoh4se$c9o$1@main.gmane.org>
Message-ID: <20021016114626.02861703.thomi@thomi.imail.net.nz>

ahhhh.. ok, thanks, i was looking at the manual thingy.....

thanks.. I'll have a look

On Tue, 15 Oct 2002 06:25:35 -0700 Thus said "Emile van Sebille"
<emile@fenx.com>:

> Thomi Richards:
> > could someone please show me a small script to open a file called
> > map.bmp (which is a color bitmap file), and do the following things:
> >
> > -> work out what the RGB value is for any given pixel in the file
> > -> work out how many pixels high and wide the file is
> > -> change the RGB values for any one given pixel..
> >
> >
> > thanks in advance. i fond that learning by practical example is
> > soooo much easier than wading through manuals which talk about
> > things which you don't want to know :-)
> >
> 
> You really should take a look at PIL's tutorial.  IIRC, it teaches by
> example and answers these questions.
> 
> --
> 
> Emile van Sebille
> emile@fenx.com
> 
> ---------
> 
> 
> 
> 
> _______________________________________________
> 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 dylan.belsey@baesystems.com  Tue Oct 15 23:55:26 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Wed, 16 Oct 2002 08:25:26 +0930
Subject: [Tutor] Binding the mouse to a list using Tk.
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B98D2AE1@wtntex1.baea.com.au>

Andy,
	I may just be me but I am still a little confused as to how this
code is supposed to work.  Perhaps if you post the whole code (if not too
large) then the list might be of more assistance. I would make the
recommendation of not using variable names that are the same as built-in
functions e.g. "list" in the makeWidgets() function.
	If "self.listbox.get(ACTIVE)" works for you, why not use it in the
handleList() function as well?  Also, it would appear that you are binding
the whole Listbox to the mouse button 1 press ie. if you click anywhere in
the listbox (even on the border), then won't this kick off your handleList
function...is this what you require?
	Just some thoughts.

		Dylan


-----Original Message-----
From: andy surany [mailto:mongo57a@comcast.net]
Sent: Wednesday, 16 October 2002 03:08
To: BELSEY, Dylan; tutor@python.org
Subject: Re: [Tutor] Binding the mouse to a list using Tk.


Ok, this got me a lot closer! But I'm still slightly off. Thanks for the
example Dylan. I stayed with Tk instead of Pmw based on the amount of code
already developed - and because the functions tended to work the same way.
But I used the "example" logic.

So now I am using:

    label = list(self.listbox.curselection())

and it looks pretty good! Except: label is the previous selection - not the
current. I am always behind by 1 (previous selection is item 2 from the
list, current is item 4, label="2").

Here are the 2 methods. As I indicated, "label" is always one behind the
current position; however, label1 is correct.

   def handleList(self, event):
        label=list(self.listbox.curselection())
        print "label is ", label

    def makeWidgets(self, options):
        sbar = Scrollbar(self)
        list = Listbox(self, relief=SUNKEN, selectmode=EXTENDED)
        sbar.config(command=list.yview)                   # xlink sbar and
list
        list.config(yscrollcommand=sbar.set)              # move one moves
other
        sbar.pack(side=RIGHT, fill=Y)                     # pack first=clip
last
        list.pack(side=LEFT, expand=YES, fill=BOTH)       # list clipped
first
        pos = 0

        for label in options:
          list.insert(pos, label)
          pos = pos+1

        list.bind('<Button-1>', self.handleList)          # set event
handler
        self.listbox = list
        label1=self.listbox.get(ACTIVE)
        print 'info=',label1


-----Original Message-----
From: BELSEY, Dylan <dylan.belsey@baesystems.com>
To: 'andy surany' <mongo57a@comcast.net>; tutor@python.org
<tutor@python.org>
Date: Tuesday, October 15, 2002 12:47 AM
Subject: RE: [Tutor] Binding the mouse to a list using Tk.


>Hi Andy,
> In the interest of code sharing, I have attached a file which I
>believe contains some of the operations that you are looking to perform.
It
>is a cut down version of a class I wrote for the current system I am
working
>on.  In its original form it obtains signals from a data server and
displays
>them ready for selection.  The user then selects signals from the left-hand
>box, presses the appropriate button ('->') and the signal appears in the
>selected signals box, on the right hand side.  This window was to aid the
>user in selecting specific signals for monitoring.  I have kept the
relevant
>functionality in the file.
> I am currently running this under WinNT.  I have also made the file
>self running, so all you have to do is get a DOS prompt in the directory
>where you have saved it and then type "example.py" or "python example.py".
> Two windows will appear.  Just ignore the first one (but don't close
>it until you are finished), for this exercise.  It is the root window,
which
>is important/necessary, but I have chosen not to use it here.
> So anyway, run it and experiment with it and then take a look at the
>code, from which I hope you can get some ideas and help.
> If you have any questions, please feel free to ask.
>
> HTH,
> Dylan
>
>
>PS: By the ways Tutors, if you see any glaring deficiencies, problems, etc.
>in the code pls. feel free to comment.  However, I'm not too interested in
a
>code review at this point in time :)
>
>
>
>
>-----Original Message-----
>From: andy surany [mailto:mongo57a@comcast.net]
>Sent: Tuesday, 15 October 2002 13:50
>To: BELSEY, Dylan; tutor@python.org
>Subject: Re: [Tutor] Binding the mouse to a list using Tk.
>
>
>Thanks Dylan. I am using the listbox methods. And everything works. If I
put
>the list.bind in the same method that calls the scrolled list, I even get a
>response when I move the cursor to list selection
(listbox.cursorselection).
>The problem is that I need the selected list item to be independent of the
>mouse (mouse is depressing a button which gets the original highlighted
list
>item). It's almost like I'm losing context.
>
>I haven't looked at getcurselection - which I will do now. I still think
>that my logic is correct - but I haven't placed it in the correct spot.
>
>Regards,
>
>Andy
>-----Original Message-----
>From: BELSEY, Dylan <dylan.belsey@baesystems.com>
>To: tutor@python.org <tutor@python.org>
>Date: Monday, October 14, 2002 6:59 PM
>Subject: RE: [Tutor] Binding the mouse to a list using Tk.
>
>
>>    Only had a brief look at your problem, but I believe that the Tkinter
>>widgets Listbox and ScrolledListBox may be what you need (and save you
>quite
>>a bit of time).  You can use the Listbox methods from within the
>>ScrolledListbox object as well.  You could then possibly associate a
>>function with your button which gets the currently selected item.
>>getcurselection() returns the text while the curselection() will return
the
>>index.
>>    A lot of this is quite similar to what your code has proposed but
using
>>the built-in widgets and their functions may shed some light on an easier
>>solution.
>>
>>    HTH,
>>        Dylan
>>
>>
>>-----Original Message-----
>>From: andy surany [mailto:mongo57a@comcast.net]
>>Sent: Tuesday, 15 October 2002 04:20
>>To: tutor@python.org
>>Subject: [Tutor] Binding the mouse to a list using Tk.
>>
>>
>>Hi all!
>>
>>What I want to do is use a button to capture the position/value of the
>>
>>selected item in a scrolled list. So the user selects the item in the list
>>
>>with a single click of the left mouse button and then clicks a button.
>>
>>Should be easy - I'm just not getting it......
>>
>>
>>
>>I'm using Tkinter. I Created a class (ScrolledList) for a scrolled list
>>which works fine. Created
>>
>>another class (aaaaa) which populates the list - and it works fine.
Created
>>
>>a handler under ScrolledList (handleList) which should trap the results of
>>
>>the bind (makeWidgets). Right now, all I'm trying to do is just print out
>>
>>the value (just testing..) - but my logic is incorrect (actually, I think
>>
>>that the logic may be correct - it's just in the wrong place...).
>>
>>Here is a synopsis of the code. The "...." is non-relevant code which I
>have
>>removed for simplification.
>>
>>
>>
>>class ScrolledList(Frame):
>>
>>    def __init__(self, options, parent=None):
>>
>>        ........
>>
>>        self.makeWidgets(options)
>>
>>    def handleList(self, event):
>>
>>        index = self.listbox.curselection()
>>
>>        label = self.listbox.get(index)
>>
>>        print "label is ", label
>>
>>    def makeWidgets(self, options):
>>
>>        ........
>>
>>        list.bind('<Button-1>', self.handleList)
>>
>>Class aaaaa
>>
>>    def update_strategy_code(self):
>>
>>        ..........
>>
>>        ScrolledList(options)
>>
>>        Button(self, text='Update',
>>
>>        command=self.edit_strategy_code).pack(side=LEFT)
>>
>>    def edit_strategy_code(self):
>>
>>        label=self.listbox.get(ACTIVE)
>>
>>        print 'info2=',label
>>
>> TIA!
>>
>>Andy (mongo57a@comcast.net)
>>
>>
>>_______________________________________________
>>Tutor maillist  -  Tutor@python.org
>>http://mail.python.org/mailman/listinfo/tutor
>
>


From goneil@scu.edu  Wed Oct 16 02:57:41 2002
From: goneil@scu.edu (Galen O'Neil)
Date: 15 Oct 2002 18:57:41 -0700
Subject: [Tutor] Anyone recommend an IDE?
In-Reply-To: <OFD8B3BF78.F7E9510F-ON80256C53.004AF89E@equant.com>
References: <OFD8B3BF78.F7E9510F-ON80256C53.004AF89E@equant.com>
Message-ID: <1034733471.3902.14.camel@lucidia>

I've been using SciTe.  You may want to look into that.
--Galen

On Tue, 2002-10-15 at 06:42, James.Rocks@equant.com wrote:
> > IDLE?
> > Thats why its part of the distro, it works on most platforms...
> > There are others but none that offer anything significantly
> > better than IDLE IMHO unless you want to pay for them.
> 
> Agreed it works but it's so ... ugly ... and boring and ... well ... yuk! I
> mean hey I actually like things that look nice ...
> 
> It's a shame boa-constructor doesn't work ... that's free, works on *nix &
> win and looks real cool! Have to wait for release 0.1.1!
> 
> Ah well ... thanks for your views guys!
> 
> J.
> 
> James C. Rocks
> Equant
> Archway House
> Canary Wharf
> London E14 9SZ
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor




From mongo57a@comcast.net  Wed Oct 16 05:14:31 2002
From: mongo57a@comcast.net (andy surany)
Date: Wed, 16 Oct 2002 00:14:31 -0400
Subject: [Tutor] Binding the mouse to a list using Tk.
Message-ID: <008601c274ca$8757f6e0$2502a8c0@emily.ewndsr01.nj.comcast.net>

Scared me there for a moment.... but no, the click works properly - that is,
only on the elements of the scrolled list. And yes, it is most unwise of me
to name variables the way I have done so - so I adjusted the names for
readability.

The functionality that I am looking for is simple. Various elements of the
list are selected for processing - which is why selectmode=EXTENDED. The
buttons determine the specific functionality that should be executed against
the items selected.

The program actually works perfectly - just one click behind. The first time
I select a list element, I get 'selected elements are []' even though I have
selected, for example, the third element of the list (should be 'selected
elements are [2]' (zero justified)); if I select another element - let's say
list element 10, I get 'selected elements are [2]'; the next selection
follows the same pattern ('selected elements are [9]').

Attached is the complete segment of the relevant code (the full code is just
too much to post). Please note that I haven't gotten around to implementing
the buttons yet (even though some code is there). I'm just trying to get the
mouse click logic right before I move on.

class WINMENU(Frame):

 def update_strategy_code(self):

    input1 = "'"+askstring('Enter strategist', 'Strategist Name?')+"'"
    command = 'Select'
    tables = ['strategy_codes']
    columns = ['strategist','code']
    condition = 'strategist='+str(input1)
    sort = 'None'

    sqlcmd = sql.Build_Query (command, tables, columns, condition, sort)

    print sqlcmd

    dbinfo = sql.Query (sqlcmd)

    dis_code = []

    for i in range(nrecs):
      dis_code.append(dbinfo.code[i])

    options = map((lambda i: dis_code[i]), range(nrecs))
    ScrolledList(options)

    Button(self, text='Update',
command=self.edit_strategy_code).pack(side=LEFT)
    Button(self, text='Delete',
command=self.delete_strategy_code).pack(side=RIGHT)

class ScrolledList(Frame):

    def __init__(self, options, parent=None):
        Frame.__init__(self, parent)
        self.pack(expand=YES, fill=BOTH)
        self.makeWidgets(options)

    def handleList(self, event):
        selected_elements=list(self.listbox.curselection())
        print "selected elements are  ", selected_elements

    def makeWidgets(self, options):
        sbar = Scrollbar(self)
        list_contents = Listbox(self, relief=SUNKEN, selectmode=EXTENDED)
        sbar.config(command=list_contents.yview)
        list_contents.config(yscrollcommand=sbar.set)
        sbar.pack(side=RIGHT, fill=Y)
        list_contents.pack(side=LEFT, expand=YES, fill=BOTH)
        pos = 0

        for label in options:
          list_contents.insert(pos, label)
          pos = pos+1

        list_contents.bind('<Button-1>', self.handleList)
        self.listbox = list_contents
        label=self.listbox.get(ACTIVE)
        print 'info=',label

Thanks.

Regards,

Andy
-----Original Message-----
From: BELSEY, Dylan <dylan.belsey@baesystems.com>
To: tutor@python.org <tutor@python.org>
Date: Tuesday, October 15, 2002 6:52 PM
Subject: RE: [Tutor] Binding the mouse to a list using Tk.


>Andy,
> I may just be me but I am still a little confused as to how this
>code is supposed to work.  Perhaps if you post the whole code (if not too
>large) then the list might be of more assistance. I would make the
>recommendation of not using variable names that are the same as built-in
>functions e.g. "list" in the makeWidgets() function.
> If "self.listbox.get(ACTIVE)" works for you, why not use it in the
>handleList() function as well?  Also, it would appear that you are binding
>the whole Listbox to the mouse button 1 press ie. if you click anywhere in
>the listbox (even on the border), then won't this kick off your handleList
>function...is this what you require?
> Just some thoughts.
>
> Dylan
>
>
>-----Original Message-----
>From: andy surany [mailto:mongo57a@comcast.net]
>Sent: Wednesday, 16 October 2002 03:08
>To: BELSEY, Dylan; tutor@python.org
>Subject: Re: [Tutor] Binding the mouse to a list using Tk.
>
>
>Ok, this got me a lot closer! But I'm still slightly off. Thanks for the
>example Dylan. I stayed with Tk instead of Pmw based on the amount of code
>already developed - and because the functions tended to work the same way.
>But I used the "example" logic.
>
>So now I am using:
>
>    label = list(self.listbox.curselection())
>
>and it looks pretty good! Except: label is the previous selection - not the
>current. I am always behind by 1 (previous selection is item 2 from the
>list, current is item 4, label="2").
>
>Here are the 2 methods. As I indicated, "label" is always one behind the
>current position; however, label1 is correct.
>
>   def handleList(self, event):
>        label=list(self.listbox.curselection())
>        print "label is ", label
>
>    def makeWidgets(self, options):
>        sbar = Scrollbar(self)
>        list = Listbox(self, relief=SUNKEN, selectmode=EXTENDED)
>        sbar.config(command=list.yview)                   # xlink sbar and
>list
>        list.config(yscrollcommand=sbar.set)              # move one moves
>other
>        sbar.pack(side=RIGHT, fill=Y)                     # pack first=clip
>last
>        list.pack(side=LEFT, expand=YES, fill=BOTH)       # list clipped
>first
>        pos = 0
>
>        for label in options:
>          list.insert(pos, label)
>          pos = pos+1
>
>        list.bind('<Button-1>', self.handleList)          # set event
>handler
>        self.listbox = list
>        label1=self.listbox.get(ACTIVE)
>        print 'info=',label1
>
>
>-----Original Message-----
>From: BELSEY, Dylan <dylan.belsey@baesystems.com>
>To: 'andy surany' <mongo57a@comcast.net>; tutor@python.org
><tutor@python.org>
>Date: Tuesday, October 15, 2002 12:47 AM
>Subject: RE: [Tutor] Binding the mouse to a list using Tk.
>
>
>>Hi Andy,
>> In the interest of code sharing, I have attached a file which I
>>believe contains some of the operations that you are looking to perform.
>It
>>is a cut down version of a class I wrote for the current system I am
>working
>>on.  In its original form it obtains signals from a data server and
>displays
>>them ready for selection.  The user then selects signals from the
left-hand
>>box, presses the appropriate button ('->') and the signal appears in the
>>selected signals box, on the right hand side.  This window was to aid the
>>user in selecting specific signals for monitoring.  I have kept the
>relevant
>>functionality in the file.
>> I am currently running this under WinNT.  I have also made the file
>>self running, so all you have to do is get a DOS prompt in the directory
>>where you have saved it and then type "example.py" or "python example.py".
>> Two windows will appear.  Just ignore the first one (but don't close
>>it until you are finished), for this exercise.  It is the root window,
>which
>>is important/necessary, but I have chosen not to use it here.
>> So anyway, run it and experiment with it and then take a look at the
>>code, from which I hope you can get some ideas and help.
>> If you have any questions, please feel free to ask.
>>
>> HTH,
>> Dylan
>>
>>
>>PS: By the ways Tutors, if you see any glaring deficiencies, problems,
etc.
>>in the code pls. feel free to comment.  However, I'm not too interested in
>a
>>code review at this point in time :)
>>
>>
>>
>>
>>-----Original Message-----
>>From: andy surany [mailto:mongo57a@comcast.net]
>>Sent: Tuesday, 15 October 2002 13:50
>>To: BELSEY, Dylan; tutor@python.org
>>Subject: Re: [Tutor] Binding the mouse to a list using Tk.
>>
>>
>>Thanks Dylan. I am using the listbox methods. And everything works. If I
>put
>>the list.bind in the same method that calls the scrolled list, I even get
a
>>response when I move the cursor to list selection
>(listbox.cursorselection).
>>The problem is that I need the selected list item to be independent of the
>>mouse (mouse is depressing a button which gets the original highlighted
>list
>>item). It's almost like I'm losing context.
>>
>>I haven't looked at getcurselection - which I will do now. I still think
>>that my logic is correct - but I haven't placed it in the correct spot.
>>
>>Regards,
>>
>>Andy
>>-----Original Message-----
>>From: BELSEY, Dylan <dylan.belsey@baesystems.com>
>>To: tutor@python.org <tutor@python.org>
>>Date: Monday, October 14, 2002 6:59 PM
>>Subject: RE: [Tutor] Binding the mouse to a list using Tk.
>>
>>
>>>    Only had a brief look at your problem, but I believe that the Tkinter
>>>widgets Listbox and ScrolledListBox may be what you need (and save you
>>quite
>>>a bit of time).  You can use the Listbox methods from within the
>>>ScrolledListbox object as well.  You could then possibly associate a
>>>function with your button which gets the currently selected item.
>>>getcurselection() returns the text while the curselection() will return
>the
>>>index.
>>>    A lot of this is quite similar to what your code has proposed but
>using
>>>the built-in widgets and their functions may shed some light on an easier
>>>solution.
>>>
>>>    HTH,
>>>        Dylan
>>>
>>>
>>>-----Original Message-----
>>>From: andy surany [mailto:mongo57a@comcast.net]
>>>Sent: Tuesday, 15 October 2002 04:20
>>>To: tutor@python.org
>>>Subject: [Tutor] Binding the mouse to a list using Tk.
>>>
>>>
>>>Hi all!
>>>
>>>What I want to do is use a button to capture the position/value of the
>>>
>>>selected item in a scrolled list. So the user selects the item in the
list
>>>
>>>with a single click of the left mouse button and then clicks a button.
>>>
>>>Should be easy - I'm just not getting it......
>>>
>>>
>>>
>>>I'm using Tkinter. I Created a class (ScrolledList) for a scrolled list
>>>which works fine. Created
>>>
>>>another class (aaaaa) which populates the list - and it works fine.
>Created
>>>
>>>a handler under ScrolledList (handleList) which should trap the results
of
>>>
>>>the bind (makeWidgets). Right now, all I'm trying to do is just print out
>>>
>>>the value (just testing..) - but my logic is incorrect (actually, I think
>>>
>>>that the logic may be correct - it's just in the wrong place...).
>>>
>>>Here is a synopsis of the code. The "...." is non-relevant code which I
>>have
>>>removed for simplification.
>>>
>>>
>>>
>>>class ScrolledList(Frame):
>>>
>>>    def __init__(self, options, parent=None):
>>>
>>>        ........
>>>
>>>        self.makeWidgets(options)
>>>
>>>    def handleList(self, event):
>>>
>>>        index = self.listbox.curselection()
>>>
>>>        label = self.listbox.get(index)
>>>
>>>        print "label is ", label
>>>
>>>    def makeWidgets(self, options):
>>>
>>>        ........
>>>
>>>        list.bind('<Button-1>', self.handleList)
>>>
>>>Class aaaaa
>>>
>>>    def update_strategy_code(self):
>>>
>>>        ..........
>>>
>>>        ScrolledList(options)
>>>
>>>        Button(self, text='Update',
>>>
>>>        command=self.edit_strategy_code).pack(side=LEFT)
>>>
>>>    def edit_strategy_code(self):
>>>
>>>        label=self.listbox.get(ACTIVE)
>>>
>>>        print 'info2=',label
>>>
>>> TIA!
>>>
>>>Andy (mongo57a@comcast.net)
>>>
>>>
>>>_______________________________________________
>>>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 gege@nst.pku.edu.cn  Wed Oct 16 04:43:18 2002
From: gege@nst.pku.edu.cn (Ares Liu)
Date: Wed, 16 Oct 2002 11:43:18 +0800
Subject: [Tutor] What's matter of mail.python.org ?
References: <008601c274ca$8757f6e0$2502a8c0@emily.ewndsr01.nj.comcast.net>
Message-ID: <02a501c274c6$2abf1e30$b400a8c0@jadeite.com>

ZzlFR0U5bDAyNzk5OiBTWVNFUlI6IHB1dG91dG1zZyAobWFpbC5weXRob24ub3JnKTogZXJyb3Ig
b24gb3V0cHV0IGNoYW5uZWwgc2VuZGluZyAiMjUwIDIuMC4wIGc5RUdFOWwwMjc5OSBNZXNzYWdl
IGFjY2VwdGVkIGZvciBkZWxpDQp2ZXJ5IjogQ29ubmVjdGlvbiByZXNldCBieSBtYWlsLnB5dGhv
bi5vcmcNCmc5RUdKSmwwMjg1MjogU1lTRVJSOiBwdXRvdXRtc2cgKG1haWwucHl0aG9uLm9yZyk6
IGVycm9yIG9uIG91dHB1dCBjaGFubmVsIHNlbmRpbmcgIjI1MCAyLjAuMCBnOUVHSkpsMDI4NTIg
TWVzc2FnZSBhY2NlcHRlZCBmb3IgZGVsaQ0KdmVyeSI6IENvbm5lY3Rpb24gcmVzZXQgYnkgbWFp
bC5weXRob24ub3JnDQpnOUVHYTBsMDI5NTg6IFNZU0VSUjogcHV0b3V0bXNnIChtYWlsLnB5dGhv
bi5vcmcpOiBlcnJvciBvbiBvdXRwdXQgY2hhbm5lbCBzZW5kaW5nICIyNTAgMi4wLjAgZzlFR2Ew
bDAyOTU4IE1lc3NhZ2UgYWNjZXB0ZWQgZm9yIGRlbGkNCnZlcnkiOiBDb25uZWN0aW9uIHJlc2V0
IGJ5IG1haWwucHl0aG9uLm9yZw0KZzlFR2EybDAyOTYxOiBTWVNFUlI6IHB1dG91dG1zZyAobWFp
bC5weXRob24ub3JnKTogZXJyb3Igb24gb3V0cHV0IGNoYW5uZWwgc2VuZGluZyAiMjIwIG5zdC5w
a3UuZWR1LmNuIEVTTVRQIFNlbmRtYWlsIDguMTEuNi84LjExLjY7DQogVHVlLCAxNSBPY3QgMjAw
MiAwMDozNjowMiArMDgwMCI6IENvbm5lY3Rpb24gcmVzZXQgYnkgbWFpbC5weXRob24ub3JnDQpn
OUVHdUdsMDMwOTU6IFNZU0VSUjogcHV0b3V0bXNnIChtYWlsLnB5dGhvbi5vcmcpOiBlcnJvciBv
biBvdXRwdXQgY2hhbm5lbCBzZW5kaW5nICIyNTAgMi4wLjAgZzlFR3VHbDAzMDk1IE1lc3NhZ2Ug
YWNjZXB0ZWQgZm9yIGRlbGkNCnZlcnkiOiBDb25uZWN0aW9uIHJlc2V0IGJ5IG1haWwucHl0aG9u
Lm9yZw0KZzlFR3VIbDAzMDk4OiBTWVNFUlI6IHB1dG91dG1zZyAobWFpbC5weXRob24ub3JnKTog
ZXJyb3Igb24gb3V0cHV0IGNoYW5uZWwgc2VuZGluZyAiMjUwIDIuMS41IDxnZWdlQG5zdC5wa3Uu
ZWR1LmNuPi4uLiBSZWNpcGllbnQgb2siDQo6IENvbm5lY3Rpb24gcmVzZXQgYnkgbWFpbC5weXRo
b24ub3JnDQpnOUVHdUhsMDMwOTg6IGxvc3QgaW5wdXQgY2hhbm5lbCBmcm9tIG1haWwucHl0aG9u
Lm9yZyBbMTIuMTU1LjExNy4yOV0gdG8gTVRBIGFmdGVyIHJjcHQNCmc5RUhEOGwwMzE4NzogU1lT
RVJSOiBwdXRvdXRtc2cgKG1haWwucHl0aG9uLm9yZyk6IGVycm9yIG9uIG91dHB1dCBjaGFubmVs
IHNlbmRpbmcgIjI1MCAyLjAuMCBnOUVIRDhsMDMxODcgTWVzc2FnZSBhY2NlcHRlZCBmb3IgZGVs
aQ0KdmVyeSI6IENvbm5lY3Rpb24gcmVzZXQgYnkgbWFpbC5weXRob24ub3JnDQpnOUVIU3hsMDMy
NjI6IFNZU0VSUjogcHV0b3V0bXNnIChtYWlsLnB5dGhvbi5vcmcpOiBlcnJvciBvbiBvdXRwdXQg
Y2hhbm5lbCBzZW5kaW5nICIyNTAgMi4wLjAgZzlFSFN4bDAzMjYyIE1lc3NhZ2UgYWNjZXB0ZWQg
Zm9yIGRlbGkNCnZlcnkiOiBDb25uZWN0aW9uIHJlc2V0IGJ5IG1haWwucHl0aG9uLm9yZw0KZzlF
SFR2bDAzMjcxOiBTWVNFUlI6IHB1dG91dG1zZyAobWFpbC5weXRob24ub3JnKTogZXJyb3Igb24g
b3V0cHV0IGNoYW5uZWwgc2VuZGluZyAiMjIwIG5zdC5wa3UuZWR1LmNuIEVTTVRQIFNlbmRtYWls
IDguMTEuNi84LjExLjY7DQogVHVlLCAxNSBPY3QgMjAwMiAwMToyOTo1NyArMDgwMCI6IENvbm5l
Y3Rpb24gcmVzZXQgYnkgbWFpbC5weXRob24ub3JnDQpnOUVIVnhsMDMyODY6IFNZU0VSUjogcHV0
b3V0bXNnIChtYWlsLnB5dGhvbi5vcmcpOiBlcnJvciBvbiBvdXRwdXQgY2hhbm5lbCBzZW5kaW5n
ICIyMjAgbnN0LnBrdS5lZHUuY24gRVNNVFAgU2VuZG1haWwgOC4xMS42LzguMTEuNjsNCiBUdWUs
IDE1IE9jdCAyMDAyIDAxOjMxOjU5ICswODAwIjogQ29ubmVjdGlvbiByZXNldCBieSBtYWlsLnB5
dGhvbi5vcmcNCmc5RUh0eGwwMzQ0MTogU1lTRVJSOiBwdXRvdXRtc2cgKG1haWwucHl0aG9uLm9y
Zyk6IGVycm9yIG9uIG91dHB1dCBjaGFubmVsIHNlbmRpbmcgIjI1MCAyLjAuMCBnOUVIdHhsMDM0
NDEgTWVzc2FnZSBhY2NlcHRlZCBmb3IgZGVsaQ0KdmVyeSI6IENvbm5lY3Rpb24gcmVzZXQgYnkg
bWFpbC5weXRob24ub3JnDQpnOUVJRElsMDM1NzM6IFNZU0VSUjogcHV0b3V0bXNnIChtYWlsLnB5
dGhvbi5vcmcpOiBlcnJvciBvbiBvdXRwdXQgY2hhbm5lbCBzZW5kaW5nICIyMjAgbnN0LnBrdS5l
ZHUuY24gRVNNVFAgU2VuZG1haWwgOC4xMS42LzguMTEuNjsNCiBUdWUsIDE1IE9jdCAyMDAyIDAy
OjEzOjE4ICswODAwIjogQ29ubmVjdGlvbiByZXNldCBieSBtYWlsLnB5dGhvbi5vcmcNCmc5RUlZ
d2wwMzcwMjogU1lTRVJSOiBwdXRvdXRtc2cgKG1haWwucHl0aG9uLm9yZyk6IGVycm9yIG9uIG91
dHB1dCBjaGFubmVsIHNlbmRpbmcgIjIyMCBuc3QucGt1LmVkdS5jbiBFU01UUCBTZW5kbWFpbCA4
LjExLjYvOC4xMS42Ow0KIFR1ZSwgMTUgT2N0IDIwMDIgMDI6MzQ6NTkgKzA4MDAiOiBDb25uZWN0
aW9uIHJlc2V0IGJ5IG1haWwucHl0aG9uLm9yZw0KTk9RVUVVRTogbWFpbC5weXRob24ub3JnIFsx
Mi4xNTUuMTE3LjI5XSBkaWQgbm90IGlzc3VlIE1BSUwvRVhQTi9WUkZZL0VUUk4gZHVyaW5nIGNv
bm5lY3Rpb24gdG8gTVRBDQpnOUVJdXdsMDM4NDE6IFNZU0VSUjogcHV0b3V0bXNnIChtYWlsLnB5
dGhvbi5vcmcpOiBlcnJvciBvbiBvdXRwdXQgY2hhbm5lbCBzZW5kaW5nICIyNTAgMi4wLjAgZzlF
SXV3bDAzODQxIE1lc3NhZ2UgYWNjZXB0ZWQgZm9yIGRlbGkNCnZlcnkiOiBDb25uZWN0aW9uIHJl
c2V0IGJ5IG1haWwucHl0aG9uLm9yZw0KTk9RVUVVRTogSURFTlQ6cm9vdEB3ZWIubXlzcWwuY29t
IFsyMTMuMTM2LjQ5LjE4M10gZGlkIG5vdCBpc3N1ZSBNQUlML0VYUE4vVlJGWS9FVFJOIGR1cmlu
ZyBjb25uZWN0aW9uIHRvIE1UQQ0KZzlGQmpQbDEzOTk1OiBTWVNFUlI6IHB1dG91dG1zZyAobWFp
bC5weXRob24ub3JnKTogZXJyb3Igb24gb3V0cHV0IGNoYW5uZWwgc2VuZGluZyAiMjUwIDIuMC4w
IGc5RkJqUGwxMzk5NSBNZXNzYWdlIGFjY2VwdGVkIGZvciBkZWxpDQp2ZXJ5IjogQ29ubmVjdGlv
biByZXNldCBieSBtYWlsLnB5dGhvbi5vcmcNCmc5RkUwTWwxNDk4OTogU1lTRVJSOiBwdXRvdXRt
c2cgKG1haWwucHl0aG9uLm9yZyk6IGVycm9yIG9uIG91dHB1dCBjaGFubmVsIHNlbmRpbmcgIjI1
MCAyLjAuMCBnOUZFME1sMTQ5ODkgTWVzc2FnZSBhY2NlcHRlZCBmb3IgZGVsaQ0KdmVyeSI6IENv
bm5lY3Rpb24gcmVzZXQgYnkgbWFpbC5weXRob24ub3JnDQoNCi1BcmVz



From dylan.belsey@baesystems.com  Wed Oct 16 05:33:02 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Wed, 16 Oct 2002 14:03:02 +0930
Subject: [Tutor] Binding the mouse to a list using Tk.
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B98D2AE3@wtntex1.baea.com.au>

	OK, here goes.... I isolated your class ScrolledList and ran it
independently.  From testing, what I suspect is happening, is that on the
button press ie. downwards action of the mouse button, your function
interrogates the listbox for the currently selected item and gets the one
that "was/is" highlighted.  I believe that the one pointed to only gets set
after this interrogation (perhaps an artefact of the sequence of how
events/bind and widget properties are set), therefore it will pick up the
previous selection.
	The simple fix is to use '<ButtonRelease-1>' instead of '<Button-1>'
for your binding, so that the listbox interrogation happens after the new
value is set.  Even though it looks, visually, like the selection is made on
the downwards press, perhaps the function is run before the visual is
set?!?!? Not sure.
	Hope this makes sense.  Good luck.

		Dylan


-----Original Message-----
From: andy surany [mailto:mongo57a@comcast.net]
Sent: Wednesday, 16 October 2002 14:15
To: BELSEY, Dylan; tutor@python.org
Subject: Re: [Tutor] Binding the mouse to a list using Tk.


Scared me there for a moment.... but no, the click works properly - that is,
only on the elements of the scrolled list. And yes, it is most unwise of me
to name variables the way I have done so - so I adjusted the names for
readability.

The functionality that I am looking for is simple. Various elements of the
list are selected for processing - which is why selectmode=EXTENDED. The
buttons determine the specific functionality that should be executed against
the items selected.

The program actually works perfectly - just one click behind. The first time
I select a list element, I get 'selected elements are []' even though I have
selected, for example, the third element of the list (should be 'selected
elements are [2]' (zero justified)); if I select another element - let's say
list element 10, I get 'selected elements are [2]'; the next selection
follows the same pattern ('selected elements are [9]').

Attached is the complete segment of the relevant code (the full code is just
too much to post). Please note that I haven't gotten around to implementing
the buttons yet (even though some code is there). I'm just trying to get the
mouse click logic right before I move on.

class WINMENU(Frame):

 def update_strategy_code(self):

    input1 = "'"+askstring('Enter strategist', 'Strategist Name?')+"'"
    command = 'Select'
    tables = ['strategy_codes']
    columns = ['strategist','code']
    condition = 'strategist='+str(input1)
    sort = 'None'

    sqlcmd = sql.Build_Query (command, tables, columns, condition, sort)

    print sqlcmd

    dbinfo = sql.Query (sqlcmd)

    dis_code = []

    for i in range(nrecs):
      dis_code.append(dbinfo.code[i])

    options = map((lambda i: dis_code[i]), range(nrecs))
    ScrolledList(options)

    Button(self, text='Update',
command=self.edit_strategy_code).pack(side=LEFT)
    Button(self, text='Delete',
command=self.delete_strategy_code).pack(side=RIGHT)

class ScrolledList(Frame):

    def __init__(self, options, parent=None):
        Frame.__init__(self, parent)
        self.pack(expand=YES, fill=BOTH)
        self.makeWidgets(options)

    def handleList(self, event):
        selected_elements=list(self.listbox.curselection())
        print "selected elements are  ", selected_elements

    def makeWidgets(self, options):
        sbar = Scrollbar(self)
        list_contents = Listbox(self, relief=SUNKEN, selectmode=EXTENDED)
        sbar.config(command=list_contents.yview)
        list_contents.config(yscrollcommand=sbar.set)
        sbar.pack(side=RIGHT, fill=Y)
        list_contents.pack(side=LEFT, expand=YES, fill=BOTH)
        pos = 0

        for label in options:
          list_contents.insert(pos, label)
          pos = pos+1

        list_contents.bind('<Button-1>', self.handleList)
        self.listbox = list_contents
        label=self.listbox.get(ACTIVE)
        print 'info=',label

Thanks.

Regards,

Andy
-----Original Message-----
From: BELSEY, Dylan <dylan.belsey@baesystems.com>
To: tutor@python.org <tutor@python.org>
Date: Tuesday, October 15, 2002 6:52 PM
Subject: RE: [Tutor] Binding the mouse to a list using Tk.


>Andy,
> I may just be me but I am still a little confused as to how this
>code is supposed to work.  Perhaps if you post the whole code (if not too
>large) then the list might be of more assistance. I would make the
>recommendation of not using variable names that are the same as built-in
>functions e.g. "list" in the makeWidgets() function.
> If "self.listbox.get(ACTIVE)" works for you, why not use it in the
>handleList() function as well?  Also, it would appear that you are binding
>the whole Listbox to the mouse button 1 press ie. if you click anywhere in
>the listbox (even on the border), then won't this kick off your handleList
>function...is this what you require?
> Just some thoughts.
>
> Dylan
>
>
>-----Original Message-----
>From: andy surany [mailto:mongo57a@comcast.net]
>Sent: Wednesday, 16 October 2002 03:08
>To: BELSEY, Dylan; tutor@python.org
>Subject: Re: [Tutor] Binding the mouse to a list using Tk.
>
>
>Ok, this got me a lot closer! But I'm still slightly off. Thanks for the
>example Dylan. I stayed with Tk instead of Pmw based on the amount of code
>already developed - and because the functions tended to work the same way.
>But I used the "example" logic.
>
>So now I am using:
>
>    label = list(self.listbox.curselection())
>
>and it looks pretty good! Except: label is the previous selection - not the
>current. I am always behind by 1 (previous selection is item 2 from the
>list, current is item 4, label="2").
>
>Here are the 2 methods. As I indicated, "label" is always one behind the
>current position; however, label1 is correct.
>
>   def handleList(self, event):
>        label=list(self.listbox.curselection())
>        print "label is ", label
>
>    def makeWidgets(self, options):
>        sbar = Scrollbar(self)
>        list = Listbox(self, relief=SUNKEN, selectmode=EXTENDED)
>        sbar.config(command=list.yview)                   # xlink sbar and
>list
>        list.config(yscrollcommand=sbar.set)              # move one moves
>other
>        sbar.pack(side=RIGHT, fill=Y)                     # pack first=clip
>last
>        list.pack(side=LEFT, expand=YES, fill=BOTH)       # list clipped
>first
>        pos = 0
>
>        for label in options:
>          list.insert(pos, label)
>          pos = pos+1
>
>        list.bind('<Button-1>', self.handleList)          # set event
>handler
>        self.listbox = list
>        label1=self.listbox.get(ACTIVE)
>        print 'info=',label1
>
>
>-----Original Message-----
>From: BELSEY, Dylan <dylan.belsey@baesystems.com>
>To: 'andy surany' <mongo57a@comcast.net>; tutor@python.org
><tutor@python.org>
>Date: Tuesday, October 15, 2002 12:47 AM
>Subject: RE: [Tutor] Binding the mouse to a list using Tk.
>
>
>>Hi Andy,
>> In the interest of code sharing, I have attached a file which I
>>believe contains some of the operations that you are looking to perform.
>It
>>is a cut down version of a class I wrote for the current system I am
>working
>>on.  In its original form it obtains signals from a data server and
>displays
>>them ready for selection.  The user then selects signals from the
left-hand
>>box, presses the appropriate button ('->') and the signal appears in the
>>selected signals box, on the right hand side.  This window was to aid the
>>user in selecting specific signals for monitoring.  I have kept the
>relevant
>>functionality in the file.
>> I am currently running this under WinNT.  I have also made the file
>>self running, so all you have to do is get a DOS prompt in the directory
>>where you have saved it and then type "example.py" or "python example.py".
>> Two windows will appear.  Just ignore the first one (but don't close
>>it until you are finished), for this exercise.  It is the root window,
>which
>>is important/necessary, but I have chosen not to use it here.
>> So anyway, run it and experiment with it and then take a look at the
>>code, from which I hope you can get some ideas and help.
>> If you have any questions, please feel free to ask.
>>
>> HTH,
>> Dylan
>>
>>
>>PS: By the ways Tutors, if you see any glaring deficiencies, problems,
etc.
>>in the code pls. feel free to comment.  However, I'm not too interested in
>a
>>code review at this point in time :)
>>
>>
>>
>>
>>-----Original Message-----
>>From: andy surany [mailto:mongo57a@comcast.net]
>>Sent: Tuesday, 15 October 2002 13:50
>>To: BELSEY, Dylan; tutor@python.org
>>Subject: Re: [Tutor] Binding the mouse to a list using Tk.
>>
>>
>>Thanks Dylan. I am using the listbox methods. And everything works. If I
>put
>>the list.bind in the same method that calls the scrolled list, I even get
a
>>response when I move the cursor to list selection
>(listbox.cursorselection).
>>The problem is that I need the selected list item to be independent of the
>>mouse (mouse is depressing a button which gets the original highlighted
>list
>>item). It's almost like I'm losing context.
>>
>>I haven't looked at getcurselection - which I will do now. I still think
>>that my logic is correct - but I haven't placed it in the correct spot.
>>
>>Regards,
>>
>>Andy
>>-----Original Message-----
>>From: BELSEY, Dylan <dylan.belsey@baesystems.com>
>>To: tutor@python.org <tutor@python.org>
>>Date: Monday, October 14, 2002 6:59 PM
>>Subject: RE: [Tutor] Binding the mouse to a list using Tk.
>>
>>
>>>    Only had a brief look at your problem, but I believe that the Tkinter
>>>widgets Listbox and ScrolledListBox may be what you need (and save you
>>quite
>>>a bit of time).  You can use the Listbox methods from within the
>>>ScrolledListbox object as well.  You could then possibly associate a
>>>function with your button which gets the currently selected item.
>>>getcurselection() returns the text while the curselection() will return
>the
>>>index.
>>>    A lot of this is quite similar to what your code has proposed but
>using
>>>the built-in widgets and their functions may shed some light on an easier
>>>solution.
>>>
>>>    HTH,
>>>        Dylan
>>>
>>>
>>>-----Original Message-----
>>>From: andy surany [mailto:mongo57a@comcast.net]
>>>Sent: Tuesday, 15 October 2002 04:20
>>>To: tutor@python.org
>>>Subject: [Tutor] Binding the mouse to a list using Tk.
>>>
>>>
>>>Hi all!
>>>
>>>What I want to do is use a button to capture the position/value of the
>>>
>>>selected item in a scrolled list. So the user selects the item in the
list
>>>
>>>with a single click of the left mouse button and then clicks a button.
>>>
>>>Should be easy - I'm just not getting it......
>>>
>>>
>>>
>>>I'm using Tkinter. I Created a class (ScrolledList) for a scrolled list
>>>which works fine. Created
>>>
>>>another class (aaaaa) which populates the list - and it works fine.
>Created
>>>
>>>a handler under ScrolledList (handleList) which should trap the results
of
>>>
>>>the bind (makeWidgets). Right now, all I'm trying to do is just print out
>>>
>>>the value (just testing..) - but my logic is incorrect (actually, I think
>>>
>>>that the logic may be correct - it's just in the wrong place...).
>>>
>>>Here is a synopsis of the code. The "...." is non-relevant code which I
>>have
>>>removed for simplification.
>>>
>>>
>>>
>>>class ScrolledList(Frame):
>>>
>>>    def __init__(self, options, parent=None):
>>>
>>>        ........
>>>
>>>        self.makeWidgets(options)
>>>
>>>    def handleList(self, event):
>>>
>>>        index = self.listbox.curselection()
>>>
>>>        label = self.listbox.get(index)
>>>
>>>        print "label is ", label
>>>
>>>    def makeWidgets(self, options):
>>>
>>>        ........
>>>
>>>        list.bind('<Button-1>', self.handleList)
>>>
>>>Class aaaaa
>>>
>>>    def update_strategy_code(self):
>>>
>>>        ..........
>>>
>>>        ScrolledList(options)
>>>
>>>        Button(self, text='Update',
>>>
>>>        command=self.edit_strategy_code).pack(side=LEFT)
>>>
>>>    def edit_strategy_code(self):
>>>
>>>        label=self.listbox.get(ACTIVE)
>>>
>>>        print 'info2=',label
>>>
>>> TIA!
>>>
>>>Andy (mongo57a@comcast.net)
>>>
>>>
>>>_______________________________________________
>>>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 lumbricus@gmx.net  Wed Oct 16 06:53:55 2002
From: lumbricus@gmx.net (lumbricus@gmx.net)
Date: Wed, 16 Oct 2002 07:53:55 +0200 (MEST)
Subject: [Tutor] recursion program
References: <1034425861.4105.15.camel@localhost.localdomain>
Message-ID: <16233.1034747635@www33.gmx.net>

Hi!

[ snip ]

> question:
> I would like to call a sound effect say from
> /usr/share/sounds/KDE_Beep_Lightning.wav when n == 0
> How?

>>> os.system("cat /usr/share/sounds/KDE_Beep_Lightning.wav > /dev/audio")
or something like that.
Better use the pygame module.

> I would also like the countdown to be in real time, how?

>>> time.sleep(1)
But this doesn't guarantee to be exactly a second (especially
on a system with lots of users, all running netrape or so).
To get "real time"(TM) you need a real time operating system.
 
> TIA
> mike Reavey

HTH, J"o!

-- 
Wir beschliessen etwas, stellen das dann in
den Raum und warten dann einige Zeit ab, was
passiert. Wenn es dann kein grosses Geschrei
gibt und keine Aufstaende, weil die meisten
gar nicht begreifen, was da beschlossen
wurde, dann machen wir weiter - Schritt fuer
Schritt, bis es kein Zurueck mehr gibt. 
   -- J-C Juncker

+++ 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  Wed Oct 16 07:13:23 2002
From: lumbricus@gmx.net (lumbricus@gmx.net)
Date: Wed, 16 Oct 2002 08:13:23 +0200 (MEST)
Subject: [Tutor] re module and looping
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C97E@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <16859.1034748803@www33.gmx.net>

Hello!

> > If you could advise me on the following, I would appreciate it...
> > I get only one tag <HTML> when I run the following. here is the re
> > code
> > 
> > 
> >     #tricky re stuff
> >     p=re.compile(r"(<.*?>)",re.DOTALL)
> >     m=p.match(alllines)

[ snip ]
 
> Mostly it will work OK but there may well be some 
> strangenesses... 

ACK
Somebody once proved, that it is impossible to 
parse html code correctly with regular expressions.
So the OP should use a html parser module instead.
 
> Alan G.

HTH, J"o!

-- 
Wir beschliessen etwas, stellen das dann in
den Raum und warten dann einige Zeit ab, was
passiert. Wenn es dann kein grosses Geschrei
gibt und keine Aufstaende, weil die meisten
gar nicht begreifen, was da beschlossen
wurde, dann machen wir weiter - Schritt fuer
Schritt, bis es kein Zurueck mehr gibt. 
   -- J-C Juncker

+++ 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  Wed Oct 16 08:19:45 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Wed, 16 Oct 2002 20:19:45 +1300
Subject: [Tutor] ints, and long ints?
Message-ID: <20021016201945.42a2d07a.thomi@thomi.imail.net.nz>

what happens when you store a number in an integer, which is larger than
the maximum numbr able to be stored in an integer?? also, how does one
sue long ints?? does python even have long ints?? (I've never seen them,
and i can't see them in the python tutorial....)

-- 
This message was brought to you by one bored guy, with nothing better to
do,
And the letter Q.
Thomi Richards,
thomi@imail.net.nz


From kalle@lysator.liu.se  Wed Oct 16 08:49:01 2002
From: kalle@lysator.liu.se (Kalle Svensson)
Date: Wed, 16 Oct 2002 09:49:01 +0200
Subject: [Tutor] ints, and long ints?
In-Reply-To: <20021016201945.42a2d07a.thomi@thomi.imail.net.nz>
References: <20021016201945.42a2d07a.thomi@thomi.imail.net.nz>
Message-ID: <20021016074901.GA1429@i92.ryd.student.liu.se>

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

[Thomi Richards]
> what happens when you store a number in an integer, which is larger
> than the maximum numbr able to be stored in an integer??

It depends on which version of Python you're using.

Python 2.1.3 (#1, Sep  7 2002, 15:29:56)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import sys
>>> i = sys.maxint
>>> i += 1
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
OverflowError: integer addition
>>> i
2147483647
>>> l = long(i)
>>> l
2147483647L
>>> l += 1
>>> l
2147483648L

But note that in Python 2.2 overflow automatically creates longs:

Python 2.2.1 (#1, Sep  7 2002, 14:34:30) 
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> i = sys.maxint
>>> i += 1
>>> i
2147483648L

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/>

iD8DBQE9rRnmdNeA1787sd0RAhswAKCsVjqx18rOCPbQDwHGknYYJQy5RQCeKkAZ
KeoKkp5ghOlgWbxgzWZ/zGA=
=Dz9N
-----END PGP SIGNATURE-----


From thomi@thomi.imail.net.nz  Wed Oct 16 09:05:37 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Wed, 16 Oct 2002 21:05:37 +1300
Subject: [Tutor] ints, and long ints?
In-Reply-To: <20021016074901.GA1429@i92.ryd.student.liu.se>
References: <20021016201945.42a2d07a.thomi@thomi.imail.net.nz>
 <20021016074901.GA1429@i92.ryd.student.liu.se>
Message-ID: <20021016210537.321eb372.thomi@thomi.imail.net.nz>

awesome, thanks for that...hmmmmmm.... i may have to make this project
available on 2.2 only :-)

-- 
This is a subliminal message.
Thomi Richards,
thomi@imail.net.nz


From darnold02@sprynet.com  Wed Oct 16 11:52:06 2002
From: darnold02@sprynet.com (Don Arnold)
Date: Wed, 16 Oct 2002 05:52:06 -0500
Subject: [Tutor] ints, and long ints?
References: <20021016201945.42a2d07a.thomi@thomi.imail.net.nz><20021016074901.GA1429@i92.ryd.student.liu.se> <20021016210537.321eb372.thomi@thomi.imail.net.nz>
Message-ID: <01f001c27502$12bf5a70$1f10ba3f@defaultcomp>

----- Original Message -----
From: "Thomi Richards" <thomi@thomi.imail.net.nz>
To: <tutor@python.org>
Sent: Wednesday, October 16, 2002 3:05 AM
Subject: Re: [Tutor] ints, and long ints?


> awesome, thanks for that...hmmmmmm.... i may have to make this project
> available on 2.2 only :-)
>

Why would that be? If you have a variable that you expect will overflow,
just bind it to a long when you assign it by appending an 'L' to it's
initial value:

>>> import sys
>>> score = 0L
>>> for i in range(10):
            score += sys.maxint
>>> score
21474836470L

That way, you don't have to worry about (our beloved) Python handling the
overflow for you.

Don



From alan.gauld@bt.com  Wed Oct 16 11:52:50 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 16 Oct 2002 11:52:50 +0100
Subject: [Tutor] looking for an interpreter
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C997@mbtlipnt02.btlabs.bt.co.uk>

Hi,

> <PRE>i need an intrerpreter and i dont knwo where to find 
> one.  

When you say "an interpreter" do you mean the python 
program language interpreter(ie software) or someone 
to interpret(ie teach) python to you - a person?

If you mean the software then
> ...i downloaded python2.2.2.  

You already have it, you just need to install the file 
you downloaded. Then go through the included tutorial
(if you already know how to program in another language) 
or go to the Newbies page on the Python web site if 
you are a complete beginner (or just visit my online tutor!).

If you mean a person then this list os full of them but 
rather than getting one single tutor you get a bunch. 
Simply post questions as they arise (while following one of 
the tutorials described above) and the people on this list 
will do their best to answer them...

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


From James.Rocks@equant.com  Wed Oct 16 11:07:36 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Wed, 16 Oct 2002 11:07:36 +0100
Subject: [Tutor] Dictionary Elements
Message-ID: <OF176658DA.A003C08D-ON80256C54.0037647E@equant.com>

Hi,

If I have a dictionary of 6 tuples e.g.

{'LONA18': 'GREEN', 'LONTSATL19': 'GREEN', 'LONTSGLA01': 'GREEN', 'LONA15':
'GREEN', 'LONA14': 'GREEN', 'LONA17': 'GREEN'}

... and I want to read BOTH key and value by numerical reference e.g. print
dictionary[1] (I know this is wrong) prints:

'LONA18'

How do I do it?

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From lists@shrestha.net.np  Wed Oct 16 10:27:19 2002
From: lists@shrestha.net.np (Aadish Shrestha)
Date: 16 Oct 2002 15:12:19 +0545
Subject: [Tutor] tkinter and menu
Message-ID: <1034760439.1599.38.camel@adu.shrestha.net.np>

I'm starting Python and Tkinter and need some help. I've created a menu
widget and did the following

menu.add_comman(label="ok", command=help)

This works fine, but i've modified my callback function help so that
depending upon the paramter it displays help on given paramter.

def help(topic):
  """ depending upont topic display help"""
  statements
      ..
  statements
     
My question is how do i pass parameter to callback function help() ??
doing .add_command(label="ok", command=help("about")) doesn't work.





From thomi@thomi.imail.net.nz  Wed Oct 16 12:24:22 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Thu, 17 Oct 2002 00:24:22 +1300
Subject: [Tutor] ints, and long ints?
In-Reply-To: <01f001c27502$12bf5a70$1f10ba3f@defaultcomp>
References: <20021016201945.42a2d07a.thomi@thomi.imail.net.nz>
 <20021016074901.GA1429@i92.ryd.student.liu.se>
 <20021016210537.321eb372.thomi@thomi.imail.net.nz>
 <01f001c27502$12bf5a70$1f10ba3f@defaultcomp>
Message-ID: <20021017002422.29d551af.thomi@thomi.imail.net.nz>

> 
> Why would that be? If you have a variable that you expect will
> overflow, just bind it to a long when you assign it by appending an
> 'L' to it's initial value:

because:

the length of the numbers will depend on the users config settings. the
default maximum number will be somewhere in the 16'000's, which is quite
safe, however, users may want to use bigger numbers, in which case i
want python to handle this for me.

why not just use long ints?? basically, memory conservation, and for
speed of execution. 

-- 
Lord, what fools these mortals be!
 -- midsummer nights dream.
Thomi Richards,
thomi@imail.net.nz


From darnold02@sprynet.com  Wed Oct 16 12:43:39 2002
From: darnold02@sprynet.com (Don Arnold)
Date: Wed, 16 Oct 2002 06:43:39 -0500
Subject: [Tutor] Dictionary Elements
References: <OF176658DA.A003C08D-ON80256C54.0037647E@equant.com>
Message-ID: <022501c27509$4c67ed30$1f10ba3f@defaultcomp>

----- Original Message -----
From: <James.Rocks@equant.com>
To: <tutor@python.org>
Sent: Wednesday, October 16, 2002 5:07 AM
Subject: [Tutor] Dictionary Elements


> Hi,
>
> If I have a dictionary of 6 tuples e.g.
>
> {'LONA18': 'GREEN', 'LONTSATL19': 'GREEN', 'LONTSGLA01': 'GREEN',
'LONA15':
> 'GREEN', 'LONA14': 'GREEN', 'LONA17': 'GREEN'}
>

These aren't really tuples, just key/value pairs.

> ... and I want to read BOTH key and value by numerical reference e.g.
print
> dictionary[1] (I know this is wrong) prints:
>
> 'LONA18'
>
> How do I do it?
>

You _can_ do it by calling the dictionary's items() method, which gives you
a list of key/value pairs:

>>> mydict = {0: 'zero', 1: 'one', 2: 'two', 3: 'three'}
>>> print mydict.items()
[(0, 'zero'), (1, 'one'), (2, 'two'), (3, 'three')]
>>> print mydict.items()[2]
(2, 'two')

But you shouldn't really want to. A dictionary is an unordered collection,
so the value of items()[2] can change as things are added or removed from
the dictionary. If you're just wanting an index to step through the
dictionary, you can do something like this:

>>> for key,item in mydict.items():
   print 'key %s has a value of %s' % (key, item)

key 0 has a value of zero
key 1 has a value of one
key 2 has a value of two
key 3 has a value of three


Hope that helps,
Don



From James.Rocks@equant.com  Wed Oct 16 13:39:17 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Wed, 16 Oct 2002 13:39:17 +0100
Subject: [Tutor] Clearing A DOS Screen
Message-ID: <OF7EF35EC4.74B85EFA-ON80256C54.0045629E@equant.com>

Hi,

Running a program outside of Pythonwin I want to clear the DOS box ... I've
tried using popen('cls') but it has no effect ... any ideas?

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From James.Rocks@equant.com  Wed Oct 16 13:40:41 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Wed, 16 Oct 2002 13:40:41 +0100
Subject: [Tutor] Dictionary Elements
Message-ID: <OF20DE1333.2C3151B0-ON80256C54.004591D1@equant.com>

> >>> for key,item in mydict.items():
>    print 'key %s has a value of %s' % (key, item)
> key 0 has a value of zero
> key 1 has a value of one
> key 2 has a value of two
> key 3 has a value of three
> Hope that helps,

It does ... exactly what I wanted.

Thanks :-)

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From magnus@thinkware.se  Wed Oct 16 15:33:10 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed, 16 Oct 2002 16:33:10 +0200
Subject: [Tutor] Dictionary Elements
In-Reply-To: <022501c27509$4c67ed30$1f10ba3f@defaultcomp>
References: <OF176658DA.A003C08D-ON80256C54.0037647E@equant.com>
Message-ID: <5.1.0.14.0.20021016155117.0325f5f0@www.thinkware.se>

At 06:43 2002-10-16 -0500, Don Arnold wrote:
>You _can_ do it by calling the dictionary's items() method, which gives you
>a list of key/value pairs:
>...
>But you shouldn't really want to. A dictionary is an unordered collection,
>so the value of items()[2] can change as things are added or removed from
>the dictionary.

Don is a bit too subtle here I think. What he
should have said is:

NEVER EVER EVER EXPECT THE ELEMENTS IN A DICTIONARY
TO COME OUT IN A PARTICULAR ORDER!!!

Even if you never change your dictionary, and even
if you do hundreds of tests, and it always behave
as you expect, you shouldn't be surprised if the
order has been changed at another time when you
run the program. A dictionary is NOT a sequence.

Sure, it might work for a year, but it might fail
if you change Python version, operating system,
run it with Jython or what ever. It's just as safe
as putting three letters in a mail box on the same
day, and expect that the recipient will read them
in the order you placed them in the box.



--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Wed Oct 16 15:42:45 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed, 16 Oct 2002 16:42:45 +0200
Subject: [Tutor] ints, and long ints?
In-Reply-To: <20021016210537.321eb372.thomi@thomi.imail.net.nz>
References: <20021016074901.GA1429@i92.ryd.student.liu.se>
 <20021016201945.42a2d07a.thomi@thomi.imail.net.nz>
 <20021016074901.GA1429@i92.ryd.student.liu.se>
Message-ID: <5.1.0.14.0.20021016152213.030d5238@www.thinkware.se>

At 21:05 2002-10-16 +1300, Thomi Richards wrote:
>awesome, thanks for that...hmmmmmm.... i may have to make this project
>available on 2.2 only :-)

2.2 and up I hope...

That's not a bad choice. I think it's pretty stable by now,
and Python 2.2.x will be along and supported for a long time.
The Python Business Forum and the Snake Farm at Link=F6ping
University will make sure that relevant bugs in 2.3 etc will
be backported to 2.2, and do what they can to make sure that
people who use Python 2.2 won't have to upgrade for at least
two years or so.

Also, Red Hat upgraded to 2.2 with their latest Linux release
(8.0) so I think it's the standard version version on most
relevant platforms. The possibly worrying exception is Jython,
which is still 2.1. From 2.2.2, a bug which was problematic
for Zope and ZODB has been fixed. ZODB works well with 2.2.2
and I think the normal Zope distros will be based on 2.2.2
very soon.

As far as I'm concerned, there is no good reason to stay
with an older python version than 2.2 unless you run
Jython.

In this particular case, if you need to support older
platforms, and don't want to use longs unless they are
needed, you can always use a try block.

Besides, while python 2.2 will do...
 >>> sys.maxint + 1
2147483648L

It will still...

 >>> int('123123123123')
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
ValueError: int() literal too large: 123123123123

So, if you are reading a string from a file or some
kind of user interaction, you might still want

try:
     x =3D int(s)
except ValueError:
     x =3D long(s)

This will work equally well with older versions.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From ironman7@tbaytel.net  Wed Oct 16 16:02:30 2002
From: ironman7@tbaytel.net (Brian Moorman)
Date: Wed, 16 Oct 2002 11:02:30 -0400
Subject: [Tutor] Script Crashing in Windows 2000
Message-ID: <3DAD7F86.5A6F0F50@tbaytel.net>

I've written a python script for a fantasy hockey league I'm in, and I'm
using Python 2.1 on Mandrake Linux 8.2.  I have a friend who downloaded
Python 2.2 on his Windows 2000 and when he runs the script, it 'crashes'
after he enters a search criteria and hits enter.  The whole screen
disappears.  I'm hoping if I include the section of code I have
questions about that someone could offer advice. The following script is
stored in the same directory as two text files, "fwfha_skaters.txt" and
"fwfha_goalies.txt" and the script works well on my computer.  If
someone could tell my why it isn't working on Windows I'd be grateful.

Brian Moorman


#!/usr/bin/python

from string import *

def skater_db(search_data):
        # Header list for database results
        print "NAME" + (" " * (21 - len("NAME"))),
        print "POS" + (" " * (5 - len("POS"))),
        print "GP" + (" " * (3 - len("GP"))),
        print "MP" + (" " * (3 - len("MP"))),
        print "D/C" + (" " * (3 - len("D/C"))),
        print "N" + (" " * (3 - len("N"))),
        print "P" + (" " * (3 - len("P"))),
        print "S" + (" " * (3 - len("S"))),
        print "D" + (" " * (3 - len("D"))),
        print "SH" + (" " * (3 - len("SH"))),
        print "PC" + (" " * (3 - len("PC"))),
        print "IF" + (" " * (3 - len("IF"))),
        print "PN" + (" " * (3 - len("PN"))),
        print "IN" + (" " * (3 - len("IN"))),
        print "RT" + (" " * (3 - len("RT"))),
        print "HI" + (" " * (3 - len("HI"))),
        print "HP" + (" " * (3 - len("HP"))),
        print "VP" + (" " * (3 - len("VP"))),
        print "PK" + (" " * (3 - len("PK"))),
        print "EXTRAS"
        data = open("fwfha_skaters.txt", "r")
        for player in data.readlines():
                player_split = player.split()
                player_split[0] = player_split[0][:-1]  # To remove the
trailing comma after last name
                if search_data in player_split and player_split[0] !=
"NAME":
                        print player_split[0] + ", " + player_split[1] +
(" " * (20 - len(player_split[0] + " " + player_split[1]))),
                        print player_split[2] + (" " * (5 -
len(player_split[2]))),
                        print player_split[3] + (" " * (3 -
len(player_split[3]))),
                        print player_split[4] + (" " * (3 -
len(player_split[4]))),
                        print player_split[5] + (" " * (3 -
len(player_split[5]))),
                        print player_split[6] + (" " * (3 -
len(player_split[6]))),
                        print player_split[7] + (" " * (3 -
len(player_split[7]))),
                        print player_split[8] + (" " * (3 -
len(player_split[8]))),
                        print player_split[9] + (" " * (3 -
len(player_split[9]))),
                        print player_split[10] + (" " * (3 -
len(player_split[10]))),
                        print player_split[11] + (" " * (3 -
len(player_split[11]))),
                        print player_split[12] + (" " * (3 -
len(player_split[12]))),
                        print player_split[13] + (" " * (3 -
len(player_split[13]))),
                        print player_split[14] + (" " * (3 -
len(player_split[14]))),
                        print player_split[15] + (" " * (3 -
len(player_split[15]))),
                        print player_split[16] + (" " * (3 -
len(player_split[16]))),
                        print player_split[17] + (" " * (3 -
len(player_split[17]))),
                        print player_split[18] + (" " * (3 -
len(player_split[18]))),
                        print player_split[19] + (" " * (3 -
len(player_split[19]))),
                        player_join = " ".join(player_split[20:])
                        print player_join
        data.close()


def goalie_db(search_data):
        # Header list for database results
        print "NAME" + (" " * (21 - len("NAME"))),
        print "POS" + (" " * (5 - len("POS"))),
        print "GP" + (" " * (5 - len("GP"))),
        print "MP" + (" " * (5 - len("MP"))),
        print "IRSV%" + (" " * (6 - len("IRSV%"))),
        print "PC" + (" " * (5 - len("PC"))),
        print "RB" + (" " * (5 - len("RB")))
        data = open("fwfha_goalies.txt", "r")
        for player in data.readlines():
                player_split = player.split()
                player_split[0] = player_split[0][:-1]
                if search_data in player_split and player_split[0] !=
"NAME":
                        print player_split[0] + ", " + player_split[1] +
(" " * (20 - len(player_split[0] + " " + player_split[1]))),
                        print player_split[2] + (" " * (5 -
len(player_split[2]))),
                        print player_split[3] + (" " * (5 -
len(player_split[3]))),
                        print player_split[4] + (" " * (5 -
len(player_split[4]))),
                        print player_split[5] + (" " * (6 -
len(player_split[5]))),
                        print player_split[6] + (" " * (5 -
len(player_split[6]))),
                        print player_split[7] + (" " * (5 -
len(player_split[7])))
        data.close()

# Main program
print "\n"*50
print "FWFHA Player Database"
print "-" * 21
print
print "Please select which database to search:."
print "1.  Skaters"
print "2.  Goaltenders"

player_query = raw_input("Choose a database: ")
print

if player_query == "1":
        player_info = raw_input("Enter a search criteria, such as first
name, last name, or special rating: ")
        skater_db(player_info)
elif player_query == "2":
        player_info = raw_input("Enter a search criteria, such as first
name or last name: ")
        goalie_db(player_info)


From SWidney@ci.las-vegas.nv.us  Wed Oct 16 16:01:07 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Wed, 16 Oct 2002 08:01:07 -0700
Subject: [Tutor] Clearing A DOS Screen
Message-ID: <0E5508EBA1620743B409A2B8365DE16FDC81C9@SOVEREIGN>

> 
> Running a program outside of Pythonwin I want to clear the 
> DOS box ... I've tried using popen('cls') but it has no 
> effect ... any ideas?
> 

>From the documentation:
"""
popen(command[, mode[, bufsize]]) 
Open a pipe to or from command. The return value is an open file object
connected to the pipe, which can be read or written depending on whether
mode is 'r' (default) or 'w'. The bufsize argument has the same meaning as
the corresponding argument to the built-in open() function. The exit status
of the command (encoded in the format specified for wait()) is available as
the return value of the close() method of the file object, except that when
the exit status is zero (termination without errors), None is returned.
Availability: Unix, Windows. 
"""

That's not what you want. You want os.system():
"""
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. 
"""

Also, since os.system() returns a value (usually zero), you'll want to dump
that somewhere or it will show up as the first character on your newly
cleared screen. Try this:

>>> import os
>>> nil = os.system('cls')


Scott


From James.Rocks@equant.com  Wed Oct 16 15:12:13 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Wed, 16 Oct 2002 15:12:13 +0100
Subject: [Tutor] Clearing A DOS Screen
Message-ID: <OF6C48F337.68014A4A-ON80256C54.004DCD4F@equant.com>

Hi Scott,

> >>> import os
> >>> nil = os.system('cls')

Thanks ... that worked :-)

I do apologise, BTW, for asking so many dumb questions ... partly it's
unfamiliarity with python, partly a long time out from programming but
mainly it's not having a clue where to find everything in the various
additional modules. I guess these will all improve over time :-)

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From mongo57a@comcast.net  Wed Oct 16 17:26:09 2002
From: mongo57a@comcast.net (andy surany)
Date: Wed, 16 Oct 2002 12:26:09 -0400
Subject: [Tutor] Binding the mouse to a list using Tk.
Message-ID: <001401c27530$bc741780$2502a8c0@emily.ewndsr01.nj.comcast.net>

That's it!!!!!!! ButtonRelease is the correct action.

Thanks so much!

-Andy
-----Original Message-----
From: BELSEY, Dylan <dylan.belsey@baesystems.com>
To: 'andy surany' <mongo57a@comcast.net>; tutor@python.org
<tutor@python.org>
Date: Wednesday, October 16, 2002 12:31 AM
Subject: RE: [Tutor] Binding the mouse to a list using Tk.


> OK, here goes.... I isolated your class ScrolledList and ran it
>independently.  From testing, what I suspect is happening, is that on the
>button press ie. downwards action of the mouse button, your function
>interrogates the listbox for the currently selected item and gets the one
>that "was/is" highlighted.  I believe that the one pointed to only gets set
>after this interrogation (perhaps an artefact of the sequence of how
>events/bind and widget properties are set), therefore it will pick up the
>previous selection.
> The simple fix is to use '<ButtonRelease-1>' instead of '<Button-1>'
>for your binding, so that the listbox interrogation happens after the new
>value is set.  Even though it looks, visually, like the selection is made
on
>the downwards press, perhaps the function is run before the visual is
>set?!?!? Not sure.
> Hope this makes sense.  Good luck.
>
> Dylan
>
>
>-----Original Message-----
>From: andy surany [mailto:mongo57a@comcast.net]
>Sent: Wednesday, 16 October 2002 14:15
>To: BELSEY, Dylan; tutor@python.org
>Subject: Re: [Tutor] Binding the mouse to a list using Tk.
>
>
>Scared me there for a moment.... but no, the click works properly - that
is,
>only on the elements of the scrolled list. And yes, it is most unwise of me
>to name variables the way I have done so - so I adjusted the names for
>readability.
>
>The functionality that I am looking for is simple. Various elements of the
>list are selected for processing - which is why selectmode=EXTENDED. The
>buttons determine the specific functionality that should be executed
against
>the items selected.
>
>The program actually works perfectly - just one click behind. The first
time
>I select a list element, I get 'selected elements are []' even though I
have
>selected, for example, the third element of the list (should be 'selected
>elements are [2]' (zero justified)); if I select another element - let's
say
>list element 10, I get 'selected elements are [2]'; the next selection
>follows the same pattern ('selected elements are [9]').
>
>Attached is the complete segment of the relevant code (the full code is
just
>too much to post). Please note that I haven't gotten around to implementing
>the buttons yet (even though some code is there). I'm just trying to get
the
>mouse click logic right before I move on.
>
>class WINMENU(Frame):
>
> def update_strategy_code(self):
>
>    input1 = "'"+askstring('Enter strategist', 'Strategist Name?')+"'"
>    command = 'Select'
>    tables = ['strategy_codes']
>    columns = ['strategist','code']
>    condition = 'strategist='+str(input1)
>    sort = 'None'
>
>    sqlcmd = sql.Build_Query (command, tables, columns, condition, sort)
>
>    print sqlcmd
>
>    dbinfo = sql.Query (sqlcmd)
>
>    dis_code = []
>
>    for i in range(nrecs):
>      dis_code.append(dbinfo.code[i])
>
>    options = map((lambda i: dis_code[i]), range(nrecs))
>    ScrolledList(options)
>
>    Button(self, text='Update',
>command=self.edit_strategy_code).pack(side=LEFT)
>    Button(self, text='Delete',
>command=self.delete_strategy_code).pack(side=RIGHT)
>
>class ScrolledList(Frame):
>
>    def __init__(self, options, parent=None):
>        Frame.__init__(self, parent)
>        self.pack(expand=YES, fill=BOTH)
>        self.makeWidgets(options)
>
>    def handleList(self, event):
>        selected_elements=list(self.listbox.curselection())
>        print "selected elements are  ", selected_elements
>
>    def makeWidgets(self, options):
>        sbar = Scrollbar(self)
>        list_contents = Listbox(self, relief=SUNKEN, selectmode=EXTENDED)
>        sbar.config(command=list_contents.yview)
>        list_contents.config(yscrollcommand=sbar.set)
>        sbar.pack(side=RIGHT, fill=Y)
>        list_contents.pack(side=LEFT, expand=YES, fill=BOTH)
>        pos = 0
>
>        for label in options:
>          list_contents.insert(pos, label)
>          pos = pos+1
>
>        list_contents.bind('<Button-1>', self.handleList)
>        self.listbox = list_contents
>        label=self.listbox.get(ACTIVE)
>        print 'info=',label
>
>Thanks.
>
>Regards,
>
>Andy
>-----Original Message-----
>From: BELSEY, Dylan <dylan.belsey@baesystems.com>
>To: tutor@python.org <tutor@python.org>
>Date: Tuesday, October 15, 2002 6:52 PM
>Subject: RE: [Tutor] Binding the mouse to a list using Tk.
>
>
>>Andy,
>> I may just be me but I am still a little confused as to how this
>>code is supposed to work.  Perhaps if you post the whole code (if not too
>>large) then the list might be of more assistance. I would make the
>>recommendation of not using variable names that are the same as built-in
>>functions e.g. "list" in the makeWidgets() function.
>> If "self.listbox.get(ACTIVE)" works for you, why not use it in the
>>handleList() function as well?  Also, it would appear that you are binding
>>the whole Listbox to the mouse button 1 press ie. if you click anywhere in
>>the listbox (even on the border), then won't this kick off your handleList
>>function...is this what you require?
>> Just some thoughts.
>>
>> Dylan
>>
>>
>>-----Original Message-----
>>From: andy surany [mailto:mongo57a@comcast.net]
>>Sent: Wednesday, 16 October 2002 03:08
>>To: BELSEY, Dylan; tutor@python.org
>>Subject: Re: [Tutor] Binding the mouse to a list using Tk.
>>
>>
>>Ok, this got me a lot closer! But I'm still slightly off. Thanks for the
>>example Dylan. I stayed with Tk instead of Pmw based on the amount of code
>>already developed - and because the functions tended to work the same way.
>>But I used the "example" logic.
>>
>>So now I am using:
>>
>>    label = list(self.listbox.curselection())
>>
>>and it looks pretty good! Except: label is the previous selection - not
the
>>current. I am always behind by 1 (previous selection is item 2 from the
>>list, current is item 4, label="2").
>>
>>Here are the 2 methods. As I indicated, "label" is always one behind the
>>current position; however, label1 is correct.
>>
>>   def handleList(self, event):
>>        label=list(self.listbox.curselection())
>>        print "label is ", label
>>
>>    def makeWidgets(self, options):
>>        sbar = Scrollbar(self)
>>        list = Listbox(self, relief=SUNKEN, selectmode=EXTENDED)
>>        sbar.config(command=list.yview)                   # xlink sbar and
>>list
>>        list.config(yscrollcommand=sbar.set)              # move one moves
>>other
>>        sbar.pack(side=RIGHT, fill=Y)                     # pack
first=clip
>>last
>>        list.pack(side=LEFT, expand=YES, fill=BOTH)       # list clipped
>>first
>>        pos = 0
>>
>>        for label in options:
>>          list.insert(pos, label)
>>          pos = pos+1
>>
>>        list.bind('<Button-1>', self.handleList)          # set event
>>handler
>>        self.listbox = list
>>        label1=self.listbox.get(ACTIVE)
>>        print 'info=',label1
>>
>>
>>-----Original Message-----
>>From: BELSEY, Dylan <dylan.belsey@baesystems.com>
>>To: 'andy surany' <mongo57a@comcast.net>; tutor@python.org
>><tutor@python.org>
>>Date: Tuesday, October 15, 2002 12:47 AM
>>Subject: RE: [Tutor] Binding the mouse to a list using Tk.
>>
>>
>>>Hi Andy,
>>> In the interest of code sharing, I have attached a file which I
>>>believe contains some of the operations that you are looking to perform.
>>It
>>>is a cut down version of a class I wrote for the current system I am
>>working
>>>on.  In its original form it obtains signals from a data server and
>>displays
>>>them ready for selection.  The user then selects signals from the
>left-hand
>>>box, presses the appropriate button ('->') and the signal appears in the
>>>selected signals box, on the right hand side.  This window was to aid the
>>>user in selecting specific signals for monitoring.  I have kept the
>>relevant
>>>functionality in the file.
>>> I am currently running this under WinNT.  I have also made the file
>>>self running, so all you have to do is get a DOS prompt in the directory
>>>where you have saved it and then type "example.py" or "python
example.py".
>>> Two windows will appear.  Just ignore the first one (but don't close
>>>it until you are finished), for this exercise.  It is the root window,
>>which
>>>is important/necessary, but I have chosen not to use it here.
>>> So anyway, run it and experiment with it and then take a look at the
>>>code, from which I hope you can get some ideas and help.
>>> If you have any questions, please feel free to ask.
>>>
>>> HTH,
>>> Dylan
>>>
>>>
>>>PS: By the ways Tutors, if you see any glaring deficiencies, problems,
>etc.
>>>in the code pls. feel free to comment.  However, I'm not too interested
in
>>a
>>>code review at this point in time :)
>>>
>>>
>>>
>>>
>>>-----Original Message-----
>>>From: andy surany [mailto:mongo57a@comcast.net]
>>>Sent: Tuesday, 15 October 2002 13:50
>>>To: BELSEY, Dylan; tutor@python.org
>>>Subject: Re: [Tutor] Binding the mouse to a list using Tk.
>>>
>>>
>>>Thanks Dylan. I am using the listbox methods. And everything works. If I
>>put
>>>the list.bind in the same method that calls the scrolled list, I even get
>a
>>>response when I move the cursor to list selection
>>(listbox.cursorselection).
>>>The problem is that I need the selected list item to be independent of
the
>>>mouse (mouse is depressing a button which gets the original highlighted
>>list
>>>item). It's almost like I'm losing context.
>>>
>>>I haven't looked at getcurselection - which I will do now. I still think
>>>that my logic is correct - but I haven't placed it in the correct spot.
>>>
>>>Regards,
>>>
>>>Andy
>>>-----Original Message-----
>>>From: BELSEY, Dylan <dylan.belsey@baesystems.com>
>>>To: tutor@python.org <tutor@python.org>
>>>Date: Monday, October 14, 2002 6:59 PM
>>>Subject: RE: [Tutor] Binding the mouse to a list using Tk.
>>>
>>>
>>>>    Only had a brief look at your problem, but I believe that the
Tkinter
>>>>widgets Listbox and ScrolledListBox may be what you need (and save you
>>>quite
>>>>a bit of time).  You can use the Listbox methods from within the
>>>>ScrolledListbox object as well.  You could then possibly associate a
>>>>function with your button which gets the currently selected item.
>>>>getcurselection() returns the text while the curselection() will return
>>the
>>>>index.
>>>>    A lot of this is quite similar to what your code has proposed but
>>using
>>>>the built-in widgets and their functions may shed some light on an
easier
>>>>solution.
>>>>
>>>>    HTH,
>>>>        Dylan
>>>>
>>>>
>>>>-----Original Message-----
>>>>From: andy surany [mailto:mongo57a@comcast.net]
>>>>Sent: Tuesday, 15 October 2002 04:20
>>>>To: tutor@python.org
>>>>Subject: [Tutor] Binding the mouse to a list using Tk.
>>>>
>>>>
>>>>Hi all!
>>>>
>>>>What I want to do is use a button to capture the position/value of the
>>>>
>>>>selected item in a scrolled list. So the user selects the item in the
>list
>>>>
>>>>with a single click of the left mouse button and then clicks a button.
>>>>
>>>>Should be easy - I'm just not getting it......
>>>>
>>>>
>>>>
>>>>I'm using Tkinter. I Created a class (ScrolledList) for a scrolled list
>>>>which works fine. Created
>>>>
>>>>another class (aaaaa) which populates the list - and it works fine.
>>Created
>>>>
>>>>a handler under ScrolledList (handleList) which should trap the results
>of
>>>>
>>>>the bind (makeWidgets). Right now, all I'm trying to do is just print
out
>>>>
>>>>the value (just testing..) - but my logic is incorrect (actually, I
think
>>>>
>>>>that the logic may be correct - it's just in the wrong place...).
>>>>
>>>>Here is a synopsis of the code. The "...." is non-relevant code which I
>>>have
>>>>removed for simplification.
>>>>
>>>>
>>>>
>>>>class ScrolledList(Frame):
>>>>
>>>>    def __init__(self, options, parent=None):
>>>>
>>>>        ........
>>>>
>>>>        self.makeWidgets(options)
>>>>
>>>>    def handleList(self, event):
>>>>
>>>>        index = self.listbox.curselection()
>>>>
>>>>        label = self.listbox.get(index)
>>>>
>>>>        print "label is ", label
>>>>
>>>>    def makeWidgets(self, options):
>>>>
>>>>        ........
>>>>
>>>>        list.bind('<Button-1>', self.handleList)
>>>>
>>>>Class aaaaa
>>>>
>>>>    def update_strategy_code(self):
>>>>
>>>>        ..........
>>>>
>>>>        ScrolledList(options)
>>>>
>>>>        Button(self, text='Update',
>>>>
>>>>        command=self.edit_strategy_code).pack(side=LEFT)
>>>>
>>>>    def edit_strategy_code(self):
>>>>
>>>>        label=self.listbox.get(ACTIVE)
>>>>
>>>>        print 'info2=',label
>>>>
>>>> TIA!
>>>>
>>>>Andy (mongo57a@comcast.net)
>>>>
>>>>
>>>>_______________________________________________
>>>>Tutor maillist  -  Tutor@python.org
>>>>http://mail.python.org/mailman/listinfo/tutor
>>>
>>>
>>
>>_______________________________________________
>>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 James.Rocks@equant.com  Wed Oct 16 15:27:55 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Wed, 16 Oct 2002 15:27:55 +0100
Subject: [Tutor] SMTP Mail
Message-ID: <OF000DE74E.5E09CB2F-ON80256C54.004EBD80@equant.com>

More dumb questions I'm afraid ... I do look up in the docs first ...
honest! :-)

OK ... I'm trying to make SMTP Mail work (module smtplib) and, well, it
does ... sort of.

This is the program I'm using to test it:

      import smtplib

      sToAddress = "james.rocks@equant.com"
      sFromAddress = "james.rocks@equant.com"
      sMessage = "Test Message"

      sSMTPServer = smtplib.SMTP(<SMTPSERVER>)
      sSMTPServer.set_debuglevel(1)
      sSMTPServer.sendmail(sFromAddress, sToAddress, sMessage)
      sSMTPServer.quit()

It's essentially copied direct from the docs without all the fancy bits ...
I was planning to put it in a function so I could call it with a from & to
address and a message. As it's a warning that's really all that's needed
though a body paramater might be nice later.

Anyway it worked, it mailed me which is good but instead of getting what I
expected (a message from me, to me entitled "Test Message") I got a message
with no title and "Message" in the body and I don't know enough about SMTP
mail to figure why?

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From SWidney@ci.las-vegas.nv.us  Wed Oct 16 16:29:51 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Wed, 16 Oct 2002 08:29:51 -0700
Subject: [Tutor] Clearing A DOS Screen
Message-ID: <0E5508EBA1620743B409A2B8365DE16FDC81CC@SOVEREIGN>

> I do apologise, BTW, for asking so many dumb questions ... partly it's
> unfamiliarity with python, partly a long time out from programming but
> mainly it's not having a clue where to find everything in the various
> additional modules. I guess these will all improve over time :-)
> 

No apologies -- questions are the raison d'etre of this list....


=^)
Scott


From alan.gauld@bt.com  Wed Oct 16 16:58:52 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 16 Oct 2002 16:58:52 +0100
Subject: [Tutor] Clearing A DOS Screen
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C99A@mbtlipnt02.btlabs.bt.co.uk>

> Running a program outside of Pythonwin I want to clear the 
> DOS box ... I've tried using popen('cls') but it has no effect 

Since CLS doesn't return anything just use os.system('CLS')

Also CLS may be a builtin command of COMMAND.COM in which 
case you need to pass something like:

os.system('COMMAND.COM /C CLS')

But I think from memory CLS does work...

Alan g


From alan.gauld@bt.com  Wed Oct 16 16:46:44 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 16 Oct 2002 16:46:44 +0100
Subject: [Tutor] Dictionary Elements
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C998@mbtlipnt02.btlabs.bt.co.uk>

> If I have a dictionary of 6 tuples e.g.
> 
> {'LONA18': 'GREEN', 'LONTSATL19': 'GREEN', 'LONTSGLA01': 
> 'GREEN', 'LONA15':
> 'GREEN', 'LONA14': 'GREEN', 'LONA17': 'GREEN'}
> 

Thats not a dictionary of tuples. Its a dictionary where 
all the keys have the same value!

> ... and I want to read BOTH key and value by numerical 
> reference e.g. print dictionary[1] (I know this is wrong) 
> prints:
> 
> 'LONA18'
> 
> How do I do it?

Use a list of tuples?

L = [('LONA18','GREEN'),('LONTSATL19','GREEN'),....('LONA17','GREEN')]

However since this looks like a status record I suspect you don't 
want tuples anyway since they are immutable - you can't update 
the GREEN to RED say...

So I'd really go for a list of lists:

L = [['LONA18','GREEN'],['LONTSATL19','GREEN'],....['LONA17','GREEN']] 

Now you can get the tuple:

L[n]

Or the 'key':

L[n][0]

or the 'value':

L[n][1]

Whats more tricky is now determining whether a name is in 
the list

if 'LON2A' in L:   - won't work.

If you need that consider a class which combines a dictionary 
holding the names and the index of the tuple within the list.
Use the class methods to maintain sync between the two...

Of course your real need may be woidely different to my 
assumptions in which case ignore my ramblings! :-)

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


From alan.gauld@bt.com  Wed Oct 16 16:55:24 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 16 Oct 2002 16:55:24 +0100
Subject: [Tutor] tkinter and menu
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C999@mbtlipnt02.btlabs.bt.co.uk>

> This works fine, but i've modified my callback function help so that
> depending upon the paramter it displays help on given paramter.
> 
> def help(topic):
>   """ depending upont topic display help"""
>   statements
>       ..
>   statements
>      
> My question is how do i pass parameter to callback function help() ??
> doing .add_command(label="ok", command=help("about")) doesn't work.

There are a few ways to do it - one is to use bind() 
instead of 'command=' then pass a custom event, pesonally 
I find that messy and prefer to use a lambda(**) in 
the command= section.

def helpHandler(context):
   # ...do it here...

Button(parent,command=lambda ctx=globalContext: helpHandler(ctx))

This makes the variable globalContext the default value for the

lambda which then passes it to the helpHandler. That works 
provided the context is different for each Button you define.

If you need to pass the context dynamically (and I think in 
this case you do) then its a case of defining a global variable 
which you update with current context and then access from 
within helpHandler. Not good programming practice but about all 
you can do...

Of course if your program is using classes it becomes better 
coz the context variable becomes a class variable which tidies 
things up a bit!

(**)
If you aren't familiar with lambda take a look at the 
Functional programming topic in my online tutor

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


From alan.gauld@bt.com  Wed Oct 16 17:22:20 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 16 Oct 2002 17:22:20 +0100
Subject: [Tutor] Clearing A DOS Screen
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C99C@mbtlipnt02.btlabs.bt.co.uk>

> I do apologise, BTW, for asking so many dumb questions ... partly it's
> unfamiliarity with python, partly a long time out from programming but
> mainly it's not having a clue where to find everything in the various
> additional modules. I guess these will all improve over time :-)

One of the beauties of Python is how all this cool stuff 
exists in the library. The problem is knowing whats there 
and how to find it! Nobody has cracked that yet... its 
just experience.

Alan G


From James.Rocks@Equant.com  Wed Oct 16 16:22:58 2002
From: James.Rocks@Equant.com (James.Rocks@Equant.com)
Date: Wed, 16 Oct 2002 16:22:58 +0100
Subject: [Tutor] SMTP Mail
Message-ID: <OF6EA73158.4DE9635C-ON80256C54.00543ADE@equant.com>

More on this:

> Anyway it worked, it mailed me which is good but instead of getting what
I
expected (a message from me, to me entitled "Test Message") I got a message
with no title and "Message" in the body and I don't know enough about SMTP
mail to figure why?

I changed the message variable (sMessage) to "Who's This From?" and got a
message the same as before but with the body text "This From?" which I
think is very strange!

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From James.Rocks@equant.com  Wed Oct 16 16:30:12 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Wed, 16 Oct 2002 16:30:12 +0100
Subject: [Tutor] SMTP Mail (Workaround)
Message-ID: <OFDC03673C.0E2E8B16-ON80256C54.0054F3F2@equant.com>

> I changed the message variable (sMessage) to "Who's This From?" and got a
> message the same as before but with the body text "This From?" which I
> think is very strange!

Even more on this:

If I make the first two characters of the message variable (sMessage) to "
\n" the rest of the message is printed correctly ... now all I need is a
way to fill in the message subject. Time to go searching on the net
methinks :-)

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ
Phone:             0207-5226856
Fax:                   0207-5126087
Mobile Phone:     07771-767405
http://www.equant.com

This e-mail (including any attachments) is confidential and may be legally
privileged.  If you are not an intended recipient or an authorized
representative of an intended recipient, you are prohibited from using,
copying or distributing the information in this e-mail or its attachments.
If you have received this e-mail in error, please notify the sender
immediately by return e-mail and delete all copies of this message and any
attachments.  Thank you.



From alan.gauld@bt.com  Wed Oct 16 17:32:09 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 16 Oct 2002 17:32:09 +0100
Subject: [Tutor] SMTP Mail
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C99D@mbtlipnt02.btlabs.bt.co.uk>

CAVEAT - I've never used smtplib in anger yet...

>       import smtplib
> 
>       sToAddress = "james.rocks@equant.com"
>       sFromAddress = "james.rocks@equant.com"
>       sMessage = "Test Message"
> 
> It's essentially copied direct from the docs without all the 
> fancy bits ...

One fancy bit is the message format:

# Add the From: and To: headers at the start!
msg = ("From: %s\r\nTo: %s\r\n\r\n"
       % (fromaddr, string.join(toaddrs, ", ")))

That basically puts the From/To headers that you see when you receive the
message in frontb of the text. I think you need to add a Sunbject field:

# Add the From: and To: headers at the start!
subj = "Here is the subject field"
msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n"
       % (fromaddr, string.join(toaddrs, ", "),subj))

At least thats how I read it....

> got a message with no title and "Message" in the body 

I assume when you say 'title' you mean the subject field?

Dunno if I'm right, but might be worth a try if nobody
comes up with a more authoratative answer!

Alan g.


From alan.gauld@bt.com  Wed Oct 16 17:20:08 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 16 Oct 2002 17:20:08 +0100
Subject: [Tutor] Script Crashing in Windows 2000
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C99B@mbtlipnt02.btlabs.bt.co.uk>

> after he enters a search criteria and hits enter.  The whole screen
> disappears.  

Dunno whats causing that but one point is that you can make 
your code much more readable and faster by using format 
strings instead of that horrible space multiplication/subtraction trick:

        print "NAME" + (" " * (21 - len("NAME"))),

# force 21 character left justified string
print "%21s", % "NAME"	  


>  print player_split[0] + ", " + player_split[1] + 
>   (" " * (20 - len(player_split[0] + " " + player_split[1]))),

nm = "%s %s" % (player_split[0],player_split[1])  #names with a space
print "%-21s" % nm    # left justify to desired length.
  
Or combining those:

print "%21s" % ("%s %s" % (player_split[0],player_split[1]))

But the latter is just as obscure IMHO as all the 
arithmetic(albeit faster!)

I suspect the next set of prints could maybe be parameterized 
into a loop too...

Sorry to be picky but all those parens were hurting my head!

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


From francois.granger@free.fr  Wed Oct 16 17:50:56 2002
From: francois.granger@free.fr (Fran=?ISO-8859-1?B?5w==?=ois Granger)
Date: Wed, 16 Oct 2002 18:50:56 +0200
Subject: [Tutor] SMTP Mail
In-Reply-To: <OF000DE74E.5E09CB2F-ON80256C54.004EBD80@equant.com>
Message-ID: <B9D36590.598AA%francois.granger@free.fr>

on 16/10/02 16:27, James.Rocks@equant.com at James.Rocks@equant.com wrote:

> OK ... I'm trying to make SMTP Mail work (module smtplib) and, well, it
> does ... sort of.
> 
> This is the program I'm using to test it:
> 
>     import smtplib
> 
>     sToAddress = "james.rocks@equant.com"
>     sFromAddress = "james.rocks@equant.com"
>     sMessage = "Test Message"
> 
>     sSMTPServer = smtplib.SMTP(<SMTPSERVER>)
>     sSMTPServer.set_debuglevel(1)
>     sSMTPServer.sendmail(sFromAddress, sToAddress, sMessage)
>     sSMTPServer.quit()

To create the mail message itself (your sMessage variable), use either the
RFC822 lib or the new email lib.......

-- 
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 terjeja@hotmail.com  Wed Oct 16 18:00:55 2002
From: terjeja@hotmail.com (Terje Johan Abrahamsen)
Date: Wed, 16 Oct 2002 17:00:55 +0000
Subject: [Tutor] putting together commands
Message-ID: <F204kyPzGNsokLQ8aZR0000003f@hotmail.com>

I am using the re module to find some text in a file. But, I do want the 
program to find different things each time. As an example I have done this:

rrr = 'tore er en hund'

I want to find whether the text has re after to.

m = re.search('(?<=to)nd', rrr)

And the program finds it. But, if I want to find 50 things, and want to find 
50 different things each time, it will be very timeconsuming to rewrite each 
one. So I write:

p = 're.search(\'(?<='
q = 'hu'
r = ')nd\', rrr)'
a = p+q+r

And I change the q 50 times, or uses it as the input in def find(q)

But, as I expected, q is a string. I cannot run a string. How do I come 
around this problem? Any suggestions?





_________________________________________________________________
Internet access plans that fit your lifestyle -- join MSN. 
http://resourcecenter.msn.com/access/plans/default.asp



From shalehperry@attbi.com  Wed Oct 16 18:42:36 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Wed, 16 Oct 2002 10:42:36 -0700
Subject: [Tutor] putting together commands
In-Reply-To: <F204kyPzGNsokLQ8aZR0000003f@hotmail.com>
References: <F204kyPzGNsokLQ8aZR0000003f@hotmail.com>
Message-ID: <200210161042.36705.shalehperry@attbi.com>

On Wednesday 16 October 2002 10:00, Terje Johan Abrahamsen wrote:
> I am using the re module to find some text in a file. But, I do want th=
e
> program to find different things each time. As an example I have done t=
his:
>
> rrr =3D 'tore er en hund'
>
> I want to find whether the text has re after to.
>
> m =3D re.search('(?<=3Dto)nd', rrr)
>
> And the program finds it. But, if I want to find 50 things, and want to
> find 50 different things each time, it will be very timeconsuming to
> rewrite each one. So I write:
>
> p =3D 're.search(\'(?<=3D'
> q =3D 'hu'
> r =3D ')nd\', rrr)'
> a =3D p+q+r
>
> And I change the q 50 times, or uses it as the input in def find(q)
>

def textSearch(q, input):
  return re.search(r'(?<=3D%s)nd' % q, input) # use a string formatter (-=
:

textSearch('hu', rrr)
textSearch('to', rrr)


From jeff@ccvcorp.com  Wed Oct 16 19:15:13 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Wed, 16 Oct 2002 11:15:13 -0700
Subject: [Tutor] Script Crashing in Windows 2000
References: <3DAD7F86.5A6F0F50@tbaytel.net>
Message-ID: <3DADACB1.8E276D94@ccvcorp.com>


Brian Moorman wrote:

> I've written a python script for a fantasy hockey league I'm in, and I'm
> using Python 2.1 on Mandrake Linux 8.2.  I have a friend who downloaded
> Python 2.2 on his Windows 2000 and when he runs the script, it 'crashes'
> after he enters a search criteria and hits enter.  The whole screen
> disappears.

I think that the script is *not* crashing -- it's just finishing and closing
the window, before you can actually read anything.  I'm presuming that your
friend is running this script either through a shortcut on the desktop or
through double-clicking the script in Windows Explorer.  That opens a window
that exists only as long as the script is running, and once the script
finishes, Windows "helpfully" closes the window immediately.

There's a couple of solutions to this.  Your friend can start a command
prompt window by himself, and then run the script within that.  Since the
command window exists independently of the script, it won't close right away
when the script finishes.  You can also add, right at the end of your
script, a call such as:

foo = raw_input("Press Enter to terminate this program")

This will prevent your script from ending until after some input is
retrieved -- which happens as soon as you press enter.  At that point, the
script ends and the window closes.

There are other ways around this issue, as well, but these two are the
simplest and most straightforward.

Jeff Shannon
Technician/Programmer
Credit International





From ATrautman@perryjudds.com  Wed Oct 16 19:17:09 2002
From: ATrautman@perryjudds.com (Alan Trautman)
Date: Wed, 16 Oct 2002 13:17:09 -0500
Subject: [Tutor] Script Crashing in Windows 2000
Message-ID: <0BA95581EDA7D611841B00A0C9AD25DD2B58AF@mail.pjinet.com>

Brian,

Are you converting the Linux/Unix file format to Windows. i.e. \n the \r\n.
The is a Unix to windows converter on your Linux box if you did the default
install. It could be improper line termination causing it to fail on any
windows box.

Alan

-----Original Message-----
From: Brian Moorman [mailto:ironman7@tbaytel.net]
Sent: Wednesday, October 16, 2002 10:03 AM
To: Python Tutor
Subject: [Tutor] Script Crashing in Windows 2000


I've written a python script for a fantasy hockey league I'm in, and I'm
using Python 2.1 on Mandrake Linux 8.2.  I have a friend who downloaded
Python 2.2 on his Windows 2000 and when he runs the script, it 'crashes'
after he enters a search criteria and hits enter.  The whole screen
disappears.  I'm hoping if I include the section of code I have
questions about that someone could offer advice. The following script is
stored in the same directory as two text files, "fwfha_skaters.txt" and
"fwfha_goalies.txt" and the script works well on my computer.  If
someone could tell my why it isn't working on Windows I'd be grateful.

Brian Moorman


#!/usr/bin/python

from string import *

def skater_db(search_data):
        # Header list for database results
        print "NAME" + (" " * (21 - len("NAME"))),
        print "POS" + (" " * (5 - len("POS"))),
        print "GP" + (" " * (3 - len("GP"))),
        print "MP" + (" " * (3 - len("MP"))),
        print "D/C" + (" " * (3 - len("D/C"))),
        print "N" + (" " * (3 - len("N"))),
        print "P" + (" " * (3 - len("P"))),
        print "S" + (" " * (3 - len("S"))),
        print "D" + (" " * (3 - len("D"))),
        print "SH" + (" " * (3 - len("SH"))),
        print "PC" + (" " * (3 - len("PC"))),
        print "IF" + (" " * (3 - len("IF"))),
        print "PN" + (" " * (3 - len("PN"))),
        print "IN" + (" " * (3 - len("IN"))),
        print "RT" + (" " * (3 - len("RT"))),
        print "HI" + (" " * (3 - len("HI"))),
        print "HP" + (" " * (3 - len("HP"))),
        print "VP" + (" " * (3 - len("VP"))),
        print "PK" + (" " * (3 - len("PK"))),
        print "EXTRAS"
        data = open("fwfha_skaters.txt", "r")
        for player in data.readlines():
                player_split = player.split()
                player_split[0] = player_split[0][:-1]  # To remove the
trailing comma after last name
                if search_data in player_split and player_split[0] !=
"NAME":
                        print player_split[0] + ", " + player_split[1] +
(" " * (20 - len(player_split[0] + " " + player_split[1]))),
                        print player_split[2] + (" " * (5 -
len(player_split[2]))),
                        print player_split[3] + (" " * (3 -
len(player_split[3]))),
                        print player_split[4] + (" " * (3 -
len(player_split[4]))),
                        print player_split[5] + (" " * (3 -
len(player_split[5]))),
                        print player_split[6] + (" " * (3 -
len(player_split[6]))),
                        print player_split[7] + (" " * (3 -
len(player_split[7]))),
                        print player_split[8] + (" " * (3 -
len(player_split[8]))),
                        print player_split[9] + (" " * (3 -
len(player_split[9]))),
                        print player_split[10] + (" " * (3 -
len(player_split[10]))),
                        print player_split[11] + (" " * (3 -
len(player_split[11]))),
                        print player_split[12] + (" " * (3 -
len(player_split[12]))),
                        print player_split[13] + (" " * (3 -
len(player_split[13]))),
                        print player_split[14] + (" " * (3 -
len(player_split[14]))),
                        print player_split[15] + (" " * (3 -
len(player_split[15]))),
                        print player_split[16] + (" " * (3 -
len(player_split[16]))),
                        print player_split[17] + (" " * (3 -
len(player_split[17]))),
                        print player_split[18] + (" " * (3 -
len(player_split[18]))),
                        print player_split[19] + (" " * (3 -
len(player_split[19]))),
                        player_join = " ".join(player_split[20:])
                        print player_join
        data.close()


def goalie_db(search_data):
        # Header list for database results
        print "NAME" + (" " * (21 - len("NAME"))),
        print "POS" + (" " * (5 - len("POS"))),
        print "GP" + (" " * (5 - len("GP"))),
        print "MP" + (" " * (5 - len("MP"))),
        print "IRSV%" + (" " * (6 - len("IRSV%"))),
        print "PC" + (" " * (5 - len("PC"))),
        print "RB" + (" " * (5 - len("RB")))
        data = open("fwfha_goalies.txt", "r")
        for player in data.readlines():
                player_split = player.split()
                player_split[0] = player_split[0][:-1]
                if search_data in player_split and player_split[0] !=
"NAME":
                        print player_split[0] + ", " + player_split[1] +
(" " * (20 - len(player_split[0] + " " + player_split[1]))),
                        print player_split[2] + (" " * (5 -
len(player_split[2]))),
                        print player_split[3] + (" " * (5 -
len(player_split[3]))),
                        print player_split[4] + (" " * (5 -
len(player_split[4]))),
                        print player_split[5] + (" " * (6 -
len(player_split[5]))),
                        print player_split[6] + (" " * (5 -
len(player_split[6]))),
                        print player_split[7] + (" " * (5 -
len(player_split[7])))
        data.close()

# Main program
print "\n"*50
print "FWFHA Player Database"
print "-" * 21
print
print "Please select which database to search:."
print "1.  Skaters"
print "2.  Goaltenders"

player_query = raw_input("Choose a database: ")
print

if player_query == "1":
        player_info = raw_input("Enter a search criteria, such as first
name, last name, or special rating: ")
        skater_db(player_info)
elif player_query == "2":
        player_info = raw_input("Enter a search criteria, such as first
name or last name: ")
        goalie_db(player_info)

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


From magnus@thinkware.se  Wed Oct 16 20:03:48 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed, 16 Oct 2002 21:03:48 +0200
Subject: [Tutor] Script Crashing in Windows 2000
In-Reply-To: <0BA95581EDA7D611841B00A0C9AD25DD2B58AF@mail.pjinet.com>
Message-ID: <5.1.0.14.0.20021016210141.02fe1138@www.thinkware.se>

At 13:17 2002-10-16 -0500, Alan Trautman wrote:
>Are you converting the Linux/Unix file format to Windows. i.e. \n the \r\n.
>The is a Unix to windows converter on your Linux box if you did the default
>install. It could be improper line termination causing it to fail on any
>windows box.

No. That's not a problem for Python. I think the
solution is as simple as Jeff suggested.

I run exactly the same scripts from Linux and Windows
without problems.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Wed Oct 16 20:11:30 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed, 16 Oct 2002 21:11:30 +0200
Subject: [Tutor] putting together commands
In-Reply-To: <F204kyPzGNsokLQ8aZR0000003f@hotmail.com>
Message-ID: <5.1.0.14.0.20021016210749.03112b58@www.thinkware.se>

At 17:00 2002-10-16 +0000, Terje Johan Abrahamsen wrote:
>But, as I expected, q is a string. I cannot run a string. How do I come=20
>around this problem? Any suggestions?

Sean is right here. You shouldn't try to run a string
*in this case*. There are times when you want that though,
and it's easy:

 >>> a =3D "print 'Hello '*5"
 >>> exec(a)
Hello Hello Hello Hello Hello

You can also evaluate expressions:

 >>> e =3D "4*5**3"
 >>> r =3D eval(e)
 >>> print r
500


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From James.Rocks@equant.com  Wed Oct 16 19:13:43 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Wed, 16 Oct 2002 19:13:43 +0100
Subject: [Tutor] SMTP Mail
Message-ID: <OF7539747F.49015570-ON80256C54.00640FB5@equant.com>

Hi Alan,

> subj = "Here is the subject field"
> msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n"
>        % (fromaddr, string.join(toaddrs, ", "),subj))

I would never have thought of that ... it's amazing!

Thanks!

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From David Lawrence" <dlphone@bellsouth.net  Wed Oct 16 21:43:12 2002
From: David Lawrence" <dlphone@bellsouth.net (David Lawrence)
Date: Wed, 16 Oct 2002 16:43:12 -0400
Subject: [Tutor] cannot save changes to dictionary in a shelve file
Message-ID: <001701c27554$a54c2a10$c100a8c0@dlawrence>

This is a multi-part message in MIME format.

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

Please help - if you'd like to skip my long intro, see my IDLE session =
capture at the end of this message. At the end of the session, you can =
see that although I added '4:"proj004"' to the end of the dictionary, =
the dictionary doesn't contain that pair after I close & open the shelve =
file. Why?

I am learning Python pretty much as my first programming language. I'm a =
working technical writer who is seeking to expand my abilities. Years =
ago I attempted to learn C++ on my own using "Teach Yourself ..." books, =
but I became a bit overwhelmed when it came to pointers (probably should =
have sought out a programmer for some help!!) and stopped.=20

I am very pleased with Python so far ... the syntax is concise, the =
documentation is plentiful and thorough, and it's Open Source. But, I'm =
having a problem with the "shelve" module. As a learning project I am =
attempting to put together a simple one-user database of projects in =
Python code. I'd like to make it object-oriented - I've written some =
code w/a "Project" class (not included) to create project objects with - =
but I'd settle for a simple searchable collection of dictionaries & =
lists if I could just figure out the persistence thing.=20

Excuse the long code example. Oviously, I created a shelve database =
file, and created a new dictionary assigned to the "projects" key. But I =
can't update the dictionary and make the shelve file retain it! At the =
end of the example, I added the key:value pair '4:"proj004" to the end =
of the dictionary, but the dictionary doesn't contain that pair after I =
close & open the shelve file.

What am I doing wrong?=20

I've also tried this with a simple list of integers instead of a =
dictionary, and it does the same thing.

Thanks for your help,

Dave

-------------------------session snapshot =
------------------------------------

Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32

Type "copyright", "credits" or "license" for more information.

IDLE 0.8 -- press F1 for help

>>> import shelve

>>> db =3D shelve.open("projectsdb","c")

>>> db.keys()

[]

>>> db["projects"] =3D {1:"proj001",2:"proj002",3:"proj003"}

>>> db["otherlist"] =3D (5,7,9,10)

>>> db.close()

>>> db.keys()

Traceback (most recent call last):

File "<pyshell#6>", line 1, in ?

db.keys()

File "C:\Program Files\Python22\lib\shelve.py", line 56, in keys

return self.dict.keys()

AttributeError: 'int' object has no attribute 'keys'

>>> db =3D shelve.open("projectsdb","c")

>>> db.keys()

['projects', 'otherlist']

>>> projects =3D db["projects"]

>>> projects

{1: 'proj001', 2: 'proj002', 3: 'proj003'}

>>> projects[4] =3D "proj004"

>>> projects

{1: 'proj001', 2: 'proj002', 3: 'proj003', 4: 'proj004'}

>>> db.close()

>>> db =3D shelve.open("projectsdb","c")

>>> db.keys()

['projects', 'otherlist']

>>> projects =3D db["projects"]

>>> projects

{1: 'proj001', 2: 'proj002', 3: 'proj003'}

>>>=20

------=_NextPart_000_0014_01C27533.1E1C0590
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 5.50.4915.500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2><FONT size=3D2>
<P>Please help -&nbsp;if you'd like to skip my long intro,&nbsp;see my =
IDLE=20
session capture&nbsp;at the end of this message. At the end of the =
session, you=20
can see that although I added '4:"proj004"' to the end of the =
dictionary, the=20
dictionary doesn't contain that pair after I close &amp; open the shelve =
file.=20
Why?</P>
<P>I am learning Python pretty much as my first programming language. =
I'm a=20
working technical writer who is seeking to expand my abilities. Years =
ago I=20
attempted to learn C++ on my own using "Teach Yourself ..." books, but I =
became=20
a bit overwhelmed when it came to pointers (probably should have sought =
out a=20
programmer for some help!!) and stopped. </P>
<P>I am very pleased with Python so far ... the syntax is concise, the=20
documentation is plentiful and thorough, and it's Open Source. But, I'm =
having a=20
problem with the "shelve" module. As a learning project I am attempting =
to put=20
together a simple one-user database of projects in Python code. I'd like =
to make=20
it object-oriented - I've written some code w/a "Project" class (not =
included)=20
to create project objects with - but I'd settle for a simple searchable=20
collection of dictionaries &amp; lists if I could just figure out the=20
persistence thing. </P>
<P>Excuse the long code example. Oviously, I created a shelve database =
file, and=20
created a new dictionary assigned to the "projects" key. But I can't =
update the=20
dictionary and make the shelve file retain it! At the end of the =
example, I=20
added the key:value pair '4:"proj004" to the end of the dictionary, but =
the=20
dictionary doesn't contain that pair after I close &amp; open the shelve =

file.</P>
<P>What am I doing wrong? </P>
<P>I've also tried this with a simple list of integers instead of a =
dictionary,=20
and it does the same thing.</P>
<P>Thanks for your help,</P>
<P>Dave</P>
<P>-------------------------session snapshot=20
------------------------------------</P>
<P>Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit (Intel)] on =
win32</P>
<P>Type "copyright", "credits" or "license" for more information.</P>
<P>IDLE 0.8 -- press F1 for help</P>
<P>&gt;&gt;&gt; import shelve</P>
<P>&gt;&gt;&gt; db =3D shelve.open("projectsdb","c")</P>
<P>&gt;&gt;&gt; db.keys()</P>
<P>[]</P>
<P>&gt;&gt;&gt; db["projects"] =3D =
{1:"proj001",2:"proj002",3:"proj003"}</P>
<P>&gt;&gt;&gt; db["otherlist"] =3D (5,7,9,10)</P>
<P>&gt;&gt;&gt; db.close()</P>
<P>&gt;&gt;&gt; db.keys()</P>
<P>Traceback (most recent call last):</P>
<P>File "&lt;pyshell#6&gt;", line 1, in ?</P>
<P>db.keys()</P>
<P>File "C:\Program Files\Python22\lib\shelve.py", line 56, in keys</P>
<P>return self.dict.keys()</P>
<P>AttributeError: 'int' object has no attribute 'keys'</P>
<P>&gt;&gt;&gt; db =3D shelve.open("projectsdb","c")</P>
<P>&gt;&gt;&gt; db.keys()</P>
<P>['projects', 'otherlist']</P>
<P>&gt;&gt;&gt; projects =3D db["projects"]</P>
<P>&gt;&gt;&gt; projects</P>
<P>{1: 'proj001', 2: 'proj002', 3: 'proj003'}</P>
<P>&gt;&gt;&gt; projects[4] =3D "proj004"</P>
<P>&gt;&gt;&gt; projects</P>
<P>{1: 'proj001', 2: 'proj002', 3: 'proj003', 4: 'proj004'}</P>
<P>&gt;&gt;&gt; db.close()</P>
<P>&gt;&gt;&gt; db =3D shelve.open("projectsdb","c")</P>
<P>&gt;&gt;&gt; db.keys()</P>
<P>['projects', 'otherlist']</P>
<P>&gt;&gt;&gt; projects =3D db["projects"]</P>
<P>&gt;&gt;&gt; projects</P>
<P>{1: 'proj001', 2: 'proj002', 3: 'proj003'}</P>
<P>&gt;&gt;&gt; </P></FONT></FONT></DIV></BODY></HTML>

------=_NextPart_000_0014_01C27533.1E1C0590--



From kalle@lysator.liu.se  Wed Oct 16 22:27:45 2002
From: kalle@lysator.liu.se (Kalle Svensson)
Date: Wed, 16 Oct 2002 23:27:45 +0200
Subject: [Tutor] cannot save changes to dictionary in a shelve file
In-Reply-To: <001701c27554$a54c2a10$c100a8c0@dlawrence>
References: <001701c27554$a54c2a10$c100a8c0@dlawrence>
Message-ID: <20021016212745.GE1429@i92.ryd.student.liu.se>

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

[David Lawrence]
> Please help - if you'd like to skip my long intro, see my IDLE
> session capture at the end of this message. At the end of the
> session, you can see that although I added '4:"proj004"' to the end
> of the dictionary, the dictionary doesn't contain that pair after I
> close & open the shelve file. Why?

Try adding 'db["projects"] = projects' before 'db.close()'.

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/>

iD8DBQE9rdnPdNeA1787sd0RAiOkAJ94Jk6hMEFD2JBSByLOd8rCKKr2wwCeIkC3
fIXgeHtJ/FDaD8DbMMCxIwQ=
=zjGT
-----END PGP SIGNATURE-----


From dylan.belsey@baesystems.com  Wed Oct 16 23:00:34 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Thu, 17 Oct 2002 07:30:34 +0930
Subject: [Tutor] tkinter and menu
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B98D2AE5@wtntex1.baea.com.au>

	Personally, lambdas more often than not cause me to break out in a
rash.  I'm not saying they are a bad thing, its just that I haven't invested
enough time to try and work them out.  So as an alternative I use a Command
class, which has been mentioned before on this list, to perform the same
function.  The link is:

http://mail.python.org/pipermail/python-list/2001-February/031420.html

	It allows one to pass in parameters to a function etc.

		Dylan



-----Original Message-----
From: alan.gauld@bt.com [mailto:alan.gauld@bt.com]
Sent: Thursday, 17 October 2002 01:55
To: lists@shrestha.net.np; tutor@python.org
Subject: RE: [Tutor] tkinter and menu


> This works fine, but i've modified my callback function help so that
> depending upon the paramter it displays help on given paramter.
> 
> def help(topic):
>   """ depending upont topic display help"""
>   statements
>       ..
>   statements
>      
> My question is how do i pass parameter to callback function help() ??
> doing .add_command(label="ok", command=help("about")) doesn't work.

There are a few ways to do it - one is to use bind() 
instead of 'command=' then pass a custom event, pesonally 
I find that messy and prefer to use a lambda(**) in 
the command= section.

def helpHandler(context):
   # ...do it here...

Button(parent,command=lambda ctx=globalContext: helpHandler(ctx))

This makes the variable globalContext the default value for the

lambda which then passes it to the helpHandler. That works 
provided the context is different for each Button you define.

If you need to pass the context dynamically (and I think in 
this case you do) then its a case of defining a global variable 
which you update with current context and then access from 
within helpHandler. Not good programming practice but about all 
you can do...

Of course if your program is using classes it becomes better 
coz the context variable becomes a class variable which tidies 
things up a bit!

(**)
If you aren't familiar with lambda take a look at the 
Functional programming topic in my online tutor

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


From magnus@thinkware.se  Thu Oct 17 00:28:45 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu, 17 Oct 2002 01:28:45 +0200
Subject: [Tutor] cannot save changes to dictionary in a shelve file
In-Reply-To: <20021016212745.GE1429@i92.ryd.student.liu.se>
References: <001701c27554$a54c2a10$c100a8c0@dlawrence>
 <001701c27554$a54c2a10$c100a8c0@dlawrence>
Message-ID: <5.1.0.14.0.20021017011809.03147208@www.thinkware.se>

At 23:27 2002-10-16 +0200, Kalle Svensson wrote:
>Try adding 'db["projects"] =3D projects' before 'db.close()'.

So 'projects =3D db[projects]' creates a copy, not a
reference? That's not very pythonic, is it?

It's not so strange that it behaves like this, if
one thinks about the underlying mechanics. But it
is a deviation from the norm that a =3D b suddenly
means copy an object, not make a new reference to
an object. This should be documented in a clearer
way I think.

I must say that I find the docs for this module very
thin... Basically just a very simple usage example.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From mongo57a@comcast.net  Thu Oct 17 04:01:22 2002
From: mongo57a@comcast.net (andy surany)
Date: Wed, 16 Oct 2002 23:01:22 -0400
Subject: [Tutor] Another question on global variables...
Message-ID: <007901c27589$7aecbde0$2502a8c0@emily.ewndsr01.nj.comcast.net>

This is a multi-part message in MIME format.

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

I know that nobody likes 'em.... but,

If I define a global variable at the beginning of my program, like:

    global abc
    abc=[]

Then assign it like:

Class numberone:

    def set_it:

        abc=['1','2']
        # This assignment works fine and the variable is used throughout the class.

Then reference it like:

Class numbertwo:

    def ref_it

        size=len(abc)
        # Here, it appears that abc is [] so the length is zero. Should be 2

Why doesn't this work? Are global assignments unique to the class which made the assignment? Or more specifically, do I need to reference a global based on class, such as numberone.abc?? (or???)

And being somewhat ignorant of programming, if I drop the whole idea of globals and try to use a function, how would it work? I can certainly set up a function to assign the variable, like:

def assign(request_type):

    If request_type==obtain:
        abc = askstring.........
    return abc

Once I leave the function, isn't abc a null variable? So I set it on the first call, but just want it to continue to pass me the value previously set on subsequent calls. Am I anywhere close?????

TIA.

        

--Boundary_(ID_t0Rz2xnpFd/Q4gHCniDxBw)
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>I know that nobody likes 'em.... but,</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>If I define a global variable at the beginning of my program, 
like:</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; global abc</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; abc=[]</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Then assign it like:</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Class numberone:</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; def set_it:</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
abc=['1','2']</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; # This assignment works 
fine and the variable is used throughout the class.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Then reference it like:</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Class numbertwo:</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; def ref_it</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
size=len(abc)</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; # Here, it appears that 
abc is [] so the length is zero. Should be 2</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Why doesn't this work? Are global assignments unique to the 
class which made the assignment? Or more specifically, do I need to reference a 
global based on class, such as numberone.abc?? (or???)</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>And being somewhat ignorant of programming, if I drop the 
whole idea of globals and try to use a function, how would it work? I can 
certainly set up a function to assign the variable, like:</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>def assign(request_type):</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; If request_type==obtain:</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; abc = 
askstring.........</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; return abc</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Once I leave the function, isn't abc a null variable? So I set 
it on the first call, but just want it to continue to pass me the&nbsp;value 
previously set on subsequent calls. Am I anywhere close?????</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>TIA.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</FONT></DIV></BODY></HTML>

--Boundary_(ID_t0Rz2xnpFd/Q4gHCniDxBw)--


From idiot1@netzero.net  Tue Oct 15 15:29:40 2002
From: idiot1@netzero.net (Kirk Bailey)
Date: Tue, 15 Oct 2002 10:29:40 -0400
Subject: [Tutor] test- this thing thinks I just subscribed?!??
References: <MPEOIFCOPCIHEDCLBLPBKEBGCIAA.rob@uselesspython.com>
Message-ID: <3DAC2654.4A43E4@netzero.net>

What software are they using for managing the list, does anyone know?

I could see it doing this ALL THE TIME,  or NEVER, or WHEN FIRST SUBSCRIBED, but
it never acted like I was NOT a member; it accepted my messages, and kept
sending me traffic, so why did it do this?

And one wonders what strange combination of circumstance stimulated that
behavior out of it?

Rob wrote:
> 
> Once in a while I receive a message from the Tutor List server addressing me
> as a new subscriber.
> 
> Rob
> 
> >
> > interesting. I just got a welcome message from the tutor list
> > server, and no
> > traffic on the list for a day. odd.
> 
> _______________________________________________
> 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
Unlimited Long Distance only $29.95/ month!
Sign Up Today! www.netzerolongdistance.com


From ironman7@tbaytel.net  Thu Oct 17 05:52:41 2002
From: ironman7@tbaytel.net (Brian Moorman)
Date: Thu, 17 Oct 2002 00:52:41 -0400
Subject: [Tutor] Python Script Running in Windows 2000
References: <20021016190601.3117.71187.Mailman@mail.python.org>
Message-ID: <3DAE4219.9472A754@tbaytel.net>

Thanks for all the advice, I learned a lot today about making
presumptions when writing my scripts.  He was running my script from the
Windows desktop, which was why the window was closing after he finished
entering the search query.  Once he started the script from the DOS
prompt, it worked great.  Thanks for pointing that out to me.  I won't
make that rookie mistake again. :)  

Brian Moorman


From rob@uselesspython.com  Thu Oct 17 07:08:19 2002
From: rob@uselesspython.com (Rob)
Date: Thu, 17 Oct 2002 01:08:19 -0500
Subject: [Tutor] test- this thing thinks I just subscribed?!??
In-Reply-To: <3DAC2654.4A43E4@netzero.net>
Message-ID: <MPEOIFCOPCIHEDCLBLPBMEGACIAA.rob@uselesspython.com>

mailman, I think.

Rob

> What software are they using for managing the list, does anyone know?
> 
> I could see it doing this ALL THE TIME,  or NEVER, or WHEN FIRST 
> SUBSCRIBED, but
> it never acted like I was NOT a member; it accepted my messages, and kept
> sending me traffic, so why did it do this?
> 
> And one wonders what strange combination of circumstance stimulated that
> behavior out of it?
> 
> Rob wrote:
> > 
> > Once in a while I receive a message from the Tutor List server 
> addressing me
> > as a new subscriber.
> > 
> > Rob
> > 
> > >
> > > interesting. I just got a welcome message from the tutor list
> > > server, and no
> > > traffic on the list for a day. odd.




From shalehperry@attbi.com  Thu Oct 17 07:28:10 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Wed, 16 Oct 2002 23:28:10 -0700
Subject: [Tutor] Another question on global variables...
In-Reply-To: <007901c27589$7aecbde0$2502a8c0@emily.ewndsr01.nj.comcast.net>
References: <007901c27589$7aecbde0$2502a8c0@emily.ewndsr01.nj.comcast.net>
Message-ID: <200210162328.10683.shalehperry@attbi.com>

On Wednesday 16 October 2002 20:01, andy surany wrote:
> I know that nobody likes 'em.... but,
>
> If I define a global variable at the beginning of my program, like:
>
>     global abc
>     abc=3D[]
>
> Then assign it like:
>
> Class numberone:
>
>     def set_it:
>
>         abc=3D['1','2']
>         # This assignment works fine and the variable is used throughou=
t
> the class.
>
> Then reference it like:
>
> Class numbertwo:
>
>     def ref_it
>
>         size=3Dlen(abc)
>         # Here, it appears that abc is [] so the length is zero. Should=
 be
> 2
>
> Why doesn't this work? Are global assignments unique to the class which
> made the assignment? Or more specifically, do I need to reference a glo=
bal
> based on class, such as numberone.abc?? (or???)
>

class numberone does not assign to the global abc it assigns to a local=20
variable called abc.  As someone else mentioned on the first thread to AS=
SIGN=20
to a global you need to declare it global in the namespace where you do t=
he=20
assignment.  Observe:

global_text =3D "My name" # I am global

def foo(new_text):
    global_text =3D new_text

def bar(new_text):
    global global_text
    global_text =3D new_text

print global_text
foo("Hello, World!")
print global_text
bar("Hello, World!")
print global_text

The output will be:

My name
My name
Hello, World!


From thomi@thomi.imail.net.nz  Thu Oct 17 09:24:22 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Thu, 17 Oct 2002 21:24:22 +1300
Subject: [Tutor] functions in other files, executing
Message-ID: <20021017212422.2c389e2f.thomi@thomi.imail.net.nz>

I am assuming that there is an easier way to execute a function from
another file, assuming that you know it's location, and the function
name than importing the file as a module?? (In fact, i think i have seen
it in one of the modules, but i cannot find it now that i need it).

any ideas?

thanks.

-- 
Thomi Richards
thomi@imail.net.nz
http://thomi.imail.net.nz/
Thomi Richards,
thomi@imail.net.nz


From dmurtagh@starband.net  Thu Oct 17 09:27:27 2002
From: dmurtagh@starband.net (dmurtagh)
Date: Thu, 17 Oct 2002 02:27:27 -0600
Subject: [Tutor] Testing ... disregard
Message-ID: <000001c275b7$0aa8e120$bfd93f94@computer>

I've just joined this group and am testing the email, thanks for your
patience!

Deb (Python Programmer wannabe)






From alan.gauld@bt.com  Thu Oct 17 10:23:52 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 17 Oct 2002 10:23:52 +0100
Subject: [Tutor] Script Crashing in Windows 2000
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9A2@mbtlipnt02.btlabs.bt.co.uk>

Doh! only one minus sign came out for some reason...

> # force 21 character left justified string
> print "%21s", % "NAME"	  

print "%-21s", % "NAME"	  > 

> nm = "%s %s" % (player_split[0],player_split[1])  #names with a space
> print "%-21s" % nm    # left justify to desired length.

OK

> Or combining those:
> print "%21s" % ("%s %s" % (player_split[0],player_split[1]))

print "%-21s" % ("%s %s" % (player_split[0],player_split[1]))

Sorry,

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


From alan.gauld@bt.com  Thu Oct 17 10:30:16 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 17 Oct 2002 10:30:16 +0100
Subject: [Tutor] cannot save changes to dictionary in a shelve file
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9A3@mbtlipnt02.btlabs.bt.co.uk>

>>> db["projects"] = {1:"proj001",2:"proj002",3:"proj003"}
>>> db["otherlist"] = (5,7,9,10)
>>> db.close()
>>> db.keys()
Traceback (most recent call last):

Because you closed db it no longer is a shelf so no 
longer has keys...

>>> db = shelve.open("projectsdb","c")
>>> db.keys()
['projects', 'otherlist']
>>> projects = db["projects"]

You now have created a local dictionary containing a copy of
the pone you shelved...

>>> projects[4] = "proj004"
>>> projects
{1: 'proj001', 2: 'proj002', 3: 'proj003', 4: 'proj004'}

You add a pair to the copy

>>> db.close()

But you didn't change the shelf!
You needed to do

db['projects'] = projects

to store your changes.

HTH,

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


From alan.gauld@bt.com  Thu Oct 17 10:50:56 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 17 Oct 2002 10:50:56 +0100
Subject: [Tutor] Another question on global variables...
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9A4@mbtlipnt02.btlabs.bt.co.uk>

If I define a global variable at the beginning of my program, like:

    global abc
    abc=[]

I think you are misunderstanding the 'global' keyword.

If you define any variable at the module level it is global
(at least within that module!). You only need the global 
keyword to override local scope within a function.

----- Ex code ------
foo = 1

def bar():
   foo = 5   # local foo

def baz():
   global foo
   foo = 5   # changes the first file level foo.
--------------------

>Class numberone:
>    def set_it:
>        abc=['1','2']
>        # This works fine and the variable is used throughout the class.

Depends what you mean, it assigns the list to a local variable
of the set_it method.... If you want to access the global abc you need:

    def set_it():
        global abc
        abc = ['1','2']

Then reference it like:

>Class numbertwo:
>    def ref_it
>        size=len(abc)
>        # Here, it appears that abc is [] so the length is zero. Should be
2
>
>Why doesn't this work? 

This is referencing the global abc which is indeed empty.

> Are global assignments unique to the class which made 
> the assignment? 

No, you never assigned to the global variable, only to a local 
within the method. That variable was lost when the method terminated.

> Or more specifically, do I need to reference a global based 
> on class, such as numberone.abc?? (or???)

That would only work if you had assigned to self.abc within 
the set_it method. (Which is the preferred way of doing thois BTW)
Your list dissapeared when set_it terminated.

> And being somewhat ignorant of programming, if I drop the 
> whole idea of globals and try to use a function, how would 
> it work? 

If you really want to access global variables within a function 
you must explicitly describe the variable as global within each 
function that uses it. A much better way is to make the global 
a parameter of the function and pass it in at call time:

------- Example ------

abc = []   # global var

def nice_set_it(n):
   L = [n,n]  # use passed parameter wehich might be the global...
   return L  # pass back a value

def bad_set_it():
   global abc
   abc = [abc,abc]

# bad_set_it()     # same effect as below, but bad practice
abc = set_it(abc)  # set abc to a new value based on the old value
-----------------------

Better still is to put the global variable in a suitable clas 
with the methods that operate on it:

------- OO Example ------

class ABC:
   self.abc = []
   def set_it(self): self.abc = [1,2]
   def get_it(self): return self.abc

foo = ABC()
foo.get_it()  # prints initial empty list
foo.set_it    # sets new list
print foo.get_it()  # prints new value
---------------------------

> def assign(request_type):
>    if request_type==obtain:
>        abc = askstring.........
>    return abc
>
> Once I leave the function, isn't abc a null variable? 

Yes but you can assign the result to a variable outside 
the function - or print it...

HTH, Try reading my topic 'Whats in aname' in the 
advanced section of my online tutor for more examples 
etc....

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




From alan.gauld@bt.com  Thu Oct 17 10:54:44 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 17 Oct 2002 10:54:44 +0100
Subject: [Tutor] functions in other files, executing
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9A5@mbtlipnt02.btlabs.bt.co.uk>

> I am assuming that there is an easier way to execute a function from
> another file, assuming that you know it's location, and the function
> name than importing the file as a module?? 

There might be another way(although I can't think of it!) 
but the easiest way is to import the module or import 
the function name:

import mod
mod.foo()   # more typing but safest

OR

from mod import foo   # usually a bad idea...
foo()

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


From magnus@thinkware.se  Thu Oct 17 11:16:32 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu, 17 Oct 2002 12:16:32 +0200
Subject: [Tutor] Another question on global variables...
In-Reply-To: <007901c27589$7aecbde0$2502a8c0@emily.ewndsr01.nj.comcast.n
 et>
Message-ID: <5.1.0.14.0.20021017111800.02af6c88@www.thinkware.se>

At 23:01 2002-10-16 -0400, andy surany wrote about globals:
>I know that nobody likes 'em.... but,

So why persist? ;)

The code you included in your mail is very fragmentaric and
includes syntax errors. It's a good thing that you don't post
one hundred lines of code were most is irrelevant, but try
to make a short *runnable* piece of code that illustrates the
phenomena you are wondering about. That makes it much easier
for us to see your problem and explain it. (Although in this
case it's obvious that you misunderstood how global is used,
as Sean explained.) Also, making a short demo for a problem
might well help you understand and solve the problem yourself.

Concerning globals, think of it this way:

When a program gets big, it's impossible to grasp the
whole program with all its details. For that reason, we
need the local scopes, so that we can be sure that the
changes we make inside a function don't get unexpected
side effects. If I have a function:

def addAndDiv(a,b,c):
    return (a+b)/c

which works in a way that is unclear to me, I might want
to temporarily change it to:

def addAndDiv(a,b,c):
     print "addAndDiv called with", a, b, c
     sum =3D a + b
     print "a+b=3D", sum
     q =3D sum / c
     print ".../c=3D", q
     return q

It's important that such a change doesn't have any side
effects on the rest of the system. In python this IS a
safe change. The only difference with this change is the
printouts that I use as a diagnostic help.

If "global" had worked as you seemed to think it did, a
"global sum" or "global q" statement in some other part of
the program would have meant that I inadvertantly changed a
global variable when I rewrote the program as above. This
would be really bad. Some completely unrelated part of the
program might sometimed work in an unexpected way due to
this simple "clarification" in addAndDiv. I should be able
to work in my local scope without scanning the entire program
every time I made a change in my function.

As python works today, I can easily change a global variable
in my local scope by a "global" statement, but by default,
variables are local. This is the only sane behaviour in any
programming language where you don't declare all varibles
explicitly, but want to be able to handle programs that are
larger than 20 rows or so.

(Do I remember correctly that Perl works the other way around?
That variables defaults to global, and that you declare them
to be local? Another reason to avoid Perl in that case...)

Nested scopes make things a bit more complicated though.

 >>> a =3D 1
 >>> def x():
...     a =3D 2
...     def y():
...             a =3D 3
...             def z():
...                     print a
...             z()
...     y()
...
 >>> x()
3
 >>> def x():
...     a =3D 2
...     def y():
...             a =3D 3
...             def z():
...                     global a
...                     print a
...             z()
...     y()
...
 >>>
 >>> x()
1

There is no way to reach the "a=3D2" value. But
this is very rarely a problem in real life. Use
of relevant varaible names will probably sort this
out. You can access varables in any surrounding
scope as long as there aren't hidden like above.
(You can't reassign them though. But if they are
mutable (like lists) you can modify them.)

Also, note that while this works:

 >>> x =3D 5
 >>> def f():
...     print x
...
 >>> f()
5

This won't.

 >>> x =3D 5
 >>> def f():
...     print x
...     x =3D "a"
...
 >>> f()
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
   File "<interactive input>", line 2, in f
UnboundLocalError: local variable 'x' referenced before assignment

Python only checks the global scope on varable access if the
same variable name is not used in the local scope. This is
regardless of whether the assignment that defines the local
variable happens before or after the access. Again, this is
the sane behaviour. If it was otherwise, there would be a lot
more strange bugs in Python programs...


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Thu Oct 17 11:21:34 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu, 17 Oct 2002 12:21:34 +0200
Subject: [Tutor] Python Script Running in Windows 2000
In-Reply-To: <3DAE4219.9472A754@tbaytel.net>
References: <20021016190601.3117.71187.Mailman@mail.python.org>
Message-ID: <5.1.0.14.0.20021017121713.02aef9c0@www.thinkware.se>

At 00:52 2002-10-17 -0400, Brian Moorman wrote:
>Thanks for all the advice, I learned a lot today about making
>presumptions when writing my scripts.  He was running my script from the
>Windows desktop, which was why the window was closing after he finished
>entering the search query.  Once he started the script from the DOS
>prompt, it worked great.  Thanks for pointing that out to me.  I won't
>make that rookie mistake again. :)

Maybe it's a good thing to end your scripts with:

import os
if os.name !=3D 'posix':
     raw_input('Press Enter to end program')

That way you won't be bothered by the query in Linux.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Thu Oct 17 11:41:50 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu, 17 Oct 2002 12:41:50 +0200
Subject: [Tutor] functions in other files, executing
In-Reply-To: <20021017212422.2c389e2f.thomi@thomi.imail.net.nz>
Message-ID: <5.1.0.14.0.20021017122439.02b11b68@www.thinkware.se>

At 21:24 2002-10-17 +1300, Thomi Richards wrote:
>I am assuming that there is an easier way to execute a function from
>another file, assuming that you know it's location, and the function
>name than importing the file as a module?? (In fact, i think i have seen
>it in one of the modules, but i cannot find it now that i need it).
>
>any ideas?

Get someone else to write the program for you?
Oh boy! Are you so lazy? ;)

What's the problem with importing the file as a
module? Can you explain what kind of problem you
are trying to solve?

Instead of

import witch
whitch.burn()

you can import single names selectively as

from whitch import burn
burn()

This saves some typing if you are going to do a
lot of burning, but is it really important? To
indicate explicitly where a function comes from
helps us understant the code better.

This selective import won't save you any runtime
or memory. burn() might need something else from
the witch module, so it's all loaded into memeory.

If you are bothered by long module names you can do:

import that_witch_module_with_the_long_name as w
w.burn()

The form

from x import y

isn't so horribly bad, but

from x import *

means that you add a lot of variable names to
your local scope, and you can't see where they
came from.

Imagine that you do:

from witch import *
from wood import *

burn()

This works well, since the wood module only
contains the functions measure() and cut().
But then a burn() function is added to the
wood module, and next time you run your program
something unexpected happens... :(



--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From mongo57a@comcast.net  Thu Oct 17 14:47:08 2002
From: mongo57a@comcast.net (andy surany)
Date: Thu, 17 Oct 2002 09:47:08 -0400
Subject: [Tutor] Another question on global variables...
Message-ID: <002f01c275e3$afdb3540$2502a8c0@emily.ewndsr01.nj.comcast.net>

ok, I think I'm straight on globals. Thanks everyone.

Alan - regarding your OO example, if I have to assign the result to an
external variable, isn't that the same as a global? Seems like I'm kinda
defeating the purpose of using a function over a global. Or have I
misunderstood?

-Andy
-----Original Message-----
From: alan.gauld@bt.com <alan.gauld@bt.com>
To: mongo57a@comcast.net <mongo57a@comcast.net>; tutor@python.org
<tutor@python.org>
Date: Thursday, October 17, 2002 5:52 AM
Subject: RE: [Tutor] Another question on global variables...


>If I define a global variable at the beginning of my program, like:
>
>    global abc
>    abc=[]
>
>I think you are misunderstanding the 'global' keyword.
>
>If you define any variable at the module level it is global
>(at least within that module!). You only need the global
>keyword to override local scope within a function.
>
>----- Ex code ------
>foo = 1
>
>def bar():
>   foo = 5   # local foo
>
>def baz():
>   global foo
>   foo = 5   # changes the first file level foo.
>--------------------
>
>>Class numberone:
>>    def set_it:
>>        abc=['1','2']
>>        # This works fine and the variable is used throughout the class.
>
>Depends what you mean, it assigns the list to a local variable
>of the set_it method.... If you want to access the global abc you need:
>
>    def set_it():
>        global abc
>        abc = ['1','2']
>
>Then reference it like:
>
>>Class numbertwo:
>>    def ref_it
>>        size=len(abc)
>>        # Here, it appears that abc is [] so the length is zero. Should be
>2
>>
>>Why doesn't this work?
>
>This is referencing the global abc which is indeed empty.
>
>> Are global assignments unique to the class which made
>> the assignment?
>
>No, you never assigned to the global variable, only to a local
>within the method. That variable was lost when the method terminated.
>
>> Or more specifically, do I need to reference a global based
>> on class, such as numberone.abc?? (or???)
>
>That would only work if you had assigned to self.abc within
>the set_it method. (Which is the preferred way of doing thois BTW)
>Your list dissapeared when set_it terminated.
>
>> And being somewhat ignorant of programming, if I drop the
>> whole idea of globals and try to use a function, how would
>> it work?
>
>If you really want to access global variables within a function
>you must explicitly describe the variable as global within each
>function that uses it. A much better way is to make the global
>a parameter of the function and pass it in at call time:
>
>------- Example ------
>
>abc = []   # global var
>
>def nice_set_it(n):
>   L = [n,n]  # use passed parameter wehich might be the global...
>   return L  # pass back a value
>
>def bad_set_it():
>   global abc
>   abc = [abc,abc]
>
># bad_set_it()     # same effect as below, but bad practice
>abc = set_it(abc)  # set abc to a new value based on the old value
>-----------------------
>
>Better still is to put the global variable in a suitable clas
>with the methods that operate on it:
>
>------- OO Example ------
>
>class ABC:
>   self.abc = []
>   def set_it(self): self.abc = [1,2]
>   def get_it(self): return self.abc
>
>foo = ABC()
>foo.get_it()  # prints initial empty list
>foo.set_it    # sets new list
>print foo.get_it()  # prints new value
>---------------------------
>
>> def assign(request_type):
>>    if request_type==obtain:
>>        abc = askstring.........
>>    return abc
>>
>> Once I leave the function, isn't abc a null variable?
>
>Yes but you can assign the result to a variable outside
>the function - or print it...
>
>HTH, Try reading my topic 'Whats in aname' in the
>advanced section of my online tutor for more examples
>etc....
>
>Alan g.
>Author of the 'Learning to Program' web site
>http://www.freenetpages.co.uk/hp/alan.gauld
>
>



From printers@sendme.cz  Thu Oct 17 14:08:21 2002
From: printers@sendme.cz (A)
Date: Thu, 17 Oct 2002 15:08:21 +0200
Subject: [Tutor] Modules - problem
Message-ID: <3DAED265.28699.F7C6B8@localhost>

Hi,
I would like to access a variable in one module from another module.For example

The main module is like this
#############
#Main modul z1.py
import z3
print "x variable=", z3.x
###########

where z3.py module is like

########
#My module z3.py
global x
x=11
#########
Now if I run z1.py for the first time it prints properly

x variable= 11

but if I do any  change in z3 module , it has no effect
For example If I change in z3
x=12
I still get
 x variable= 11
Why?
Thank you for help.
Is it possible to name module with a different extension from py? For example is it possible 
to import z3.cod file?
Ladislav



From magnus@thinkware.se  Thu Oct 17 14:17:33 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu, 17 Oct 2002 15:17:33 +0200
Subject: [Tutor] Another question on global variables...
In-Reply-To: <002f01c275e3$afdb3540$2502a8c0@emily.ewndsr01.nj.comcast.n
 et>
Message-ID: <5.1.0.14.0.20021017150743.02b62de0@www.thinkware.se>

At 09:47 2002-10-17 -0400, andy surany wrote:
>ok, I think I'm straight on globals. Thanks everyone.

Great!

>Alan - regarding your OO example, if I have to assign the result to an
>external variable, isn't that the same as a global? Seems like I'm kinda
>defeating the purpose of using a function over a global. Or have I
>misunderstood?

The point is to contain variables to the smallest
possible namespace. I'm not sure what you refer to
here. The variable called "self.abc" only exists
inside one instance of the ABC class.

The variable name "abc" or even "self.abc" can be
used for other stuff in other places of the code
without getting mixed up.

Or are you referring to storing the result of
foo.get_it() somewhere? As long as foo exists,
you don't need to store it, and where ever you
use/store it, should typically be in another
local namespace.

 >>------- OO Example ------
> >
> >class ABC:
> >   self.abc =3D []
> >   def set_it(self): self.abc =3D [1,2]
> >   def get_it(self): return self.abc
> >
> >foo =3D ABC()
> >foo.get_it()  # prints initial empty list
> >foo.set_it    # sets new list
> >print foo.get_it()  # prints new value
> >---------------------------




--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From alan.gauld@bt.com  Thu Oct 17 13:57:40 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 17 Oct 2002 13:57:40 +0100
Subject: [Tutor] Another question on global variables...
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9AC@mbtlipnt02.btlabs.bt.co.uk>

> Alan - regarding your OO example, if I have to assign the result to an
> external variable, isn't that the same as a global? 

It might be, or more likely it would be a local variable 
within another function, or an instance variable in 
another object.

> >------- OO Example ------
> >
> >class ABC:
> >   self.abc = []
> >   def set_it(self): self.abc = [1,2]
> >   def get_it(self): return self.abc
> >
> >foo = ABC()
> >foo.get_it()  # prints initial empty list
> >foo.set_it()    # sets new list
> >print foo.get_it()  # prints new value
> >---------------------------

> >...you can assign the result to a variable outside
> >the function - or print it...

------ Extending above example -----

class XYZ:
  def doit(self, anABC):
    myVar = anABC.get_it()   # assign value of ABC.abc to myVar
    return str(myVar)
  def another(self, anABC):
    if len(anABC.get_it()) == 0:  #is empty
       anABC.set_it()
    print anABC.get_it()
  def internaluse(self,anABC):
    self.abc = anABC.get_it()

x = XYZ()
print x.doit(foo)  #--> '[1, 2]'
x.another(foo)     #--> [1,2]
x.internalize(foo) # no output
print x.abc        #--> [1, 2]
---------------------------------

[ NB This is actually bad OO design since much of 
  what XYZ is doing should be done by methods in 
  ABC... ]

This illustrates how to use the variable passing 
mechanisms well enough I hope....

Alan G.


From James.Rocks@equant.com  Thu Oct 17 13:26:38 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Thu, 17 Oct 2002 13:26:38 +0100
Subject: [Tutor] Defining & Importing Functions
Message-ID: <OF7F2743F3.FCC652CD-ON80256C55.00428C57@equant.com>

Hi,

Up until recently I kept my programs in the Python (c:\python21) install
directory (which somebody told me was not a good idea) ... that in mind I
created a sub-folder for them and put them in there but that caused
problems in that I didn't seem to be able to import from a specified
location i.e. all files imported appeared to need to be in the main python
directory which is (to my mind at any rate) a severe limitation. However,
knowing me, it's probably me & not python :-)

I also have problem running functions that are in the same text file as my
main program ... e.g. if I define a function called "SMPTAlert()" in my
main program how do I "call" it?

My preferred way of organising my files would be to have a main program
file (with all the main routines directly associated with that part of the
program) in one file & any common project functions in a separate project
function file ... these would all be in the project directory. Any routines
that are reusable beyond the scope of the project would go in a separate
project file in a comon folder reachable by any project programs ... in
this case (and I'm unsure whether this is wise or not) that will be the
Python install folder.

Any thoughts?

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ.



From rlegge@tc3net.com  Thu Oct 17 16:03:09 2002
From: rlegge@tc3net.com (Ray Leggett)
Date: Thu, 17 Oct 2002 11:03:09 -0400
Subject: [Tutor] functions in other files, executing
In-Reply-To: <20021017212422.2c389e2f.thomi@thomi.imail.net.nz>
References: <20021017212422.2c389e2f.thomi@thomi.imail.net.nz>
Message-ID: <200210171103.09152.rlegge@tc3net.com>

Hmm.  i don't see any reason to NOT import a module that contains the fun=
ction=20
you need.  If you just want one function from a module, you can just impo=
rt=20
that function.  Why are you looking for a different way?

On Thursday 17 October 2002 04:24, Thomi Richards wrote:
> I am assuming that there is an easier way to execute a function from
> another file, assuming that you know it's location, and the function
> name than importing the file as a module?? (In fact, i think i have see=
n
> it in one of the modules, but i cannot find it now that i need it).
>
> any ideas?
>
> thanks.



From steve@funkyjesus.net  Thu Oct 17 16:33:37 2002
From: steve@funkyjesus.net (Steve)
Date: Thu, 17 Oct 2002 16:33:37 +0100
Subject: [Tutor] Threading weirdness
Message-ID: <20021017163337.B18453@troll.local.net>

Hi,
I'm having some real problems with some threading. Here's the particular snippet
that's giving me grief:

while self.queue and (self.numThreads < self.maxThreads):
	target = self.queue.pop()
	ret = Worker(target)
	print "adding thread " + str(self.numThreads) + "/" + str(self.maxThreads) + "\n"
	ret.start()
	self.threadList.append(ret)
	self.numThreads = self.numThreads + 1

	tmpNumThreads = self.numThreads
		for ret in self.threadList[:] :
			if ret.done:
				self.threadList.remove(ret)
				self.numThreads = self.numThreads - 1
		if tmpNumThreads == self.numThreads:
			time.sleep(1)

Now self.maxThreads is supplied as an argument that I'm pulling from getopt.
That works fine, but what happens is regardless of the size of maxThreads it
just keeps on going until it's finished, adding threads as it goes.

I must be doing something blatantly wrong here, could someone please point out
what it is!

Thanks,
Steve

-- 
I have spent most of my money on women and beer. The rest I just wasted...


From magnus@thinkware.se  Thu Oct 17 17:10:28 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu, 17 Oct 2002 18:10:28 +0200
Subject: [Tutor] Modules - problem
In-Reply-To: <3DAED265.28699.F7C6B8@localhost>
Message-ID: <5.1.0.14.0.20021017175605.02b0f678@www.thinkware.se>

Have a look at the documentation for reload and
__import__ (Library reference section 2.1)

It's probably easier for us to be helpful if you
tell us what you are trying to achieve. There might
be other options that are more relevant, like openinig
a file and running exec (or rexec) on the contents, or
using the ConfigParser module.

You can import files with non-typical filenames using
the imp module (see Lib Ref 3.21), but AFAIK that mean
that no compiled version will be saved. (.pyc)

At 15:08 2002-10-17 +0200, A wrote:
>Hi,
>I would like to access a variable in one module from another module.For=20
>example
>
>The main module is like this
>#############
>#Main modul z1.py
>import z3
>print "x variable=3D", z3.x
>###########
>
>where z3.py module is like
>
>########
>#My module z3.py
>global x
>x=3D11
>#########
>Now if I run z1.py for the first time it prints properly
>
>x variable=3D 11
>
>but if I do any  change in z3 module , it has no effect
>For example If I change in z3
>x=3D12
>I still get
>  x variable=3D 11
>Why?
>Thank you for help.
>Is it possible to name module with a different extension from py? For=20
>example is it possible
>to import z3.cod file?
>Ladislav
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From carlosdsousa@hotmail.com  Thu Oct 17 18:58:43 2002
From: carlosdsousa@hotmail.com (Carlos Sousa)
Date: Thu, 17 Oct 2002 17:58:43 +0000
Subject: [Tutor] problem in conversion
Message-ID: <F128kjj2SFLWyqn2OVQ00002f89@hotmail.com>

I to all

I need to extract the hour and minute from a field x (x is a timestamp field 
in postgres)

printing the content of x['date_part']  is  '2002-02-05 09:30:00.00'

I can extract the hour or the minute but not both.

I´m trying to transform it into a string and then see if can find a way to 
see if, for instance '09:30' belongs to the string

I hope my problem was understod and If someone could help me it would be 
appreciated

thanks for your time and and replay





_________________________________________________________________
Get faster connections -- switch to MSN Internet Access! 
http://resourcecenter.msn.com/access/plans/default.asp



From dlphone@bellsouth.net  Thu Oct 17 20:16:16 2002
From: dlphone@bellsouth.net (dlphone@bellsouth.net)
Date: Thu, 17 Oct 2002 15:16:16 -0400
Subject: [Tutor] cannot save changes to dictionary in a shelve file
Message-ID: <20021017191616.RNJM21221.imf18bis.bellsouth.net@localhost>

Alan, thank you for your quick and clear explanation. I understand, and I was able to save a change to a shelve file when I reassigned the local dictionary to the shelved dictionary.

Regards,
Dave

----- Original Message ----- 
From: <alan.gauld@bt.com>
To: <dlphone@bellsouth.net>; <tutor@python.org>
Sent: Thursday, October 17, 2002 5:30 AM
Subject: RE: [Tutor] cannot save changes to dictionary in a shelve file


> >>> db["projects"] = {1:"proj001",2:"proj002",3:"proj003"}
> >>> db["otherlist"] = (5,7,9,10)
> >>> db.close()
> >>> db.keys()
> Traceback (most recent call last):
> 
> Because you closed db it no longer is a shelf so no 
> longer has keys...
> 
> >>> db = shelve.open("projectsdb","c")
> >>> db.keys()
> ['projects', 'otherlist']
> >>> projects = db["projects"]
> 
> You now have created a local dictionary containing a copy of
> the pone you shelved...
> 
> >>> projects[4] = "proj004"
> >>> projects
> {1: 'proj001', 2: 'proj002', 3: 'proj003', 4: 'proj004'}
> 
> You add a pair to the copy
> 
> >>> db.close()
> 
> But you didn't change the shelf!
> You needed to do
> 
> db['projects'] = projects
> 
> to store your changes.
> 
> HTH,
> 
> Alan g.
> Author of the 'Learning to Program' web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>



From dlphone@bellsouth.net  Thu Oct 17 21:08:04 2002
From: dlphone@bellsouth.net (dlphone@bellsouth.net)
Date: Thu, 17 Oct 2002 16:08:04 -0400
Subject: [Tutor] creating an object instance w/out hard-coding the name
Message-ID: <20021017200806.TLSL21221.imf18bis.bellsouth.net@localhost>

Hello all:

I would like to create a new object instance from user input, or using an iterated variable, for a small OODB. Can this be done? Assuming that 'Project' is my class, then Creating an instance as follows won't work, because the new instance will literally be named 'projName'. 

projName = raw_input("Name your project")
projName = Project()

Regards,
Dave



From magnus@thinkware.se  Thu Oct 17 21:14:54 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu, 17 Oct 2002 22:14:54 +0200
Subject: [Tutor] problem in conversion
In-Reply-To: <F128kjj2SFLWyqn2OVQ00002f89@hotmail.com>
Message-ID: <5.1.0.14.0.20021017215855.02b16000@www.thinkware.se>

At 17:58 2002-10-17 +0000, Carlos Sousa wrote:
>I to all
>
>I need to extract the hour and minute from a field x (x is a timestamp=20
>field in postgres)
>
>printing the content of x['date_part']  is  '2002-02-05 09:30:00.00'
>
>I can extract the hour or the minute but not both.
>
>I=B4m trying to transform it into a string and then see if can find a way=
 to=20
>see if, for instance '09:30' belongs to the string
>
>I hope my problem was understod and If someone could help me it would be=20
>appreciated

Maybe...

There are a number of Python PostgreSQL drivers, and I fear
that they might handle dates differently.

In case the use mxDateTime (which I think they do), you should
have a look at the docs for that. See:
http://www.egenix.com/files/python/mxDateTime.html

If this is the kind of object you have, you could do something
similar to:
 >>> from mx.DateTime import *
 >>> t =3D now()
 >>> print t
2002-10-17 22:02:41.74
 >>> t.hour
22
 >>> t.minute
2
 >>> "%02d:%02d" % (t.hour, t.minute)
'22:02'

Or simply:

 >>> t.time[:5]
'22:02'

Or even better:

 >>> t.strftime('%H:%M')
'22:02'

If you have a string like the one you showed above, you
should be able to do this:

 >>> '2002-02-05 09:30:00.00'[11:16]
'09:30'

Although, I imagine that locale settings might
influence the look of this string... :(

On the other hand, why convert it to a string? You
could as well test like this:

if (t.hour, t.minute) =3D=3D (9,30):
     #do something

This is probably faster, more robust and
easier to understand than the other versions.



--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From dylan.belsey@baesystems.com  Fri Oct 18 01:21:41 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Fri, 18 Oct 2002 09:51:41 +0930
Subject: [Tutor] Defining & Importing Functions
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B98D2AE9@wtntex1.baea.com.au>

	Try setting the PYTHONPATH system variable to the directory where
your files exist.  I think that Danny Yoo talked a bit about this in a
previous thread.
	I'm not sure I understand your problem re defining functions in the
same file.  As I understand it, if you write your function up above your
main code then you can just call the function as is.  For example:

>>> def helper():
	print "yo!"

	
>>> if __name__ == '__main__':
	helper()

	
yo!
>>> 

	This also works when in a file and run from the DOS prompt.  The
main thing is that the function must be defined before the main code.

	HTH,
		Dylan


-----Original Message-----
From: James.Rocks@equant.com [mailto:James.Rocks@equant.com]
Sent: Thursday, 17 October 2002 22:27
To: tutor@python.org
Subject: [Tutor] Defining & Importing Functions


Hi,

Up until recently I kept my programs in the Python (c:\python21) install
directory (which somebody told me was not a good idea) ... that in mind I
created a sub-folder for them and put them in there but that caused
problems in that I didn't seem to be able to import from a specified
location i.e. all files imported appeared to need to be in the main python
directory which is (to my mind at any rate) a severe limitation. However,
knowing me, it's probably me & not python :-)

I also have problem running functions that are in the same text file as my
main program ... e.g. if I define a function called "SMPTAlert()" in my
main program how do I "call" it?

My preferred way of organising my files would be to have a main program
file (with all the main routines directly associated with that part of the
program) in one file & any common project functions in a separate project
function file ... these would all be in the project directory. Any routines
that are reusable beyond the scope of the project would go in a separate
project file in a comon folder reachable by any project programs ... in
this case (and I'm unsure whether this is wise or not) that will be the
Python install folder.

Any thoughts?

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ.


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


From thomi@thomi.imail.net.nz  Thu Oct 17 11:24:08 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Thu, 17 Oct 2002 23:24:08 +1300
Subject: [Tutor] functions in other files, executing
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9A5@mbtlipnt02.btlabs.bt.co.uk>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9A5@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20021017232408.1f2ec3b3.thomi@thomi.imail.net.nz>

yes, i am aware of the import function. the problem i am trying to get
around however, is that i have about 20-50 to import, an each one is in
a different directory. i know where the directories are, but i do not
want to fill up sys.path with a whole heap of directories...

then again, maybe this is OK?

On Thu, 17 Oct 2002 10:54:44 +0100 Thus said alan.gauld@bt.com:

> > I am assuming that there is an easier way to execute a function from
> > another file, assuming that you know it's location, and the function
> > name than importing the file as a module?? 
> 
> There might be another way(although I can't think of it!) 
> but the easiest way is to import the module or import 
> the function name:
> 
> import mod
> mod.foo()   # more typing but safest
> 
> OR
> 
> from mod import foo   # usually a bad idea...
> foo()
> 
> 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


-- 
 "Avoid the Gates of Hell.  Use Linux"

Thomi Richards,
thomi@imail.net.nz


From magnus@thinkware.se  Fri Oct 18 10:58:36 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri, 18 Oct 2002 11:58:36 +0200
Subject: [Tutor] creating an object instance w/out hard-coding the
 name
In-Reply-To: <20021017200806.TLSL21221.imf18bis.bellsouth.net@localhost>
Message-ID: <5.1.0.14.0.20021018115725.02b10dd8@www.thinkware.se>

At 16:08 2002-10-17 -0400, dlphone@bellsouth.net wrote:
>Hello all:
>
>I would like to create a new object instance from user input, or using an 
>iterated variable, for a small OODB. Can this be done? Assuming that 
>'Project' is my class, then Creating an instance as follows won't work, 
>because the new instance will literally be named 'projName'.
>
>projName = raw_input("Name your project")
>projName = Project()

You *can* do this, but you shouldn't. It would only cause
sorrows. The only one to introduce variable names in the
program should be the programmer. I think you would have
figured that out in time. It would have been extremely hard
to get the rest of the program to work. But go on coding, I
think the use of variable names will become clearer.

I suggest you place the projects in a dictionary.

projects = {}
...
projName = raw_input("Name your project: ")
if projects.has_key(projName):
     print "That name is already taken."
     ...
else:
     projects[projName] = Project()
     ...


-- 
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 Oct 18 11:41:55 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri, 18 Oct 2002 12:41:55 +0200
Subject: [Tutor] functions in other files, executing
In-Reply-To: <20021017232408.1f2ec3b3.thomi@thomi.imail.net.nz>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9A5@mbtlipnt02.btlabs.bt.co.uk>
 <5104D4DBC598D211B5FE0000F8FE7EB20E66C9A5@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <5.1.0.14.0.20021018115944.02b18c38@www.thinkware.se>

At 23:24 2002-10-17 +1300, Thomi Richards wrote:
>yes, i am aware of the import function. the problem i am trying to get
>around however, is that i have about 20-50 to import, an each one is in
>a different directory. i know where the directories are, but i do not
>want to fill up sys.path with a whole heap of directories...

Aha, that's where the problem lies. Now I see...

I'm curious about the rationale behind using so
many dictionaries and files, but it's probably no
problem. At least if they are reasonably closely
collected. Can you make a package of all these
modules? (Or most of them.)

Have a look at how __init__.py files are made.
There are a few in Python, if you look in the
installation dir.

The tutorial chapter 6.4 describes packages,
but you can make much more advanced things
than you see in that short description.

Does anyone know of a more elaborate description
of how to do magic with __init__.py files? I've
seen some tricks in some files that could be
useful here, but I don't really know where to
find documentation about it.

BTW, it you worry about a big sys.path, I guess
you can remove directories once you have imported
the relevant pieces, but I haven't tested that.

On the other hand, I'm still surpriced that you
have so many modules in so many directories.
Maybe import isn't the right thing here after
all. Can you tell us what it is you are doing?
What's in this multitude of files? Why do they
have to be spread out like that?

Another option would be to open the files as
text, and use restricted exection or exec to
run them instead.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From dlphone@bellsouth.net  Fri Oct 18 13:09:45 2002
From: dlphone@bellsouth.net (dlphone@bellsouth.net)
Date: Fri, 18 Oct 2002 8:09:45 -0400
Subject: [Tutor] creating an object instance w/out hard-coding the  name
Message-ID: <20021018120945.DYVM7377.imf24bis.bellsouth.net@localhost>

Thank you, Magnus. If I understand you, you suggest that I create a dictionary key from the user input, and that key becomes a reference to a new project object instance.

Dave 
> 
> From: Magnus Lycka <magnus@thinkware.se>
> Date: 2002/10/18 Fri AM 05:58:36 EDT
> To: <dlphone@bellsouth.net>,  tutor@python.org
> Subject: Re: [Tutor] creating an object instance w/out hard-coding the
>   name
> 
> At 16:08 2002-10-17 -0400, dlphone@bellsouth.net wrote:
> >Hello all:
> >
> >I would like to create a new object instance from user input, or using an 
> >iterated variable, for a small OODB. Can this be done? Assuming that 
> >'Project' is my class, then Creating an instance as follows won't work, 
> >because the new instance will literally be named 'projName'.
> >
> >projName = raw_input("Name your project")
> >projName = Project()
> 
> You *can* do this, but you shouldn't. It would only cause
> sorrows. The only one to introduce variable names in the
> program should be the programmer. I think you would have
> figured that out in time. It would have been extremely hard
> to get the rest of the program to work. But go on coding, I
> think the use of variable names will become clearer.
> 
> I suggest you place the projects in a dictionary.
> 
> projects = {}
> ...
> projName = raw_input("Name your project: ")
> if projects.has_key(projName):
>      print "That name is already taken."
>      ...
> else:
>      projects[projName] = Project()
>      ...
> 
> 
> -- 
> 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 Oct 18 13:42:24 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri, 18 Oct 2002 14:42:24 +0200
Subject: [Tutor] creating an object instance w/out hard-coding
 the  name
In-Reply-To: <20021018120945.DYVM7377.imf24bis.bellsouth.net@localhost>
Message-ID: <5.1.0.14.0.20021018142138.02b47058@www.thinkware.se>

At 08:09 2002-10-18 -0400, dlphone@bellsouth.net wrote:
>Thank you, Magnus. If I understand you, you suggest that I create a=20
>dictionary key from the user input, and that key becomes a reference to a=
=20
>new project object instance.

Yes, don't you think that's a good solution?

Imagine that you could magically introduce
a new variable in the code (which you actually
can, but never mind that now).

You let the user call his project, and
like magic, the next line of code will
reflect his chosen name. So, if he chose
the name "xfiles", it would be:

xfiles =3D Project()

Now what? Everywhere in the program you want
to do anything with the project, it should say
xfiles.report() or xfiles.members.add() or
whatever. If he had called it something else,
your code should say something else. And what
if there are several projects. What should it
say in the code where you do things with
projects?

If you still want to try this, be my guest.

projName =3D raw_input('Project name please: ')
exec(projName + ' =3D Project()')

I don't think it will make you happy...

Besides, there are a lot of restrictions on
variable names that you don't want in project
names. Projects couldn't be called "C++", "42nd
street", "if" or "X-files" for instance.

And what if he would give his project a name you
already use as a variable name. Imagine this:

print "Enter projects, end by pressing only Enter"

while 1:
     projName =3D raw_input('Project name please: ')
     if projName =3D '': break
     exec('%s =3D Project()' % projName)

What will happen if the first project name entered
is "Project"?

You will for quite natural reasons get something like
this when the *second* project name has been entered:

Traceback (most recent call last):
   ...
AttributeError: Project instance has no __call__ method

Well, unless you have a call method in the Project
class, but then you've done something quite different
than could be expected.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From James.Rocks@equant.com  Fri Oct 18 13:21:21 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Fri, 18 Oct 2002 13:21:21 +0100
Subject: [Tutor] Defining & Importing Functions
Message-ID: <OFC0618B9D.5955ACE3-ON80256C56.0043991B@equant.com>

Hi Dylan,

> As I understand it, if you write your function up above your
> main code then you can just call the function as is.

Yes I understand that ... now :-)

I've never met a language where you define the functions above the main
code ... but then I'm not exactly wordly wise in programming terms :-)

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From James.Rocks@equant.com  Fri Oct 18 13:29:37 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Fri, 18 Oct 2002 13:29:37 +0100
Subject: [Tutor] Moving Files Around
Message-ID: <OF770C9489.D112B0A1-ON80256C56.0043E94F@equant.com>

Hi,

I have (as some of you know) been looking for an IDE for python and of all
of them SciTe looked the most promising ... until Boa-Constructor which is,
quite frankly, superb!

So I decided to convert my existing files to it ... gah! They won't run!
Even under Pythonwin in which I developed them. If I move them back they do
... yet I have changed all hard-coded references!

Any ideas?

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From lumbricus@gmx.net  Fri Oct 18 16:44:36 2002
From: lumbricus@gmx.net (lumbricus@gmx.net)
Date: Fri, 18 Oct 2002 17:44:36 +0200 (MEST)
Subject: [Tutor] Defining & Importing Functions
References: <OFC0618B9D.5955ACE3-ON80256C56.0043991B@equant.com>
Message-ID: <31846.1034955876@www33.gmx.net>

Hello!

[ snip ]

> I've never met a language where you define the functions above the main
> code ... 

C, perl, Lisp, others?
Well, you don't _have_ to it that way in other languages, but it 
usually works.

$ cat t.c
#include <stdio.h>

void pr(const char *text) {
        printf("%s", text);
}

int main(void)
{
pr("hello\n");
return 0;
}

$ gcc -ansi -pedantic -Wall t.c
$ ./a.out
hello
$ 

> James

HTH, J"o!


-- 
Wir beschliessen etwas, stellen das dann in
den Raum und warten dann einige Zeit ab, was
passiert. Wenn es dann kein grosses Geschrei
gibt und keine Aufstaende, weil die meisten
gar nicht begreifen, was da beschlossen
wurde, dann machen wir weiter - Schritt fuer
Schritt, bis es kein Zurueck mehr gibt. 
   -- J-C Juncker

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



From alan.gauld@bt.com  Fri Oct 18 17:41:53 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 18 Oct 2002 17:41:53 +0100
Subject: [Tutor] Moving Files Around
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9BC@mbtlipnt02.btlabs.bt.co.uk>

> I have (as some of you know) been looking for an IDE for 
> python and of all of them SciTe looked the most promising 

Last time I looked SciTe was a very nice editor but not 
in any way an IDE. Basically its a demo of the Scintilla 
editor component which is used in several IDEs, 
including Pythonwin. Has it changed recently?

> So I decided to convert my existing files to it ... gah! They 
> won't run!

How are you trying to run them in SciTe?
Don't you have to configure the environment etc to make 
that happen? And even if you do they will simply launch 
a DOS box, run the program and exit - leaving you no 
clue as to what happened?

What happens? Do you get error messages?
Do your files run from a DOS prompt?

> Even under Pythonwin in which I developed them. If I move 
> them back they do ... yet I have changed all hard-coded 
> references!

The IDE shouldn't require any hard coded references! 
What kind of references do you mean?

I'm confused...

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


From alan.gauld@bt.com  Fri Oct 18 17:37:40 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 18 Oct 2002 17:37:40 +0100
Subject: [Tutor] Defining & Importing Functions
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9BB@mbtlipnt02.btlabs.bt.co.uk>

> I've never met a language where you define the functions 
> above the main code ... but then I'm not exactly wordly 
> wise in programming terms :-)

Its the case in nearly every language I've come across. 
And certainly in interpreted code - The interpreter has 
to know what a name is before it can use it!

Of compiled languages Pascal, C++(*) and COBOL all 
require this...

(*)C++ actually only needs a function declaration to 
precede main not the definition, but since declaration 
and definition occur at the same place in Python the 
effect is the same...

Regards,

Alan g.


From alan.gauld@bt.com  Fri Oct 18 17:31:42 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 18 Oct 2002 17:31:42 +0100
Subject: [Tutor] functions in other files, executing
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9BA@mbtlipnt02.btlabs.bt.co.uk>

> Another option would be to open the files as
> text, and use restricted exection or exec to
> run them instead.

That could be dangerous if the files defined more 
than the functions you want to use - name collisions etc.

Also if there is any code in there that does more than 
define classes/functions it would get executed with 
unpredictable results.

If the problem is really bad I'd look at using OS facilities 
to create links to the needed libraries from a single folder 
and then import from there.

But I suspect the real issue is why you have so many 
different locations? Is it possible to rationalize the 
storage of the libraries? Even if multiple projects and 
programmers are involved a shared repository is 
probably "a good thing"...

Alan g.


From rlegge@tc3net.com  Fri Oct 18 18:33:21 2002
From: rlegge@tc3net.com (Ray Leggett)
Date: Fri, 18 Oct 2002 13:33:21 -0400
Subject: [Tutor] invalid syntax? huh!?!
Message-ID: <001001c276cc$74beea30$0100a8c0@gandalf>

Ok, I'm writing a script in Python 2.2 on windows that basically scans
another python module and lists all the lines beginning with "class" and
"def" in them.  Basically, it will print out a reference to the module.

Well, i wrote the thing in maybe 20 minutes tops.  Ran it with another
python module as an argument, and got the following:

File "C:\scripts\modscan.py", line 16
  for line in fp.readlines()
  ^
SyntaxError:  invalid syntax

Now, this is really puzzling to me.  As far as I can tell, the for loop I
used is correct in any number of languages, including python.  Here is the
script: (formatting a little mangled by outlook)
--------------------------------------------------------
#!/usr/bin/python

"scans a python module and lists all classes and functions"

import sys
import re

ModuleToScan = sys.argv[1]

def SetRegExp():
 ScanClass = re.compile("class")
 ScanDef = re.compile("def")

def ScanModule(ModuleToScan):
 fp = open(ModuleToScan)
  for line in fp.readlines()
   if ScanClass.search(line):
    print line
   else
    if ScanDef.search(line):
    print line
 fp.close()
 return

SetRegExp()
ScanModule(ModuleToScan)
--------------------------------------------------------------------------

Any ideas?  This one has me really puzzled.




From jeff@ccvcorp.com  Fri Oct 18 18:38:07 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Fri, 18 Oct 2002 10:38:07 -0700
Subject: [Tutor] functions in other files, executing
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9A5@mbtlipnt02.btlabs.bt.co.uk> <20021017232408.1f2ec3b3.thomi@thomi.imail.net.nz>
Message-ID: <3DB046FF.AFA7CD50@ccvcorp.com>


Thomi Richards wrote:

> yes, i am aware of the import function. the problem i am trying to get
> around however, is that i have about 20-50 to import, an each one is in
> a different directory. i know where the directories are, but i do not
> want to fill up sys.path with a whole heap of directories...
>
> then again, maybe this is OK?

I'd be kind of wondering why you have such a scattered directory structure,
but it *is* okay.  Rather than dynamically adding them to sys.path directly,
I'd suggest either using a .PTH file or the PYTHONPATH environment variable.

I'd also suggest that, if you have that many modules in so many different
directories, that you try to organize them into one or more packages.  You
can then have just a single import statement (per package), and it'll be
easier to track just where a specific function is defined.

>>> import mypackage
>>> x = mypackage.subpackage1.tools.getdata()

I'd even go so far as to submit that, if your application requires that many
directories but doesn't lend itself to being organized into packages, you
may wish to rethink your architecture.  There might be valid reasons for
doing it as you are, but not knowing just what you're doing, no likely
reasons spring to mind.

Jeff Shannon
Technician/Programmer
Credit International




From jeff@ccvcorp.com  Fri Oct 18 18:49:37 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Fri, 18 Oct 2002 10:49:37 -0700
Subject: [Tutor] invalid syntax? huh!?!
References: <001001c276cc$74beea30$0100a8c0@gandalf>
Message-ID: <3DB049B1.890C81FD@ccvcorp.com>


Ray Leggett wrote:

> File "C:\scripts\modscan.py", line 16
>   for line in fp.readlines()
>   ^
> SyntaxError:  invalid syntax
>
> [....]

> def ScanModule(ModuleToScan):
>  fp = open(ModuleToScan)
>   for line in fp.readlines()
>    if ScanClass.search(line):

[...]

If you get a syntax error at the beginning of a line, then it's often an
indication that there's something wrong with the *previous* line, line
termination, etc.

In this case, you've got an indentation problem.  The 'for ...' should line up
with the 'fp = ...' in the previous line.  There's no change of program flow,
so there should be no change of indentation.  There's another indentation
problem elsewhere in your code, too -- the nested 'if ...' in your 'else...'
clause needs to have the line below it ('print line') indented.  These things
will probably be easier to spot if you use standard 4-space indentation
instead of the single-space indentation that you seem to be using.  (Or is
that just various mailers munging tabs?  Either way, I recommend 4 spaces,
since that's the Pythonlabs standard... :) )

There's another syntax error that'll bite you as soon as you fix this one, too
-- the for statement needs to be terminated with a colon, which you've
accidentally left out.

Jeff Shannon
Technician/Programmer
Credit International




From shalehperry@attbi.com  Fri Oct 18 18:51:35 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Fri, 18 Oct 2002 10:51:35 -0700
Subject: [Tutor] invalid syntax? huh!?!
In-Reply-To: <001001c276cc$74beea30$0100a8c0@gandalf>
References: <001001c276cc$74beea30$0100a8c0@gandalf>
Message-ID: <200210181051.35359.shalehperry@attbi.com>

On Friday 18 October 2002 10:33, Ray Leggett wrote:
> Ok, I'm writing a script in Python 2.2 on windows that basically scans
> another python module and lists all the lines beginning with "class" an=
d
> "def" in them.  Basically, it will print out a reference to the module.
>
> Well, i wrote the thing in maybe 20 minutes tops.  Ran it with another
> python module as an argument, and got the following:
>
> File "C:\scripts\modscan.py", line 16
>   for line in fp.readlines()
>   ^
> SyntaxError:  invalid syntax
>
> Now, this is really puzzling to me.  As far as I can tell, the for loop=
 I
> used is correct in any number of languages, including python.  Here is =
the
> script: (formatting a little mangled by outlook)

will assume the formatting is correct then

>
> def ScanModule(ModuleToScan):
>  fp =3D open(ModuleToScan)
>   for line in fp.readlines()

there is no ':' on the end of this line.  A for loop's beginning statemen=
t=20
must end with a colon just like the if lines do.

>    if ScanClass.search(line):
>     print line
>    else

ditto for 'else' statements.


From python <python@inkedmn.net>  Fri Oct 18 18:57:51 2002
From: python <python@inkedmn.net> (python)
Date: Fri, 18 Oct 2002 10:57:51 -0700
Subject: Re[2]: [Tutor] invalid syntax? huh!?!
In-Reply-To: <3DB049B1.890C81FD@ccvcorp.com>
References: <001001c276cc$74beea30$0100a8c0@gandalf>
 <3DB049B1.890C81FD@ccvcorp.com>
Message-ID: <1171690962.20021018105751@inkedmn.net>

you need a colon at the end of this line:

for line in fp.readlines():


brett

JS> Ray Leggett wrote:

>> File "C:\scripts\modscan.py", line 16
>>   for line in fp.readlines()
>>   ^
>> SyntaxError:  invalid syntax
>>
>> [....]

>> def ScanModule(ModuleToScan):
>>  fp = open(ModuleToScan)
>>   for line in fp.readlines()
>>    if ScanClass.search(line):

JS> [...]

JS> If you get a syntax error at the beginning of a line, then it's often an
JS> indication that there's something wrong with the *previous* line, line
JS> termination, etc.

JS> In this case, you've got an indentation problem.  The 'for ...' should line up
JS> with the 'fp = ...' in the previous line.  There's no change of program flow,
JS> so there should be no change of indentation.  There's another indentation
JS> problem elsewhere in your code, too -- the nested 'if ...' in your 'else...'
JS> clause needs to have the line below it ('print line') indented.  These things
JS> will probably be easier to spot if you use standard 4-space indentation
JS> instead of the single-space indentation that you seem to be using.  (Or is
JS> that just various mailers munging tabs?  Either way, I recommend 4 spaces,
JS> since that's the Pythonlabs standard... :) )

JS> There's another syntax error that'll bite you as soon as you fix this one, too
JS> -- the for statement needs to be terminated with a colon, which you've
JS> accidentally left out.

JS> Jeff Shannon
JS> Technician/Programmer
JS> Credit International



JS> _______________________________________________
JS> Tutor maillist  -  Tutor@python.org
JS> http://mail.python.org/mailman/listinfo/tutor



From rlegge@tc3net.com  Fri Oct 18 18:58:36 2002
From: rlegge@tc3net.com (Ray Leggett)
Date: Fri, 18 Oct 2002 13:58:36 -0400
Subject: Re[2]: [Tutor] invalid syntax? huh!?!
References: <001001c276cc$74beea30$0100a8c0@gandalf> <3DB049B1.890C81FD@ccvcorp.com> <1171690962.20021018105751@inkedmn.net>
Message-ID: <000901c276cf$fc026b40$0100a8c0@gandalf>

Yeah, i saw that after i posted.  But I fixed the two colons, and I still
get the same error message,.

----- Original Message -----
From: "python" <python@inkedmn.net>
To: "Jeff Shannon" <jeff@ccvcorp.com>
Cc: "Ray Leggett" <rlegge@tc3net.com>; <tutor@python.org>
Sent: Friday, October 18, 2002 1:57 PM
Subject: Re[2]: [Tutor] invalid syntax? huh!?!


>
> you need a colon at the end of this line:
>
> for line in fp.readlines():
>
>
> brett
>
> JS> Ray Leggett wrote:
>
> >> File "C:\scripts\modscan.py", line 16
> >>   for line in fp.readlines()
> >>   ^
> >> SyntaxError:  invalid syntax
> >>
> >> [....]
>
> >> def ScanModule(ModuleToScan):
> >>  fp = open(ModuleToScan)
> >>   for line in fp.readlines()
> >>    if ScanClass.search(line):
>
> JS> [...]
>
> JS> If you get a syntax error at the beginning of a line, then it's often
an
> JS> indication that there's something wrong with the *previous* line, line
> JS> termination, etc.
>
> JS> In this case, you've got an indentation problem.  The 'for ...' should
line up
> JS> with the 'fp = ...' in the previous line.  There's no change of
program flow,
> JS> so there should be no change of indentation.  There's another
indentation
> JS> problem elsewhere in your code, too -- the nested 'if ...' in your
'else...'
> JS> clause needs to have the line below it ('print line') indented.  These
things
> JS> will probably be easier to spot if you use standard 4-space
indentation
> JS> instead of the single-space indentation that you seem to be using.
(Or is
> JS> that just various mailers munging tabs?  Either way, I recommend 4
spaces,
> JS> since that's the Pythonlabs standard... :) )
>
> JS> There's another syntax error that'll bite you as soon as you fix this
one, too
> JS> -- the for statement needs to be terminated with a colon, which you've
> JS> accidentally left out.
>
> JS> Jeff Shannon
> JS> Technician/Programmer
> JS> Credit International
>
>
>
> JS> _______________________________________________
> JS> Tutor maillist  -  Tutor@python.org
> JS> http://mail.python.org/mailman/listinfo/tutor
>



From rlegge@tc3net.com  Fri Oct 18 19:10:26 2002
From: rlegge@tc3net.com (Ray Leggett)
Date: Fri, 18 Oct 2002 14:10:26 -0400
Subject: [Tutor] Thanks guys!
Message-ID: <000701c276d1$a2a12f30$0100a8c0@gandalf>

Thanks everybody who responded to my earlier post.  Between the various
suggestions I was able to figure out what I was doing wrong a lot faster
than if I had been doing this by myself.  For the curious, here is the
finished script: (btw, outlook messes up the formatting!)
---------------------------------------------------------
#!/usr/bin/python

"scans a python module and lists all classes and functions"

import sys
import re

ModuleToScan = sys.argv[1]
ScanClass = re.compile('class')
ScanDef = re.compile('def')

def ScanModule(ModuleToScan):
 fp = open(ModuleToScan)
 source = fp.readlines()
 for line in source:
  if ScanClass.search(line):
   print line
  if ScanDef.search(line):
   print line
 fp.close()
 return

ScanModule(ModuleToScan)





From shalehperry@attbi.com  Fri Oct 18 19:17:40 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Fri, 18 Oct 2002 11:17:40 -0700
Subject: Re[2]: [Tutor] invalid syntax? huh!?!
In-Reply-To: <000901c276cf$fc026b40$0100a8c0@gandalf>
References: <001001c276cc$74beea30$0100a8c0@gandalf> <1171690962.20021018105751@inkedmn.net> <000901c276cf$fc026b40$0100a8c0@gandalf>
Message-ID: <200210181117.40787.shalehperry@attbi.com>

On Friday 18 October 2002 10:58, Ray Leggett wrote:
> Yeah, i saw that after i posted.  But I fixed the two colons, and I sti=
ll
> get the same error message,.
>

#!/usr/bin/python

"scans a python module and lists all classes and functions"

import sys
import re

ModuleToScan =3D sys.argv[1]

def ScanModule(ModuleToScan):
    ScanClass =3D re.compile("class")
    ScanDef =3D re.compile("def")

    fp =3D open(ModuleToScan)
    for line in fp.readlines():
        if ScanClass.search(line):
            print line
        elif ScanDef.search(line):
            print line
    fp.close()
    return

ScanModule(ModuleToScan)

works here.

I moved ScanClass and ScanDef into ScanModule because otherwise they woul=
d not=20
be defined.  Putting them in a separate function would have made sense if=
=20
they were also declared global.

Pay attention to whitespace, things must line up.


From shalehperry@attbi.com  Fri Oct 18 19:19:19 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Fri, 18 Oct 2002 11:19:19 -0700
Subject: [Tutor] Thanks guys!
In-Reply-To: <000701c276d1$a2a12f30$0100a8c0@gandalf>
References: <000701c276d1$a2a12f30$0100a8c0@gandalf>
Message-ID: <200210181119.19875.shalehperry@attbi.com>

On Friday 18 October 2002 11:10, Ray Leggett wrote:
>
> def ScanModule(ModuleToScan):
>  fp =3D open(ModuleToScan)
>  source =3D fp.readlines()
>  for line in source:

there is no need to use a variable here the python idiom is simply 'for l=
ine=20
in fp.readlines()'.

if you run this program on itself you will expose some flaws in your desi=
gn=20
(-:


From SWidney@ci.las-vegas.nv.us  Fri Oct 18 19:41:16 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Fri, 18 Oct 2002 11:41:16 -0700
Subject: [Tutor] invalid syntax? huh!?!
Message-ID: <0E5508EBA1620743B409A2B8365DE16FDC81DA@SOVEREIGN>

> Ok, I'm writing a script in Python 2.2 on windows that basically
> scans another python module and lists all the lines beginning
> with "class" and "def" in them.  Basically, it will print out a
> reference to the module.
> 
> Here is the script: (formatting a little mangled by outlook)
> --------------------------------------------------------
> #!/usr/bin/python
> 
> "scans a python module and lists all classes and functions"
> 
> import sys
> import re
> 
> ModuleToScan = sys.argv[1]
> 
> def SetRegExp():
>  ScanClass = re.compile("class")
>  ScanDef = re.compile("def")
> 
> def ScanModule(ModuleToScan):
>  fp = open(ModuleToScan)
>   for line in fp.readlines()
>    if ScanClass.search(line):
>     print line
>    else
>     if ScanDef.search(line):
>     print line
>  fp.close()
>  return
> 
> SetRegExp()
> ScanModule(ModuleToScan)
> --------------------------------------------------------------

Did a little refactoring (just for fun), came up with this:
#####

#!/usr/bin/python
"""List all class and function declarations in a .py file"""

import re, sys

ScanClass = re.compile("class")
ScanDef = re.compile("def")

def ScanModule(ModuleToScan):
    fp = open(ModuleToScan, 'r')
    for line in fp.readlines():
        if ScanClass.search(line):
            print line
        elif ScanDef.search(line):
            print line
    fp.close()

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print "Usage: modscan <module filename> [...]"
        sys.exit()
    for fname in sys.argv[1:]:
        print "Filename: %s" % (fname,)
        ScanModule(fname)

#####
Seems to work, feel free to kick it around. Should run from the command line
with any number of filenames, and can be imported at the interactive prompt.


Scott


From mongo57a@comcast.net  Fri Oct 18 20:45:48 2002
From: mongo57a@comcast.net (andy surany)
Date: Fri, 18 Oct 2002 15:45:48 -0400
Subject: [Tutor] parameter passing
Message-ID: <003601c276de$f545ba00$2502a8c0@emily.ewndsr01.nj.comcast.net>

This is a multi-part message in MIME format.

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

Maybe I'm going nuts......

THIS WORKS:
class aaa:
    def whowantstoknow:
        input1="'"+askstring('Enter your name','Name?')+"'"
        Button(self,text='name',command=self.update_name()).pack(side=LEFT)
    def update_name(self):
        # do some stuff.....

THIS DOES NOT (in fact, the button statement - and any other button statement is ignored. But there is no error.):

class aaa:
    def whowantstoknow:
        input1="'"+askstring('Enter your name','Name?')+"'"
        Button(self,text='name',command=self.update_name(input1)).pack(side=LEFT)
    def update_name(self,input1):
        print 'name is ',input1

The answer is probably staring me in the face...... I'm just not seeing it.
TIA

--Boundary_(ID_COaoZYr7R8z+JxYxcQC/ew)
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>Maybe I'm going nuts......</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>THIS WORKS:</FONT></DIV>
<DIV><FONT size=2>
<DIV><FONT size=2>class aaa:</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; def whowantstoknow:</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
input1="'"+askstring('Enter your name','Name?')+"'"</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
Button(self,text='name',command=self.update_name()).pack(side=LEFT)</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; def update_name(self):</FONT></DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # do some stuff.....</DIV>
<DIV>&nbsp;</DIV>
<DIV>THIS DOES NOT (in fact, the button statement - and any other button 
statement is ignored. But there is no error.):</DIV>
<DIV>&nbsp;</DIV></FONT></DIV>
<DIV><FONT size=2>class aaa:</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; def whowantstoknow:</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
input1="'"+askstring('Enter your name','Name?')+"'"</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
Button(self,text='name',command=self.update_name(input1)).pack(side=LEFT)</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; def update_name(self,input1):</FONT></DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; print 'name is 
',input1</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>The answer is probably staring me in the face...... I'm just 
not seeing it.</FONT></DIV>
<DIV><FONT size=2>TIA</FONT></DIV></BODY></HTML>

--Boundary_(ID_COaoZYr7R8z+JxYxcQC/ew)--


From jrclare@lycos.com  Fri Oct 18 20:37:41 2002
From: jrclare@lycos.com (James Clare)
Date: Fri, 18 Oct 2002 15:37:41 -0400
Subject: [Tutor] Books
Message-ID: <MCPGPPDJLOOPABAA@mailcity.com>

Hello everyone. I'm new to this list. I have read many online tutorials about python and enjoy them much. I was wondering though, are there any books out there that get a little more involved with the practical uses of this language. I understand the basics of many languages but would like to take python a couple steps further. I guess I'm looking for books or tutorials that give examples of useful system administration and OOP programs. I work with both Windows NT and Linux. I would like to concentrate on Linux though. I have R.H 7.3. at home and would like examples of scripts that can be used in place of perl and shell scripting. I originally thought Java would be an ideal language to learn OOP in but got bogged down with all the calls to GUI components. How do I get started writing GUI stuff in python? Is it anything like Java GUI programming?
Thanks 
Jim



____________________________________________________________
Get 250 full-color business cards FREE right now!
http://businesscards.lycos.com 


From emil@lysator.liu.se  Fri Oct 18 20:56:59 2002
From: emil@lysator.liu.se (Emil Styrke)
Date: 18 Oct 2002 21:56:59 +0200
Subject: [Tutor] functions in other files, executing
In-Reply-To: <20021017232408.1f2ec3b3.thomi@thomi.imail.net.nz>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9A5@mbtlipnt02.btlabs.bt.co.uk>
 <20021017232408.1f2ec3b3.thomi@thomi.imail.net.nz>
Message-ID: <87lm4v1px0.fsf@i110.ryd.student.liu.se>

Thomi Richards <thomi@thomi.imail.net.nz> writes:

> yes, i am aware of the import function. the problem i am trying to get
> around however, is that i have about 20-50 to import, an each one is in
> a different directory. i know where the directories are, but i do not
> want to fill up sys.path with a whole heap of directories...
> 

Maybe the imp module could be interesting?  The following code is
untested, though.

>>> def load_from_path(name, path):
>>>     (file, pathname, desc) = imp.find_module(name, path)
>>>     return imp.load_module(name, file, pathname, desc)

        /Emil


> then again, maybe this is OK?
> 
> On Thu, 17 Oct 2002 10:54:44 +0100 Thus said alan.gauld@bt.com:
> 
> > > I am assuming that there is an easier way to execute a function from
> > > another file, assuming that you know it's location, and the function
> > > name than importing the file as a module?? 
> > 
> > There might be another way(although I can't think of it!) 
> > but the easiest way is to import the module or import 
> > the function name:
> > 
> > import mod
> > mod.foo()   # more typing but safest
> > 
> > OR
> > 
> > from mod import foo   # usually a bad idea...
> > foo()
> > 
> > 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
> 
> 
> -- 
>  "Avoid the Gates of Hell.  Use Linux"
> 
> Thomi Richards,
> thomi@imail.net.nz
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From emil@lysator.liu.se  Fri Oct 18 21:21:00 2002
From: emil@lysator.liu.se (Emil Styrke)
Date: 18 Oct 2002 22:21:00 +0200
Subject: [Tutor] Modules - problem
In-Reply-To: <3DAED265.28699.F7C6B8@localhost>
References: <3DAED265.28699.F7C6B8@localhost>
Message-ID: <87hefj1osz.fsf@i110.ryd.student.liu.se>

"A" <printers@sendme.cz> writes:

> Hi,
> I would like to access a variable in one module from another module.For example
> 
> The main module is like this
> #############
> #Main modul z1.py
> import z3
> print "x variable=", z3.x
> ###########
> 
> where z3.py module is like
> 
> ########
> #My module z3.py
> global x
> x=11
> #########
> Now if I run z1.py for the first time it prints properly
> 
> x variable= 11
> 
> but if I do any  change in z3 module , it has no effect
> For example If I change in z3
> x=12
> I still get
>  x variable= 11
> Why?

If you are changing the x value from a function inside z3, have you remembered to declare x global inside that function?  Otherwise you would just change the local variable x.

For example, in z3:

def change_x():
        global x   # You need this declaration, else x will be local.
        x = 12

Hope that helps!

        /Emil


> Thank you for help.
> Is it possible to name module with a different extension from py? For example is it possible 
> to import z3.cod file?
> Ladislav
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From dlphone@bellsouth.net  Fri Oct 18 21:20:06 2002
From: dlphone@bellsouth.net (dlphone@bellsouth.net)
Date: Fri, 18 Oct 2002 16:20:06 -0400
Subject: [Tutor] creating an object instance w/out hard-coding  the  name
Message-ID: <20021018202006.MDYN9260.imf21bis.bellsouth.net@[192.168.1.31]>

thank you Magnus; I appreciate your explanation. I'll stay away from letting users introduce new program variables. As expected, I have much to learn.

Dave
> 
> From: Magnus Lycka <magnus@thinkware.se>
> Date: 2002/10/18 Fri AM 08:42:24 EDT
> To: <dlphone@bellsouth.net>,  tutor@python.org
> Subject: Re: Re: [Tutor] creating an object instance w/out hard-coding
>   the  name
> 
> At 08:09 2002-10-18 -0400, dlphone@bellsouth.net wrote:
> >Thank you, Magnus. If I understand you, you suggest that I create a 
> >dictionary key from the user input, and that key becomes a reference to a 
> >new project object instance.
> 
> Yes, don't you think that's a good solution?
> 
> Imagine that you could magically introduce
> a new variable in the code (which you actually
> can, but never mind that now).
> 
> You let the user call his project, and
> like magic, the next line of code will
> reflect his chosen name. So, if he chose
> the name "xfiles", it would be:
> 
> xfiles = Project()
> 
> Now what? Everywhere in the program you want
> to do anything with the project, it should say
> xfiles.report() or xfiles.members.add() or
> whatever. If he had called it something else,
> your code should say something else. And what
> if there are several projects. What should it
> say in the code where you do things with
> projects?
> 
> If you still want to try this, be my guest.
> 
> projName = raw_input('Project name please: ')
> exec(projName + ' = Project()')
> 
> I don't think it will make you happy...
> 
> Besides, there are a lot of restrictions on
> variable names that you don't want in project
> names. Projects couldn't be called "C++", "42nd
> street", "if" or "X-files" for instance.
> 
> And what if he would give his project a name you
> already use as a variable name. Imagine this:
> 
> print "Enter projects, end by pressing only Enter"
> 
> while 1:
>      projName = raw_input('Project name please: ')
>      if projName = '': break
>      exec('%s = Project()' % projName)
> 
> What will happen if the first project name entered
> is "Project"?
> 
> You will for quite natural reasons get something like
> this when the *second* project name has been entered:
> 
> Traceback (most recent call last):
>    ...
> AttributeError: Project instance has no __call__ method
> 
> Well, unless you have a call method in the Project
> class, but then you've done something quite different
> than could be expected.
> 
> 
> -- 
> Magnus Lyckå, Thinkware AB
> Älvans väg 99, SE-907 50 UMEÅ
> tel: 070-582 80 65, fax: 070-612 80 65
> http://www.thinkware.se/  mailto:magnus@thinkware.se
> 
> 



From jimmy_130@lycos.com  Fri Oct 18 23:42:12 2002
From: jimmy_130@lycos.com (James M Lang)
Date: Fri, 18 Oct 2002 18:42:12 -0400
Subject: [Tutor] Help!!! please help!!
Message-ID: <LOLPGIPPMPIABBAA@mailcity.com>

I know this has almost nothing to do with python but, where do you get USB drivers? My computer had something wrong, ending with me erasing the whole hard drive(don't worry, I got python back.). I reinstalled Windows ME BUT.....
The USB port seems to be dead. The trackball I have is not powered, and my graphing calculator cannot be found by the computer, etc.
So, how can I make Windows ME recognizem my USB port again?


____________________________________________________________
Get 250 full-color business cards FREE right now!
http://businesscards.lycos.com 


From thomi@thomi.imail.net.nz  Fri Oct 18 23:42:13 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Sat, 19 Oct 2002 11:42:13 +1300
Subject: [Tutor] functions in other files, executing
In-Reply-To: <3DB046FF.AFA7CD50@ccvcorp.com>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9A5@mbtlipnt02.btlabs.bt.co.uk>
 <20021017232408.1f2ec3b3.thomi@thomi.imail.net.nz>
 <3DB046FF.AFA7CD50@ccvcorp.com>
Message-ID: <20021019114213.617155b9.thomi@thomi.imail.net.nz>

> I'd even go so far as to submit that, if your application requires
> that many directories but doesn't lend itself to being organized into
> packages, you may wish to rethink your architecture.  There might be
> valid reasons for doing it as you are, but not knowing just what
> you're doing, no likely reasons spring to mind.

basically, every module has to be in it's own directory, because they
each have extra bits of data in separate files with them. things like an
icon.bmp, we can't have all the modules in the same dir, otherwise the
icon.bmp files would overwrite each other. i guess i could put the
modules in the same dir, and have the icons in another one...hmmmm.

thanks for all your help anyway, I'll have to find some documentation
online i guess...

-- 
This message was brought to you by one bored guy, with nothing better to
do,
And the letter Q.
Thomi Richards,
thomi@imail.net.nz


From lbrannma@cablespeed.com  Sat Oct 19 00:23:21 2002
From: lbrannma@cablespeed.com (Lance)
Date: Fri, 18 Oct 2002 16:23:21 -0700
Subject: [Tutor] How can I get the hostid of a computer?
Message-ID: <002a01c276fd$5920cb00$3212eb42@MYNEWBOX>

This is a multi-part message in MIME format.

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

Any advice would be appreciated.

Thanks,
Lance

------=_NextPart_000_0027_01C276C2.ACA67BC0
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>Any advice would be =
appreciated.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Lance</FONT></DIV>
<DIV>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0027_01C276C2.ACA67BC0--




From jeff@ccvcorp.com  Sat Oct 19 02:27:18 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Fri, 18 Oct 2002 18:27:18 -0700
Subject: [Tutor] functions in other files, executing
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9A5@mbtlipnt02.btlabs.bt.co.uk>
 <20021017232408.1f2ec3b3.thomi@thomi.imail.net.nz>
 <3DB046FF.AFA7CD50@ccvcorp.com> <20021019114213.617155b9.thomi@thomi.imail.net.nz>
Message-ID: <3DB0B4F6.1928EB24@ccvcorp.com>


Thomi Richards wrote:

> > I'd even go so far as to submit that, if your application requires
> > that many directories but doesn't lend itself to being organized into
> > packages, you may wish to rethink your architecture.  There might be
> > valid reasons for doing it as you are, but not knowing just what
> > you're doing, no likely reasons spring to mind.
>
> basically, every module has to be in it's own directory, because they
> each have extra bits of data in separate files with them. things like an
> icon.bmp, we can't have all the modules in the same dir, otherwise the
> icon.bmp files would overwrite each other. i guess i could put the
> modules in the same dir, and have the icons in another one...hmmmm.

Yes, that would probably be better.  Also, instead of putting each in a
unique directory, try giving each icon bitmap a unique filename, preferably
one that indicates what it's *for*.  Then you'll not only be able to put
them all in the same directory, but it'll be easier to identify which is
which.  If you've got 20 files all named "icon.bmp", it'd be far to easily
to accidentally save one of them into the wrong directory, and it's more
practical to use descriptive names like "leftarrow.bmp", "open.bmp",
"stop.bmp", etc....

If you still feel the need to organize this into more than one directory
(and really, I don't see any compelling reason to have the bitmaps, etc,  in
a separate directory from the modules), then you can set up several
subpackages, hopefully dividing your set of modules into two or three
separate functional units.  (Ideally, each submodule should be more-or-less
independent of other submodules, though this may get fudged a bit in
practice.)

Jeff Shannon
Technician/Programmer
Credit International




From nano@intermatik.co.id  Sat Oct 19 03:48:52 2002
From: nano@intermatik.co.id (nano)
Date: 19 Oct 2002 09:48:52 +0700
Subject: [Tutor] no-mail
Message-ID: <1034995741.2942.1.camel@jrwd.internal.intermatik.com>

i haven't received any mail from the list since yesterday,

do i have to re-register?

thanks,

nano'






From kojo@hal-pc.org  Sat Oct 19 05:14:14 2002
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Fri, 18 Oct 2002 23:14:14 -0500
Subject: [Tutor] no-mail
In-Reply-To: <1034995741.2942.1.camel@jrwd.internal.intermatik.com>
Message-ID: <web-23683715@mail.hal-pc.org>

Nano?  Did you get this?

On 19 Oct 2002 09:48:52 +0700
  nano <nano@intermatik.co.id> wrote:
]i haven't received any mail from the list since 
]yesterday,
]
]do i have to re-register?
]
]thanks,
]
]nano'
]
]
]
]
]
]_______________________________________________
]Tutor maillist  -  Tutor@python.org
]http://mail.python.org/mailman/listinfo/tutor

****************************
Kojo Idrissa
kojo@hal-pc.org

http://www.hal-pc.org/~kojo
****************************


From kojo@hal-pc.org  Sat Oct 19 15:39:13 2002
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Sat, 19 Oct 2002 09:39:13 -0500
Subject: [Tutor] extramural papers in python??
In-Reply-To: <5.1.0.14.0.20021010224013.04b1cc50@www.thinkware.se>
Message-ID: <web-23712869@mail.hal-pc.org>

Sorry I've been so slow on this. I know Magnus and the 
person who asked the question originally wanted to know 
about this paper, so here it is.  The title is:
"A comparison of C++, Java and Python" by Ling Zhou
It's a Comp Sci Masters Thesis from Texas A&M University. 
 I don't know if you can find it online.

Sadly, as I was looking around on the web to see if you 
could, I came across a comment I posted in 2000 on the 
Jython list (I used to lurk there too) saying the same 
thing.  2 years later and I still don't know if the paper 
can be found online.  I'm pathetic.

On the other hand, it may be available through some sort 
of inter-library loan, although that may be a bit extreme 
from Australia.  I think that's where the person who first 
raised the question is from.

HTH,

On Thu, 10 Oct 2002 22:44:43 +0200
  Magnus Lycka <magnus@thinkware.se> wrote:
]At 12:40 2002-10-10 -0500, you wrote:
]>Runs a paper using python?  I'm not sure I understand 
the 
]>question.  If you're looking for papers ABOUT python, or 
]>FEATURING python, I know there's a Master's Thesis at 
]>Texas A&M that compares Python, Java and C++.  If that 
]>will help, send me an email and I'll get the citation 
for 
]>you later this evening.
]
]I don't understand what he is saying either,
]but I think he wan't to write a paper...
]
]I'm interested in that Python, Java & C++
]comparision though. It would fit on
]http://www.thinkware.se/cgi-bin/thinki.cgi/PythonDocs
]
]Please send me a reference if you find 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
]

****************************
Kojo Idrissa
kojo@hal-pc.org

http://www.hal-pc.org/~kojo
****************************


From ckasso@sprynet.com  Sat Oct 19 17:32:36 2002
From: ckasso@sprynet.com (Chris Kassopulo)
Date: Sat, 19 Oct 2002 12:32:36 -0400
Subject: SciTE was Re: [Tutor] Moving Files Around
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9BC@mbtlipnt02.btlabs.bt.co.uk>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9BC@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20021019123236.6720e13f.ckasso@sprynet.com>

On Fri, 18 Oct 2002 17:41:53 +0100
alan.gauld@bt.com wrote:

> Last time I looked SciTe was a very nice editor but not 
> in any way an IDE. Basically its a demo of the Scintilla 
> editor component which is used in several IDEs, 
> including Pythonwin. Has it changed recently?

I use SciTE under Linux.  It is a good text editor for
Python: syntax highlighting, indent and undent blocks
with TAB and BACKTAB, parenthesis matching, etc.
  
Like idle, you run a script that you are editing and it
opens another pane that shows the output of the script
along with any error messages and exit codes.  You can
click on the error and it will bring up that section of
code.

The only real drawback is that it cannot handle scripts
that require user input.  I understand that this works
under windows.

Is it an IDE? I think the term is used much more loosely
these days, so yes I guess it is.

Chris Kassopulo


From magnus@thinkware.se  Sat Oct 19 17:44:13 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat, 19 Oct 2002 18:44:13 +0200
Subject: [Tutor] Books
In-Reply-To: <MCPGPPDJLOOPABAA@mailcity.com>
Message-ID: <5.1.0.14.0.20021019174023.02b0b090@www.thinkware.se>

At 15:37 2002-10-18 -0400, James Clare wrote:
>Hello everyone. I'm new to this list. I have read many online tutorials=20
>about python and enjoy them much. I was wondering though, are there any=20
>books out there that get a little more involved with the practical uses of=
=20
>this language.

See http://www.python.org/cgi-bin/moinmoin/PythonBooks

>I understand the basics of many languages but would like to take python a=
=20
>couple steps further. I guess I'm looking for books or tutorials that give=
=20
>examples of useful system administration and OOP programs.

pass...

>I work with both Windows NT and Linux.

For Win 32, have a look at
http://www.thinkware.se/cgi-bin/thinki.cgi/PythonProgrammingOnWinThirtyTwo

>  I would like to concentrate on Linux though.

One book (which I haven't read) that seems linux
focused is "Web Programming in Python: Techniques
for Integrating Linux, Apache and MySQL" See
http://www.python.org/cgi-bin/moinmoin/WebProgrammingBooks

>I have R.H 7.3. at home and would like examples of scripts that can be=20
>used in place of perl and shell scripting.

Red Hat stayed with python 1.5.2 for their admin
tools, and they made it in such a stupid way that
typing "python" at the prompts _had_ to start
1.5.2. So in R.H. 7.x, you have to type python2
to run python 2.x.x. This is a bit of a hazzle,
but R.H. 8.0 is up-to-date.

>I originally thought Java would be an ideal language to learn OOP in but=20
>got bogged down with all the calls to GUI components. How do I get started=
=20
>writing GUI stuff in python? Is it anything like Java GUI programming?

Well, if you like AWT and swing, you have to
use the Java implementation of Python, called
Jython, see http://www.jython.org/

Otherwise the most common GUI tool kits are
probably Tkinter (included in the standard
libs) and wxPython (http://www.wxpython.org/)

See also http://www.python.org/cgi-bin/moinmoin/GuiBooks


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Sat Oct 19 17:53:59 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat, 19 Oct 2002 18:53:59 +0200
Subject: [Tutor] parameter passing
In-Reply-To: <003601c276de$f545ba00$2502a8c0@emily.ewndsr01.nj.comcast.n
 et>
Message-ID: <5.1.0.14.0.20021019184525.02b45d10@www.thinkware.se>

I'm not a Tkinter expert, but I think I know
enough to say something here...

At 15:45 2002-10-18 -0400, andy surany wrote:
>Maybe I'm going nuts......
>
>THIS WORKS:
>class aaa:
>     def whowantstoknow:
>         input1=3D"'"+askstring('Enter your name','Name?')+"'"
>        =
 Button(self,text=3D'name',command=3Dself.update_name()).pack(side=3DLEFT)
>     def update_name(self):
>         # do some stuff.....

Really? Must be some freak accident.

When you define a widget like a button, you should tell
the button what function to call in case of an event.

For instance "command=3Dself.update_name". Note the lack of ().
What you typed--"command=3Dself.update_name()"--means that you
run the self.update_name when you define the button in
"whowantstoknow" and that you assign the return value from
the update_name function as the callback function for the button.
This is probably wrong (unless update_name returns a function.)

>
>THIS DOES NOT (in fact, the button statement - and any other button=20
>statement is ignored. But there is no error.):
>
>class aaa:
>     def whowantstoknow:
>         input1=3D"'"+askstring('Enter your name','Name?')+"'"
>=20
>Button(self,text=3D'name',command=3Dself.update_name(input1)).pack(side=3DL=
EFT)
>     def update_name(self,input1):
>         print 'name is ',input1
>

The simple way to avoid parameter passing here is to
store inputl as an instance attribute, i.e. self.inputl.

You CAN pass params in callbacks, but that makes the code a bit
more complex. Let's save that for later...


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Sat Oct 19 18:03:57 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat, 19 Oct 2002 19:03:57 +0200
Subject: [Tutor] How can I get the hostid of a computer?
In-Reply-To: <002a01c276fd$5920cb00$3212eb42@MYNEWBOX>
Message-ID: <5.1.0.14.0.20021019185706.02b17b40@www.thinkware.se>

At 16:23 2002-10-18 -0700, Lance wrote:
>Any advice would be appreciated.

I don't know of any OS independent way.
I'm not even sure what you mean by hostid.
Host name? Domain name? NETBIOS name?

If you have a way to get this "hostid" from
the command line in the OS, it's trivial
to get it from within Python.

E.g. in Linux:
 >>> import os
 >>> host = os.popen('uname -n').read().strip()
 >>> print host
palanga.ume1.thinkware.se



-- 
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  Sat Oct 19 18:34:08 2002
From: lumbricus@gmx.net (lumbricus@gmx.net)
Date: Sat, 19 Oct 2002 19:34:08 +0200 (MEST)
Subject: [Tutor] How can I get the hostid of a computer?
References: <5.1.0.14.0.20021019185706.02b17b40@www.thinkware.se>
Message-ID: <28287.1035048848@www21.gmx.net>

Hi!

> At 16:23 2002-10-18 -0700, Lance wrote:

[ snip ]

> E.g. in Linux:
>  >>> import os
>  >>> host = os.popen('uname -n').read().strip()
>  >>> print host
> palanga.ume1.thinkware.se

Better:

>>> import os
>>> host=os.uname()[1]

HTH, J"o!


-- 
Wir beschliessen etwas, stellen das dann in
den Raum und warten dann einige Zeit ab, was
passiert. Wenn es dann kein grosses Geschrei
gibt und keine Aufstaende, weil die meisten
gar nicht begreifen, was da beschlossen
wurde, dann machen wir weiter - Schritt fuer
Schritt, bis es kein Zurueck mehr gibt. 
   -- J-C Juncker

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



From lbrannma@cablespeed.com  Sat Oct 19 19:02:19 2002
From: lbrannma@cablespeed.com (Lance)
Date: Sat, 19 Oct 2002 11:02:19 -0700
Subject: [Tutor] How can I get the hostid of a computer?
References: <5.1.0.14.0.20021019185706.02b17b40@www.thinkware.se>
Message-ID: <001e01c27799$aa95c980$3212eb42@MYNEWBOX>

I must be referring to the MacID, the CPU specific identifier on which
licensing managers are based.

----- Original Message ----- 
From: "Magnus Lycka" <magnus@thinkware.se>
To: "Lance" <lbrannma@cablespeed.com>; "Tutor" <tutor@python.org>
Sent: Saturday, October 19, 2002 10:03 AM
Subject: Re: [Tutor] How can I get the hostid of a computer?


> At 16:23 2002-10-18 -0700, Lance wrote:
> >Any advice would be appreciated.
> 
> I don't know of any OS independent way.
> I'm not even sure what you mean by hostid.
> Host name? Domain name? NETBIOS name?
> 
> If you have a way to get this "hostid" from
> the command line in the OS, it's trivial
> to get it from within Python.
> 
> E.g. in Linux:
>  >>> import os
>  >>> host = os.popen('uname -n').read().strip()
>  >>> print host
> palanga.ume1.thinkware.se
> 
> 
> 
> -- 
> 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 lbrannma@cablespeed.com  Sat Oct 19 19:01:33 2002
From: lbrannma@cablespeed.com (Lance)
Date: Sat, 19 Oct 2002 11:01:33 -0700
Subject: [Tutor] How can I get the hostid of a computer?
References: <5.1.0.14.0.20021019185706.02b17b40@www.thinkware.se> <28287.1035048848@www21.gmx.net>
Message-ID: <000e01c27799$8f4b8cf0$3212eb42@MYNEWBOX>

Thanks,.. but this is what I get with the uname method:

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in ?
    host = os.uname()[2]
AttributeError: 'module' object has no attribute 'uname'

----- Original Message -----
From: <lumbricus@gmx.net>
To: <tutor@python.org>
Sent: Saturday, October 19, 2002 10:34 AM
Subject: Re: [Tutor] How can I get the hostid of a computer?


> Hi!
>
> > At 16:23 2002-10-18 -0700, Lance wrote:
>
> [ snip ]
>
> > E.g. in Linux:
> >  >>> import os
> >  >>> host = os.popen('uname -n').read().strip()
> >  >>> print host
> > palanga.ume1.thinkware.se
>
> Better:
>
> >>> import os
> >>> host=os.uname()[1]
>
> HTH, J"o!
>
>
> --
> Wir beschliessen etwas, stellen das dann in
> den Raum und warten dann einige Zeit ab, was
> passiert. Wenn es dann kein grosses Geschrei
> gibt und keine Aufstaende, weil die meisten
> gar nicht begreifen, was da beschlossen
> wurde, dann machen wir weiter - Schritt fuer
> Schritt, bis es kein Zurueck mehr gibt.
>    -- J-C Juncker
>
> +++ GMX - Mail, Messaging & more  http://www.gmx.net +++
> NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>




From mongo57a@comcast.net  Sat Oct 19 20:10:31 2002
From: mongo57a@comcast.net (andy surany)
Date: Sat, 19 Oct 2002 15:10:31 -0400
Subject: [Tutor] parameter passing
Message-ID: <001c01c277a3$322734c0$2502a8c0@emily.ewndsr01.nj.comcast.net>

Well after searching the web for any example that might pass a parame=
ter in
a Tk Button call - and finding not a one, I stumbled across
www.bembry.org/tech/python/tknotes4/shtml which basically told me tha=
t it
can't be done as I have tried (can't pass a parameter with "command")=
.

Lucky for me, he had a great example of how it can be done, and I am =
posting
the answer because I think the knowledge is worthwhile (if anybody
cares.......):

So,

Incorrect -

Button(self,text=3D'name',command=3Dself.update_name([input1]).pack(s=
ide=3DLEFT)

Correct -
    action =3D lambda x=3D[input1]:self.update_name(x)
    Button(self,text=3D'name',command=3Daction).pack(side=3DLEFT)

My thanks to the author of the site.....and to those of you that resp=
onded.

-Andy

-----Original Message-----
=46rom: Magnus Lycka <magnus@thinkware.se>
To: andy surany <mongo57a@comcast.net>; tutor@python.org <tutor@pytho=
n.org>
Date: Saturday, October 19, 2002 12:48 PM
Subject: Re: [Tutor] parameter passing


I'm not a Tkinter expert, but I think I know
enough to say something here...

At 15:45 2002-10-18 -0400, andy surany wrote:
>Maybe I'm going nuts......
>
>THIS WORKS:
>class aaa:
>     def whowantstoknow:
>         input1=3D"'"+askstring('Enter your name','Name?')+"'"
>
Button(self,text=3D'name',command=3Dself.update_name()).pack(side=
=3DLEFT)
>     def update_name(self):
>         # do some stuff.....

Really? Must be some freak accident.

When you define a widget like a button, you should tell
the button what function to call in case of an event.

For instance "command=3Dself.update_name". Note the lack of ().
What you typed--"command=3Dself.update_name()"--means that you
run the self.update_name when you define the button in
"whowantstoknow" and that you assign the return value from
the update_name function as the callback function for the button.
This is probably wrong (unless update_name returns a function.)

>
>THIS DOES NOT (in fact, the button statement - and any other button
>statement is ignored. But there is no error.):
>
>class aaa:
>     def whowantstoknow:
>         input1=3D"'"+askstring('Enter your name','Name?')+"'"
>
>Button(self,text=3D'name',command=3Dself.update_name(input1)).pack(s=
ide=3DLEFT)
>     def update_name(self,input1):
>         print 'name is ',input1
>

The simple way to avoid parameter passing here is to
store inputl as an instance attribute, i.e. self.inputl.

You CAN pass params in callbacks, but that makes the code a bit
more complex. Let's save that for later...


--
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor




From magnus@thinkware.se  Sat Oct 19 21:38:00 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat, 19 Oct 2002 22:38:00 +0200
Subject: [Tutor] How can I get the hostid of a computer?
In-Reply-To: <28287.1035048848@www21.gmx.net>
References: <5.1.0.14.0.20021019185706.02b17b40@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021019223624.02b0d3c8@www.thinkware.se>

At 19:34 2002-10-19 +0200, lumbricus@gmx.net wrote:
>Better:
>
> >>> import os
> >>> host=3Dos.uname()[1]

But still OS dependent... I don't think Lance is on a posix os.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Sat Oct 19 21:53:56 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat, 19 Oct 2002 22:53:56 +0200
Subject: [Tutor] How can I get the hostid of a computer?
In-Reply-To: <001e01c27799$aa95c980$3212eb42@MYNEWBOX>
References: <5.1.0.14.0.20021019185706.02b17b40@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021019224514.02b02438@www.thinkware.se>

At 11:02 2002-10-19 -0700, Lance wrote:
>I must be referring to the MacID, the CPU specific identifier on which
>licensing managers are based.

As I told you, I don't think there is any OS independent
way, so we can't really help you unless you tell what OS
you use.

If you by MacID mean MAC address, or Media Access Control
address, i.e. the hardware address in the network card,
this could work on Win 2000 for instance. The solution on
unix/linux is very similar. Please note that some machines
have several network cards (or none) which makes life more
difficult.

 >>> import os, re
 >>> pattern =3D re.compile(r'\w\w-\w\w-\w\w-\w\w-\w\w-\w\w')
 >>> text =3D os.popen('ipconfig /all').read()
 >>> m =3D pattern.search(text)
 >>> m.group(0)
'00-01-02-E0-FF-FF'


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From ckasso@sprynet.com  Sat Oct 19 22:28:18 2002
From: ckasso@sprynet.com (Chris Kassopulo)
Date: Sat, 19 Oct 2002 17:28:18 -0400
Subject: [Tutor] SciTE was Re: Moving Files Around
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9BC@mbtlipnt02.btlabs.bt.co.uk>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9BC@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20021019172818.12b27ee0.ckasso@sprynet.com>

On Fri, 18 Oct 2002 17:41:53 +0100
alan.gauld@bt.com wrote:

> Last time I looked SciTe was a very nice editor but not 
> in any way an IDE. Basically its a demo of the Scintilla 
> editor component which is used in several IDEs, 
> including Pythonwin. Has it changed recently?

I use SciTE under Linux.  It is a good text editor for
Python: syntax highlighting, indent and undent blocks
with TAB and BACKTAB, parenthesis matching, etc.
  
Like idle, you run a script that you are editing and it
opens another pane that shows the output of the script
along with any error messages and exit codes.  You can
click on the error and it will bring up that section of
code.

The only real drawback is that it cannot handle scripts
that require user input.  I understand that this works
under windows.

Is it an IDE? I think the term is used much more loosely
these days, so yes I guess it is.

Chris Kassopulo


From mongo57a@comcast.net  Sun Oct 20 01:04:58 2002
From: mongo57a@comcast.net (andy surany)
Date: Sat, 19 Oct 2002 20:04:58 -0400
Subject: [Tutor] How do I.......(another Tk, list question)
Message-ID: <003601c277cc$54690e40$2502a8c0@emily.ewndsr01.nj.comcast.net>

This is a multi-part message in MIME format.

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

Hi all!

I have built a scrolled list which I am populating from a remote database. I have also written functions to add/update/delete elements of the database based on list selections.

Now I would like to reflect the results of those change functions in the displayed list. Seems to me I have 2 choices: 1 is to re-execute the query and re-populate the box; the other is to handle the individual elements of the list (I have the location and value of each selected list element). If I do not re-execute the query, are there extensions to Listbox which would allow me to add/delete elements?

I tried just "re-calling" the routine that did the query and built the box. It worked - but gave me a whole new ScrolledList (so there are 2 on the display.....). Am I on the right track with this?

Your comments are appreciated.
TIA

--Boundary_(ID_+tutBRNWyPp4VNnkNMY+mQ)
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 all!</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>I have built a scrolled list which I am populating from a 
remote database. I have also written functions to add/update/delete elements of 
the database based on list selections.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Now I would like to reflect the results&nbsp;of those change 
functions in the displayed list. Seems to me I have 2 choices: 1 is to 
re-execute the query and re-populate the box; the other is to handle the 
individual elements of the list (I have the location and value&nbsp;of each 
selected list element). If I do not re-execute the query, are there extensions 
to Listbox which would allow me to add/delete elements?</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>I tried just&nbsp;"re-calling" the routine that did the query 
and built the box. It worked - but gave me a whole new ScrolledList (so there 
are 2 on the display.....). Am I on the right track with this?</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Your comments are appreciated.</FONT></DIV>
<DIV><FONT size=2>TIA</FONT></DIV></BODY></HTML>

--Boundary_(ID_+tutBRNWyPp4VNnkNMY+mQ)--


From lbrannma@cablespeed.com  Sun Oct 20 00:19:46 2002
From: lbrannma@cablespeed.com (Lance)
Date: Sat, 19 Oct 2002 16:19:46 -0700
Subject: [Tutor] How can I get the hostid of a computer?
References: <5.1.0.14.0.20021019185706.02b17b40@www.thinkware.se> <5.1.0.14.0.20021019224514.02b02438@www.thinkware.se>
Message-ID: <002901c277c6$03b26c90$3212eb42@MYNEWBOX>

Thanks Magnus,

That worked great for me... I'm running XP.

Lance

----- Original Message -----
From: "Magnus Lycka" <magnus@thinkware.se>
To: "Lance" <lbrannma@cablespeed.com>; "Tutor" <tutor@python.org>
Sent: Saturday, October 19, 2002 1:53 PM
Subject: Re: [Tutor] How can I get the hostid of a computer?


At 11:02 2002-10-19 -0700, Lance wrote:
>I must be referring to the MacID, the CPU specific identifier on which
>licensing managers are based.

As I told you, I don't think there is any OS independent
way, so we can't really help you unless you tell what OS
you use.

If you by MacID mean MAC address, or Media Access Control
address, i.e. the hardware address in the network card,
this could work on Win 2000 for instance. The solution on
unix/linux is very similar. Please note that some machines
have several network cards (or none) which makes life more
difficult.

 >>> import os, re
 >>> pattern = re.compile(r'\w\w-\w\w-\w\w-\w\w-\w\w-\w\w')
 >>> text = os.popen('ipconfig /all').read()
 >>> m = pattern.search(text)
 >>> m.group(0)
'00-01-02-E0-FF-FF'


--
Magnus Lyckå, Thinkware AB
Älvans väg 99, SE-907 50 UMEÅ
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se






From magnus@thinkware.se  Sun Oct 20 00:50:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sun, 20 Oct 2002 01:50:02 +0200
Subject: [Tutor] How do I.......(another Tk, list question)
In-Reply-To: <003601c277cc$54690e40$2502a8c0@emily.ewndsr01.nj.comcast.n
 et>
Message-ID: <5.1.0.14.0.20021020014135.02b02060@www.thinkware.se>

At 20:04 2002-10-19 -0400, andy surany wrote:
>Now I would like to reflect the results of those change functions in the=20
>displayed list. Seems to me I have 2 choices: 1 is to re-execute the query=
=20
>and re-populate the box; the other is to handle the individual elements of=
=20
>the list (I have the location and value of each selected list element). If=
=20
>I do not re-execute the query, are there extensions to Listbox which would=
=20
>allow me to add/delete elements?

I'd go for the refill from the database if performance is
ok. And maybe not only when I changed... Perhaps someone else
can change it? Or maybe I can open a second instance of the
program (or an SQL monitor) and change it outside the scope
of this app. This might need to be reflected in the list...

I use the GoF Observer (publish/subscribe) pattern for these
sorts of things. But I just have one thread/process/user to
worry about in my app. (So far.)

>I tried just "re-calling" the routine that did the query and built the=20
>box. It worked - but gave me a whole new ScrolledList (so there are 2 on=20
>the display.....). Am I on the right track with this?

You should have one routine that builds the box.
Then you should have a second routine to fill it.
In general, try to make your functions do just one thing.

In this case, you just call the second routine a second
time. (The refill routine will empty the list before
adding elements of course.)

Save a handle to the control as an attribute of the
surrounding class.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From thomi@thomi.imail.net.nz  Sun Oct 20 01:10:02 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Sun, 20 Oct 2002 13:10:02 +1300
Subject: [Tutor] extramural papers in python??
In-Reply-To: <web-23712869@mail.hal-pc.org>
References: <5.1.0.14.0.20021010224013.04b1cc50@www.thinkware.se>
 <web-23712869@mail.hal-pc.org>
Message-ID: <20021020131002.2fdedd0e.thomi@thomi.imail.net.nz>

thanks, I'll have a look tonight. I'm from New Zealand :-)

On Sat, 19 Oct 2002 09:39:13 -0500 Thus said "Kojo Idrissa"
<kojo@hal-pc.org>:

> Sorry I've been so slow on this. I know Magnus and the 
> person who asked the question originally wanted to know 
> about this paper, so here it is.  The title is:
> "A comparison of C++, Java and Python" by Ling Zhou
> It's a Comp Sci Masters Thesis from Texas A&M University. 
>  I don't know if you can find it online.
> 
> Sadly, as I was looking around on the web to see if you 
> could, I came across a comment I posted in 2000 on the 
> Jython list (I used to lurk there too) saying the same 
> thing.  2 years later and I still don't know if the paper 
> can be found online.  I'm pathetic.
> 
> On the other hand, it may be available through some sort 
> of inter-library loan, although that may be a bit extreme 
> from Australia.  I think that's where the person who first 
> raised the question is from.
> 
> HTH,
> 
> On Thu, 10 Oct 2002 22:44:43 +0200
>   Magnus Lycka <magnus@thinkware.se> wrote:
> ]At 12:40 2002-10-10 -0500, you wrote:
> ]>Runs a paper using python?  I'm not sure I understand 
> the 
> ]>question.  If you're looking for papers ABOUT python, or 
> ]>FEATURING python, I know there's a Master's Thesis at 
> ]>Texas A&M that compares Python, Java and C++.  If that 
> ]>will help, send me an email and I'll get the citation 
> for 
> ]>you later this evening.
> ]
> ]I don't understand what he is saying either,
> ]but I think he wan't to write a paper...
> ]
> ]I'm interested in that Python, Java & C++
> ]comparision though. It would fit on
> ]http://www.thinkware.se/cgi-bin/thinki.cgi/PythonDocs
> ]
> ]Please send me a reference if you find 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
> ]
> 
> ****************************
> Kojo Idrissa
> kojo@hal-pc.org
> 
> http://www.hal-pc.org/~kojo
> ****************************
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


-- 
This message was brought to you by one bored guy, with nothing better to
do,
And the letter Q.
Thomi Richards,
thomi@imail.net.nz


From magnus@thinkware.se  Sun Oct 20 01:38:17 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sun, 20 Oct 2002 02:38:17 +0200
Subject: [Tutor] extramural papers in python??
In-Reply-To: <20021020131002.2fdedd0e.thomi@thomi.imail.net.nz>
References: <web-23712869@mail.hal-pc.org>
 <5.1.0.14.0.20021010224013.04b1cc50@www.thinkware.se>
 <web-23712869@mail.hal-pc.org>
Message-ID: <5.1.0.14.0.20021020023235.02b14388@www.thinkware.se>

At 13:10 2002-10-20 +1300, Thomi Richards wrote:
>thanks, I'll have a look tonight. I'm from New Zealand :-)

Doesn't seem to be on the net. Perhaps the email
address to the author found here still works?

http://csweb1.cs.tamu.edu/student-org/awics/people.shtml

The paper is five-six years old though...


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From jay@hostfx.net  Sun Oct 20 15:00:39 2002
From: jay@hostfx.net (Jay Dorsey)
Date: Sun, 20 Oct 2002 10:00:39 -0400
Subject: [Tutor] Wishful thinking - Python and Docbook
Message-ID: <3DB2B707.4000804@hostfx.net>

I've been lurking on the mail list for a few weeks now and have become 
increasingly interested in learning Python.  However, I'm one of those 
people that learns best by doing things, and I've been trying to come up 
with a 'project' for myself to work on so I can maintain some focus.

I'm a ColdFusion web developer with not much real programming 
experience, but I do feel I have the capacity for it (just not all the 
time I'd like at the moment).  One of the tools I would like to build as 
  part of what I have to do at work is some type of Docbook application, 
for creating documents that follow the Docbook specification. 
ColdFusion isn't the right tool for the job I'm almost certain of.  My 
question is, is Python?

I'd like to build a GUI interface, something like a trimmed down Word, 
specifically that conforms to the Docbook XML specification.  What do I 
need to look into for the GUI part.  I understand that I still need to 
work on the core programming concepts, but if anyone can clue me in as 
to where to put some focus at (I see TkInter mentioned in posts, I know 
it's a GUI toolkit that can work on 'nix and Windows, but would it suit 
my needs?).

I know there isn't really any right or wrong to how I build this, I'm 
just looking for some advice from people that have experience.

Also, if you know of anyone that's worked on, is working on, or wants to 
work on, a similar type project, please let me know; I've not been able 
to find anything of the like about it.

Regards,

Jay



From magnus@thinkware.se  Sun Oct 20 20:04:24 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sun, 20 Oct 2002 21:04:24 +0200
Subject: [Tutor] Wishful thinking - Python and Docbook
In-Reply-To: <3DB2B707.4000804@hostfx.net>
Message-ID: <5.1.0.14.0.20021020204657.02b03ea0@www.thinkware.se>

Hi Jay, I'm sure Python is a reasonable tool for such a
task. It sounds like a very ambitious first programming
project though.

Python is fairly strong on both GUI and XML handling.

If I were you, I'd try to identify different components
here, and try to think of smaller pieces that might be
useful on their own, but also useful in this application.

Maybe you could start with a piece of code that validates
Docbook XML, or converts to XML from some simple markup?

It's also a good thing to learn the Python standard lib
and various third party libraries. Don't reinvent the wheel.
Maybe reStructuredText & DocFactory would be useful to you.
See http://docutils.sourceforge.net/rst.html and
http://docutils.sourceforge.net/sandbox/gschwant/docfactory/README.html

I wouldn't start with GUI in my first Python code. It's not
the eaisest end to start in.

At 10:00 2002-10-20 -0400, Jay Dorsey wrote:
>I've been lurking on the mail list for a few weeks now and have become=20
>increasingly interested in learning Python.  However, I'm one of those=20
>people that learns best by doing things, and I've been trying to come up=20
>with a 'project' for myself to work on so I can maintain some focus.
>
>I'm a ColdFusion web developer with not much real programming experience,=
=20
>but I do feel I have the capacity for it (just not all the time I'd like=20
>at the moment).  One of the tools I would like to build as  part of what I=
=20
>have to do at work is some type of Docbook application, for creating=20
>documents that follow the Docbook specification. ColdFusion isn't the=20
>right tool for the job I'm almost certain of.  My question is, is Python?
>
>I'd like to build a GUI interface, something like a trimmed down Word,=20
>specifically that conforms to the Docbook XML specification.  What do I=20
>need to look into for the GUI part.  I understand that I still need to=20
>work on the core programming concepts, but if anyone can clue me in as to=
=20
>where to put some focus at (I see TkInter mentioned in posts, I know it's=
=20
>a GUI toolkit that can work on 'nix and Windows, but would it suit my=
 needs?).
>
>I know there isn't really any right or wrong to how I build this, I'm just=
=20
>looking for some advice from people that have experience.
>
>Also, if you know of anyone that's worked on, is working on, or wants to=20
>work on, a similar type project, please let me know; I've not been able to=
=20
>find anything of the like about it.
>
>Regards,
>
>Jay
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From Gillisai@btinternet.com  Sun Oct 20 20:25:33 2002
From: Gillisai@btinternet.com (Alex Gillis)
Date: Sun, 20 Oct 2002 20:25:33 +0100
Subject: [Tutor] from Numeric import *
Message-ID: <001a01c2786e$76d37360$17507ad5@oemcomputer>

This is a multi-part message in MIME format.

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

from Numeric import *

doesn't work so i can't use arrays, I learnt this command from a =
tutorial that might be out of date, ohw do I import the array function.  =
Yes, I am a complete novice.

------=_NextPart_000_0017_01C27876.D7621A80
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 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>from Numeric import *</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>doesn't work so i can't use arrays, I =
learnt this=20
command from a tutorial that might be out of date, ohw do I import the =
array=20
function.&nbsp; Yes, I am a complete novice.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0017_01C27876.D7621A80--



From mongo57a@comcast.net  Sun Oct 20 21:50:22 2002
From: mongo57a@comcast.net (andy surany)
Date: Sun, 20 Oct 2002 16:50:22 -0400
Subject: [Tutor] An OO question as relates to Python.
Message-ID: <003b01c2787a$4eed1a20$2502a8c0@emily.ewndsr01.nj.comcast.net>

This is a multi-part message in MIME format.

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

Hi all!

It has been a long time since I did much programming - and consequently, I am relatively new to OO techniques. (It probably shows from some of the previous questions that I have put forward to the group)

I understand the concept of classes (or think that I do....) and in fact, I've written a program in which I create a couple of classes - and "borrow" a couple from the work of others. So my question is really one of reference to a class - specifically in Python. In general, how do you maintain a reference to a class - which means, how do I really reference the functionality in a routine belonging to one class from another? I seem to be doing fine within a single class - but multiple classes are giving me problems.

Perhaps one of you could refer me to a good online work on the subject...... or throw some good examples my way.

TIA

--Boundary_(ID_1LtsjT3OygtYAoa4FLCLKw)
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 all!</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>It has been a long time since I did much programming - and 
consequently, I am relatively new to OO techniques. (It probably shows from some 
of the previous questions that I have put forward to the group)</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>I understand the concept of classes (or think that I do....) 
and in fact, I've written a program in which I create a couple of classes - and 
"borrow" a couple from the work of others. So my question is really one of 
reference to a class - specifically in Python. In general, how do you maintain a 
reference to a class - which means, how do I really reference the functionality 
in a routine belonging to one class from another? I seem to be doing fine within 
a single class - but multiple classes are giving me problems.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Perhaps one of you could refer me to a good online work on the 
subject...... or throw some good examples my way.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>TIA</FONT></DIV></BODY></HTML>

--Boundary_(ID_1LtsjT3OygtYAoa4FLCLKw)--


From python <python@inkedmn.net>  Mon Oct 21 00:09:31 2002
From: python <python@inkedmn.net> (python)
Date: Sun, 20 Oct 2002 16:09:31 -0700
Subject: [Tutor] An OO question as relates to Python.
In-Reply-To: <003b01c2787a$4eed1a20$2502a8c0@emily.ewndsr01.nj.comcast.net>
References: <003b01c2787a$4eed1a20$2502a8c0@emily.ewndsr01.nj.comcast.net>
Message-ID: <157167569529.20021020160931@inkedmn.net>

try this:

http://www.ibiblio.org/obp/thinkCSpy/


as> Hi all!

as> It has been a long time since I did much programming - and consequently, I am relatively new to OO techniques. (It probably shows from some of the previous questions that I have put forward to
as> the group)

as> I understand the concept of classes (or think that I do....) and in fact, I've written a program in which I create a couple of classes - and "borrow" a couple from the work of others. So my
as> question is really one of reference to a class - specifically in Python. In general, how do you maintain a reference to a class - which means, how do I really reference the functionality in a
as> routine belonging to one class from another? I seem to be doing fine within a single class - but multiple classes are giving me problems.

as> Perhaps one of you could refer me to a good online work on the subject...... or throw some good examples my way.

as> TIA



From Gillisai@btinternet.com  Fri Oct 18 02:10:48 2002
From: Gillisai@btinternet.com (Alex Gillis)
Date: Fri, 18 Oct 2002 02:10:48 +0100
Subject: [Tutor] program closes straight away + python compiler?
Message-ID: <000a01c27643$33445d80$de707ad5@oemcomputer>

This is a multi-part message in MIME format.

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

When using a program i've written with python, the window closes as soon =
as its finished its job, which is usually too quick for me to even read =
the last print.  How do I change this?  Also, is there some sort of =
python compiler available or similar so that I could make python =
programs available to people without the python interpreter?

------=_NextPart_000_0007_01C2764B.93884000
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 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>When using a program i've =
written&nbsp;with python,=20
the window closes as soon as its finished its job, which is usually too =
quick=20
for me to even read the last print.&nbsp; How do I change this?&nbsp; =
Also, is=20
there some sort of python compiler available or similar so that I could =
make=20
python programs available to people without the python=20
interpreter?</FONT></DIV></BODY></HTML>

------=_NextPart_000_0007_01C2764B.93884000--



From wheelcrdan@hotmail.com  Sun Oct 20 18:29:21 2002
From: wheelcrdan@hotmail.com (Dan Dud)
Date: Sun, 20 Oct 2002 11:29:21 -0600
Subject: [Tutor] Help
Message-ID: <F18qwyLx5GjxJOAzGlD00005ecf@hotmail.com>

Hello everyone

I hope everyone weekend is going great I have this simple program that 
everything works as I would have thought but it exits on the wrong password 
but doesn't on the wrong user name what did I do wrong here is the code

#!/usr/bin/python
import time, sys
name=raw_input("Halt who the hell are you\n")
password=raw_input("what is your password\n")
if name == "Danny":
    print "Hi\n", name
    if name != "Danny":
        print "unknown user exiting the system"
        sys.exit()

if password == "b":
    print "Ok the time and date is\n"
    print time.ctime()
if password != "b":
    print "unknown password exiting the system now"
    sys.exit()


Also if I wanted this to start after I log into my linux box who would i do 
that I figured you had to import os but from there I'm clueless thanks for 
everyone help and have a great weekend

Danny D




_________________________________________________________________
Surf the Web without missing calls! Get MSN Broadband.  
http://resourcecenter.msn.com/access/plans/freeactivation.asp



From mylene.reiners@cmg.com  Mon Oct 21 09:08:38 2002
From: mylene.reiners@cmg.com (Mylene Reiners)
Date: Mon, 21 Oct 2002 10:08:38 +0200
Subject: [Tutor] Help
Message-ID: <B569A4D2254ED2119FE500104BC1D5CD01A69519@NL-EIN-MAIL01>

Hi Dan,

Mind the importance of indentation in Python.
    if name !=3D "Danny":
is only tested if the name already was "Danny" ...

(check the indentation difference in the name and the pw part...)

Myl=E8ne

-----Original Message-----
From: Dan Dud
To: tutor@python.org
Sent: 10/20/2002 7:29 PM
Subject: [Tutor] Help


Hello everyone

I hope everyone weekend is going great I have this simple program that=20
everything works as I would have thought but it exits on the wrong
password=20
but doesn't on the wrong user name what did I do wrong here is the code

#!/usr/bin/python
import time, sys
name=3Draw_input("Halt who the hell are you\n")
password=3Draw_input("what is your password\n")
if name =3D=3D "Danny":
    print "Hi\n", name
    if name !=3D "Danny":
        print "unknown user exiting the system"
        sys.exit()

if password =3D=3D "b":
    print "Ok the time and date is\n"
    print time.ctime()
if password !=3D "b":
    print "unknown password exiting the system now"
    sys.exit()


Also if I wanted this to start after I log into my linux box who would =
i
do=20
that I figured you had to import os but from there I'm clueless thanks
for=20
everyone help and have a great weekend

Danny D




_________________________________________________________________
Surf the Web without missing calls! Get MSN Broadband. =20
http://resourcecenter.msn.com/access/plans/freeactivation.asp


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


From magnus@thinkware.se  Mon Oct 21 09:25:19 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Mon, 21 Oct 2002 10:25:19 +0200
Subject: [Tutor] An OO question as relates to Python.
In-Reply-To: <003b01c2787a$4eed1a20$2502a8c0@emily.ewndsr01.nj.comcast.n
 et>
Message-ID: <5.1.0.14.0.20021021085509.02b226e8@www.thinkware.se>

At 16:50 2002-10-20 -0400, andy surany wrote:
>I understand the concept of classes (or think that I do....) and in fact,=
=20
>I've written a program in which I create a couple of classes - and=20
>"borrow" a couple from the work of others. So my question is really one of=
=20
>reference to a class - specifically in Python. In general, how do you=20
>maintain a reference to a class - which means, how do I really reference=20
>the functionality in a routine belonging to one class from another? I seem=
=20
>to be doing fine within a single class - but multiple classes are giving=20
>me problems.

I learnt a lot about OOP from Bertrand Meyer's Object
Oriented Software Construction. But it's really a brick...
Chapter 9 in the standard Python tutorial covers classes.

I think you should think more about objects and less
about classes. Typically, you only call classes when
you create objects, i.e. instances of the class. You
rarely make explicit calls to the functions (or rather,
methods) in a class. So it's the objects, or to be more
specific, the instances of the class you need references
to. The point with classes is that you collect code and
data on one bundle. This is the instance, often called
the object. The class is like a template for instances,
and you create instances by calling the class.

Just like you keep a reference to another type of
object, such as an integer or a list, you keep a
reference to an instance object with a variable.

This is no different in Python than in other languages.
I think the source of confusion are GUI programming
examples. In GUI's there are so many things happening
under the hood, and there are often implicit references
to objects which means that you can code in a style
which would otherwise mean that the objects disappeared
as soon as you had instanciated them. This makes these
GUI examples smaller and seemingly simpler, but since
more is done under the hood, it's bound to mislead the
OO novice.

Going back to python, you CAN call a class directly,
but typically you don't.

Maybe the following code might be of some help, where
instances of the SortedPersonList instanciate Person
objects, and place them in a list.

Perhaps this is all obvious to Andy, but a lot of people
are confused by OOP, so I think this might be useful.

---
class Person:
     def __init__(self, first, last):
         self.first =3D first
         self.last =3D last
     def whoami(self):
         return "My name is %s %s" % (self.first, self.last)
     def __cmp__(self, other):
         return cmp(self.last+self.first, other.last+other.first)

p =3D Person('Ron', 'Obvious')
p.whoami()
# Will print "My name is Ron Obvious"

class SortedPersonList:
     def __init__(self, listOfNames):
         self.persons =3D []
         for firstName, secondName in listOfNames:
             p =3D Person(firstName, secondName)
             self.persons.append(p)
         self.persons.sort()
     def printList(self):
         for p in self.persons:
             print p.whoami()

a =3D [('Andy', 'Surany'),
      ('Magnus', 'Lyck=E5'),
      ('Alex', 'Gillis'),
      ('Jay', 'Dorsey')]

recentTutorPosters =3D SortedPersonList(a)

recentTutorPosters.printList()
# Will print an alphabetical list with "My name is..." items.
---

Some comments:

The variable "self" which is used in places, corresponds to
the "this pointer" in for instance Java and C++. This is the
big difference between Python and the others. In Python, there
is no implicit this pointer. Explicit is better than implicit!

A method call such as "recentTutorPosters.printList()" can be
seen as a short form of: "SortedPersonList.printList(recentTutorPosters)".

Thus, the first parameter in any method in a class, should be an
instance object of the class in question. By convention this is
called "self".

The __init__ method is special. It is used to construct an
instance object. It has no return statement. "self" is always
returned. It's invoked automatiacally when you call the class.

E.g. p =3D Person('Ron', 'Obvious') could be seen as:

p =3D a new instance of the Person class
Person.__init__(p, 'Ron', 'Obvious')

Finally, the __cmp__ method is a special method. It's called
when you want to compare instances of a class. For instance,
if you write...

ron =3D Person('Ron', 'Obvious')
don =3D Person('Donald', 'Duck')
if ron < don:
     print "Ron's less than Don"

... the '<' operator will run:
Person.__cmp__(ron, don) and if __cmp__ returns a negative
number (meaning that ron was less than don) it will return
true. In the case above, __cmp__ is used when we sort the
list of Person instances.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Mon Oct 21 09:39:04 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Mon, 21 Oct 2002 10:39:04 +0200
Subject: [Tutor] program closes straight away + python compiler?
In-Reply-To: <000a01c27643$33445d80$de707ad5@oemcomputer>
Message-ID: <5.1.0.14.0.20021021102602.02b11e30@www.thinkware.se>

At 02:10 2002-10-18 +0100, Alex Gillis wrote:
>When using a program i've written with python, the window closes as soon=20
>as its finished its job, which is usually too quick for me to even read=20
>the last print.  How do I change this?

Get a slower computer! ;)

Or, end your program with:
raw_input('Press enter to close')

I think there should be a tutor FAQ, this question
is certainly FA. Is there a searchable archive of
the mailing list somewhere?

>  Also, is there some sort of python compiler available or similar so that=
=20
> I could make python programs available to people without the python=20
> interpreter?

Yes and no... :)

There is no complete python compiler. It's long been
"common knowledge" that Python is to dynamic for a
compiler to be viable. Now, there are a number of
projects working in that direction anyway.

Then there are other ways to bundle python programs
into a single executable to make distribution simpler.
The most common are py2exe and McMillan Installer. See
http://www.thinkware.se/cgi-bin/thinki.cgi/PythonInstallers

These tools don't give the speedup one could imagine from
native compilation, but they make it into one big exe. It
includes the python interpreter and the libraries you need.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From dyoo@hkn.eecs.berkeley.edu  Mon Oct 21 10:32:00 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 21 Oct 2002 02:32:00 -0700 (PDT)
Subject: [Tutor] Re: [meta-sig] accpeting wild characters from command line
In-Reply-To: <20021021082209.27388.qmail@web40703.mail.yahoo.com>
Message-ID: <Pine.LNX.4.44.0210210222370.13148-100000@hkn.eecs.berkeley.edu>

Hi Roslyn,

The 'meta-sig' is not really meant for questions about Python
specifically;  it's actually meant for meta-Python issues (i.e. the
creation of special interest groups, administrative stuff.)  Boring stuff.
*grin*


People have already recommended you to look for a more appropriate forum
for questions, and ignoring their warning is not a good thing to do.
Let's not disturb them: a roused list-admin is not a happy sight.


You'll get better help if you post to a forum specifically meant for
Python learning.  A good one is Python-Tutor:

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


We'd be happy to hear from you!  For your convenience, I'll forward your
message to the list.  In the future, please post general Python-learning
questions to tutor, not meta-sig.



> i have a list of .txt files that i would like to enter from command
> line, but as its a hassle to write all the names i would like to just
> type in *.txt at the python command line. could someone tell me how i
> can have python interpret that wils char, is there any built in
> function?? thanks.


You may find the 'glob' module useful for this.  See:

    http://python.org/doc/lib/module-glob.html

for examples of how to use this module.



I hope this helps!



From roserachjose@yahoo.com  Mon Oct 21 10:39:38 2002
From: roserachjose@yahoo.com (roslyn jose)
Date: Mon, 21 Oct 2002 02:39:38 -0700 (PDT)
Subject: [Tutor] accepting wild chars from pythons command line
Message-ID: <20021021093938.27131.qmail@web40701.mail.yahoo.com>

--0-1640949064-1035193178=:26384
Content-Type: text/plain; charset=us-ascii


hi,

i have a list of .txt files that i would like to enter from command
 line, but as its a hassle to write all the names i would like to just
 type in *.txt at the python command line. could someone tell me how i
 can have python interpret that wils char, is there any built in
 function?? thanks.

regards,

roslyn



---------------------------------
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site
--0-1640949064-1035193178=:26384
Content-Type: text/html; charset=us-ascii

<P>hi,</P>
<P>i have a list of .txt files that i would like to enter from command<BR>&nbsp;line, but as its a hassle to write all the names i would like to just<BR>&nbsp;type in *.txt at the python command line. could someone tell me how i<BR>&nbsp;can have python interpret that wils char, is there any built in<BR>&nbsp;function?? thanks.<BR><BR>regards,</P>
<P>roslyn</P><p><br><hr size=1>Do you Yahoo!?<br>
<a href="http://webhosting.yahoo.com/ ">Y! Web Hosting</a> - Let the expert host your web site
--0-1640949064-1035193178=:26384--


From alan.gauld@bt.com  Mon Oct 21 11:34:19 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 21 Oct 2002 11:34:19 +0100
Subject: [Tutor] Books
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9C1@mbtlipnt02.btlabs.bt.co.uk>

> books or tutorials that give examples of useful system 
> administration and OOP programs. 

Lutz' "Programming Python" 2bnd Edition may please you....

It covers sys admin type examples and has a fair bit 
on GUIs under Python.

> How do I get started writing GUI stuff in python? 

I'd go visit the Tkinter section of the python web 
site and follow the linked tutorials...

> Is it anything like Java GUI programming?

At one level yes, all GUI programming shares similar 
concepts. Certainly Python GUIs tend to use concepts 
likelayout managers, callback functions etc etc.
If you use jython you can even use the Java AWT/Swing 
classes!

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


From thomi@thomi.imail.net.nz  Mon Oct 21 11:53:51 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Mon, 21 Oct 2002 23:53:51 +1300
Subject: [Tutor] what i miss is a C style for loop
Message-ID: <20021021235351.2c73d51f.thomi@thomi.imail.net.nz>

yep, thats right, i live those C style for loops. they are compact, and
easy to use, once you get the hang of it..

so I thought I'd make my own, except i soon realized that the for
keyword has to be...integrated with the rest of the language... but
how?? sure, i could download the python source code, and get lost trying
to make it.... any ideas??

It's not really important, but it'd be nice... i could call it cfor or
forc... of course, it'd be completely useless on other peoples machines,
unless it is portable...hmmmm


(please excuse my sleep deprived ravings)

-- 
This is a subliminal message.
Thomi Richards,
thomi@imail.net.nz


From darnold02@sprynet.com  Mon Oct 21 11:57:52 2002
From: darnold02@sprynet.com (Don Arnold)
Date: Mon, 21 Oct 2002 05:57:52 -0500
Subject: [Tutor] accepting wild chars from pythons command line
References: <20021021093938.27131.qmail@web40701.mail.yahoo.com>
Message-ID: <05f701c278f0$bed046c0$1f10ba3f@defaultcomp>

----- Original Message -----
From: roslyn jose
To: tutor@python.org
Sent: Monday, October 21, 2002 4:39 AM
Subject: [Tutor] accepting wild chars from pythons command line


hi,
i have a list of .txt files that i would like to enter from command
 line, but as its a hassle to write all the names i would like to just
 type in *.txt at the python command line. could someone tell me how i
 can have python interpret that wils char, is there any built in
 function?? thanks.

regards,
roslyn

The glob module handles this. Specifically, glob.glob(arg) will return you a
list of files that match the template 'arg', so you can do something like
this:

import glob
import sys

filelist = []

if len(sys.argv) > 1:
    for argument in sys.argv[1:]:
        filelist.extend(glob.glob(argument))

print filelist


HTH,

Don



From James.Rocks@equant.com  Mon Oct 21 11:06:58 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Mon, 21 Oct 2002 11:06:58 +0100
Subject: [Tutor] Defining & Importing Functions
Message-ID: <OF7A358ED7.D4AEF16D-ON80256C59.00369A66@equant.com>

Hi again,

Still trying to resolve this one.

O/S:        Windows XP
Python Inst:      c:\Python21
IDE Inst (Boa):   c:\boa
Prog Dir:   c:\Python21\CTX (not on path or in PYTHONPATH variable)
New Prog Dir:     c:\boa\Projects\CTX  (not on path but IS in PYTHONPATH
variable)

When I run my program from the original program folder (where I developed
it) it's fine. When I run it (or any other python program) from a new
folder (a subfolder of c:\boa) I get:

>>> execfile("c:\boa\Projects\CTX\ctxrept.py")
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
IOError: [Errno 22] Invalid argument
>>>

In neither case is the program in the same folder as the python program and
a further test I've done indicates that if I run the program from another
folder (c:\Python21\Projects\CTX) it also works implying that Python (on
Windows at any rate) must be either in the same folder or a parent folder
of the project.

Perhaps the answer is to re-install boa as a subfolder of c:\Python21 but I
really feel that it shouldn't matter where I run my program from, it should
just pick up the executable and "run with it"!

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From alan.gauld@bt.com  Mon Oct 21 11:46:18 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 21 Oct 2002 11:46:18 +0100
Subject: [Tutor] parameter passing
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9C2@mbtlipnt02.btlabs.bt.co.uk>

> Lucky for me, he had a great example of how it can be done, 
> and I am posting the answer because I think the knowledge 
> is worthwhile 
> Incorrect -
> 
> Button(self,text='name',command=self.update_name([input1]).pac
> k(side=LEFT)
> 
> Correct -
>     action = lambda x=[input1]:self.update_name(x)
>     Button(self,text='name',command=action).pack(side=LEFT)

But note one caveat. If input1 changes between the time 
you define the Button(or more accurately the lambda) 
and the time you press the button the new input1 will 
be ignored! (This is because default arguments in 
Python are stored at the time of definition, not at 
the time of use)

If you want to use the current value of input1 each time 
the command is called you must store it as an instance 
variable and access it that way - as Magnus originally 
stated.

Also note that the lambda format is not necessary 
(as someone showed last week you can use a command 
pattern) since you can just define a short function:

def button_callback(self,inp = input1): 
   return self.update_name(inp)
Button(self,command=self.button_callback).pack()

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



From alan.gauld@bt.com  Mon Oct 21 11:55:18 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 21 Oct 2002 11:55:18 +0100
Subject: [Tutor] How do I.......(another Tk, list question)
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9C3@mbtlipnt02.btlabs.bt.co.uk>

> I tried just "re-calling" the routine that did the 
> query and built the box. It worked - but gave me 
> a whole new ScrolledList 

The problem is something that has been evident in the 
earlier code you posted. You are creating the GUI 
elements dynamically within your processing functions. 
Occasionally thats a sensible thing to do but not 
very often. You would be much better creating the 
GUI in a separate function and storing references 
to the various GUI controls as class variables. 
Then write the event handlers to control the GUI 
parts separately - this leads to much better 
reuse too.

> Am I on the right track with this?

I suspect not.
Try taking all of the Button creation, List 
creation code etc out to a buildGUI method.
Have the widgets stored as variables. 
Then write separate functions to populate 
the lists with data and finally event handlers 
to process the data when desired. In this way 
you can repopulate the lists whenever you want, 
you can recreate the GUI whenever (and as often 
as) you want. And you can process the data 
as and when you want. 

Separating functionality out to atomic levels 
like this - each function does only one job 
- makes for reusable and more flexible code.

Of course there may be a valid reason for not 
doing this, but I can't think odf one off hand!

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


From alan.gauld@bt.com  Mon Oct 21 11:31:17 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 21 Oct 2002 11:31:17 +0100
Subject: [Tutor] functions in other files, executing
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9C0@mbtlipnt02.btlabs.bt.co.uk>

> basically, every module has to be in it's own directory, 
> because they each have extra bits of data in separate 
> files with them. 

Its quite common for a module to depend on some 
kind of external configuration data. Applying the 
old CS maxim of "You can do it with one more level 
of indirection" this is normally tackled by having 
a config file that is read at startup by the module. 
The config file then includes the references to the 
real data - in your case the full path to the needed 
icons...

Now when you want to reuse the module in another 
project you just create a new config file pointing 
at the new projects icons... Now you can keep the 
modules and config files in the same folder or, 
probably better, keep the modules together but put 
the module file in a project specific directory 
specified by an environment variable say. Then each 
project can have its own environment variable and 
its own folder of config files....

If you need more control still then you can create 
a module init function that takes the config file 
path as a parameter. Then users can run several 
instances at the same time(on different projects 
say) for the slight penalty of having to call the 
init function:

import foo
foo.init('some/path/here/')

Like I said, "You can do it with one more 
level of indirection...."

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



From alan.gauld@bt.com  Mon Oct 21 12:11:27 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 21 Oct 2002 12:11:27 +0100
Subject: [Tutor] An OO question as relates to Python.
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9C4@mbtlipnt02.btlabs.bt.co.uk>

> I understand the concept of classes (or think that I do....) 

> In general, how do you maintain a reference to a class 

OK, I don't think you really mean this but I'll answer 
it anyway!

A class reference is just like any other variable.
Thus:

class Foo:
   def __init__(self): print "Creating a FOO instance"

To create a reference to the class Foo we just assign 
a variable:

Bar = Foo  # note no parens!

Now we can create instances of FOO using either Bar or FOO:

inst1 = Foo()  # one instance of Foo
inst2 = Bar()  # Also an instance of Foo

That is occasionally useful when dealing with abstract 
frameworks which must create internal instances of 
different classes at runtime(somewhat like C++ templates)
and readers of my book can find a description in the 
second case study, while others can see the commented 
code on the Usdeless Python website...

However I don't think that really what you want, I think 
you mean how to manage references to different instances, 
and for that you again use variables just as we did 
above with inst1 and inst2.

> - which means, how do I really reference the functionality 
> in a routine belonging to one class from another? 

But you really shouldn't do this. (Its possible, but ugly 
and very bad practice!) Instead pass a referenbde to the 
object(instance) and then call the method when required.

Here's an example:

class A:
  def f(self): print 'in f of A'

class B:
  def x(self,anObject): self.object = anObject
  def y(self): print self.object.f()

a = A()  # create an A instance
b = B()  # create a B instance
b.x(a)   # pass refernce to a to b
b.y()    # calls the f method of a.

> Perhaps one of you could refer me to a good online 
> work on the subject...... or throw some good examples my way.

Have you looked at my online tutor topic on OOP?

HTH,

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


From alan.gauld@bt.com  Mon Oct 21 12:16:52 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 21 Oct 2002 12:16:52 +0100
Subject: [Tutor] program closes straight away + python compiler?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9C5@mbtlipnt02.btlabs.bt.co.uk>

> When using a program i've written with python, 
> the window closes as soon as its finished its job, 

This should be in the Python FAQ, I must check sometime!

There are several options:
1) put a line like this at the end of your program:

raw_input('Hit Enter to quit')

Which will pause the window until you hit the enter key.

2) Run the program from a DOS prompt rather than double 
clicking. That way the window stays open.

3) Create a shortcut then adjust the properties so that 
it doesn't close on exit(its a checkbox somewhere...)

> Also, is there some sort of python compiler available 
> or similar so that I could make python programs 
> available to people without the python interpreter?

Likewise I hope this is in the FAQ....

There are several tools for doing this. On windows 
the most popular is py2exe. Be aware tho that what they 
really do is just bundle the python interpreter and 
any required libraries into an executable file. 
So if you distribute many scripts you wind up having 
lots of pythons installed which takes up more space 
than just giving out python once....

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


From alan.gauld@bt.com  Mon Oct 21 12:19:36 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 21 Oct 2002 12:19:36 +0100
Subject: [Tutor] An OO question as relates to Python.
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9C6@mbtlipnt02.btlabs.bt.co.uk>

> I learnt a lot about OOP from Bertrand Meyer's Object
> Oriented Software Construction. But it's really a brick...
> Chapter 9 in the standard Python tutorial covers classes.

Meyer is probably the best OO book around but as Magnus 
says its huge! It also is geared towards Meyer's own 
language Eiffel which while good is hardly mainstream! 
But the principles are rock solid if you can afford 
the time to read it(and the cash to buy it!)!

Alan G


From alan.gauld@bt.com  Mon Oct 21 12:20:53 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 21 Oct 2002 12:20:53 +0100
Subject: [Tutor] program closes straight away + python compiler?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9C7@mbtlipnt02.btlabs.bt.co.uk>

> I think there should be a tutor FAQ, this question
> is certainly FA. Is there a searchable archive of
> the mailing list somewhere?

The ActiveState web site has a search facility for the archives.

And yes a tutor FAQ has been mooted in the past but I 
don't think anyone ever did anything....

Alan G.


From magnus@thinkware.se  Mon Oct 21 12:40:04 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Mon, 21 Oct 2002 13:40:04 +0200
Subject: [Tutor] accepting wild chars from pythons command line
In-Reply-To: <20021021093938.27131.qmail@web40701.mail.yahoo.com>
Message-ID: <5.1.0.14.0.20021021132330.02b00bb8@www.thinkware.se>

At 02:39 2002-10-21 -0700, roslyn jose wrote:
>i have a list of .txt files that i would like to enter from command
>  line, but as its a hassle to write all the names i would like to just
>  type in *.txt at the python command line. could someone tell me how i
>  can have python interpret that wils char, is there any built in
>  function?? thanks.

I'm not sure what you mean by the "python command line".

Do you call your programs from inside the interactive python
interpreter, or do you refer to ad-hoc work in the python
interpreter?

Inside the python interpreter you could do something like:

 >>> import glob
 >>> filenames =3D glob.glob('*.txt')
 >>> print filenames
['this.txt', 'that.txt']

If you refer to commands entered on the operating system
command line, things are different, depending on you
operating system.

In unix '*.txt' will be expanded by the command shell
before the python program is started, while Windows leaves
such things to the application (unless you run a unix-style
command shell such as bash.exe.)

The consequence of this is that if you have a program
called printargs.py like this:

import sys
print sys.argv

and run it at a windows command line, it will look like
this in Windows:

G:\temp>python printargs.py *.tmp
['printargs.py', '*.tmp']

G:\temp>python printargs.py "*.tmp"
['printargs.py', '*.tmp']

But in unix it will look like this (depending
on directory content):

[mly@palanga mly]$ python printargs.py *.txt
['printargs.py', 'exempel.txt', 'temp.txt']

[mly@palanga mly]$ python printargs.py "*.txt"
['printargs.py', '*.txt']

In other words, wildcards are handled differently
depending on platform, and we need to be aware of
that to do things right (and give correct answers).


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From jrclare@lycos.com  Mon Oct 21 12:46:19 2002
From: jrclare@lycos.com (James Clare)
Date: Mon, 21 Oct 2002 07:46:19 -0400
Subject: [Tutor] Books
Message-ID: <BIIPCMNCMOANBBAA@mailcity.com>

Thanks alot. I'll leave the message below so others can follow the links.
Jim
 
--

On Mon, 21 Oct 2002 11:34:19  
 alan.gauld wrote:
>> books or tutorials that give examples of useful system 
>> administration and OOP programs. 
>
>Lutz' "Programming Python" 2bnd Edition may please you....
>
>It covers sys admin type examples and has a fair bit 
>on GUIs under Python.
>
>> How do I get started writing GUI stuff in python? 
>
>I'd go visit the Tkinter section of the python web 
>site and follow the linked tutorials...
>
>> Is it anything like Java GUI programming?
>
>At one level yes, all GUI programming shares similar 
>concepts. Certainly Python GUIs tend to use concepts 
>likelayout managers, callback functions etc etc.
>If you use jython you can even use the Java AWT/Swing 
>classes!
>
>Alan g.
>Author of the 'Learning to Program' web site
>http://www.freenetpages.co.uk/hp/alan.gauld
>


____________________________________________________________
Get 250 full-color business cards FREE right now!
http://businesscards.lycos.com 


From James.Rocks@equant.com  Mon Oct 21 11:52:07 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Mon, 21 Oct 2002 11:52:07 +0100
Subject: [Tutor] Defining & Importing Functions
Message-ID: <OFDADB22BD.30C544E1-ON80256C59.003B4A55@equant.com>

OK ...

I think I'm beginning to suss a possible reason for this and one that
implies it is purely a Windows issue.

If I place the python files I am running in a subfolder of Python it's
fine, if I place in a sub folder of that it's fine, if I create another
subfolder it is not fine. If I place the files in a subfolder of c: it's
fine and likewise for a sub folder of that but any deeper and it's a no, no
so it appears that Python can (on Windows XP at least) only handle a
program running from a nested folder or less ... anything more than two
levels of folder and it can't handle it. Not sure whether it is (if indeed
I am right) the depth of folders of the length of the pathname but its
something to work with :-)

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From magnus@thinkware.se  Mon Oct 21 13:34:34 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Mon, 21 Oct 2002 14:34:34 +0200
Subject: [Tutor] what i miss is a C style for loop
In-Reply-To: <20021021235351.2c73d51f.thomi@thomi.imail.net.nz>
Message-ID: <5.1.0.14.0.20021021134208.02b1db58@www.thinkware.se>

At 23:53 2002-10-21 +1300, Thomi Richards wrote:
>yep, thats right, i live those C style for loops. they are compact, and
>easy to use, once you get the hang of it..

I'll quote Yoda: "You must unlearn what you have learned!" ;)

Each time I try to program Perl I'm painfully made aware
that I really have to follow the style and idioms of the
programming language I use. My pythonesque perl programs
won't work... C style python programs won't be good python
programs.

Could you please post some examples of how you typically
use for loops, in some kind of context, and let us show
how these things are normally solved in python?

I assume that Guido's reasoning was along the lines that
C style for loops are just a shorthand for while loops.

for (init; test; update) {block;}

is basically the same thing as

init;
while (test) {block; update;}

It doesn't really add anything substantial to the language,
and it's even ambiguous, at least in C++. (Are declarations
in the for statement inside or outside the loop?)

There are also common off-by-one errors that appear with
C/C++/Java for loops. As you said: "once you get the hang
of it"...

The python for loop typically eliminate such problems
by iterating over a sequence instead of providing index
numbers. The range and xrange functions provide a tool
for looping over integer ranges, with whatever stepping
you like. You can loop directly over the lines in a file,
not needing to worry about EOF etc.

Some people are confused by range(x) stopping short of x,
but it's completely consistent with other parts of the
language such as indexing and slicing, so understanding
that part of python is a general issue in the language.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From James.Rocks@equant.com  Mon Oct 21 12:27:42 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Mon, 21 Oct 2002 12:27:42 +0100
Subject: [Tutor] Importing Files
Message-ID: <OFAF70CFAE.E79A87A8-ON80256C59.003E057D@equant.com>

Hi,

I asked this before but the answer moved rapidly away from what I wanted an
answer to ... that's the nature of conversations methinks :-)

To import a file or a function into a program you use:

      >>> import libname

or

      >>> from libname import functionname|*

Yes?

Now I have writrten a number of functions I would like to use in more than
one program but I can't seem to do it unless I put that function file in
the Python Install folder (c:\python21) ... is there any way to import a
file or a function from a file yet keep it in a place that suits me? In
other words will "import" only work if the file is in a specific
place/specific places?

James

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ



From magnus@thinkware.se  Mon Oct 21 14:37:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Mon, 21 Oct 2002 15:37:02 +0200
Subject: [Tutor] Tutor FAQ
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9C7@mbtlipnt02.btlabs
 .bt.co.uk>
Message-ID: <5.1.0.14.0.20021021144924.02b49c10@www.thinkware.se>

At 12:20 2002-10-21 +0100, alan.gauld@bt.com wrote:
> > I think there should be a tutor FAQ, this question
> > is certainly FA. Is there a searchable archive of
> > the mailing list somewhere?
>
>The ActiveState web site has a search facility for the archives.

Would it be possible to get a link to that in the
mailing list sig?

Any list admin reading this these days???

>And yes a tutor FAQ has been mooted in the past but I
>don't think anyone ever did anything....

I guess one might think that it should be enough
with the normal Python FAQ, but it's not always so
easy to find information there, and it's not really
geared specifically to the kind of people who ask
questions on the Tutor list.

I don't know though... Maybe putting a pointer to the
python FAQ in the tutor sig, and an effort from us to
keep the python FAQ up-to-date would be best?

Otherwise a Wiki page would be a simple way to make
a FAQ possible. My Thinki wiki is available, and I
guess the Python Wiki could as well...

A related issue is a page of "How do I do this trick
in Python"-page. I think it would be helpful for
"converts" to see how the things they do in C, Java,
Perl, VB or whatever are usually done in Python.

Questions often pop up regards switch/case, for loops,
do-while, conditional expressions etc.

There is some stuff at http://www.c2.com/cgi/wiki?PythonIdioms
but more of a comparision might be useful.

Although, often the question regarding some detail
stems from viewing a problem from the perspective of
a non-pythonic style, and we need to look at the
pythonic way from a higher perspective.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From alan.gauld@bt.com  Mon Oct 21 15:15:33 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 21 Oct 2002 15:15:33 +0100
Subject: [Tutor] what i miss is a C style for loop
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9C9@mbtlipnt02.btlabs.bt.co.uk>

> yep, thats right, i live those C style for loops. they are 
> compact, and easy to use, once you get the hang of it..

The C for loop is just a while loop in disguise 
so you can duplicate the basic functions, but 
the full C for loop power is not really feasible 
in Python

for(a=0,b=5;c=b;a=0,b+=7){....}

for example. Valid if strange C but hard to do in any 
sane python function.

But if you stick to the basic C style:

for(i=0;i<limit;i++){...}

Then you can do:

def cfor(initvalue,limit,incr, func):
    i = initvalue
    while i < limit:
       func(i)
       i += incr

But that's a poor imitation of a C for loop...

Also you need to allow access to the global 
environment from within the loop without name 
clashes etc...

Anything more potent would really be pretty 
complex and probably very slow! 

Alan g.


From francois.granger@free.fr  Mon Oct 21 16:28:52 2002
From: francois.granger@free.fr (Fran=?ISO-8859-1?B?5w==?=ois Granger)
Date: Mon, 21 Oct 2002 17:28:52 +0200
Subject: [Tutor] Importing Files
In-Reply-To: <OFAF70CFAE.E79A87A8-ON80256C59.003E057D@equant.com>
Message-ID: <B9D9E9D4.59BC8%francois.granger@free.fr>

on 21/10/02 13:27, James.Rocks@equant.com at James.Rocks@equant.com wrote:

> Now I have writrten a number of functions I would like to use in more than
> one program but I can't seem to do it unless I put that function file in
> the Python Install folder (c:\python21) ... is there any way to import a
> file or a function from a file yet keep it in a place that suits me? In
> other words will "import" only work if the file is in a specific
> place/specific places?

You can add this place to your Python path. This operation is plateform
dependant (On MacOS I use the EditPythonPref applet) on Windows, you may
have to edit the registery ?

Another way is to put them in $Python$/lib/site-packages wich is already in
the Python path.
-- 
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 charlie@begeistert.org  Mon Oct 21 19:02:28 2002
From: charlie@begeistert.org (Charlie Clark)
Date: Mon, 21 Oct 2002 18:02:28 +0000
Subject: [Tutor] Re: importing functions, paths, etc.
In-Reply-To: <20021021133102.4101.32832.Mailman@mail.python.org>
References: <20021021133102.4101.32832.Mailman@mail.python.org>
Message-ID: <20021021180228.1519.4@gormenghast.1035204383.fake>

On 2002-10-21 at 13:31:02 [+0000], you wrote:
> 
> Now I have writrten a number of functions I would like to use in more tha=
n
> one program but I can't seem to do it unless I put that function file in
> the Python Install folder (c:\python21) ... is there any way to import a
> file or a function from a file yet keep it in a place that suits me? In
> other words will "import" only work if the file is in a specific
> place/specific places?
> 
Hi James,

what you want to do is really easy. I haven't been able to follow all the 
discussion on this but it seems you haven't been introduced to the 
Pythonpath - the path which python searches for modules. Like so much of 
Python you can change this to suit your needs. There are several ways of 
changing it depending on the situation: you can change it directly in the 
Python environment variables - available in windows in the control panel 
settings. I find this arcane and the way Python runs under windows is one 
of the reasons I don't like developing on it. But you can also change the 
path directly from within Python. Try this:
start a python session:
>>> import sys
>>> sys.path
['', '/boot/home/config/lib/python2.1', 
'/boot/home/config/lib/python2.1/plat-beos5', 
'/boot/home/config/lib/python2.1/lib-tk', 
'/boot/home/config/lib/python2.1/lib-dynload', 
'/boot/home/config/lib/python2.1/site-packages']   

As you can see the path is just a list. It's easy to add a directory:
>>> sys.path.append("/boot/home/projects/equant")

I think you can then access modules directly from that folder but you might=
 
have to write a special module
import myModule

myModule.SpecialFunction()

away you go.

Loading the same module from different times shouldn't cause any problems. 
I think Python handles this fairly efficiently as well by avoiding copies 
of module in memory but that is speculation on my part. It is fairly common=
 
to have utility modules just for that. Of course, which functions you put 
in which module is an aspect of program design. There's nothing wrong with 
putting all your functions into one module but it usually a good idea to 
group functions and stuff together according to how they will be used.

ie avoid
from ThisModule import small_function
from ThatModule import another_small_function
from AnotherModule import small_function as it_needs_a different_name

I think it's common sense to see where that leads to. Namespaces are our 
friends.

Charlie
-- 
Charlie Clark
Helmholtzstr. 20
D=1Asseldorf
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226


From alan.gauld@bt.com  Mon Oct 21 16:57:19 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 21 Oct 2002 16:57:19 +0100
Subject: [Tutor] Importing Files
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9CA@mbtlipnt02.btlabs.bt.co.uk>

> other words will "import" only work if the file is in a specific
> place/specific places?

No.
import looks at the sys.path setting and searches 
all of the folders in that path.

It also uses the PYTHONPATH environment variable but 
I suspect that it does so by adding the folders 
defined there to the sys.path settings at startup.

What this means is that you can define a default set 
of folders in PYTHONPATH and then add others as 
needed within a program by modifying sys.path.

In addition there is the package magic that uses the 
init files within folders to allow searching of 
folders nested within the top level ones defined 
in sys.path.... Read the reference pages in the 
documentation on packages for the full story.

As a for instance, I have python installed in D:\python
and save all my reusable modules in D:\PROJECTS\MODULES
I also have project source code in:

D:\PROJECTS\<PROJNAME>

Thus I can import modules from the standard python places
(the D:\PYTHON..... part), my libraries(defined in 
PYTHONPATH) and from my current folder (C:\PROJECTS\PROJNAME)

HTH,

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


From James.Alexander.McCarney@Cognicase.com  Mon Oct 21 17:50:29 2002
From: James.Alexander.McCarney@Cognicase.com (McCarney, James Alexander)
Date: Mon, 21 Oct 2002 12:50:29 -0400
Subject: [Tutor] Capturing browser pop-ups / push advertising. etc.
Message-ID: <23FD7B1A77E8D211BCB900001D108C02023FCA71@camelot>

Hi Pythonistas universal and triumphant! ;-)

Is there a way any of you know how to capture what is on a pushed browser
screen or pop-up...

For instance, if I access a site, then more 'cr*p' than you can shake a
stick at gets launched. I would like to see what it is as text. 

I am probably biting off more than I can chew here.

Insights appreciated. Cheers.

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 shalehperry@attbi.com  Mon Oct 21 18:03:49 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Mon, 21 Oct 2002 10:03:49 -0700
Subject: [Tutor] Capturing browser pop-ups / push advertising. etc.
In-Reply-To: <23FD7B1A77E8D211BCB900001D108C02023FCA71@camelot>
References: <23FD7B1A77E8D211BCB900001D108C02023FCA71@camelot>
Message-ID: <200210211003.49527.shalehperry@attbi.com>

On Monday 21 October 2002 09:50, McCarney, James Alexander wrote:
> Hi Pythonistas universal and triumphant! ;-)
>
> Is there a way any of you know how to capture what is on a pushed brows=
er
> screen or pop-up...
>
> For instance, if I access a site, then more 'cr*p' than you can shake a
> stick at gets launched. I would like to see what it is as text.
>
> I am probably biting off more than I can chew here.
>
> Insights appreciated. Cheers.
>

ideas:

a) using something like mozilla, you could likely plugin to their javascr=
ipt=20
system and get the info (not likely in python though)

b) the canonical way to do this is to implement a http proxy and within t=
he=20
proxy watch for the javascript and do something else with it


From magnus@thinkware.se  Mon Oct 21 19:27:34 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Mon, 21 Oct 2002 20:27:34 +0200
Subject: [Tutor] Capturing browser pop-ups / push advertising. etc.
In-Reply-To: <23FD7B1A77E8D211BCB900001D108C02023FCA71@camelot>
Message-ID: <5.1.0.14.0.20021021202609.02b21a78@www.thinkware.se>

At 12:50 2002-10-21 -0400, McCarney, James Alexander wrote:
>Hi Pythonistas universal and triumphant! ;-)
>
>Is there a way any of you know how to capture what is on a pushed browser
>screen or pop-up...

I don't have a python based solution, but
you could use privoxy, see http://www.privoxy.org/


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From dyoo@hkn.eecs.berkeley.edu  Mon Oct 21 19:33:28 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 21 Oct 2002 11:33:28 -0700 (PDT)
Subject: [Tutor] Re: Tutor FAQ
In-Reply-To: <5.1.0.14.0.20021021144924.02b49c10@www.thinkware.se>
Message-ID: <Pine.LNX.4.44.0210211122450.22554-100000@hkn.eecs.berkeley.edu>


On Mon, 21 Oct 2002, Magnus Lycka wrote:

> At 12:20 2002-10-21 +0100, alan.gauld@bt.com wrote:
>
> > > I think there should be a tutor FAQ, this question is certainly FA.
> > > Is there a searchable archive of the mailing list somewhere?
> >
> >The ActiveState web site has a search facility for the archives.
>
> Would it be possible to get a link to that in the mailing list sig?
>
> Any list admin reading this these days???

(Waaa, I'm sorry, I've actually cut myself off temporarily from the list.)


Yes, I can add a link from the description page to Activestate's
searchable archive... ok, done!



> Otherwise a Wiki page would be a simple way to make a FAQ possible. My
> Thinki wiki is available, and I guess the Python Wiki could as well...

I think adding to the Python-wiki would be a good solution to this.



From mongo57a@comcast.net  Mon Oct 21 22:29:47 2002
From: mongo57a@comcast.net (andy surany)
Date: Mon, 21 Oct 2002 17:29:47 -0400
Subject: [Tutor] An OO question as relates to Python.
Message-ID: <002a01c27948$fb2c8400$2502a8c0@emily.ewndsr01.nj.comcast.net>

Thanks Alan - the example is what I was looking for. However, I'm still a
little off track. Maybe what I really need is the ability to establish a
"handle" to a specific frame. What I am doing is this:

Set up a scrolled list, and add data to it (in class ScrolledList). This is
what I would call my "utility" class and it contains a number of utility
methods. Within this class is a generic "refresh the list" routine called
populate_list.

Now I have another class (class WINMENU) which allows a user to operate on
the data in the list. In fact, the list is initially populated by using
ScrolledList(options). After the user has finished operationg on the data, I
need to update the list - but not create a new one. Right now I end up with
2 scrolled lists, 2 sets of buttons, etc. So either I must be executing the
entire ScrolledList class 2x, or I must need some kind of handle to the
original window (or both????). If I have interpreted the example correctly,
this is what I wrote:

    a=ScrolledList(options)
    b=populate_list(a)

I re-read the OOP section of the tutor. I guess that what I want to do is
inherit the attributes of the ScrolledList class to the WINMENU class. Am I
anywhere near the mark? But ScrolledList is not defined at the point WINMENU
is accessed (class WINMENU(Frame,ScrolledList) yields "ScrolledList not
defined"), as follows:

class WINMENU(Frame)
  .....
class ScrolledList(options)
  def populate_list(options)
  .......
If __name__='__main__'
  root=Tk()
  WINMENU(root)
  root.mainloop()

I'm getting dizzy from going around in circles.............

Thanks.

-----Original Message-----
From: alan.gauld@bt.com <alan.gauld@bt.com>
To: mongo57a@comcast.net <mongo57a@comcast.net>; tutor@python.org
<tutor@python.org>
Date: Monday, October 21, 2002 7:21 AM
Subject: RE: [Tutor] An OO question as relates to Python.


>> I understand the concept of classes (or think that I do....)
>
>> In general, how do you maintain a reference to a class
>
>OK, I don't think you really mean this but I'll answer
>it anyway!
>
>A class reference is just like any other variable.
>Thus:
>
>class Foo:
>   def __init__(self): print "Creating a FOO instance"
>
>To create a reference to the class Foo we just assign
>a variable:
>
>Bar = Foo  # note no parens!
>
>Now we can create instances of FOO using either Bar or FOO:
>
>inst1 = Foo()  # one instance of Foo
>inst2 = Bar()  # Also an instance of Foo
>
>That is occasionally useful when dealing with abstract
>frameworks which must create internal instances of
>different classes at runtime(somewhat like C++ templates)
>and readers of my book can find a description in the
>second case study, while others can see the commented
>code on the Usdeless Python website...
>
>However I don't think that really what you want, I think
>you mean how to manage references to different instances,
>and for that you again use variables just as we did
>above with inst1 and inst2.
>
>> - which means, how do I really reference the functionality
>> in a routine belonging to one class from another?
>
>But you really shouldn't do this. (Its possible, but ugly
>and very bad practice!) Instead pass a referenbde to the
>object(instance) and then call the method when required.
>
>Here's an example:
>
>class A:
>  def f(self): print 'in f of A'
>
>class B:
>  def x(self,anObject): self.object = anObject
>  def y(self): print self.object.f()
>
>a = A()  # create an A instance
>b = B()  # create a B instance
>b.x(a)   # pass refernce to a to b
>b.y()    # calls the f method of a.
>
>> Perhaps one of you could refer me to a good online
>> work on the subject...... or throw some good examples my way.
>
>Have you looked at my online tutor topic on OOP?
>
>HTH,
>
>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



From terjeja@hotmail.com  Mon Oct 21 21:54:07 2002
From: terjeja@hotmail.com (Terje Johan Abrahamsen)
Date: Mon, 21 Oct 2002 20:54:07 +0000
Subject: [Tutor] Activate window
Message-ID: <F8Sg1Hbb6m4TYirzmLy000000b4@hotmail.com>

I have been playing around with the Win32com modules and transfer info back 
and forth between the different MS Office applications. But, I haven't found 
the way to activate an application. I do not mean, start it, but to bring it 
to front. Lets say that I have Word and Excel, and move info back and forth. 
Then after that is done, I would like to make Excel the active window so I 
can type myself there, without having to mouseclick on it. This regardless 
of Word was the active window that I last used. Is there any easy way to do 
this?

Thanks in advance,
Terje





_________________________________________________________________
Internet access plans that fit your lifestyle -- join MSN. 
http://resourcecenter.msn.com/access/plans/default.asp



From thomi@thomi.imail.net.nz  Mon Oct 21 22:21:02 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Tue, 22 Oct 2002 10:21:02 +1300
Subject: [Tutor] what i miss is a C style for loop
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9C9@mbtlipnt02.btlabs.bt.co.uk>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9C9@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20021022102102.4c22dbec.thomi@thomi.imail.net.nz>

ahh well, i know that i can do while loops, but it just seemed to me
that for loops were somewhat "neater"....

thanks all the same :-)

On Mon, 21 Oct 2002 15:15:33 +0100 Thus said alan.gauld@bt.com:

> > yep, thats right, i live those C style for loops. they are 
> > compact, and easy to use, once you get the hang of it..
> 
> The C for loop is just a while loop in disguise 
> so you can duplicate the basic functions, but 
> the full C for loop power is not really feasible 
> in Python
> 
> for(a=0,b=5;c=b;a=0,b+=7){....}
> 
> for example. Valid if strange C but hard to do in any 
> sane python function.
> 
> But if you stick to the basic C style:
> 
> for(i=0;i<limit;i++){...}
> 
> Then you can do:
> 
> def cfor(initvalue,limit,incr, func):
>     i = initvalue
>     while i < limit:
>        func(i)
>        i += incr
> 
> But that's a poor imitation of a C for loop...
> 
> Also you need to allow access to the global 
> environment from within the loop without name 
> clashes etc...
> 
> Anything more potent would really be pretty 
> complex and probably very slow! 
> 
> Alan g.
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


-- 
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 jrclare@lycos.com  Mon Oct 21 19:43:01 2002
From: jrclare@lycos.com (James Clare)
Date: Mon Oct 21 18:43:01 2002
Subject: [Tutor] Activate window
Message-ID: <FOOBOILLHBHFCBAA@mailcity.com>

use the alt & tab keys at the same time  
--

On Mon, 21 Oct 2002 20:54:07  
 Terje Johan Abrahamsen wrote:
>I have been playing around with the Win32com modules and transfer info back 
>and forth between the different MS Office applications. But, I haven't found 
>the way to activate an application. I do not mean, start it, but to bring it 
>to front. Lets say that I have Word and Excel, and move info back and forth. 
>Then after that is done, I would like to make Excel the active window so I 
>can type myself there, without having to mouseclick on it. This regardless 
>of Word was the active window that I last used. Is there any easy way to do 
>this?
>
>Thanks in advance,
>Terje
>
>
>
>
>
>_________________________________________________________________
>Internet access plans that fit your lifestyle -- join MSN. 
>http://resourcecenter.msn.com/access/plans/default.asp
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>


____________________________________________________________
Get 250 full-color business cards FREE right now!
http://businesscards.lycos.com 


From magnus@thinkware.se  Mon Oct 21 20:07:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Mon Oct 21 19:07:01 2002
Subject: [Tutor] An OO question as relates to Python.
In-Reply-To: <002a01c27948$fb2c8400$2502a8c0@emily.ewndsr01.nj.comcast.n
 et>
Message-ID: <5.1.0.14.0.20021022005332.029ea490@www.thinkware.se>

At 17:29 2002-10-21 -0400, andy surany wrote:
>I re-read the OOP section of the tutor. I guess that what I want to do is
>inherit the attributes of the ScrolledList class to the WINMENU class. Am I
>anywhere near the mark?

Inheritance means "is-a". An employee is a person, so it might
be reasonable that an Emplyee class inherits from a Person class.
WINMENU is a kind of Frame I guess, and thus inherits from Frame.
But it IS NOT a scrolled list, is it? I think it HAS a scrolled
list. Has implies composition, not inheritance. Your frame class
inheriting "ScrolledList" sounds a bit like Employee inheriting
a Salary class. An employee is definitely not a kind of salary.

>But ScrolledList is not defined at the point WINMENU
>is accessed (class WINMENU(Frame,ScrolledList) yields "ScrolledList not
>defined"), as follows:

That could be fixed by changing places, but it's not
what you want unless I'm confused here.

I think I sent a solution to this to you in a previous
email? (Maybe you didn't see my changes in your code?)

In your WINMENU class, I think you need an attribute (also
called a member variable) that points out the ScrolledList.
"self.myScrolledList = ScrolledList(...)" This is set when
you create your scrolled list.

When you populate the list, you simply do
self.myScrolledList.populate_list(options)

>I'm getting dizzy from going around in circles.............

Well, others pay good money for such attractions
and you get it for free! :) No hangover either,
I hope...


-- 
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  Mon Oct 21 20:13:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Mon Oct 21 19:13:02 2002
Subject: [Tutor] what i miss is a C style for loop
In-Reply-To: <20021022102102.4c22dbec.thomi@thomi.imail.net.nz>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9C9@mbtlipnt02.btlabs.bt.co.uk>
 <5104D4DBC598D211B5FE0000F8FE7EB20E66C9C9@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <5.1.0.14.0.20021022011240.02a03ff8@www.thinkware.se>

At 10:21 2002-10-22 +1300, Thomi Richards wrote:
>ahh well, i know that i can do while loops, but it just seemed to me
>that for loops were somewhat "neater"....

I'm still curious about what you would want
to use the for loops for. Some concrete examples?

It might well be that things you are used to
doing with for loops are done completely without
loops in Python, or that python for loops or
list comprehension solves it even neater...

We have quite a bag of tricks here... (And
Python 2.3 adds a little more...)


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Mon Oct 21 20:48:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Mon Oct 21 19:48:01 2002
Subject: [Tutor] Activate window
In-Reply-To: <F8Sg1Hbb6m4TYirzmLy000000b4@hotmail.com>
Message-ID: <5.1.0.14.0.20021022014805.02b4bfd8@www.thinkware.se>

At 20:54 2002-10-21 +0000, Terje Johan Abrahamsen wrote:
>I have been playing around with the Win32com modules and transfer info=20
>back and forth between the different MS Office applications. But, I=20
>haven't found the way to activate an application. I do not mean, start it,=
=20
>but to bring it to front. Lets say that I have Word and Excel, and move=20
>info back and forth. Then after that is done, I would like to make Excel=20
>the active window so I can type myself there, without having to mouseclick=
=20
>on it. This regardless of Word was the active window that I last used. Is=
=20
>there any easy way to do this?

You might try the python-win32 mailing list for this.
http://mail.python.org/mailman/listinfo/python-win32

I thought that maybe

xlApp.Visible =3D 0
xlApp.Visible =3D 1

would bring it to top, but that doesn't seem to work...


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From wheelcrdan@hotmail.com  Mon Oct 21 23:41:01 2002
From: wheelcrdan@hotmail.com (Dan Dud)
Date: Mon Oct 21 22:41:01 2002
Subject: [Tutor] help (stack are confusing me could someone help out with this simple program)
Message-ID: <F142vLgAusVxONvzyJx0000a382@hotmail.com>

help

Hi everyone

Hope everyone is having a great monday, well at least as good as mondays 
could get.. Anyways I have this program that I just want it to compare two 
things and let you choose if its <,>, == I am starting to catch on alot 
after starting to read "how to think like computer scientest.... I've been 
reading so many books and articles anything I can get my hands on but none 
of them apply them to each other like that does.. Here is the code I know 
the stack is messed up I understand first in last out but not sure how to 
make this work correctly tring to apply that. Does anyone have any 
sugestions to better brake down a program so I know what to put in first and 
what to put in last here is the program I know it needs help I just don't 
quite know where


def x():
    print x()
def y():
    print y()

def compare(x,y):
	if x < y:
		print x, "is less then", y

	elif x > y:
		print x, "is greater then", y
	else:
		print "and", y, "are equal"

def functionA ():
    if x == y:
        print x, "and", y, "are equal"
    else:
        if x < y:
            print x, "is less then", y
        else:
            print x, "is greater than", y

def functionB ():
    print
def functionC ():
    print

def disbatch (choice):
	if choice == 'a' or 'A':
		functionA()
	elif choice == 'b' or 'B':
		functionB()
	elif choice == 'c' or 'C':
		functionC()
	else:
		print "Invalad choice"

Thanks ahead of time for the help have a great night or mornig what ever it 
might be..

Danny D





_________________________________________________________________
Surf the Web without missing calls! Get MSN Broadband. 
http://resourcecenter.msn.com/access/plans/freeactivation.asp



From dman@dman.ddts.net  Tue Oct 22 00:17:09 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Mon Oct 21 23:17:09 2002
Subject: [Tutor] Re: accepting wild chars from pythons command line
In-Reply-To: <20021021093938.27131.qmail@web40701.mail.yahoo.com>
References: <20021021093938.27131.qmail@web40701.mail.yahoo.com>
Message-ID: <20021022033452.GA28789@dman.ddts.net>

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

On Mon, Oct 21, 2002 at 02:39:38AM -0700, roslyn jose wrote:
|=20
| hi,
|=20
| i have a list of .txt files that i would like to enter from command
|  line, but as its a hassle to write all the names i would like to just
|  type in *.txt at the python command line. could someone tell me how i
|  can have python interpret that wils char, is there any built in
|  function?? thanks.

Actually, python will never see the '*' character.  The /shell/
expands it first.  Depending on your system and environment, that
shell is often one of  bash, ash, csh, tcsh, ksh, zsh, command.com or
cmd.exe.  The beauty of shell metacharacters is that the shell handles
their expansion and your program can't tell the difference.

-D


--EeQfGwPcQSOJBaQU
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

iEYEARECAAYFAj20x1wACgkQO8l8XBKTpRTeRgCgheP1EWpWjqtsUbq7kijUBIl5
NuQAoKobT9DyNQevahel9y+z2sM8X4JR
=g/5b
-----END PGP SIGNATURE-----

--EeQfGwPcQSOJBaQU--


From mongo57a@comcast.net  Tue Oct 22 00:18:11 2002
From: mongo57a@comcast.net (andy surany)
Date: Mon Oct 21 23:18:11 2002
Subject: [Tutor] An OO question as relates to Python.
Message-ID: <004d01c27982$3d616e60$2502a8c0@emily.ewndsr01.nj.comcast.net>

Thanks everyone! It finally clicked! I had the right code - in the wrong
place.

It is working the way I want. I appreciate the help - and the education.

Regards,

Andy
-----Original Message-----
From: Magnus Lycka <magnus@thinkware.se>
To: tutor@python.org <tutor@python.org>
Date: Monday, October 21, 2002 7:07 PM
Subject: Re: [Tutor] An OO question as relates to Python.


>At 17:29 2002-10-21 -0400, andy surany wrote:
>>I re-read the OOP section of the tutor. I guess that what I want to do is
>>inherit the attributes of the ScrolledList class to the WINMENU class. Am
I
>>anywhere near the mark?
>
>Inheritance means "is-a". An employee is a person, so it might
>be reasonable that an Emplyee class inherits from a Person class.
>WINMENU is a kind of Frame I guess, and thus inherits from Frame.
>But it IS NOT a scrolled list, is it? I think it HAS a scrolled
>list. Has implies composition, not inheritance. Your frame class
>inheriting "ScrolledList" sounds a bit like Employee inheriting
>a Salary class. An employee is definitely not a kind of salary.
>
>>But ScrolledList is not defined at the point WINMENU
>>is accessed (class WINMENU(Frame,ScrolledList) yields "ScrolledList not
>>defined"), as follows:
>
>That could be fixed by changing places, but it's not
>what you want unless I'm confused here.
>
>I think I sent a solution to this to you in a previous
>email? (Maybe you didn't see my changes in your code?)
>
>In your WINMENU class, I think you need an attribute (also
>called a member variable) that points out the ScrolledList.
>"self.myScrolledList = ScrolledList(...)" This is set when
>you create your scrolled list.
>
>When you populate the list, you simply do
>self.myScrolledList.populate_list(options)
>
>>I'm getting dizzy from going around in circles.............
>
>Well, others pay good money for such attractions
>and you get it for free! :) No hangover either,
>I hope...
>
>
>--
>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 dman@dman.ddts.net  Tue Oct 22 00:22:01 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Mon Oct 21 23:22:01 2002
Subject: [Tutor] Re: How can I get the hostid of a computer?
In-Reply-To: <5.1.0.14.0.20021019224514.02b02438@www.thinkware.se>
References: <5.1.0.14.0.20021019185706.02b17b40@www.thinkware.se> <5.1.0.14.0.20021019224514.02b02438@www.thinkware.se>
Message-ID: <20021022033933.GB28789@dman.ddts.net>

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

On Sat, Oct 19, 2002 at 10:53:56PM +0200, Magnus Lycka wrote:
| At 11:02 2002-10-19 -0700, Lance wrote:
| >I must be referring to the MacID, the CPU specific identifier on which
| >licensing managers are based.
|=20
| As I told you, I don't think there is any OS independent
| way, so we can't really help you unless you tell what OS
| you use.
|=20
| If you by MacID mean MAC address, or Media Access Control
| address, i.e. the hardware address in the network card,

Actually, he said CPU identifier.  AFAIK the Pentium III was the first
CPU to have a unique ID embedded in it, but I don't know if any others
do.  I also don't know how to access that ID.  Various software
license managers do their own thing when it comes to identifying a
host, and some don't even bother trying.  In short it is nearly
impossible to identify a machine without creating some problem or PITA
for the owner of the machine (eg if you use the network card, then the
network card dies or the owner wants to upgrade to a faster one it
screws up your licensing system even though the host is the same.  If
you use the timestamp on a system directory and the owner must
reinstall the OS (usually windows) then the same sort of problem is
created.).  I know about those issues because I had the task of
implementing a licensing solution at one of my jobs.

-D

--=20
Come to me, all you who are weary and burdened, and I will give you
rest.  Take my yoke upon you and learn from me, for I am gentle and
humble in heart, and you will find rest for your souls.  For my yoke
is easy and my burden is light.
        Matthew 11:28-30
=20
http://dman.ddts.net/~dman/

--ZfOjI3PrQbgiZnxM
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

iEYEARECAAYFAj20yHUACgkQO8l8XBKTpRRmRQCfe6wWlPyY4i89gAiekG3W0Jmr
0xMAn3rCxnvGUgWPk3Mnh922rrMfzlBx
=ZK8Q
-----END PGP SIGNATURE-----

--ZfOjI3PrQbgiZnxM--


From mylene.reiners@cmg.com  Tue Oct 22 02:55:06 2002
From: mylene.reiners@cmg.com (Mylene Reiners)
Date: Tue Oct 22 01:55:06 2002
Subject: [Tutor] help (stack are confusing me could someone help out w
 ith this simple program)
Message-ID: <B569A4D2254ED2119FE500104BC1D5CD01A6951B@NL-EIN-MAIL01>

 Dan,

What are you trying to accomplish?
If you want input x,y and output x > y, x < y or x = y, the 
part (partially copied from your mail :) ):

Python 2.1.3 (#1, Jul 29 2002, 22:34:51)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> x = 5
>>> y = 6
>>> if x < y:
...    print "x < y"
... elif x > y:
...    print "x > y"
... else:
...    print "x = y"
...
x < y
>>>

will do fine. I guess you found out that already. But what 
else do you want to know?

Mylene
-----Original Message-----
From: Dan Dud
To: tutor@python.org
Sent: 10/22/2002 4:39 AM
Subject: [Tutor] help (stack are confusing me could someone help out with
this simple program)

help

Hi everyone

Hope everyone is having a great monday, well at least as good as mondays

could get.. Anyways I have this program that I just want it to compare
two 
things and let you choose if its <,>, == I am starting to catch on alot 
after starting to read "how to think like computer scientest.... I've
been 
reading so many books and articles anything I can get my hands on but
none 
of them apply them to each other like that does.. Here is the code I
know 
the stack is messed up I understand first in last out but not sure how
to 
make this work correctly tring to apply that. Does anyone have any 
sugestions to better brake down a program so I know what to put in first
and 
what to put in last here is the program I know it needs help I just
don't 
quite know where


def x():
    print x()
def y():
    print y()

def compare(x,y):
	if x < y:
		print x, "is less then", y

	elif x > y:
		print x, "is greater then", y
	else:
		print "and", y, "are equal"

def functionA ():
    if x == y:
        print x, "and", y, "are equal"
    else:
        if x < y:
            print x, "is less then", y
        else:
            print x, "is greater than", y

def functionB ():
    print
def functionC ():
if     print

def disbatch (choice):
	if choice == 'a' or 'A':
		functionA()
	elif choice == 'b' or 'B':
		functionB()
	elif choice == 'c' or 'C':
		functionC()
	else:
		print "Invalad choice"

Thanks ahead of time for the help have a great night or mornig what ever
it 
might be..

Danny D





_________________________________________________________________
Surf the Web without missing calls! Get MSN Broadband. 
http://resourcecenter.msn.com/access/plans/freeactivation.asp


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


From thomi@thomi.imail.net.nz  Tue Oct 22 06:15:02 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Tue Oct 22 05:15:02 2002
Subject: [Tutor] what i miss is a C style for loop
In-Reply-To: <5.1.0.14.0.20021022011240.02a03ff8@www.thinkware.se>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9C9@mbtlipnt02.btlabs.bt.co.uk>
 <5104D4DBC598D211B5FE0000F8FE7EB20E66C9C9@mbtlipnt02.btlabs.bt.co.uk>
 <5.1.0.14.0.20021022011240.02a03ff8@www.thinkware.se>
Message-ID: <20021022221408.24d66b86.thomi@thomi.imail.net.nz>

i don't have any concrete examples... I thought "what i need here is a C
style loop... trouble is, i can't remember where it was.... ahh well...

probably something like:

for i in range(10):
	do_something_with(i);
	i+=1;


etc...

On Tue, 22 Oct 2002 01:18:47 +0200 Thus said Magnus Lycka
<magnus@thinkware.se>:

> At 10:21 2002-10-22 +1300, Thomi Richards wrote:
> >ahh well, i know that i can do while loops, but it just seemed to me
> >that for loops were somewhat "neater"....
> 
> I'm still curious about what you would want
> to use the for loops for. Some concrete examples?
> 
> It might well be that things you are used to
> doing with for loops are done completely without
> loops in Python, or that python for loops or
> list comprehension solves it even neater...
> 
> We have quite a bag of tricks here... (And
> Python 2.3 adds a little more...)
> 
> 
> -- 
> Magnus Lyckå, Thinkware AB
> Älvans väg 99, SE-907 50 UMEÅ
> tel: 070-582 80 65, fax: 070-612 80 65
> http://www.thinkware.se/  mailto:magnus@thinkware.se
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


-- 
This message was brought to you by one bored guy, with nothing better to
do,
And the letter Q.
Thomi Richards,
thomi@imail.net.nz


From scot@possum.in-berlin.de  Tue Oct 22 06:51:00 2002
From: scot@possum.in-berlin.de (Scot W. Stevenson)
Date: Tue Oct 22 05:51:00 2002
Subject: [Tutor] Activate window
In-Reply-To: <F8Sg1Hbb6m4TYirzmLy000000b4@hotmail.com>
References: <F8Sg1Hbb6m4TYirzmLy000000b4@hotmail.com>
Message-ID: <200210221103.51396.scot@possum.in-berlin.de>

Hello Terje, 

> I have been playing around with the Win32com modules and transfer info
> back and forth between the different MS Office applications. But, I
> haven't found the way to activate an application. I do not mean, start
> it, but to bring it to front. Lets say that I have Word and Excel, and
> move info back and forth. Then after that is done, I would like to make
> Excel the active window so I can type myself there, without having to
> mouseclick on it. 

I wonder if this might be a Windows and not a Python problem - in Linux, 
you would set your windowmanager (such as KDE or Blackbox) to do something 
called "focus follows mouse", which means that whenever you move the mouse 
over a window, it gets the focus ("brings it to the front"). There are 
ways to tweak this - how long the mouse has to be over the window, is it 
an exact or "sloppy" focus. 

It has been a long time since I have used Windows for anything but "Diablo 
II" and "Age of Kings", but I can't remember any Microsoft product having 
"focus follows mouse". I think you might have to resort to the "ALT-TAB" 
combination to cycle thru the windows - or was it "CTRL-TAB"?

Y, Scot

-- 
  Scot W. Stevenson wrote me on Tuesday, 22. Oct 2002 in Zepernick, Germany   
       on his happy little Linux system that has been up for 516 hours        
        and has a CPU that is falling asleep at a system load of 0.02.        



From thomi@thomi.imail.net.nz  Tue Oct 22 07:05:02 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Tue Oct 22 06:05:02 2002
Subject: [Tutor] Activate window
In-Reply-To: <200210221103.51396.scot@possum.in-berlin.de>
References: <F8Sg1Hbb6m4TYirzmLy000000b4@hotmail.com>
 <200210221103.51396.scot@possum.in-berlin.de>
Message-ID: <20021022230317.5e42acd6.thomi@thomi.imail.net.nz>

> It has been a long time since I have used Windows for anything but
> "Diablo II" and "Age of Kings", but I can't remember any Microsoft
> product having "focus follows mouse". I think you might have to resort
> to the "ALT-TAB" combination to cycle thru the windows - or was it
> "CTRL-TAB"?

there is a windows power toys program called xmouse, which emulates the
X mouse behavior. It's not very good, or even easy to use, but it may
help you there.

-- 
Thomi Richards
thomi@imail.net.nz
http://thomi.imail.net.nz/
Thomi Richards,
thomi@imail.net.nz


From magnus@thinkware.se  Tue Oct 22 07:49:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Oct 22 06:49:01 2002
Subject: OT: Re: [Tutor] Re: accepting wild chars from pythons command
 line
In-Reply-To: <20021022033452.GA28789@dman.ddts.net>
References: <20021021093938.27131.qmail@web40701.mail.yahoo.com>
 <20021021093938.27131.qmail@web40701.mail.yahoo.com>
Message-ID: <5.1.0.14.0.20021022125019.02ae4e58@www.thinkware.se>

At 23:34 2002-10-21 -0400, Derrick 'dman' Hudson wrote:
>Actually, python will never see the '*' character.  The /shell/
>expands it first.  Depending on your system and environment, that
>shell is often one of  bash, ash, csh, tcsh, ksh, zsh, command.com or
>cmd.exe.  The beauty of shell metacharacters is that the shell handles
>their expansion and your program can't tell the difference.

It seems you don't use Windows...you lucky bastard! ;)

Neither cmd.exe not command.com will do anything with
* or other wildcard characters.

That's why you could write

copy *.txt *.bak

in DOS to create backup versions for all your text
files. In the days when most people knew DOS, this
was often a confusing problem for Unix newbies...


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Tue Oct 22 07:51:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Oct 22 06:51:02 2002
Subject: [Tutor] An OO question as relates to Python.
In-Reply-To: <004d01c27982$3d616e60$2502a8c0@emily.ewndsr01.nj.comcast.n
 et>
Message-ID: <5.1.0.14.0.20021022125514.02ab8c48@www.thinkware.se>

At 00:19 2002-10-22 -0400, andy surany wrote:
>Thanks everyone! It finally clicked! I had the right code - in the wrong
>place.

Well, computer programs are often picky with things like that... ;)


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Tue Oct 22 08:46:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Oct 22 07:46:01 2002
Subject: [Tutor] what i miss is a C style for loop
In-Reply-To: <20021022221408.24d66b86.thomi@thomi.imail.net.nz>
References: <5.1.0.14.0.20021022011240.02a03ff8@www.thinkware.se>
 <5104D4DBC598D211B5FE0000F8FE7EB20E66C9C9@mbtlipnt02.btlabs.bt.co.uk>
 <5104D4DBC598D211B5FE0000F8FE7EB20E66C9C9@mbtlipnt02.btlabs.bt.co.uk>
 <5.1.0.14.0.20021022011240.02a03ff8@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021022131135.02a5f680@www.thinkware.se>

At 22:14 2002-10-22 +1300, Thomi Richards wrote:
>i don't have any concrete examples... I thought "what i need here is a C
>style loop... trouble is, i can't remember where it was.... ahh well...
>probably something like:
>
>for i in range(10):
>         do_something_with(i);
>         i+=3D1;

This is halfways between C and python. :)

First, skip the ; unless you have several statements on the same line.

Second, the python for loop iterates over a sequence, such as a
list. The range operator returns a list. i will be given a new
value from the sequence on each iteration. So:

for i in range(10):
     do_something_with(i)

which is the same as

for i in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
     do_something_with(i)

This is just like a foreach loop in unix shell script.

If your c program would look like

for (i =3D 5; i < 10, i +=3D 2)
     do_something_with(i);

Your python program will look like:

for i in range(5,10,2):
     do_something_with(i)

With something like:

int i;
int l =3D 10;
int a[len] =3D {1, 5, 6, 2, 3, 4, 9, 0, 7, 8};
int sum =3D 0;

for (i =3D 0; i < l; i++)
     sum +=3D a[i];

you'd do:

a =3D [1, 5, 6, 2, 3, 4, 9, 0, 7, 8]
sum =3D 0
for x in a:
     sum +=3D x

or

a =3D [1, 5, 6, 2, 3, 4, 9, 0, 7, 8]
sum =3D reduce(lambda x,y: x+y, a)

or

from operator import add
a =3D [1, 5, 6, 2, 3, 4, 9, 0, 7, 8]
sum =3D reduce(add, a)

In general, the common C idiom

int length =3D ...;
<some type> a[lenght];
...

for (i =3D 0; i < length; i++):
     do_something_with(a[i]);

becomes

for x in a:
     do_something_with(x)

You don't need to think about any index variable or
bounds checking. A python sequence knows it's own
bounds.

Another C example:

int i;
int l =3D ...;
char source[l] =3D "something";
char target[l];

for (i=3D0; i < l; i++)
     target[i] =3D encrypt(source[i]);

becomes:

source =3D "something"
target =3D map(encrypt, source)

I don't feel that I miss c for loops at all...


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From thorsten@thorstenkampe.de  Tue Oct 22 08:48:02 2002
From: thorsten@thorstenkampe.de (Thorsten Kampe)
Date: Tue Oct 22 07:48:02 2002
Subject: [Tutor] Re: Capturing browser pop-ups / push advertising. etc.
In-Reply-To: <20021022031709.5351.52613.Mailman@mail.python.org>
References: <20021022031709.5351.52613.Mailman@mail.python.org>
Message-ID: <882944531.20021022134746@thorstenkampe.de>

Un peu tres OT, n'est pas?

* McCarney, James Alexander
> Is there a way any of you know how to capture what is on a pushed
> browser screen or pop-up...

"SnagIt" has a "Web Capture" to capture web pages, it's the best
screen capture tool available.

> For instance, if I access a site, then more 'cr*p' than you can
> shake a stick at gets launched. I would like to see what it is as
> text.

Use a decent browser: Opera. Opera has a "Accept pop-up windows/Refuse
pop-up windows/Open pop-up windows in background" functionality.


Thorsten Kampe



From James.Rocks@equant.com  Tue Oct 22 08:53:01 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Tue Oct 22 07:53:01 2002
Subject: [Tutor] Re: importing functions, paths, etc.
Message-ID: <OFEE0DE13E.36F4A0C6-ON80256C5A.00401177@equant.com>

Hi Charlie, Alan & Co.

Yes you are/were right ... the environment vaiable pythonpath appears to
dictate much of what I can or cannot do with respect to importing files ...

The structure I've come up with (which seems to work) is to put Python 2.1
in one folder, Boa-Constructor IDE in another and my Python projects in
subfolders of c:\Projects (where I store all my common stuff).

Thanks for that :-)

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ
Phone:             0207-5226856
Fax:                   0207-5126087
Mobile Phone:     07771-767405
http://www.equant.com

This e-mail (including any attachments) is confidential and may be legally
privileged.  If you are not an intended recipient or an authorized
representative of an intended recipient, you are prohibited from using,
copying or distributing the information in this e-mail or its attachments.
If you have received this e-mail in error, please notify the sender
immediately by return e-mail and delete all copies of this message and any
attachments.  Thank you.



From magnus@thinkware.se  Tue Oct 22 08:55:03 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Oct 22 07:55:03 2002
Subject: [Tutor] help (stack are confusing me could someone help
 out with this simple program)
In-Reply-To: <F142vLgAusVxONvzyJx0000a382@hotmail.com>
Message-ID: <5.1.0.14.0.20021022114741.029ea130@www.thinkware.se>

At 20:39 2002-10-21 -0600, Dan Dud wrote:
>def x():
>    print x()

What's the purpose of this function? When you
call this function, the following happens:

Ok, we're in the x function, hm...what are we
going to do. Yes we should print the return value
from a function x called without parameters. So,
let us call x. Ok, we're in the x function, hm...
what are we going to do. Yes we should print the
return value from a function x called without
parameters. So, let us call x. Ok, we're in the x
function, hm...what are we going to do. Yes we
should print the return value from a function x
called without parameters. So, let us call x. Ok,
we're in the x function, hm...what are we going
to do. Yes we should print the return value from
a function x called without parameters. So, let
us call x...Ad infinitum... (or rather until the
stack is full...)

Besides calling itself recursively, it doesn't
do anything. It will never ever get to printing
anything. What did you think it would do?

Can you tell us what you want your program to do?

Further down in the code you compare the
functions x and y. Why do you want to do that?
The "value" of functions used in comparisions
is just their addresses in the RAM when you run
the program.

It seems to me that you haven't quite got the
hang of functions and variables. Perhaps you
should work through the python tutorial or
Alan Gaulds tutorial at
http://www.freenetpages.co.uk/hp/alan.gauld/

Feel free to return here with more questions,
but I think you have to step back a bit. You
seem to be slightly over your head now.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From jrclare@lycos.com  Tue Oct 22 09:15:32 2002
From: jrclare@lycos.com (James Clare)
Date: Tue Oct 22 08:15:32 2002
Subject: [Tutor] what i miss is a C style for loop
Message-ID: <PBBHANINAABCCBAA@mailcity.com>

variable++ would be better than variable = variable + 1
Python dosen't have that function does it?
Is there a different short hand way to do variable = variable + 1? 
--

On Tue, 22 Oct 2002 22:14:08  
 Thomi Richards wrote:
>i don't have any concrete examples... I thought "what i need here is a C
>style loop... trouble is, i can't remember where it was.... ahh well...
>
>probably something like:
>
>for i in range(10):
>	do_something_with(i);
>	i+=1;
>
>
>etc...
>
>On Tue, 22 Oct 2002 01:18:47 +0200 Thus said Magnus Lycka
><magnus@thinkware.se>:
>
>> At 10:21 2002-10-22 +1300, Thomi Richards wrote:
>> >ahh well, i know that i can do while loops, but it just seemed to me
>> >that for loops were somewhat "neater"....
>> 
>> I'm still curious about what you would want
>> to use the for loops for. Some concrete examples?
>> 
>> It might well be that things you are used to
>> doing with for loops are done completely without
>> loops in Python, or that python for loops or
>> list comprehension solves it even neater...
>> 
>> We have quite a bag of tricks here... (And
>> Python 2.3 adds a little more...)
>> 
>> 
>> -- 
>> Magnus Lyckå, Thinkware AB
>> Älvans väg 99, SE-907 50 UMEÅ
>> tel: 070-582 80 65, fax: 070-612 80 65
>> http://www.thinkware.se/  mailto:magnus@thinkware.se
>> 
>> 
>> _______________________________________________
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>
>
>-- 
>This message was brought to you by one bored guy, with nothing better to
>do,
>And the letter Q.
>Thomi Richards,
>thomi@imail.net.nz
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>


____________________________________________________________
Get 250 full-color business cards FREE right now!
http://businesscards.lycos.com 


From James.Rocks@equant.com  Tue Oct 22 09:18:07 2002
From: James.Rocks@equant.com (James.Rocks@equant.com)
Date: Tue Oct 22 08:18:07 2002
Subject: [Tutor] Python & wxWindows Question
Message-ID: <OF04F3DBB5.4FBDD857-ON80256C5A.00433FC9@equant.com>

Hi,

Anyone know anything about wxWindows being used with Python?

I want to use a control on a dialog that allows me to update it at runtime
(text, colour, font etc.) and i wondered if anyone here knew much about
this kind of thing ... what I don't want is a box that halts program
execution i.e. the display must change and the program continue.

Thanks

James C. Rocks
Equant
Archway House
Canary Wharf
London E14 9SZ
Phone:             0207-5226856
Fax:                   0207-5126087
Mobile Phone:     07771-767405
http://www.equant.com

This e-mail (including any attachments) is confidential and may be legally
privileged.  If you are not an intended recipient or an authorized
representative of an intended recipient, you are prohibited from using,
copying or distributing the information in this e-mail or its attachments.
If you have received this e-mail in error, please notify the sender
immediately by return e-mail and delete all copies of this message and any
attachments.  Thank you.



From charlie@begeistert.org  Tue Oct 22 09:41:02 2002
From: charlie@begeistert.org (Charlie Clark)
Date: Tue Oct 22 08:41:02 2002
Subject: [Tutor] Re: C-style loops
Message-ID: <20021022144548.3515.8@gormenghast.1035280495.fake>

On 2002-10-22 at 12:15:32 [+0000], you wrote:
>
> variable++ would be better than variable =3D variable + 1
> Python dosen't have that function does it?
> Is there a different short hand way to do variable =3D variable + 1?
"Variable++" is ugly and non-intuitive

variable =3D variable + 1
is explicit if long-winded

Python (I think it was 1.6) introduced "incremental assignments)
variable +=3D 1
this is apparently a little faster and seems well-accepted. I use a lot
myself and you included it in your source code. As Magnus has said, you
don't need it in for statements in Python and being able to loop through
any kind of sequence is so cool and natural that I feel sorry for all users
of other languages where it's not possible.

for item in list:
  print item

for item in dictionary.keys():
  print item

for item, value in dictionary.items():
  print item, value

and so on. Great stuff!

Charlie
-- 
Charlie Clark
Helmholtzstr. 20
D=1Asseldorf
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226


From kp87@lycos.com  Tue Oct 22 11:31:12 2002
From: kp87@lycos.com (kevin parks)
Date: Tue Oct 22 10:31:12 2002
Subject: [Tutor] RE: what i miss is a C style for loop & the python way
Message-ID: <OBFHEGECAMKICBAA@mailcity.com>

Since i have started working with python, i find it hard to imagine missing anything from C!

Use what Python has for a few months and then tells us if you still miss some  feature of C or an aspect of C syntax. I bet you a bowl of kimchee stew you won't look back at nothing! Don't go through contortions to make Python syntax like what you are used to, rather make a few adjustments to Python's quirks and you will be writing real Python code, much more quickly. Remember, this isn't Perl. 

See Tim Peter's "The Python Way"

   1. Beautiful is better than ugly.
   2. Explicit is better than implicit.
   3. Simple is better than complex.
   4. Complex is better than complicated.
   5. Flat is better than nested.
   6. Sparse is better than dense.
   7. Readability counts.
   8. Special cases aren't special enough to break the rules.
   9. Although practicality beats purity.
  10. Errors should never pass silently.
  11. Unless explicitly silenced.
  12. In the face of ambiguity, refuse the temptation to guess.
  13. There should be one-- and preferably only one --obvious way to do it.
  14. Although that way may not be obvious at first unless you're Dutch.
  15. Now is better than never.
  16. Although never is often better than *right* now.
  17. If the implementation is hard to explain, it's a bad idea.
  18. If the implementation is easy to explain, it may be a good idea.
  19. Namespaces are one honking great idea -- let's do more of those!


I would like to nominate number 20 for newbies like myself.

20. built-in is better than homebrewed (why reinvent the wheel!?)

(see the sort method as an example of something that is constantly snubbed despite the fact that anything you try to band-aid together is likely to be slower anyway)

If you miss anything about C, i suspect it is because you haven't been using Python long enough.


cheers,

kevin (hardly the one to be giving advice, but what the heck!)



PS. (gernerators and list comprehensions sort of weaken # 13 a bit, but it still remains in spirit, true. Besides, you going to argue with Tim? I sure as lambda ain't!)




____________________________________________________________
Get 250 full-color business cards FREE right now!
http://businesscards.lycos.com 


From shalehperry@attbi.com  Tue Oct 22 11:44:01 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue Oct 22 10:44:01 2002
Subject: [Tutor] what i miss is a C style for loop
In-Reply-To: <PBBHANINAABCCBAA@mailcity.com>
References: <PBBHANINAABCCBAA@mailcity.com>
Message-ID: <200210220743.05229.shalehperry@attbi.com>

On Tuesday 22 October 2002 05:13, James Clare wrote:
> variable++ would be better than variable =3D variable + 1
> Python dosen't have that function does it?
> Is there a different short hand way to do variable =3D variable + 1?

a +=3D 1 is all you get.


From lumbricus@gmx.net  Tue Oct 22 12:27:00 2002
From: lumbricus@gmx.net (lumbricus@gmx.net)
Date: Tue Oct 22 11:27:00 2002
Subject: [Tutor] Re: C-style loops
References: <20021022144548.3515.8@gormenghast.1035280495.fake>
Message-ID: <25371.1035300293@www55.gmx.net>

Hi!

> On 2002-10-22 at 12:15:32 [+0000], you wrote:
[ snip ]

> "Variable++" is ugly and non-intuitive

No, it's pretty and intuitive.

"Basically, the only 'intuitive' interface is the nipple. 
After that, it's all learned."
	--Bruce Ediger

[ snip ]

> Charlie

Greetings, J"o!

-- 
Wir beschliessen etwas, stellen das dann in
den Raum und warten dann einige Zeit ab, was
passiert. Wenn es dann kein grosses Geschrei
gibt und keine Aufstaende, weil die meisten
gar nicht begreifen, was da beschlossen
wurde, dann machen wir weiter - Schritt fuer
Schritt, bis es kein Zurueck mehr gibt. 
   -- J-C Juncker

+++ 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  Tue Oct 22 12:38:10 2002
From: lumbricus@gmx.net (lumbricus@gmx.net)
Date: Tue Oct 22 11:38:10 2002
Subject: OT: Re: [Tutor] Re: accepting wild chars from pythons command  line
References: <5.1.0.14.0.20021022125019.02ae4e58@www.thinkware.se>
Message-ID: <25135.1035300989@www55.gmx.net>

Hello!

[ snip ]

> It seems you don't use Windows...you lucky bastard! ;)

This has got nothing to do with luck ;->
ftp.kernel.org
ftp.freebsd.org
ftp.netbsd.org
ftp.openbsd.org

SCNR

[ snip ]

HTH, J"o!

> -- 
> Magnus Lyckå, Thinkware AB
> Älvans väg 99, SE-907 50 UMEÅ
> tel: 070-582 80 65, fax: 070-612 80 65
> http://www.thinkware.se/  mailto:magnus@thinkware.se

-- 
Wir beschliessen etwas, stellen das dann in
den Raum und warten dann einige Zeit ab, was
passiert. Wenn es dann kein grosses Geschrei
gibt und keine Aufstaende, weil die meisten
gar nicht begreifen, was da beschlossen
wurde, dann machen wir weiter - Schritt fuer
Schritt, bis es kein Zurueck mehr gibt. 
   -- J-C Juncker

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



From alan.gauld@bt.com  Tue Oct 22 12:57:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Oct 22 11:57:01 2002
Subject: [Tutor] An OO question as relates to Python.
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9D0@mbtlipnt02.btlabs.bt.co.uk>

> Now I have another class (class WINMENU) which allows a user 
> to operate on the data in the list. 

In OO terms thats BAD! Unless....

> inherit the attributes of the ScrolledList class to the 
> WINMENU class. 

you do this. That allows you to write specfic list 
handling code but get at all of the generic stuff too.


> class WINMENU(Frame)
>   .....
> class ScrolledList(options)
>   def populate_list(options)
>   .......

You need to reverse the order of declaration so that 
the definition of WINMENU can see the ScrolledList. 
Either that or move ScrolledList into its own module 
- this makes it easier to reuse in the future too...

Then you can:

import ScrolledList

class WinMenu(ScrolledList.ScrolledList): # use parent in module
    .....

Try drawing a picture of the classes and their relationships.
Use an arrow to show inheritance and plain lines to show
usage relationships.

Include the GUI elements for which you store handles and 
any application level classes - data sources if you like.
If you want a formal notation look at UML
http://www.omg.org/

HTH,

Alan G


From jrclare@lycos.com  Tue Oct 22 12:58:04 2002
From: jrclare@lycos.com (James Clare)
Date: Tue Oct 22 11:58:04 2002
Subject: [Tutor] what i miss is a C style for loop
Message-ID: <HNLHJHJNLJPICBAA@mailcity.com>

considering it's only one more key that's pretty cool.
C: a++
python: a+=1
Thanks, and sorry for being to lazy to look it up! 
--

On Tue, 22 Oct 2002 07:43:05  
 Sean 'Shaleh' Perry wrote:
>On Tuesday 22 October 2002 05:13, James Clare wrote:
>> variable++ would be better than variable = variable + 1
>> Python dosen't have that function does it?
>> Is there a different short hand way to do variable = variable + 1?
>
>a += 1 is all you get.
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>


____________________________________________________________
Get 250 full-color business cards FREE right now!
http://businesscards.lycos.com 


From magnus@thinkware.se  Tue Oct 22 13:43:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Oct 22 12:43:01 2002
Subject: [Tutor] RE: what i miss is a C style for loop & the python
 way
In-Reply-To: <OBFHEGECAMKICBAA@mailcity.com>
Message-ID: <5.1.0.14.0.20021022183853.02a60b78@www.thinkware.se>

At 10:29 2002-10-22 -0400, kevin parks wrote:
>Since i have started working with python, i find it hard to imagine=20
>missing anything from C!

Well, raw execution speed is certainly better
in C in some cases... But as Don Knuth said,
premature optimization is the root of all evil. ;)

>20. built-in is better than homebrewed (why reinvent the wheel!?)

Very true, but not really unique to Python.

A 20b could be directly stolen from the 7th commandment:

"Thou shalt study thy libraries and strive not to reinvent
them without cause, that thy code may be short and readable
and thy days pleasant and productive."

(See http://www.lysator.liu.se/c/ten-commandments.html )


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From karthik@james.hut.fi  Tue Oct 22 15:35:01 2002
From: karthik@james.hut.fi (Karthikesh Raju)
Date: Tue Oct 22 14:35:01 2002
Subject: [Tutor] classes question
In-Reply-To: <20021022160004.7706.17686.Mailman@mail.python.org>
Message-ID: <Pine.SGI.4.21.0210222132580.97320-100000@james.hut.fi>

Hi,

i just started to write a class, when i was struck:

i did something like:


import Numeric
import RandomArray

class source:
      def __init__(self, k=1,n=1,type='uniform'):
              self.k = k
              self.n = n
              self.type = type
              if type == 'uniform':
                    self.data = RandomArray.random([K,N])
     
Now i want to do __add__ overloading and the function should return an
another source

i did:

def __add__(self, other):
     return source(self.data + other)

i keep getting errors when i try x+5; x is an object of type source.
i want to be able to implement

x+5
x+y (x,y are of type sources)

and other non source types should be converted to source types.

Any help is great,

thankx in advance,
karthik


-----------------------------------------------------------------------
Karthikesh Raju,		    email: karthik@james.hut.fi		
Researcher,			    http://www.cis.hut.fi/karthik
Helsinki University of Technology,  Tel: +358-9-451 5389
Laboratory of Comp. & Info. Sc.,    Fax: +358-9-451 3277
Department of Computer Sc.,
P.O Box 5400, FIN 02015 HUT,
Espoo, FINLAND
-----------------------------------------------------------------------




From magnus@thinkware.se  Tue Oct 22 17:23:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Oct 22 16:23:01 2002
Subject: [Tutor] classes question
In-Reply-To: <Pine.SGI.4.21.0210222132580.97320-100000@james.hut.fi>
References: <20021022160004.7706.17686.Mailman@mail.python.org>
Message-ID: <5.1.0.14.0.20021022213518.04314e98@www.thinkware.se>

At 21:33 2002-10-22 +0300, Karthikesh Raju wrote:
>               self.k =3D k
>               self.n =3D n
...
>                     self.data =3D RandomArray.random([K,N])

Is this deliberate? Are K and N global variables?
Python is case sensitive, K is not the same thing as k.

>def __add__(self, other):
>      return source(self.data + other)

I suppose this method definition was indented as it should.
As written here, it's not part of the class. It's always
a bit difficult to judge edited code snippets like this.
Posting a minimal but runnable program is always good. Then
we know whether oddities are part of the program or just a
consequence of editing an email.

>i keep getting errors when i try x+5; x is an object of type source.

Exact error messages are helpful too.

>i want to be able to implement
>
>x+5
>x+y (x,y are of type sources)
>
>and other non source types should be converted to source types.

Can you please write how addition of source objects
should work mathematically? What you coded was along
the lines that:

If x is source and y is integer, z =3D x + y =3D> z is a
new source objects instanciated with k =3D x.data + y,
n =3D 1, type =3D 'uniform'.

This won't work since k should be an integer, and
x.data is an array.

A few style issues: It's common practice to capitalize
class names, e.g. Source. It's also common practice to
avoid hiding builtin functions like you do when you call
a variable 'type'. If you need to use the type() function
for some test in init, you need to rename the parameter
type, which is bad, since it's part of the interface of
the class. (You can get around this with something like
"python_type =3D type" before the class definition, and then
using python_type() inside the source class, but that is
a bit awkward. Breaking these "rules" isn't illegal in
python but it usually makes life simpler if we comply...

I imagine you might want something like:

class source:
     def __init__(self, k=3D1, n=3D1, type=3D'uniform'):
         self.k =3D k
         self.n =3D n
         self.type =3D type
         if type =3D=3D 'uniform':
             self.data =3D RandomArray.random([k,n])
         else:
             pass # What???
     def __add__(self, other):
         if isinstance(other, source):
             assert (self.k=3D=3Dother.k) and (self.n=3D=3Dother.n)\
                    and (self.type=3D=3Dother.type))
             result =3D source(self.k, self.n, self.type)
             result.data =3D self.data + other.data
             return result
         elif type(other) =3D=3D type(0):
             result =3D source(self.k,self.n, self.type)
             result.data =3D self.data + other
             return result
         else:
             raise TypeError, "Only integer or source can be added to=
 source"
     # Assuming a+b =3D=3D b+a
     __radd__ =3D __add__



--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From learning_python@turbonet.com  Tue Oct 22 21:23:02 2002
From: learning_python@turbonet.com (learning_python@turbonet.com)
Date: Tue Oct 22 20:23:02 2002
Subject: [Tutor] Hash of Lists?
Message-ID: <119420-22002103230221855@M2W057.mail2web.com>

I've been perusing the archives for several days, but I haven't come acros=
s
Python applicable info on what Perl users apparently call a "hash of lists=
=2E"

If I understand correctly, this functionality is replicated in Python
through "dictionaries," which are described as being implemented as
"resizable hash tables" with "immutable keys=2E"

I'm looking for a newbie-level tutorial of these concepts, hopefully with
example code=2E  I've googled and googled, to no avail=2E

Can anyone point me towards a relevant URL?

Thank you very much, and I must add that my browsing of the archives has
been very pleasant, due to the virtual non-existence of flames or trolls=2E=


Hoping to claw myself up from newbie status soon, and no longer lurking,

Chas



--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web=2Ecom/ =2E




From shalehperry@attbi.com  Tue Oct 22 22:02:01 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue Oct 22 21:02:01 2002
Subject: [Tutor] Hash of Lists?
In-Reply-To: <119420-22002103230221855@M2W057.mail2web.com>
References: <119420-22002103230221855@M2W057.mail2web.com>
Message-ID: <200210221800.59802.shalehperry@attbi.com>

On Tuesday 22 October 2002 17:22, learning_python@turbonet.com wrote:
> I've been perusing the archives for several days, but I haven't come ac=
ross
> Python applicable info on what Perl users apparently call a "hash of
> lists."
>
> If I understand correctly, this functionality is replicated in Python
> through "dictionaries," which are described as being implemented as
> "resizable hash tables" with "immutable keys."
>
> I'm looking for a newbie-level tutorial of these concepts, hopefully wi=
th
> example code.  I've googled and googled, to no avail.
>
> Can anyone point me towards a relevant URL?
>

d =3D {}

d['chargers'] =3D [1,0,1,0,1] # list of wins/losses with 1 meaning a win
d['raiders'] =3D [1,1,1,1,0]
d['panthers'] =3D [0,0,0,0,0]

etc.

They key must be immutable (strings are) the data can be anything.

for team in d.keys():
    wins =3D reduce(operator.add, d[team])
    print '%s has won %d games' % (team, wins)

or perhaps this example cribbed from the thread "sorting into lists".

> Hey everyone,
>
> Let's say I've got a list like the following:
>
> l =3D [1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4]
>
> I'm trying to figure out a good way to turn this list into
>
> [[1, 1, 1], [2, 2], [3, 3, 3, 3], [4, 4]]

Hi Tim,

Is this grouping identical elements?  Do we have to worry about what
happens when the list isn't in order?  More information on the problem
might allow us to write more appropriate programs.


Here's one approach that uses dictionaries:

###
def formGroups(L):
    groups =3D {}
    for item in L:
        groups.setdefault(item, []).append(item) # **import line!!!**
    return groups.values()
###

explanation:
setdefaults() is a method on dictionaries which returns the value if the =
key=20
exists of inserts a default value into the dictionary.  So if item is in =
the=20
dictionary groups the list it points to is returns and the lists append()=
=20
method is called which adds another item to the list.  Otherwise an empty=
=20
list is put in the dictionary (that []) and then item is appended.

if you wrote this by hand you'd get

if not groups.has_key(item):
    groups[item] =3D []
groups[item].append(item)

Hope this helps you on the path to enlightenment.  if not, please let us =
have=20
a more specific question.


From dyoo@hkn.eecs.berkeley.edu  Wed Oct 23 00:57:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue Oct 22 23:57:01 2002
Subject: [Tutor] Hash of Lists?  [Dictionaries]
In-Reply-To: <200210221800.59802.shalehperry@attbi.com>
Message-ID: <Pine.LNX.4.44.0210222026090.12617-100000@hkn.eecs.berkeley.edu>


On Tue, 22 Oct 2002, Sean 'Shaleh' Perry wrote:

> On Tuesday 22 October 2002 17:22, learning_python@turbonet.com wrote:
>
> > I've been perusing the archives for several days, but I haven't come
> > across Python applicable info on what Perl users apparently call a
> > "hash of lists."
> >
> > If I understand correctly, this functionality is replicated in Python
> > through "dictionaries," which are described as being implemented as
> > "resizable hash tables" with "immutable keys."

Hello!

Yes, the concept of a "hash" in Perl directly maps to the "dictionary"
concept in Python.  *grin*


> d = {}
>
> d['chargers'] = [1,0,1,0,1] # list of wins/losses with 1 meaning a win
> d['raiders'] = [1,1,1,1,0]
> d['panthers'] = [0,0,0,0,0]

This 'd' is a dictionary (hashtable) that allows us to associate team
names with their win-loss records.  The mapped values can be any Python
object, including the win-loss lists that Sean uses here.



Dictionaries can be really useful!  We can do simple things, like
associate file extensions to their descriptions:

###
>> langs = {}
>>> langs['.c'] = 'C'
>>> langs['.py'] = 'Python'
>>> langs['.pl'] = 'Perl'
>>> langs['.scm'] = 'Scheme'
>>> langs['.sml'] = 'Standard ML'
>>>
>>> langs
{'.py': 'Python',
 '.pl': 'Perl',
 '.sml': 'Standard ML',
 '.c': 'C',
 '.scm':  'Scheme'}
>>>
>>> langs['.c']
'C'
###


If you're familiar with Perl, think of all Python values as "scalars".
In Python, it's a snap to have a dictionary that maps strings to lists:

###
>>> hellos = {} hellos['python'] = ''' ###
... print "hello world!" ... '''.strip().split('\n')
>>>
>>> hellos['C'] = '''
... int main(void) {
...     printf("hello world!\n");
... }
... '''.strip().split('\n')
>>>
>>> hellos['scm'] = '''
... (begin (display "hello world!")###
...  (newline))
... '''.strip().split('\n')
>>>
>>> hellos
{
 'python': ['print "hello world!"'],
 'scm':    ['(begin (display "hello world!")',
            '       (newline))'],
 'C':      ['int main(void) {',
            '    printf("hello world!', '");',
            '}']
}
###

[I adulterated some of the output to make it look nicer as an email
message.  Hope I didn't introduce more typos...]



One neat thing about Python is that the keys that we can use for our
dictionaries don't have to be strings or integers: they can also be
tuples!  This is actually quite useful at times!  For example, we can
represent a sparse matrix with ease if we use tuples as the keys:


###
>>> def print_matrix(matrix, i, j):
...    for y in range(i-1, -1, -1):
...        for x in range(j):
...            if matrix.has_key((x, y)):
...                print matrix[x,y],
...            else:
...                print '0',
...        print
...
>>> def make_ones(n):
...    matrix = {}
...    for i in range(n):
...        matrix[(i, i)] = 1
...    return matrix
...
>>> m = make_ones(5)
>>> print_matrix(m, 5, 5)
0 0 0 0 1
0 0 0 1 0
0 0 1 0 0
0 1 0 0 0
1 0 0 0 0
###


I hope this helps make the dictionary concept more concrete for you.
Good luck!



From goneil@scu.edu  Wed Oct 23 03:08:02 2002
From: goneil@scu.edu (Galen O'Neil)
Date: Wed Oct 23 02:08:02 2002
Subject: [Tutor] Graphing from python (replacement for matlab??)
Message-ID: <1035353241.3112.27.camel@localhost.localdomain>

Hola,
I'm doing some difference equations, math that requires a few simple
loops and if statements, then needs to be plotted.  I'm using octave,
and it works, but the programs are SO UGLY!  I want to use python!!  Are
there any good, and easy to use, graphing utilities, or can I interface
it with gnuplot?
It's actually not _that_ bad, but I would still like to use python if
its feasible.  For small programs, and small numbers of iterations, the
speed difference should be negligible.  How would python compare with
octave for larger computations?
Thank you!!
Galen

<Matlab/Octave code>

function x=tent(start, alpha, times)

x(1)=start;

for n=1:times,
	if x(n) < .5, x(n+1)=2*alpha*x(n);
		else x(n+1)=2*alpha*[1-x(n)];
	end
end

</Matlab/Octave code>





From dylan.belsey@baesystems.com  Wed Oct 23 03:23:02 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Wed Oct 23 02:23:02 2002
Subject: [Tutor] independent process
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B98D2AF0@wtntex1.baea.com.au>

Hi Tutors,
	I need some advice on how to run an independent application from
within Python.
	Here is the scenario.  I am using WinNT, with Python 2.1.1 and
Tkinter (inc. Pmw) for my GUIs.  Currently I have created a GUI that has
three buttons on it.  The first button initiates a system command to create
a text file and a .dat file, from a binary file, by calling a prewritten C++
utility (in executable form).  The second button also runs a system command
to load a database using the .dat file.  The command looks something like: 

	"mysql < SignalRecording1.dat"

	It is the third button that I am having trouble with.  I need this
button, when pressed, to start up a front-end to the database, by calling
the front-end's executable.  Currently I am using MySQL-Front. I have put
the location of the .exe in an environment variable.  So I interrogate the
variable using: 

	self.DB_GUI = os.getenv("DB_GUI") 

and then run either: 

	os.system("%s" %(self.DB_GUI)) 
or 
	CommandEnv = os.popen3("%s" %(self.DB_GUI))

	My problem is that with either of these commands, the GUI containing
the buttons hangs until I close the MySQL-Front application.  Is there away
to spawn this as a totally independent process/application so that the user
can close the initial GUI or keep using it without having to quit the
front-end?  Note: I am using Windows.

	TIA,
		Dylan



From dylan.belsey@baesystems.com  Wed Oct 23 04:14:02 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Wed Oct 23 03:14:02 2002
Subject: [Tutor] independent process
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B98D2AF1@wtntex1.baea.com.au>

OK, I have just been shown a possible solution to this problem.

	os.system("start %s" %(self.DB_GUI))

	Using "start" will create an independent process in DOS/Windows
systems.  However, is there a Python, platform independent way of doing
this.  I am also open to any other solutions that people may have.

		Dylan


-----Original Message-----
From: BELSEY, Dylan [mailto:dylan.belsey@baesystems.com]
Sent: Wednesday, 23 October 2002 16:27
To: 'tutor@python.org'
Subject: [Tutor] independent process


Hi Tutors,
	I need some advice on how to run an independent application from
within Python.
	Here is the scenario.  I am using WinNT, with Python 2.1.1 and
Tkinter (inc. Pmw) for my GUIs.  Currently I have created a GUI that has
three buttons on it.  The first button initiates a system command to create
a text file and a .dat file, from a binary file, by calling a prewritten C++
utility (in executable form).  The second button also runs a system command
to load a database using the .dat file.  The command looks something like: 

	"mysql < SignalRecording1.dat"

	It is the third button that I am having trouble with.  I need this
button, when pressed, to start up a front-end to the database, by calling
the front-end's executable.  Currently I am using MySQL-Front. I have put
the location of the .exe in an environment variable.  So I interrogate the
variable using: 

	self.DB_GUI = os.getenv("DB_GUI") 

and then run either: 

	os.system("%s" %(self.DB_GUI)) 
or 
	CommandEnv = os.popen3("%s" %(self.DB_GUI))

	My problem is that with either of these commands, the GUI containing
the buttons hangs until I close the MySQL-Front application.  Is there away
to spawn this as a totally independent process/application so that the user
can close the initial GUI or keep using it without having to quit the
front-end?  Note: I am using Windows.

	TIA,
		Dylan


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


From magnus@thinkware.se  Wed Oct 23 05:09:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Oct 23 04:09:02 2002
Subject: [Tutor] Graphing from python (replacement for matlab??)
In-Reply-To: <1035353241.3112.27.camel@localhost.localdomain>
Message-ID: <5.1.0.14.0.20021023101150.02af0870@www.thinkware.se>

You might be interested in SciPy, see http://www.scipy.org/
or other scientific and mathematical stuff (see
http://www.thinkware.se/cgi-bin/thinki.cgi/PythonInScience )

Other plotting things can be found at:
http://www.thinkware.se/cgi-bin/thinki.cgi/PythonForImaging


At 23:07 2002-10-22 -0700, Galen O'Neil wrote:
>Hola,
>I'm doing some difference equations, math that requires a few simple
>loops and if statements, then needs to be plotted.  I'm using octave,
>and it works, but the programs are SO UGLY!  I want to use python!!  Are
>there any good, and easy to use, graphing utilities, or can I interface
>it with gnuplot?
>It's actually not _that_ bad, but I would still like to use python if
>its feasible.  For small programs, and small numbers of iterations, the
>speed difference should be negligible.  How would python compare with
>octave for larger computations?
>Thank you!!
>Galen
>
><Matlab/Octave code>
>
>function x=3Dtent(start, alpha, times)
>
>x(1)=3Dstart;
>
>for n=3D1:times,
>         if x(n) < .5, x(n+1)=3D2*alpha*x(n);
>                 else x(n+1)=3D2*alpha*[1-x(n)];
>         end
>end
>
></Matlab/Octave code>
>
>
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From thomi@thomi.imail.net.nz  Wed Oct 23 05:09:17 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Wed Oct 23 04:09:17 2002
Subject: [Tutor] independent process
In-Reply-To: <86C3892A0C52D411AF5000A0C9EAA3B98D2AF1@wtntex1.baea.com.au>
References: <86C3892A0C52D411AF5000A0C9EAA3B98D2AF1@wtntex1.baea.com.au>
Message-ID: <20021023210816.38d6da76.thomi@thomi.imail.net.nz>

ummm... i think you may be looking for the fork pid thingy what?? I'm
not sure if it is windows compat. though.. look under wither OS or
system modules... can't remember which right now...

On Wed, 23 Oct 2002 16:47:44 +0930 Thus said "BELSEY, Dylan"
<dylan.belsey@baesystems.com>:

> OK, I have just been shown a possible solution to this problem.
> 
> 	os.system("start %s" %(self.DB_GUI))
> 
> 	Using "start" will create an independent process in DOS/Windows
> systems.  However, is there a Python, platform independent way of
> doing this.  I am also open to any other solutions that people may
> have.
> 
> 		Dylan
> 
> 
> -----Original Message-----
> From: BELSEY, Dylan [mailto:dylan.belsey@baesystems.com]
> Sent: Wednesday, 23 October 2002 16:27
> To: 'tutor@python.org'
> Subject: [Tutor] independent process
> 
> 
> Hi Tutors,
> 	I need some advice on how to run an independent application from
> within Python.
> 	Here is the scenario.  I am using WinNT, with Python 2.1.1 and
> Tkinter (inc. Pmw) for my GUIs.  Currently I have created a GUI that
> has three buttons on it.  The first button initiates a system command
> to create a text file and a .dat file, from a binary file, by calling
> a prewritten C++ utility (in executable form).  The second button also
> runs a system command to load a database using the .dat file.  The
> command looks something like: 
> 
> 	"mysql < SignalRecording1.dat"
> 
> 	It is the third button that I am having trouble with.  I need
> 	this
> button, when pressed, to start up a front-end to the database, by
> calling the front-end's executable.  Currently I am using MySQL-Front.
> I have put the location of the .exe in an environment variable.  So I
> interrogate the variable using: 
> 
> 	self.DB_GUI = os.getenv("DB_GUI") 
> 
> and then run either: 
> 
> 	os.system("%s" %(self.DB_GUI)) 
> or 
> 	CommandEnv = os.popen3("%s" %(self.DB_GUI))
> 
> 	My problem is that with either of these commands, the GUI
> 	containing
> the buttons hangs until I close the MySQL-Front application.  Is there
> away to spawn this as a totally independent process/application so
> that the user can close the initial GUI or keep using it without
> having to quit the front-end?  Note: I am using Windows.
> 
> 	TIA,
> 		Dylan
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


-- 
Lord, what fools these mortals be!
 -- midsummer nights dream.
Thomi Richards,
thomi@imail.net.nz


From magnus@thinkware.se  Wed Oct 23 05:20:03 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Oct 23 04:20:03 2002
Subject: [Tutor] independent process
In-Reply-To: <86C3892A0C52D411AF5000A0C9EAA3B98D2AF1@wtntex1.baea.com.au
 >
Message-ID: <5.1.0.14.0.20021023101546.02aa1a08@www.thinkware.se>

At 16:47 2002-10-23 +0930, BELSEY, Dylan wrote:
>OK, I have just been shown a possible solution to this problem.
>
>         os.system("start %s" %(self.DB_GUI))
>
>         Using "start" will create an independent process in DOS/Windows
>systems.  However, is there a Python, platform independent way of doing
>this.  I am also open to any other solutions that people may have.

Not that I know of. If you look at section 6.1 of the library
reference, you'll see that things like os.fork() is only
available in unix etc.

In unix and friends you would change "start %s" to "%s &". I
don't know about MacOS. I suppose MacOSX works just as unix,
but I don't suppose that works with previous versions.

I reasonable approximation might be (untested):

import os
def runDetached(cmd):
     try:
         fmt =3D {'nt': 'start %s',
                'posix': '%s &'}[os.name]
     except KeyError:
         fmt =3D "%s"
     os.system(fmt % cmd)


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Wed Oct 23 05:39:10 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Oct 23 04:39:10 2002
Subject: [Tutor] classes question
In-Reply-To: <Pine.SGI.4.21.0210231014280.22131-100000@synapse.hut.fi>
References: <5.1.0.14.0.20021022213518.04314e98@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021023102750.02a519f8@www.thinkware.se>

At 10:26 2002-10-23 +0300, Karthikesh Raju wrote:
>i think this is quite close. The only issue here is
> >>>  result =3D source(self.k, self.n, self.type)
>This generates unnecessary data which is then replaced with the actual
>data. Any methods to reasonably do it otherways.

Ok. add a parameter with default value "data =3D None"
to sources.__init__. Then use a construct like this
in the body of __init__:

if data is not None:
     self.data =3D data
else:
     <whatever you do today.>

I think you understand how to adapt __add__ to that...

>Actually, since i come from a non-classy world, is my approach right.

I might be more critical if I knew more about
the mathematics you are involved in, but in
general it seems reasonable to me.

I'm not an expert in performance for heavy calculations though.
You'll probably get more informed advice somewhere else. I
was about to suggest the python-numerics mailing list, but that
seems dead. Let's see... Aha, numpy-discussion is the place. See
http://www.geocrawler.com/lists/3/SourceForge/1329/0



--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From scot@possum.in-berlin.de  Wed Oct 23 06:36:03 2002
From: scot@possum.in-berlin.de (Scot W. Stevenson)
Date: Wed Oct 23 05:36:03 2002
Subject: [Tutor] Tkinter and non-ASCII-characters, again
Message-ID: <200210231135.19518.scot@possum.in-berlin.de>

This has been covered before, but the solution I found in the archives 
doesn't seem work for me: 

I'm asking for input into a Tkinter Entry widget, and have to be able to 
accept German Umlauts, which are not part of ASCII. Typing in Umlauts 
gives me:

================================
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.2/lib-tk/Tkinter.py", line 1292, in __call__
    return apply(self.func, args)
  File "test2.py", line 513, in search
    if eval(teststring):
UnicodeError: ASCII encoding error: ordinal not in range(128)
=================================

Now, Gregor demonstrated a solution to this on the 24. Sept such that:

============================
import sys,  locale
loc = locale.getdefaultlocale()
if loc[1]:
    encoding = loc[1]
if encoding != "ascii":
    sys.setdefaultencoding(encoding)
=============================

But putting this in the "sitecustomize.py" file is not an option in this 
case, as the program might end up running on machines where I can't fool 
around with that file. Also, I get this error (SuSE 8.0, Python 2.2):

=============================
>>> encoding = locale.getdefaultlocale()[1]
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.2/locale.py", line 337, in getdefaultlocale
    return _parse_localename(localename)
  File "/usr/lib/python2.2/locale.py", line 271, in _parse_localename
    raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: de_DE@euro
==============================

so this won't work anyway. The Python Cookbook isn't much help, since it 
and other examples I've found seem to want me to do the full Unicode 
dance, which seems like complete overkill to me: All I want to do is 
switch the default character set for Tkinter from "ascii" to "iso-8859". 
It has to be a Tkinter problem, since the command line version of the same 
funktion works fine...

Terribly frustrating.

Thank you for any help,
Y, Scot

-- 
Scot W. Stevenson wrote me on Wednesday, 23. Oct 2002 in Zepernick, Germany  
       on his happy little Linux system that has been up for 540 hours        
        and has a CPU that is falling asleep at a system load of 0.07.        



From alan.gauld@bt.com  Wed Oct 23 06:38:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed Oct 23 05:38:02 2002
Subject: [Tutor] Activate window
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB2181C7974@mbtlipnt02.btlabs.bt.co.uk>

> ... I can't remember any Microsoft 
> product having  "focus follows mouse". 

Actually you can set that by hacking the registry.
The easy way is to use the free tweakUI applet from 
Microsofts website...

However I actually thought the original poster was asking 
how to do it from Python! I think the win32 module and 
visible=1 posted earlier were the correct answers...

Alan G


From alan.gauld@bt.com  Wed Oct 23 08:09:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed Oct 23 07:09:01 2002
Subject: [Tutor] classes question
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9D4@mbtlipnt02.btlabs.bt.co.uk>

> class source:

It's conventional to capitalise class names (ie Source)
- its not necessary but it does make it easier for 
new readers of your code (like us!) to guess 
whats going on....

>       def __init__(self, k=1,n=1,type='uniform'):
>               self.k = k
>               self.n = n
>               self.type = type
>               if type == 'uniform':
>                     self.data = RandomArray.random([K,N])

So data only exists if uniform is set?
This is dangerous since your add method relies 
on the existence of self.data.
Maybe you should set a default Data value?
Either that or....

> def __add__(self, other):
>      return source(self.data + other)

add a check that data exist:

      if self.data: return .....
      else: return self (or None?)

Alternatively

      try: return ....
      except NameRError: return None

I assume NameErrror is what you are getting?

The other problem is that you are adding a number 
(self.data) to an object (other). I'm not sure 
what semantics you expect add to produce but my 
guess is you should be adding the data items of 
each object:

     return Source(self.data+other.data)

BTW: Its always a good idea to post the error message 
when asking questions on the list.

Let's worry about the other stuff once you get this bit 
working!

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


From alan.gauld@bt.com  Wed Oct 23 08:17:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed Oct 23 07:17:02 2002
Subject: [Tutor] Python & wxWindows Question
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9D3@mbtlipnt02.btlabs.bt.co.uk>

> Anyone know anything about wxWindows being used with Python?

Quite a few folks use wxPython on this list.

> I want to use a control on a dialog that allows me to update 
> it at runtime(text, colour, font etc.) 

Pretty much any control will do that (in pretty much 
any GUI toolkit!)

> ... what I don't want is a box that halts program
> execution 

Again, virtually anycontrol will do that too.

Can you say why you think it might be a problem? 
What have you tried so far? What happened?
Normally finding a way to generate the updates 
without blocking is the hard bit, not sending 
the updates to the control...

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


From wheelcrdan@hotmail.com  Wed Oct 23 12:53:03 2002
From: wheelcrdan@hotmail.com (Dan Dud)
Date: Wed Oct 23 11:53:03 2002
Subject: [tutor] functions and classes
Message-ID: <F49mymsnJsWuVvdshEx0001096b@hotmail.com>

Hi everyone

Hope everyone is doing great. I wrote some functions that looked confusing 
and I tried to define everything before but I think I have it right now,,, 
How do these look??? I took the idea out of chapter 4 how to think like a 
computer scientest chapter 4

def compare(x,y): # this is what I think the compare should look like
    if x < y:
        print x, "is less then", y
    elif x > y:
        print x, "is greater then", y
    else:
        print x, "and", y, "are equal"


here is the second one

def disbatch(choice): # this is what I think the disbatch should look like
    if choice == 'A':
        functionA()
    elif choice == 'B':
        functionB()
    elif choice == 'C':
        functionC()
    else:
        print "Invlaid choice"


the next question is When I define a class do I import these then use them 
by calling them then define the class or do I do that afterwards
thanks for the everyone help

Danny D


_________________________________________________________________
Choose an Internet access plan right for you -- try MSN! 
http://resourcecenter.msn.com/access/plans/default.asp



From mongo57a@comcast.net  Wed Oct 23 13:04:02 2002
From: mongo57a@comcast.net (andy surany)
Date: Wed Oct 23 12:04:02 2002
Subject: [Tutor] Interfacing to the web
Message-ID: <002c01c27ab6$1472ce60$2502a8c0@emily.ewndsr01.nj.comcast.net>

This is a multi-part message in MIME format.

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

Hi All!

Here is what I need to accomplish:

    From a python program, I need to launch a browser. The user then uses the browser to interact with the web site. However, the python program must continually monitor the data from the web site to capture specific data elements.

    Unfortunately, I can't point the program to the specific URL as there is a significant and secure (cookies, etc.) exchange that must occur in order to reach the page.

    In the archives, I found a section on parsing HTML which I think would be very helpful. However, I am unsure how to a) launch the browser from the program, and b) how to passively (important point...) interact with the return data stream (i.e. how to apply html parsing in this case).

Anybody have advice?

TIA
-Andy

--Boundary_(ID_vM3DNYHmNYAPsMoh0/dmFg)
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 All!</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Here is what I need to accomplish:</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; From a python program, I need to launch a 
browser. The user then uses the browser to interact with the web site. However, 
the python program must continually monitor the data from the web site to 
capture specific data elements.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; Unfortunately, I can't point the program 
to&nbsp;the specific URL as there is a significant and secure (cookies, etc.) 
exchange that must occur in order to reach the page.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp; In the archives, I found a section on 
parsing HTML which I think would be very helpful. However, I am unsure how to a) 
launch the browser from the program, and b) how to passively (important 
point...) interact with the return data stream (i.e. how to apply html parsing 
in this case).</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Anybody have advice?</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>TIA</FONT></DIV>
<DIV><FONT size=2>-Andy</FONT></DIV></BODY></HTML>

--Boundary_(ID_vM3DNYHmNYAPsMoh0/dmFg)--


From rob@uselesspython.com  Wed Oct 23 13:12:02 2002
From: rob@uselesspython.com (Rob)
Date: Wed Oct 23 12:12:02 2002
Subject: [Tutor] Interfacing to the web
In-Reply-To: <002c01c27ab6$1472ce60$2502a8c0@emily.ewndsr01.nj.comcast.net>
Message-ID: <MPEOIFCOPCIHEDCLBLPBMENOCIAA.rob@uselesspython.com>

import webbrowser
webbrowser.open('http://www.python.org')

This is a simple way to use the default browser to open a web page, but it
sounds like your problem is a good deal more sophisticated than that.

Have you looked at urrllib and urllib2 to see if they have any utilities
that would be of use to you?

I suspect that the security issues may turn out to be a profound challenge
for this. Do you have any other way to access the data than through a
cookie-driven website?

Rob Andrews
http://uselesspython.com

-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
andy surany
Sent: Wednesday, October 23, 2002 12:03 PM
To: tutor@python.org
Subject: [Tutor] Interfacing to the web


Hi All!

Here is what I need to accomplish:

    From a python program, I need to launch a browser. The user then uses
the browser to interact with the web site. However, the python program must
continually monitor the data from the web site to capture specific data
elements.

    Unfortunately, I can't point the program to the specific URL as there is
a significant and secure (cookies, etc.) exchange that must occur in order
to reach the page.

    In the archives, I found a section on parsing HTML which I think would
be very helpful. However, I am unsure how to a) launch the browser from the
program, and b) how to passively (important point...) interact with the
return data stream (i.e. how to apply html parsing in this case).

Anybody have advice?

TIA
-Andy




From francois.granger@free.fr  Wed Oct 23 13:47:01 2002
From: francois.granger@free.fr (Fran=?ISO-8859-1?B?5w==?=ois Granger)
Date: Wed Oct 23 12:47:01 2002
Subject: [Tutor] classes question
In-Reply-To: <Pine.SGI.4.21.0210222132580.97320-100000@james.hut.fi>
Message-ID: <B9DC9F03.5A7E2%francois.granger@free.fr>

on 22/10/02 20:33, Karthikesh Raju at karthik@james.hut.fi wrote:

> and other non source types should be converted to source types.

Have a look to /lib/UserString.py for an example of this behavior.....

-- 
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  Wed Oct 23 14:01:02 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed Oct 23 13:01:02 2002
Subject: [tutor] functions and classes
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9DA@mbtlipnt02.btlabs.bt.co.uk>

> def compare(x,y): # this is what I think the compare should look like
> def disbatch(choice): # this is what I think the disbatch 

They look OK to me apart from some typos.

> the next question is When I define a class do I import these 
> then use them by calling them then define the class or do I 
> do that afterwards

Depends what you want to do.
Assuming you oput the two functions in a file called 
httlacs4.py (How to think....4!)

You can import the file and use the functions before 
defining a class:

import httlacs4 as h    # I'm lazy!

h.compare(4,5)
h.disbatch("A")   

# - OOPs probably an error unless functionA has been written too...

class foo:
  pass

Or you could define the class before the calls to compare/disbatch.

What you can't do is call or even reference the functions 
before you do the import. Thus you couldn't use compare 
inside the class unless you put the import before the 
class definition.

As a general rule its best to

1) Do any imports necessary
2) define any data types/classes/functions
3) write executable code(like calling compare etc)

in that order.

It also makes it easier to debug if you follow that structure consistently.

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


From mongo57a@comcast.net  Wed Oct 23 14:09:02 2002
From: mongo57a@comcast.net (andy surany)
Date: Wed Oct 23 13:09:02 2002
Subject: [Tutor] Interfacing to the web
Message-ID: <003d01c27abf$780486e0$2502a8c0@emily.ewndsr01.nj.comcast.net>

Thanks Rob.

Yes, it is easy to open the default browser. But I need to have "hooks" into
the browser to parse the return string(s).

Unfortunately, there is no other way to get to the data (financial data on a
secure site). My only other alternative would be to record the entire
session and use urllib to "playback" the session (prompting the user for
password info). I would also have to "transpose" the cookies. This does not
allow for direct interaction with the site, but should accomplish the task.
And I think it might be a whole heck of a lot easier.

What do you guys think? I will look at the libs you mentioned to see what is
available.

Regards,

Andy
-----Original Message-----
From: Rob <rob@uselesspython.com>
To: tutor@python.org <tutor@python.org>
Date: Wednesday, October 23, 2002 12:12 PM
Subject: RE: [Tutor] Interfacing to the web


>import webbrowser
>webbrowser.open('http://www.python.org')
>
>This is a simple way to use the default browser to open a web page, but it
>sounds like your problem is a good deal more sophisticated than that.
>
>Have you looked at urrllib and urllib2 to see if they have any utilities
>that would be of use to you?
>
>I suspect that the security issues may turn out to be a profound challenge
>for this. Do you have any other way to access the data than through a
>cookie-driven website?
>
>Rob Andrews
>http://uselesspython.com
>
>-----Original Message-----
>From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
>andy surany
>Sent: Wednesday, October 23, 2002 12:03 PM
>To: tutor@python.org
>Subject: [Tutor] Interfacing to the web
>
>
>Hi All!
>
>Here is what I need to accomplish:
>
>    From a python program, I need to launch a browser. The user then uses
>the browser to interact with the web site. However, the python program must
>continually monitor the data from the web site to capture specific data
>elements.
>
>    Unfortunately, I can't point the program to the specific URL as there
is
>a significant and secure (cookies, etc.) exchange that must occur in order
>to reach the page.
>
>    In the archives, I found a section on parsing HTML which I think would
>be very helpful. However, I am unsure how to a) launch the browser from the
>program, and b) how to passively (important point...) interact with the
>return data stream (i.e. how to apply html parsing in this case).
>
>Anybody have advice?
>
>TIA
>-Andy
>
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor



From dman@dman.ddts.net  Wed Oct 23 14:17:01 2002
From: dman@dman.ddts.net (Derrick 'dman' Hudson)
Date: Wed Oct 23 13:17:01 2002
Subject: [Tutor] Re: OT: Re: Re: accepting wild chars from pythons command line
In-Reply-To: <5.1.0.14.0.20021022125019.02ae4e58@www.thinkware.se>
References: <20021021093938.27131.qmail@web40701.mail.yahoo.com> <20021021093938.27131.qmail@web40701.mail.yahoo.com> <5.1.0.14.0.20021022125019.02ae4e58@www.thinkware.se>
Message-ID: <20021023173505.GA25624@dman.ddts.net>

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

On Tue, Oct 22, 2002 at 12:54:46PM +0200, Magnus Lycka wrote:
| At 23:34 2002-10-21 -0400, Derrick 'dman' Hudson wrote:
| >Actually, python will never see the '*' character.  The /shell/
| >expands it first.  Depending on your system and environment, that
| >shell is often one of  bash, ash, csh, tcsh, ksh, zsh, command.com or
| >cmd.exe.  The beauty of shell metacharacters is that the shell handles
| >their expansion and your program can't tell the difference.
|=20
| It seems you don't use Windows...you lucky bastard! ;)

I avoid it when at all possible.  When it isn't possible, I either
don't do real work, grab putty and use my own machine (remotely), or
install cygwin and use bash exclusively.

| Neither cmd.exe not command.com will do anything with
| * or other wildcard characters.

Oh.  I guess every DOS program I've run from cmd.exe or command.com
did the expansion itself and I never knew the difference.  Then I
learned UNIX and have used a *nix shell ever since (I started
programing, on UNIX, around the time I learned it).

| That's why you could write
|=20
| copy *.txt *.bak
|=20
| in DOS to create backup versions for all your text
| files. In the days when most people knew DOS, this
| was often a confusing problem for Unix newbies...

Oh, I see.  mcp(1)

(Actually I don't do that very often and am not familiar with the
command.  I use CVS or a tarball for backups.)



To the OP :

Either you can code the expansion yourself (the glob module should
help) or you can use a decent shell.  Go to cygwin.com and install at
least 'bash', then use it instead of cmd.exe or command.com to run
your scripts from.  An advantage of letting the shell perform wildcard
expansion is it simplifies your programs, and it also allows you to do
something like this :
    ./my_script.py `find . -t d -print`
(the arguments to the script will be a list of the absolute path to
all directories under the current directory)

-D

--=20
How great is the love the Father has lavished on us,
that we should be called children of God!
        1 John 3:1
=20
http://dman.ddts.net/~dman/

--ikeVEW9yuYc//A+q
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

iEYEARECAAYFAj223ckACgkQO8l8XBKTpRSYGACfdJQWRC+F8C8mACrRVE5E45Xx
0QoAn0kmeWRx4cj4mbvxOtLLQaUkd01Y
=/zfW
-----END PGP SIGNATURE-----

--ikeVEW9yuYc//A+q--


From mongo57a@comcast.net  Wed Oct 23 14:20:01 2002
From: mongo57a@comcast.net (andy surany)
Date: Wed Oct 23 13:20:01 2002
Subject: [Tutor] Interfacing to the web
Message-ID: <004601c27ac0$fa430180$2502a8c0@emily.ewndsr01.nj.comcast.net>

(addendum to last response)

I guess what I would really love to have is a generic browser written in
Python where the source is available. Then I can mod the source to provide
what I need......

Anybody out there ever develop a python browser???????

Regards,

Andy
-----Original Message-----
From: Rob <rob@uselesspython.com>
To: tutor@python.org <tutor@python.org>
Date: Wednesday, October 23, 2002 12:12 PM
Subject: RE: [Tutor] Interfacing to the web


>import webbrowser
>webbrowser.open('http://www.python.org')
>
>This is a simple way to use the default browser to open a web page, but it
>sounds like your problem is a good deal more sophisticated than that.
>
>Have you looked at urrllib and urllib2 to see if they have any utilities
>that would be of use to you?
>
>I suspect that the security issues may turn out to be a profound challenge
>for this. Do you have any other way to access the data than through a
>cookie-driven website?
>
>Rob Andrews
>http://uselesspython.com
>
>-----Original Message-----
>From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
>andy surany
>Sent: Wednesday, October 23, 2002 12:03 PM
>To: tutor@python.org
>Subject: [Tutor] Interfacing to the web
>
>
>Hi All!
>
>Here is what I need to accomplish:
>
>    From a python program, I need to launch a browser. The user then uses
>the browser to interact with the web site. However, the python program must
>continually monitor the data from the web site to capture specific data
>elements.
>
>    Unfortunately, I can't point the program to the specific URL as there
is
>a significant and secure (cookies, etc.) exchange that must occur in order
>to reach the page.
>
>    In the archives, I found a section on parsing HTML which I think would
>be very helpful. However, I am unsure how to a) launch the browser from the
>program, and b) how to passively (important point...) interact with the
>return data stream (i.e. how to apply html parsing in this case).
>
>Anybody have advice?
>
>TIA
>-Andy
>
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor



From karthik@synapse.hut.fi  Wed Oct 23 14:23:01 2002
From: karthik@synapse.hut.fi (Karthikesh Raju)
Date: Wed Oct 23 13:23:01 2002
Subject: [Tutor] classes question
In-Reply-To: <5.1.0.14.0.20021022213518.04314e98@www.thinkware.se>
Message-ID: <Pine.SGI.4.21.0210231014280.22131-100000@synapse.hut.fi>

Hi Magnus and all pythoners,

On Tue, 22 Oct 2002, Magnus Lycka wrote:

> At 21:33 2002-10-22 +0300, Karthikesh Raju wrote:
> >               self.k =3D k
> >               self.n =3D n
> ...
> >                     self.data =3D RandomArray.random([K,N])
>=20
> Is this deliberate? Are K and N global variables?
> Python is case sensitive, K is not the same thing as k.

It was a mistake. Actually what i did was a very fast writeup into the
mail. k,n are the number of users and number of blocks peruser. K,N are
not global variables.

What i wanted was to convert all my matlab code into python for more than
speed reasons. So, i wanted to write a class that generated sources. i
just used uniform as a first hack. It should generate sources with
different distributions (eg: uniform, gaussian, rayliegh etc
etc). All these data are compliant to mathematical operations
(add/sub/mul/div), and if matrix then all linear algebra operations

The first trick was to try addition: and i got struck there

>=20
> >def __add__(self, other):
> >      return source(self.data + other)
>=20
> I suppose this method definition was indented as it should.
> As written here, it's not part of the class. It's always
> a bit difficult to judge edited code snippets like this.
> Posting a minimal but runnable program is always good. Then
> we know whether oddities are part of the program or just a
> consequence of editing an email.

It is a part of the class, and i was overloading the basic operations

>=20
> >i keep getting errors when i try x+5; x is an object of type source.
>=20
> Exact error messages are helpful too.
>=20
Sothing to the  likes of this cant be done .....

> If x is source and y is integer, z =3D x + y =3D> z is a
> new source objects instanciated with k =3D x.data + y,
> n =3D 1, type =3D 'uniform'.
>=20
> This won't work since k should be an integer, and
> x.data is an array.
>=20
> A few style issues: It's common practice to capitalize
> class names, e.g. Source. It's also common practice to
> avoid hiding builtin functions like you do when you call
> a variable 'type'. If you need to use the type() function
> for some test in init, you need to rename the parameter
> type, which is bad, since it's part of the interface of
> the class. (You can get around this with something like
> "python_type =3D type" before the class definition, and then
...

i didnt know i was breaking these rules (too much of matlab is bad for
programming :-( ). Type could have been even distribution or anything. i
was an error of ignorance :-)

> I imagine you might want something like:
>=20
> class source:
>      def __init__(self, k=3D1, n=3D1, type=3D'uniform'):
>          self.k =3D k
>          self.n =3D n
>          self.type =3D type
>          if type =3D=3D 'uniform':
>              self.data =3D RandomArray.random([k,n])
>          else:
>              pass # What???
>      def __add__(self, other):
>          if isinstance(other, source):
>              assert (self.k=3D=3Dother.k) and (self.n=3D=3Dother.n)\
>                     and (self.type=3D=3Dother.type))
>              result =3D source(self.k, self.n, self.type)
>              result.data =3D self.data + other.data
               return result
>          elif type(other) =3D=3D type(0):
>              result =3D source(self.k,self.n, self.type)
>              result.data =3D self.data + other
>              return result
>          else:
>              raise TypeError, "Only integer or source can be added to s=
ource"
>      # Assuming a+b =3D=3D b+a
>      __radd__ =3D __add__
>=20
>=20

i think this is quite close. The only issue here is=20
>>>  result =3D source(self.k, self.n, self.type)
This generates unnecessary data which is then replaced with the actual
data. Any methods to reasonably do it otherways.

Actually, since i come from a non-classy world, is my approach right.

Build up source classes, build class of detectors glue them together alon=
g
with the channels class..

best regards
karthik



>=20
> --=20
> Magnus Lyck=E5, Thinkware AB
> =C4lvans v=E4g 99, SE-907 50 UME=C5
> tel: 070-582 80 65, fax: 070-612 80 65
> http://www.thinkware.se/  mailto:magnus@thinkware.se
>=20



From cderr@simons-rock.edu  Wed Oct 23 14:23:12 2002
From: cderr@simons-rock.edu (charlie derr)
Date: Wed Oct 23 13:23:12 2002
Subject: [Tutor] pty
References: <3DA900A8.2AF70EED@netzero.net>
Message-ID: <3DB6AE51.4000201@simons-rock.edu>

I can't seem to figure out how to use pty.openpty() successfully.  I've read the documentation and I don't really understand what master and slave mean in the context of file descriptors.  To give a 
little more background, my goal is to create a simple utility function which gets passed a username/password pair and (using su) checks to see if this is a valid user on the local linux machine. 
When I tried this using popen2 i saw the error "su: must be run in a terminal", so someone told me that using a pseudo-tty was the way to go.  The module pty seems to be the way to do that in python, 
but as I said above, I can't figure out what to do with the master file descriptor (or the slave file descriptor) that I create.

 >>> import pty
 >>> (masterfd, slavefd) = pty.openpty()
 >>> import os
 >>> mas = os.fdopen(masterfd)
 >>> sla = os.fdopen(slavefd)
 >>>


that all works well, but I don't know what to do next


 >>> mas.write('ls')
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
IOError: [Errno 9] Bad file descriptor

 >>> sla.write('ls')
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
IOError: [Errno 9] Bad file descriptor

and reading either one just hangs python completely

 >>> mas.read()



If someone could provide some simple example code for a complete pseudo terminal session, I'd be most grateful.  (And/or feel free to correct my assumption(s) about pty being the best way to code my 
simple authentication utility.)

	thanks very much in advance,
		~c



From jpaish@freenet.edmonton.ab.ca  Wed Oct 23 14:23:27 2002
From: jpaish@freenet.edmonton.ab.ca (Joseph Paish)
Date: Wed Oct 23 13:23:27 2002
Subject: Fwd: Re: [Tutor] assigning types(?) to list elements
Message-ID: <02102309142205.20271@localhost.localdomain>

thanks for all the replies.

haven't had a chance yet to test them out to see if they do what i want (i
suspect that they do just from looking at them), but at least now i have
something to work with

joe

On Monday 14 October 2002 06:08, you wrote:
> i'm not sure what the correct terminology for what i am trying to do is, so
> i'll just describe it the best i can.
>
> # code follows
>
> file_handle = open ('/path/to/datafile.txt', 'r')
>
> for each_line in file_handle.readlines() :
>         each_line = each_line.rstrip() # strip off carriage return
>         temp1, temp2, temp3, temp4, temp5, temp6 = string.split(each_line)
>
>         # a sample record is : 'abc 123.45 74 98 234.56 345.67'
>
>         # temp1 is a string so it doesn't need any conversion
>         # but i do need to convert the others so i can do calculations with
>         #    them
>
>         temp2  = float(temp2)
>         temp3  = int(temp3)
>         temp4  = int(temp4)
>         temp5 = float(temp5)
>         temp6 = float(temp6)
>
> # end code
>
> is there an easier way to assign a type to each of the variables so that i
> can do calculations with them.  the way it is now, if i don't do any
> conversion and add a number to any of temp2 thru temp6, i end up with a
> concatenated string.
>
> i guess i am asking if there is another way to make each of the variables
> the correct type without doing it one variable at a time the way it is now.
>
> there are a lot more than just the six variables i am using for this
> example, so one line of code for each variable would get very long.
>
> a pointer to documentation would be very helpful so that i can understand
> any suggestions for doing what i am trying to do.  of course, an example of
> the correct way to do it wouldn't be turned down :-)
>
> thanks
>
> joe
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-------------------------------------------------------


From dyoo@hkn.eecs.berkeley.edu  Wed Oct 23 14:41:03 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed Oct 23 13:41:03 2002
Subject: [Tutor] Interfacing to the web
In-Reply-To: <004601c27ac0$fa430180$2502a8c0@emily.ewndsr01.nj.comcast.net>
Message-ID: <Pine.LNX.4.44.0210231036440.11391-100000@hkn.eecs.berkeley.edu>


On Wed, 23 Oct 2002, andy surany wrote:

> (addendum to last response)
>
> I guess what I would really love to have is a generic browser written in
> Python where the source is available. Then I can mod the source to
> provide what I need......
>
> Anybody out there ever develop a python browser???????

The Mozilla web browser has Python hooks that we can use to puppet the
browser.  We can find more information here:

    http://aspn.activestate.com/ASPN/Downloads/Komodo/PyXPCOM/

    http://www-106.ibm.com/developerworks/webservices/library/co-pyxp1.html


I'm being vague here because I simply haven't had time to try out an
example for myself yet.  Simply speaking, I have no clue if this will
work.  *grin* If someone can get a working PyXPCOM example, perhaps a
summary of the experience would be helpful for people on Tutor?


Good luck to you!



From jeff@ccvcorp.com  Wed Oct 23 14:54:01 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Wed Oct 23 13:54:01 2002
Subject: [Tutor] Python & wxWindows Question
References: <OF04F3DBB5.4FBDD857-ON80256C5A.00433FC9@equant.com>
Message-ID: <3DB6E213.B214E543@ccvcorp.com>


James.Rocks@equant.com wrote:

> Hi,
>
> Anyone know anything about wxWindows being used with Python?

Take a look at wxpython.org.  Most of wxWindows has been wrapped for
convenient use from Python, and wxPython's creator (Robin Dunn) has also added
a fair number of convenience features that make things even easier.  Don't
forget to check out the wxpython-users mailing list, which tends to be very
helpful.


> I want to use a control on a dialog that allows me to update it at runtime
> (text, colour, font etc.) and i wondered if anyone here knew much about
> this kind of thing ... what I don't want is a box that halts program
> execution i.e. the display must change and the program continue.

This should be fairly simple to do with just about any GUI toolkit, as Alan
mentioned.  It's certainly possible with wxPython.

Jeff Shannon
Technician/Programmer
Credit International




From jeff@ccvcorp.com  Wed Oct 23 14:58:01 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Wed Oct 23 13:58:01 2002
Subject: [Tutor] Activate window
References: <5104D4DBC598D211B5FE0000F8FE7EB2181C7974@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <3DB6E316.6FD8518@ccvcorp.com>


alan.gauld@bt.com wrote:

> However I actually thought the original poster was asking
> how to do it from Python! I think the win32 module and
> visible=1 posted earlier were the correct answers...

I believe that using the visible property of Excel and Word through
win32com will determine whether or not the window is shown or hidden,
but it won't activate the window (make it the foreground window and
give it the focus).  It may be necessary to use Windows Scripting Host
features for that (which are also available through win32com).  Excel
and Word may also have a method to activate themselves, so try
searching through their scripting docs for "Activate".

Jeff Shannon
Technician/Programmer
Credit International




From alan.gauld@bt.com  Wed Oct 23 15:00:03 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed Oct 23 14:00:03 2002
Subject: [Tutor] Interfacing to the web
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9DB@mbtlipnt02.btlabs.bt.co.uk>

Its possible to use DDE to access the Netscape browsers and
they also have a COM model now I believe - but don't know of any published
API...

IE does have a well developed COM interface and you could 
use that from the win32 extensions once you get the 
Windows handle or progIDS for your browser window. 

If you are on *nix then I'm not sure how you'd do it!

Alan G.


From alan.gauld@bt.com  Wed Oct 23 15:03:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed Oct 23 14:03:01 2002
Subject: [Tutor] Interfacing to the web
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9DC@mbtlipnt02.btlabs.bt.co.uk>

The source for Grail still exists although its not supported 
and doesn't work with latest Python versions. However the 
design will mostly still be valid I guess!


Alan G.


From francois.granger@free.fr  Wed Oct 23 15:56:01 2002
From: francois.granger@free.fr (=?iso-8859-1?Q?Fran=E7ois?= Granger)
Date: Wed Oct 23 14:56:01 2002
Subject: [Tutor] Interfacing to the web
In-Reply-To: <003d01c27abf$780486e0$2502a8c0@emily.ewndsr01.nj.comcast.net>
References: <003d01c27abf$780486e0$2502a8c0@emily.ewndsr01.nj.comcast.net>
Message-ID: <a05100306b9dca0970ebd@[192.168.1.11]>

At 14:10 -0400 on 23/10/02, in message Re: [Tutor] Interfacing to the 
web, andy surany wrote:
>
>Yes, it is easy to open the default browser. But I need to have "hooks" into
>the browser to parse the return string(s).

Or do a local proxy server where your script act in between the 
browser (connecting to 127.0.0.1) and the internet. I have seen some 
info on this in Python. I don't know where....


-- 
Le courrier électronique 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://minilien.com/?IXZneLoID0 - 
http://marc.herbert.free.fr/mail/


From SWidney@ci.las-vegas.nv.us  Wed Oct 23 16:54:01 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Wed Oct 23 15:54:01 2002
Subject: [Tutor] Activate window
Message-ID: <0E5508EBA1620743B409A2B8365DE16FDC81FF@sovereign.ci.las-vegas.nv.us>

> > However I actually thought the original poster was asking
> > how to do it from Python! I think the win32 module and
> > visible=1 posted earlier were the correct answers...
> 
> I believe that using the visible property of Excel and Word through
> win32com will determine whether or not the window is shown or hidden,
> but it won't activate the window (make it the foreground window and
> give it the focus).  It may be necessary to use Windows Scripting Host
> features for that (which are also available through win32com).  Excel
> and Word may also have a method to activate themselves, so try
> searching through their scripting docs for "Activate".

For the impatient:

>>> import win32com.client
>>> xl = win32com.client.Dispatch("Excel.Application")
>>> xl.Visible = 1
>>> wd = win32com.client.Dispatch("Word.Application")
>>> wd.Visible = 1
>>> sh = win32com.client.Dispatch("WScript.Shell")
>>> sh.AppActivate(wd)
1
>>> sh.AppActivate(xl)
1
>>>


Enjoy!
Scott


From magnus@thinkware.se  Wed Oct 23 18:21:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Oct 23 17:21:01 2002
Subject: [Tutor] Interfacing to the web
In-Reply-To: <002c01c27ab6$1472ce60$2502a8c0@emily.ewndsr01.nj.comcast.n
 et>
Message-ID: <5.1.0.14.0.20021023225503.02a56a08@www.thinkware.se>

At 13:03 2002-10-23 -0400, andy surany wrote:
>Hi All!
>
>Here is what I need to accomplish:
>
>     From a python program, I need to launch a browser. The user then uses=
=20
> the browser to interact with the web site. However, the python program=20
> must continually monitor the data from the web site to capture specific=20
> data elements.
>
>     Unfortunately, I can't point the program to the specific URL as there=
=20
> is a significant and secure (cookies, etc.) exchange that must occur in=20
> order to reach the page.

I see two reasonable ways to go about this.

One is to use a web proxy that acts as a man-in-the-middle.
I'm not aware of any python proxies though, but maybe it's
possible tobuild plugins for some proxies? Something along
the line of privoxy (www.privoxy.org) or squid
(www.squid-cache.org) might be useful??? See
http://www.squid-cache.org/related-software.html

Another option could be to build a custom web browser.
If you use wxPython, there is a HTML window component
that could be useful. If you are in MS Windows, you
could also plug into Internet Explorer or at least
use parts of it. See the wxPython demo.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From mongo57a@comcast.net  Wed Oct 23 18:44:02 2002
From: mongo57a@comcast.net (andy surany)
Date: Wed Oct 23 17:44:02 2002
Subject: [Tutor] Interfacing to the web
Message-ID: <008201c27ae5$daf6c4e0$2502a8c0@emily.ewndsr01.nj.comcast.net>

=46rom the responses I have received, it sounds like a proxy is the b=
est bet.
However, my application is meant to run on Linux, Windows, and Mac
platforms, so that may rule out some software (it looks like squid is=
 for
linux only????, and privoxy does not allow code extensions).

So I will search for a good proxy. Anyone write a good one????? Or kn=
ow of
one?(given the above caveats...).

TIA
-Andy


-----Original Message-----
=46rom: Magnus Lycka <magnus@thinkware.se>
To: andy surany <mongo57a@comcast.net>; tutor@python.org <tutor@pytho=
n.org>
Date: Wednesday, October 23, 2002 5:20 PM
Subject: Re: [Tutor] Interfacing to the web


At 13:03 2002-10-23 -0400, andy surany wrote:
>Hi All!
>
>Here is what I need to accomplish:
>
>     From a python program, I need to launch a browser. The user the=
n uses
> the browser to interact with the web site. However, the python prog=
ram
> must continually monitor the data from the web site to capture spec=
ific
> data elements.
>
>     Unfortunately, I can't point the program to the specific URL as=
 there
> is a significant and secure (cookies, etc.) exchange that must occu=
r in
> order to reach the page.

I see two reasonable ways to go about this.

One is to use a web proxy that acts as a man-in-the-middle.
I'm not aware of any python proxies though, but maybe it's
possible tobuild plugins for some proxies? Something along
the line of privoxy (www.privoxy.org) or squid
(www.squid-cache.org) might be useful??? See
http://www.squid-cache.org/related-software.html

Another option could be to build a custom web browser.
If you use wxPython, there is a HTML window component
that could be useful. If you are in MS Windows, you
could also plug into Internet Explorer or at least
use parts of it. See the wxPython demo.


--
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se





From magnus@thinkware.se  Wed Oct 23 18:47:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Oct 23 17:47:02 2002
Subject: [tutor] functions and classes
In-Reply-To: <F49mymsnJsWuVvdshEx0001096b@hotmail.com>
Message-ID: <5.1.0.14.0.20021023232814.02a4a600@www.thinkware.se>

At 09:51 2002-10-23 -0600, Dan Dud wrote:
>def compare(x,y): # this is what I think the compare should look like
>    if x < y:
>        print x, "is less then", y
>    elif x > y:
>        print x, "is greater then", y
>    else:
>        print x, "and", y, "are equal"

This obviously works. A shorter version could be:

def compare(x,y):
     print ["%s is less than %s", "%s and %s are equal",
            "%s is greater than %s"][cmp(x,y)+1] % (x,y)

The builtin function cmp(x,y) returns -1, 0 or 1 depending
on whether x < y, x =3D=3D y or x > y.

>def disbatch(choice): # this is what I think the disbatch should look like
>    if choice =3D=3D 'A':
>        functionA()
>    elif choice =3D=3D 'B':
>        functionB()
>    elif choice =3D=3D 'C':
>        functionC()
>    else:
>        print "Invlaid choice"

It looks like this could work as well. Also this could use
the pythonic strength in datatypes instead of an if statement:

def dispatch(choice):
     try:
         {'A': functionA, 'B': functionB, 'C': functionC}[choice]()
     except KeyError:
         print "Invalid choice"

This is the same thing, just shorter.

>the next question is When I define a class do I import these then use them=
=20
>by calling them then define the class or do I do that afterwards
>thanks for the everyone help

You use import when you want to use code in another file a.k.a. module.
Whether you import these or not depends on your choice of program
structure.

Python is a multi-paradigm language just like C++. You don't need to
have classes. It's difficult to say how you should organize your
code when we don't know what you are trying to accomplish. Take one
step at a time, and it will probably work out.

It requires a certain skill to be able to program in very small
steps, and to always have working code that grows line by line.
But it's still a good choice. If you write more than ten lines
of code with your code in a state of flux, you get lost. At least
if you are as confused as I am.



--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Wed Oct 23 19:17:05 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Oct 23 18:17:05 2002
Subject: [Tutor] Interfacing to the web
In-Reply-To: <008201c27ae5$daf6c4e0$2502a8c0@emily.ewndsr01.nj.comcast.n
 et>
Message-ID: <5.1.0.14.0.20021024001742.04335858@www.thinkware.se>

At 18:45 2002-10-23 -0400, andy surany wrote:
> From the responses I have received, it sounds like a proxy is the best=
 bet.
>However, my application is meant to run on Linux, Windows, and Mac
>platforms, so that may rule out some software (it looks like squid is for
>linux only????, and privoxy does not allow code extensions).

But the proxy doesn't have to run on the machine you sit at.
Any machine on the network is fine. The firewall is often a
good choice. :)


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From Gillisai@btinternet.com  Wed Oct 23 20:23:02 2002
From: Gillisai@btinternet.com (Alex Gillis)
Date: Wed Oct 23 19:23:02 2002
Subject: [Tutor] Advanced programmes using Python?
Message-ID: <000001c27ae9$e5aa3120$f6297ad5@oemcomputer>

This is a multi-part message in MIME format.

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

I'm very new to all this and I'm told that you can create any programme =
from just a few basic commands.  I can't quite see it though.  Can you =
convinvce me?  I'm also interested in some sort of animation as output =
eg. a planet orbiting the sun.  How would I go about this, is there a =
special output for this that I don't know?

------=_NextPart_000_0009_01C27A13.C4CAFD80
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 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I'm very new to all this and I'm told =
that you can=20
create any programme from just a few basic commands.&nbsp;&nbsp;I can't =
quite=20
see it though.&nbsp; Can you convinvce me?&nbsp; I'm also interested in =
some=20
sort of animation as output eg.&nbsp;a planet orbiting the sun.&nbsp; =
How=20
would&nbsp;I go about this, is there a special output for this that I =
don't=20
know?</FONT></DIV></BODY></HTML>

------=_NextPart_000_0009_01C27A13.C4CAFD80--



From magnus@thinkware.se  Wed Oct 23 20:31:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Oct 23 19:31:01 2002
Subject: [Tutor] Interfacing to the web
In-Reply-To: <008201c27ae5$daf6c4e0$2502a8c0@emily.ewndsr01.nj.comcast.n
 et>
Message-ID: <5.1.0.14.0.20021024005050.043421f8@www.thinkware.se>

At 18:45 2002-10-23 -0400, andy surany wrote:
> From the responses I have received, it sounds like a proxy is the best=
 bet.

Twisted (version 1.0 just released) might be useful.
http://www.twistedmatrix.com/

apt-proxy v2 uses Twisted. (Ok, that's not a web proxy,
it's a proxy for downloading Debian packages, but Twisted
is AFAIK very useful for for web communication.)


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From rob@uselesspython.com  Wed Oct 23 20:31:14 2002
From: rob@uselesspython.com (Rob)
Date: Wed Oct 23 19:31:14 2002
Subject: [Tutor] Advanced programmes using Python?
In-Reply-To: <000001c27ae9$e5aa3120$f6297ad5@oemcomputer>
Message-ID: <MPEOIFCOPCIHEDCLBLPBGEONCIAA.rob@uselesspython.com>

This is a multi-part message in MIME format.

------=_NextPart_000_0008_01C27AC3.5B7A7A80
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

http://www.vpython.org/

Take a look at Visual Python for some relatively quick & easy animation
examples.

Rob
  -----Original Message-----
  From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
Alex Gillis
  Sent: Tuesday, October 22, 2002 3:41 PM
  To: tutor@python.org
  Subject: [Tutor] Advanced programmes using Python?


  I'm very new to all this and I'm told that you can create any programme
from just a few basic commands.  I can't quite see it though.  Can you
convinvce me?  I'm also interested in some sort of animation as output eg. a
planet orbiting the sun.  How would I go about this, is there a special
output for this that I don't know?

------=_NextPart_000_0008_01C27AC3.5B7A7A80
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 color=3D#0000ff size=3D2><A=20
href=3D"http://www.vpython.org/">http://www.vpython.org/</A></FONT></DIV>=

<DIV><FONT face=3DArial color=3D#0000ff size=3D2></FONT>&nbsp;</DIV>
<DIV><SPAN class=3D567103723-23102002><FONT face=3DArial color=3D#0000ff =
size=3D2>Take a=20
look at Visual Python for some relatively quick &amp; easy animation=20
examples.</FONT></SPAN></DIV>
<DIV><SPAN class=3D567103723-23102002><FONT face=3DArial color=3D#0000ff =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D567103723-23102002><FONT face=3DArial color=3D#0000ff =

size=3D2>Rob</FONT></SPAN></DIV>
<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> =
tutor-admin@python.org=20
  [mailto:tutor-admin@python.org]<B>On Behalf Of </B>Alex =
Gillis<BR><B>Sent:</B>=20
  Tuesday, October 22, 2002 3:41 PM<BR><B>To:</B>=20
  tutor@python.org<BR><B>Subject:</B> [Tutor] Advanced programmes using=20
  Python?<BR><BR></FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>I'm very new to all this and I'm told =
that you=20
  can create any programme from just a few basic commands.&nbsp;&nbsp;I =
can't=20
  quite see it though.&nbsp; Can you convinvce me?&nbsp; I'm also =
interested in=20
  some sort of animation as output eg.&nbsp;a planet orbiting the =
sun.&nbsp; How=20
  would&nbsp;I go about this, is there a special output for this that I =
don't=20
  know?</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0008_01C27AC3.5B7A7A80--




From dyoo@hkn.eecs.berkeley.edu  Wed Oct 23 21:08:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed Oct 23 20:08:01 2002
Subject: [Tutor] Advanced programmes using Python?   [programming like
 lego blocks]
In-Reply-To: <000001c27ae9$e5aa3120$f6297ad5@oemcomputer>
Message-ID: <Pine.LNX.4.44.0210231655500.25031-100000@hkn.eecs.berkeley.edu>


On Tue, 22 Oct 2002, Alex Gillis wrote:

> I'm very new to all this and I'm told that you can create any programme
> from just a few basic commands.  I can't quite see it though.

Neither can we.  *grin*

But it's amazing how programs are a lot like Lego: the pieces themselves
are simple, but can be put together into magnificant and grotesque forms.


Have you had a chance to look at Useless Python yet?  It has a collection
of programs that you can browse through to see how these basic commands
fit together.

    http://uselesspython.com

You might not understand everything yet, but it's good to get a feel for
things.  And the programs there have been written, mostly, by people on
this Tutor mailing list, so you can always ask here about any program on
that site.


So yes, it's weird that there are only a few basic commands, but we
shouldn't be fooled: there's astonishing power in a function call or
import statement.


I hope this helps!



From magnus@thinkware.se  Wed Oct 23 21:37:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Oct 23 20:37:01 2002
Subject: [Tutor] Advanced programmes using Python?
In-Reply-To: <000001c27ae9$e5aa3120$f6297ad5@oemcomputer>
Message-ID: <5.1.0.14.0.20021024013735.04342340@www.thinkware.se>

Hi Alex, wecome to Python and the Tutor list.

At 21:41 2002-10-22 +0100, Alex Gillis wrote:
>I'm very new to all this and I'm told that you can create any programme=20
>from just a few basic commands.  I can't quite see it though.  Can you=20
>convinvce me?'

No. Were not selling anything here. You will have to
convince yourself. One way or the other. :)

What do you mean by "a few basic commands"?

If you mean that it should be possible to write
a program such as a word processor or an astronimical
modeller in a few lines of code. No, that's impossible.
Will never happen. Ever. There might be ready-made
programs that you can adapt very simply. You can make a
simple web server in just a few lines of python code, but
that's because it's basically written for you already.
As soon as you want something really new, you have much
more work to do.

If you mean that you can write those things by repeatedly
using a limited collection of symbols in a clever way,
like you write a book from just 26 letter, 10 digits and
a few more symbols, then yes, you can do that. It depends
a little on how you count and what you mean by few... The
basic vocabulary of python is fairly small and simple. But
there are certainly a lot of different functions in Python.
It comes with about 200 standard modules designed for
different tasks. Each has a number of functions etc.

Python is a programming language. It's maybe 3-10 times
more effective to use than C++. This means that a program
that would take ten man-years in C++ might take one to
three man-years in Python. (If we accept such an absurb
concept as a man-year as a measure of required programming
effort. Men are known to program at very different speed...)

There is no Silver Bullet in software development. With
just a few commands you will make a simple, but maybe
very useful program--if you know what you are doing.

Large programs still take several man-months to produce
if they venture into a new field. Just understanding exactly
what it is we want to achieve, how our program should behave
in all possible situations etc, will take a significant
amount of time. All these things don't go away because you
choose an efficient language. Don't expect too much.

A strength with Python is that has a rich standard library,
and many good, freely available 3rd party libraries. This
means that with a bit of luck, 95% of what you need is
already there, and you can produce a working solution by
gluing things together and adapting them a little. Like the
web server. (But why code a simple web server in python,
there are plenty of web-servers already...)

Knowing where to find what you need and how to use it is
still required though.

What have you tried so-far? Have you installed Python
and worked through the tutorial?

I've collected some quotes of other Python users at
http://www.thinkware.se/cgi-bin/thinki.cgi/PythonQuotes
Maybe that can give you some kind of understanding of
what to expect, but behind "very new to all this" I
expect there is no programming experience at all. I can
well understand that it's difficult to know what to expect
then.

>   I'm also interested in some sort of animation as output eg. a planet=20
> orbiting the sun.  How would I go about this, is there a special output=20
> for this that I don't know?

Maybe you should take a look at some of the existing
Python tools that do things like that? Alice and VPython
comes to my mind... There is a bunch listed at:

http://www.thinkware.se/cgi-bin/thinki.cgi/PythonForImaging

I hope that you will come back with more concrete programming
questions soon. Have fun!

/Magnus


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From nano@intermatik.co.id  Wed Oct 23 22:35:02 2002
From: nano@intermatik.co.id (nano)
Date: Wed Oct 23 21:35:02 2002
Subject: [Tutor] application development
Message-ID: <1035423040.2851.17.camel@jrwd.internal.intermatik.com>

hi everyone,
i'm sure many of you have the experience in developing application for
business process, like accounting, ppic, etc; which need GUI,
network-able, stable and fast enough.
i want to develop such application, and wondering what is the best
development tools for it; or even another language to work with python.
can you help me? maybe you can share your experience.


thanks in advace,

nano'





From magnus@thinkware.se  Wed Oct 23 22:53:00 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Oct 23 21:53:00 2002
Subject: [Tutor] application development
In-Reply-To: <1035423040.2851.17.camel@jrwd.internal.intermatik.com>
Message-ID: <5.1.0.14.0.20021024034729.02a50450@www.thinkware.se>

At 08:29 2002-10-24 +0700, nano wrote:
>hi everyone,
>i'm sure many of you have the experience in developing application for
>business process, like accounting, ppic, etc; which need GUI,

What's ppic?

>network-able, stable and fast enough.
>i want to develop such application, and wondering what is the best
>development tools for it; or even another language to work with python.
>can you help me? maybe you can share your experience.

There are many aspects to consider:

How cost sensitive are you?

What licences are acceptable? GPL will stop you from making
your code proprietary.

What operating system? Windows? Linux? Several?

What's the system complexity?

Might an existing system fit? Perhaps with some
modification? Perhaps you should look at GNU Enterprise
or other systems available at freshmeat.net?

Is this a multi-user system?

Is there legacy systems to consider?

What's the experience of the developer(s)?
Languages? OOP?

Perhaps you should take a look at Twisted, which was
just released in version 1.0 after a long test period.
I hear people are very happy about it. It provides both
networking, database connectivity and other enterprise
aspects. http://www.twistedmatrix.com/


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From nano@intermatik.co.id  Thu Oct 24 06:35:02 2002
From: nano@intermatik.co.id (nano)
Date: Thu Oct 24 05:35:02 2002
Subject: [Tutor] application development
In-Reply-To: <5.1.0.14.0.20021024034729.02a50450@www.thinkware.se>
References: <5.1.0.14.0.20021024034729.02a50450@www.thinkware.se>
Message-ID: <1035451914.2851.468.camel@jrwd.internal.intermatik.com>

Thanks Magnus,

First of all, sorry for reply-ing direct to you, because in these past
several days i cannot receive any mail from tutor-list. i've told it to
Danny, the administrator, and he said that maybe the error comes from my
ISP.

-PPIC =3D Production,Planning and Inventory Control
-we are 'cost-sensitive', i mean that we don't have enough money to buy
license for Delphi, Kylix, etc; maybe it'll ok for a few hundred dollars
-we would like to develop an application that can run in both linux and
windows
-this will be a multi-user system, maybe a multi-level system
administration
-we had experience in Python,C, and OOP, in this short time we've
planned to learn java and jython=20
-i will look at Twisted, as you suggest

Thanks again Magnus, you're very kind!
I look forward for further advice for you.

nano'


On Thu, 2002-10-24 at 08:58, Magnus Lycka wrote:
> At 08:29 2002-10-24 +0700, nano wrote:
> >hi everyone,
> >i'm sure many of you have the experience in developing application for
> >business process, like accounting, ppic, etc; which need GUI,
>=20
> What's ppic?
>=20
> >network-able, stable and fast enough.
> >i want to develop such application, and wondering what is the best
> >development tools for it; or even another language to work with python.
> >can you help me? maybe you can share your experience.
>=20
> There are many aspects to consider:
>=20
> How cost sensitive are you?
>=20
> What licences are acceptable? GPL will stop you from making
> your code proprietary.
>=20
> What operating system? Windows? Linux? Several?
>=20
> What's the system complexity?
>=20
> Might an existing system fit? Perhaps with some
> modification? Perhaps you should look at GNU Enterprise
> or other systems available at freshmeat.net?
>=20
> Is this a multi-user system?
>=20
> Is there legacy systems to consider?
>=20
> What's the experience of the developer(s)?
> Languages? OOP?
>=20
> Perhaps you should take a look at Twisted, which was
> just released in version 1.0 after a long test period.
> I hear people are very happy about it. It provides both
> networking, database connectivity and other enterprise
> aspects. http://www.twistedmatrix.com/
>=20
>=20
> --=20
> Magnus Lyck=E5, Thinkware AB
> =C4lvans v=E4g 99, SE-907 50 UME=C5
> tel: 070-582 80 65, fax: 070-612 80 65
> http://www.thinkware.se/  mailto:magnus@thinkware.se
>=20
>=20




From maillist@kuwest.de  Thu Oct 24 11:51:02 2002
From: maillist@kuwest.de (Jens Kubieziel)
Date: Thu Oct 24 10:51:02 2002
Subject: [Tutor] ASCII and Unicode
Message-ID: <20021024135911.GC1932@kubieziel.de>

Hi, 

I'm trying to get through the Python Tutorial and have some Problems
with Unicode-Strings. It is suggested to use 
     >>>u"äöü"
to print out Unicode-values. IDLE says here
     UnicodeError: ASCII enconding error: ordinal not in range (128)
I'm working with Python 2.1.3 and IDLE 0.8. How can I solve this?
-- 
Jens Kubieziel                                   mailto:jens@kubieziel.de
Jedenfalls ist es besser, ein eckiges Etwas zu sein als ein rundes
 Nichts. Friedrich Hebbel


From francois.granger@free.fr  Thu Oct 24 12:47:01 2002
From: francois.granger@free.fr (Fran=?ISO-8859-1?B?5w==?=ois Granger)
Date: Thu Oct 24 11:47:01 2002
Subject: [Tutor] ASCII and Unicode
In-Reply-To: <20021024135911.GC1932@kubieziel.de>
Message-ID: <B9DDE269.5AC54%francois.granger@free.fr>

on 24/10/02 15:59, Jens Kubieziel at maillist@kuwest.de wrote:

> I'm trying to get through the Python Tutorial and have some Problems
> with Unicode-Strings. It is suggested to use
>>>> u"=E4=F6=FC"
> to print out Unicode-values. IDLE says here
>    UnicodeError: ASCII enconding error: ordinal not in range (128)
> I'm working with Python 2.1.3 and IDLE 0.8. How can I solve this?
Does this help ?

http://www.reportlab.com/i18n/python_unicode_tutorial.html

--=20
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 maillist@kuwest.de  Thu Oct 24 15:38:02 2002
From: maillist@kuwest.de (Jens Kubieziel)
Date: Thu Oct 24 14:38:02 2002
Subject: [Tutor] ASCII and Unicode
In-Reply-To: <B9DDE269.5AC54%francois.granger@free.fr>
References: <20021024135911.GC1932@kubieziel.de> <B9DDE269.5AC54%francois.granger@free.fr>
Message-ID: <20021024183739.GA14054@kubieziel.de>

On Thu, Oct 24, 2002 at 05:46:18PM +0200, François Granger wrote:
> on 24/10/02 15:59, Jens Kubieziel at maillist@kuwest.de wrote:
> 
> > I'm trying to get through the Python Tutorial and have some Problems
> > with Unicode-Strings. It is suggested to use
> >>>> u"äöü"
> > to print out Unicode-values. IDLE says here
> >    UnicodeError: ASCII enconding error: ordinal not in range (128)
> > I'm working with Python 2.1.3 and IDLE 0.8. How can I solve this?
> Does this help ?
> 
> http://www.reportlab.com/i18n/python_unicode_tutorial.html

Nope, not. I does only describe the Win way. I work with a Debian
Linux box.
-- 
Jens Kubieziel                                   mailto:jens@kubieziel.de
Frauen sind wie Übersetzungen: die schönen sind nicht treu, und die
 treuen sind nicht schön. (G.B. Shaw)


From Doug.Shawhan@gecits.ge.com  Thu Oct 24 16:41:03 2002
From: Doug.Shawhan@gecits.ge.com (Doug.Shawhan@gecits.ge.com)
Date: Thu Oct 24 15:41:03 2002
Subject: [Tutor] Binary data in anydbm/pickle/marshal?
Message-ID: <47B6167F8E69D31194BA0008C7918D4205C54E93@msxcvg02itscge.gecits.ge.com>

I have a need to store binary data (specifically images) in a database. Is
it possible to use anydbm, pickle or marshal for this? I have attempted it
with all and have had little joy. (yes I use 'w+b' when opening the files
for reading/writing! :-)

A quick example would be wonderful!

d


From villarsf@bellsouth.net  Thu Oct 24 18:06:01 2002
From: villarsf@bellsouth.net (Frantz Villarson)
Date: Thu Oct 24 17:06:01 2002
Subject: [Tutor] Learning
Message-ID: <000a01c27b03$47294300$4700d6d1@z0p4u0>

This is a multi-part message in MIME format.

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

Looking for ways to learn computer programming, how to programming whit =
Python.Thank.

------=_NextPart_000_0007_01C27AE1.BED8BA60
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 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY style=3D"COLOR: #000000; FONT-FAMILY: " bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Looking for ways to learn computer =
programming, how=20
to programming whit Python.Thank.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0007_01C27AE1.BED8BA60--



From Doug.Shawhan@gecits.ge.com  Thu Oct 24 18:13:01 2002
From: Doug.Shawhan@gecits.ge.com (Doug.Shawhan@gecits.ge.com)
Date: Thu Oct 24 17:13:01 2002
Subject: [Tutor] Learning
Message-ID: <47B6167F8E69D31194BA0008C7918D4205C54E98@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_01C27BA2.02557AB0
Content-Type: text/plain;
	charset="iso-8859-1"

Hi Frantz
 
Try:
 <http://python.org/doc/current/tut/tut.html>
http://python.org/doc/current/tut/tut.html
 
This is a good starting-off point! You can find most of what you need at the
http://www.python.org <http://www.python.org>  website.
 
Good luck!
 

-----Original Message-----
From: Frantz Villarson [mailto:villarsf@bellsouth.net]
Sent: Wednesday, October 23, 2002 9:16 PM
To: tutor@python.org
Subject: [Tutor] Learning


Looking for ways to learn computer programming, how to programming whit
Python.Thank.


------_=_NextPart_001_01C27BA2.02557AB0
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 style="COLOR: #000000; FONT-FAMILY: " bgColor=#ffffff>
<DIV><FONT face=Arial size=2><SPAN class=556011021-24102002>Hi 
Frantz</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=556011021-24102002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=556011021-24102002>Try:</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=556011021-24102002></SPAN></FONT><A 
href="http://python.org/doc/current/tut/tut.html"><FONT face=Arial><FONT 
size=2>http://python.org/doc/current/tut/tut.html</FONT></FONT></A></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><SPAN class=556011021-24102002><FONT face=Arial size=2>This is a good 
starting-off point! You can find most of what you need at the <A 
href="http://www.python.org">http://www.python.org</A> 
website.</FONT></SPAN></DIV>
<DIV><SPAN class=556011021-24102002><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=556011021-24102002><FONT face=Arial size=2>Good 
luck!</FONT></SPAN></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</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> Frantz Villarson 
  [mailto:villarsf@bellsouth.net]<BR><B>Sent:</B> Wednesday, October 23, 2002 
  9:16 PM<BR><B>To:</B> tutor@python.org<BR><B>Subject:</B> [Tutor] 
  Learning<BR><BR></FONT></DIV>
  <DIV><FONT face=Arial size=2>Looking for ways to learn computer programming, 
  how to programming whit Python.Thank.</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------_=_NextPart_001_01C27BA2.02557AB0--


From dyoo@hkn.eecs.berkeley.edu  Thu Oct 24 21:29:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu Oct 24 20:29:01 2002
Subject: [Tutor] Learning
In-Reply-To: <47B6167F8E69D31194BA0008C7918D4205C54E98@msxcvg02itscge.gecits.ge.com>
Message-ID: <Pine.LNX.4.44.0210241723110.14857-100000@hkn.eecs.berkeley.edu>


On Thu, 24 Oct 2002 Doug.Shawhan@gecits.ge.com wrote:

> Hi Frantz
>
> Try:
>  <http://python.org/doc/current/tut/tut.html>
> http://python.org/doc/current/tut/tut.html
>
> This is a good starting-off point!

Depending on Frantz's experience, this answer is actually a bit flexible.


The official tutorial assumes that the person already knows how to program
in a computer language other than Python.  Because it assumes this, it
goes really darn fast.  The official tutorial is great if one comes from a
C or Java background, but I've heard wild curses from other people who
come from an blank-slate sort of situation. *grin*


Frantz, if you haven't programmed before, you may also want to try the
Newcomers page too:

    http://python.org/doc/Newbies.html

It has good resources for the beginning programmer.


I hope this helps!



From scot@possum.in-berlin.de  Fri Oct 25 01:21:01 2002
From: scot@possum.in-berlin.de (Scot W. Stevenson)
Date: Fri Oct 25 00:21:01 2002
Subject: [Tutor] Tkinter and non-ASCII-characters, again
In-Reply-To: <5.1.0.14.0.20021023121158.02a51b40@www.thinkware.se>
References: <5.1.0.14.0.20021023121158.02a51b40@www.thinkware.se>
Message-ID: <200210250008.55547.scot@possum.in-berlin.de>

Hello Magnus, 

> locale.setlocale(locale.LC_ALL, 'de_DE@euro')
> works in a linux machine with python 2.1.2 that
> I just tested.

Doesn't work for me - the problem is that I am feeding part of the string 
input into an "eval()" call, and that doesn't like the Unicode Tkinter is 
feeding back even if is part of a string. I made it work by putting a 

thisstring = thisstring.encode("ISO-8859-1")

around every input the user gives me, but this is _not_ the way things 
should be, I think...

Thank you for the help!
Y, Scot


-- 
   Scot W. Stevenson wrote me on Friday, 25. Oct 2002 in Zepernick, Germany   
       on his happy little Linux system that has been up for 577 hours        
        and has a CPU that is falling asleep at a system load of 0.00.        



From magnus@thinkware.se  Fri Oct 25 08:46:00 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Fri Oct 25 07:46:00 2002
Subject: [Tutor] Did you learn to program with Python???
Message-ID: <5.1.0.14.0.20021025133553.02b11008@www.thinkware.se>

We only learn to program from the very beginning once...
I started learning with BASIC on Apple ][ many years ago.

I was a fairly experienced programmer when I first met
Python. I have this idea that Python is a good language
for beginners, but obviously I can't say that from any
first hand experience.

(I do believe that it was with Python I really learned
how to use objects though...)

Are there any people on this mailing list for whom Python
was the first programming language, or perhaps even better,
not the first they tried, but the first that worked? :)
(Are there any counter examples?)

How did you learn Python?

What resource was most helpful?

Some book?

Some tutorial on the web?

Some mailing list or IRC channel etc?

Some person near you?

Something else?

As experienced programmers, we can look at different
tutorials and form an opinion about their usefulness,
but it's really difficult to see something with the
eyes of a beginner when you have years of python
experience... I mean: I can see if a tutorial is correct,
and in some sense well written, but I can't really see
how helpful it would be for a complete newbie...

Obviously, we're all slightly different... Both in the
way we approach problems and in what previous experience
we have. I don't think there is one way of learning to
program that fits everybody, but real world experiences
would still be interesting.



--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From Michael Montagne <montagne@boora.com>  Fri Oct 25 11:13:20 2002
From: Michael Montagne <montagne@boora.com> (Michael Montagne)
Date: Fri Oct 25 10:13:20 2002
Subject: [Tutor] IDE
Message-ID: <20021025141311.GA2148@boora.com>

OK I admit it, it is much easier to learn when I have my options
displayed to me (ala VB).  What are the best IDEs out there that will
show me available methods for an object?  It seems komodo did it but it
wanted me to have the ActiveState python.   I'd like to use IDLE but it
doesn't seem to have this ability.  Wing is too expensive and BlackAdder is iffy.


-- 
  Michael Montagne  [montagne@boora.com]   503.226.1575 
--    


From rob@uselesspython.com  Fri Oct 25 11:17:01 2002
From: rob@uselesspython.com (Rob)
Date: Fri Oct 25 10:17:01 2002
Subject: [Tutor] Did you learn to program with Python???
In-Reply-To: <5.1.0.14.0.20021025133553.02b11008@www.thinkware.se>
Message-ID: <MPEOIFCOPCIHEDCLBLPBKEAMCJAA.rob@uselesspython.com>

Python was the first language that made any real sense to me, and has given
me the ability to understand other languages better.

The resource that has worked for me, beyond all others, has been this list.
The next most valuable experience for me has been working on the Useless
Python website, which has involved tinkering with a lot of people's code.

So my short answer is the Tutor List and playing with code.

Rob
http://uselesspython.com

> -----Original Message-----

> Are there any people on this mailing list for whom Python
> was the first programming language, or perhaps even better,
> not the first they tried, but the first that worked? :)
> (Are there any counter examples?)
>
> How did you learn Python?
>
> What resource was most helpful?
>




From linux1011@HotPOP.com  Fri Oct 25 11:18:01 2002
From: linux1011@HotPOP.com (David Mccowan)
Date: Fri Oct 25 10:18:01 2002
Subject: [Tutor] Did you learn to program with Python???
In-Reply-To: <5.1.0.14.0.20021025133553.02b11008@www.thinkware.se>
References: <5.1.0.14.0.20021025133553.02b11008@www.thinkware.se>
Message-ID: <20021025083307.43d643ea.linux1011@HotPOP.com>

On Fri, 25 Oct 2002 13:51:42 +0200
Magnus Lycka <magnus@thinkware.se> wrote:

I fist did some very minor programming in basic, when I was in the
6th/7th grade.  I did not like it, and after that I really stoped.

Then, in my senior year in high school my girlfreind talked me in to
taking an APCS class, and at that time the test was on C++ (I think it
is based on java now).  I did extreemly well in that considering the
theacher and the enviorenement most likely due to my ability to seek
outside source for information, and my ability to stand very bad
documentation.  But I never like C++.

Then during spring break I discovered python and wrote a 3d Tic Tac Toe
program that week.  And that was with just using the tutorial for
documentation.

Then in college I discovered lisp, and scheme, and even though I like
lisp better, do to time contraints, and the difference in
lisp based languages compared with c style programs, python is still the
only language I have ever solved any majorly complexed tasks in.

I still do a significant amount of programming in python.  As far as
documentation is concerned, the standard documentation that comes with
python is the best I have seen as far as languages are concerned (I am
comparing this to my experience with Java, C++, Perl, Scheme, Lisp, and
C, your experience my be different). The documentation is so good, that
I will most likely never by a python book except for the only one I have
now (Python and Tkinter Programming, which documentation was seriously
lacking when I started programming in Python).

In relation to objects, I really did not understand the significance of
abstraction until I sudied lisp.  But I can say that implementing
classes and objects in python is really easy.

My only complaint is that python does not support recursion very well,
although I am comparing this with lisp which is designed to do recursion
very well.  Despite the fact that I seem to think recursively, this is
not a major issure becuase I can easy implement recursive like systems
with loops.


> We only learn to program from the very beginning once...
> I started learning with BASIC on Apple ][ many years ago.
> 
> I was a fairly experienced programmer when I first met
> Python. I have this idea that Python is a good language
> for beginners, but obviously I can't say that from any
> first hand experience.
> 
> (I do believe that it was with Python I really learned
> how to use objects though...)
> 
> Are there any people on this mailing list for whom Python
> was the first programming language, or perhaps even better,
> not the first they tried, but the first that worked? :)
> (Are there any counter examples?)
> 
> How did you learn Python?
> 
> What resource was most helpful?
> 
> Some book?
> 
> Some tutorial on the web?
> 
> Some mailing list or IRC channel etc?
> 
> Some person near you?
> 
> Something else?
> 
> As experienced programmers, we can look at different
> tutorials and form an opinion about their usefulness,
> but it's really difficult to see something with the
> eyes of a beginner when you have years of python
> experience... I mean: I can see if a tutorial is correct,
> and in some sense well written, but I can't really see
> how helpful it would be for a complete newbie...
> 
> Obviously, we're all slightly different... Both in the
> way we approach problems and in what previous experience
> we have. I don't think there is one way of learning to
> program that fits everybody, but real world experiences
> would still be interesting.
> 
> 
> 
> -- 
> Magnus Lyckå, Thinkware AB
> Älvans väg 99, SE-907 50 UMEÅ
> tel: 070-582 80 65, fax: 070-612 80 65
> http://www.thinkware.se/  mailto:magnus@thinkware.se
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From csmith@blakeschool.org  Fri Oct 25 14:02:08 2002
From: csmith@blakeschool.org (Christopher Smith)
Date: Fri Oct 25 13:02:08 2002
Subject: [Tutor] symbolic algebra; Jython
Message-ID: <fc.004c4b6b00abf010004c4b6b00abf010.abf1f2@blakeschool.org>

This is a followup to the August 2001 discussion about symbolic algebra 
systems.

I found such a system that is more advanced than Pythonica...but it's
written in java.  But...I just completed an installation and successful 
test of Jython, a program which feels like Python but allows you to 
access java classes as if they were just another python module.  
Specifically, I did a test of the symbolic algebra manipulation system.

After binding the Jython-21.jar with the option set to get stdin from
the Message Window (and otherwise typing in everything as specified at
http://www.jython.org/MacOS_Install.html) I was able to create a
working Jython application.

I put the symbolic folder in the same folder as the newly created
Jython application and then successfully ran through the small test
suite found in mathtest.java which is part of the symbolic algebra
system download:

####

Jython 2.1 on java1.1.8 (JIT: MRJ22Jitc.01) Type "copyright", "credits"
or "license" for more information.
>>> from symbolic import * m=Math_interpreter() #create an instance of
>>> the manipulator m.calculate("DIFF(SINH(x^2),x)") #derivative of
>>> sinh(x^2) wrt x
'(((2*x)*exp(x^2))+((exp(-x^2)*x)*2))/2'
>>> m.setOutputMode(Math_interpreter.TEX_OUTPUT) m.getLastResult()
'\\frac{{{{2}{x}}{exp\\left({{x}^{2}}\\right)}}+{{{exp\\left({-{x}^{2}}
\\right)}{x}}{2}}}{2}'
>>> m.setOutputMode(Math_interpreter.INFIX_OUTPUT)
>>> m.calculate("INT(x^2*SIN(x),x)")
'(2*((sin(x)*x)+cos(x)))-(x^2*cos(x))'
>>> m.setOutputMode(Math_interpreter.STRUCTURED_OUTPUT)
>>> m.getLastResult()
'                         2        \n2 (sin(x) x + cos(x)) - x  cos(x)
\n'
>>> print _ #let's see it printed not repr'ed
2 2 (sin(x) x + cos(x)) - x  cos(x)

>>> 

####

A demo of a java applet online which allows you to manipulate algebraic
expressions is located along with the reference page at
http://www.mb.hs-wismar.de/Mitarbeiter/Pawletta/00Uwe/formel.html.

The symbolic folder of classes can be downloaded from
http://www.mb.hs-wismar.de/Mitarbeiter/Pawletta/00Uwe/symjpack.tar.gz
(a quick download at only 36 K).

Jython and directions for the MacOS installation are at
http://www.jython.org/MacOS_Install.html; the Jython home, from where
versions for other systems can be downloaded is at
http://www.jython.org/index.html.


/c



From dyoo@hkn.eecs.berkeley.edu  Fri Oct 25 15:52:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri Oct 25 14:52:01 2002
Subject: [Tutor] IDE
In-Reply-To: <20021025141311.GA2148@boora.com>
Message-ID: <Pine.LNX.4.44.0210251136580.22702-100000@hkn.eecs.berkeley.edu>


On Fri, 25 Oct 2002, Michael Montagne wrote:

> OK I admit it, it is much easier to learn when I have my options
> displayed to me (ala VB).  What are the best IDEs out there that will
> show me available methods for an object?  It seems komodo did it but it
> wanted me to have the ActiveState python.  I'd like to use IDLE but it
> doesn't seem to have this ability.  Wing is too expensive and BlackAdder
> is iffy.

Hi Michael,


Let's see... there's a link to many text editors from Python's wiki-wiki
page:

    http://www.python.org/cgi-bin/moinmoin/PythonEditors

Too... many... choices!  *grin*



But have you looked at Scintilla's SciTE editor?

    http://www.scintilla.org/SciTE.html

It appears to do what you're looking for, and it has a pretty good
following; I've heard it recommended on Tutor several times.

    http://aspn.activestate.com/ASPN/search?query=scite
         &list_name=python-Tutor&type=Archive_python-Tutor_list&start=20



I believe that it's the text editor that's used in the PyCrust project:

    http://www.onlamp.com/pub/a/python/2002/07/18/pycrust.html

and I've heard some really good stuff about PyCrust lately; it's worth a
look.


Good luck to you!



From Doug.Shawhan@gecits.ge.com  Fri Oct 25 16:02:01 2002
From: Doug.Shawhan@gecits.ge.com (Doug.Shawhan@gecits.ge.com)
Date: Fri Oct 25 15:02:01 2002
Subject: [Tutor] IDE
Message-ID: <47B6167F8E69D31194BA0008C7918D4205C54EA3@msxcvg02itscge.gecits.ge.com>

>But have you looked at Scintilla's SciTE editor?
>
>    http://www.scintilla.org/SciTE.html


I cannot reccomend SciTE enough. One can turn on command completion, .etc
with little effort (the config file is well-commented). I find that it's
runtime-window-next-to-the-editor method is much more intuitive than the
"Visual ***"-type IDE's like wing and komodo. 

Very simple and stable. I generally open an IDLE window to try code snippets
in, then paste them into SciTE and run the script from there.

d


From dlphone@bellsouth.net  Fri Oct 25 16:07:03 2002
From: dlphone@bellsouth.net (dlphone@bellsouth.net)
Date: Fri Oct 25 15:07:03 2002
Subject: [Tutor] Did you learn to program with Python???
Message-ID: <20021025190808.DSVA1252.imf21bis.bellsouth.net@[192.168.1.31]>

Magnus -

This is perhaps the ONLY Python question I am qualified to answer. 

I am learning Python now, having started a few weeks ago. I attempted to learn 
C++ on my own (with a massive Borland C++ compiler I found used, and a "Teach 
Yourself C++ in 24 Hours" book.) I was overwhelmed by pointers and a new job, 
so I stopped.

Then recently I read "The Cathedral and the Bazaar" and learned about open-
source development and Python. I decided to try again to learn programming, 
this time with Python. 

I tested a few beginner books. The most useful for me to start was Josh 
Cogliati's excellent Non-Programmer's Tutorial for Python. It includes many 
small examples and great explanations, which gave me the structure & immediate 
feedback I needed. I think I am at the newbie crawling stage now, so I am 
learning by writing little programs for work - like the projects OODB - and 
learning games for my 5-year old son. To do this I consult Chris Fehily's 
Python Visual Quickstart Guide primarily. 
And of course the tutor@python.org list allows me to tap the minds of Python 
experts and others, which has been very helpful.

The 'official' Python tutorial has been very helpful too. 

As I'm trying to learn this in my spare time (isn't everyone?), I seek the 
structure of a tutorial to keep me on track.

Dave


> 
> Message: 7
> Date: Fri, 25 Oct 2002 13:51:42 +0200
> To: tutor@python.org
> From: Magnus Lycka <magnus@thinkware.se>
> Subject: [Tutor] Did you learn to program with Python???
> 
> 
> Are there any people on this mailing list for whom Python
> was the first programming language, or perhaps even better,
> not the first they tried, but the first that worked? :)
> (Are there any counter examples?)
> 
> How did you learn Python?
> 
> What resource was most helpful?
> 
> Some book?
> 
> Some tutorial on the web?
> 
> Some mailing list or IRC channel etc?
> 
> Some person near you?
> 
> Something else?
> 




From James.Alexander.McCarney@Cognicase.com  Fri Oct 25 16:24:02 2002
From: James.Alexander.McCarney@Cognicase.com (McCarney, James Alexander)
Date: Fri Oct 25 15:24:02 2002
Subject: [Tutor] Did you learn to program with Python???
Message-ID: <23FD7B1A77E8D211BCB900001D108C02023FCA8C@camelot>

Hey, a question I can handle!

> >>Are there any people on this mailing list for whom Python
> >>was the first programming language, or perhaps even better,
> >>not the first they tried, but the first that worked? :)

Yes to that--the first that worked the way I wanted it to, anyway. 


> >>How did you learn Python?

The tuts, particularly Alan's; the O'Reilly book--but it's a trifle tough
sledding if you don't know why to use the different kinds of collections;
puzzling through the code; asking questions of the tut list.

> >>
> >>What resource was most helpful?

The tut list.

> >>Something else?

Lots of chocolate and Coca-Cola ;-)




From dmurtagh@starband.net  Fri Oct 25 19:57:01 2002
From: dmurtagh@starband.net (dmurtagh)
Date: Fri Oct 25 18:57:01 2002
Subject: FW: [Tutor] Did you learn to program with Python???
Message-ID: <000001c27c79$b1bf3360$bfd93f94@computer>

Sorry Magnus ... did it again, except this time I sent this second reply
directly to your admin instead of the list ... Hopefully I've got it
right this time ... third time's a charm? LOL
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>


Hello folks! So far I've just been watching this list but feel it is
time to jump in. I am a first time programmer, just starting to learn
python. The only other language I sort of grasp is iptscrae (if ya don't
know, don't ask LOL).

I've joined this group in hopes of picking your brains as what I am
about to do with python may not have been done as yet. I am into a NEW
graphical chat and the chosen scripts for that will be made using
python. I need to learn python well enough to create these scripts using
older iptscrae scripts as a guide.=20

I hope I am not confusing you on this ... I may be and if so I do
apologize. My point of posting today is to answer the original post, to
introduce myself and to get settled in. I have answered your questions
below.=20

Thanks ...=20

Deb {python ssssscripter wannabee}



-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org] On Behalf
Of Magnus Lycka
Sent: Friday, October 25, 2002 5:52 AM
To: tutor@python.org
Subject: [Tutor] Did you learn to program with Python???


We only learn to program from the very beginning once...
I started learning with BASIC on Apple ][ many years ago.

I was a fairly experienced programmer when I first met
Python. I have this idea that Python is a good language
for beginners, but obviously I can't say that from any
first hand experience.

(I do believe that it was with Python I really learned
how to use objects though...)

Are there any people on this mailing list for whom Python
was the first programming language, or perhaps even better,
not the first they tried, but the first that worked? :)
(Are there any counter examples?)

How did you learn Python? Just recently d/l it, starting to learn it
now.

What resource was most helpful? Python.org!

Some book? I avoid books LOL

Some tutorial on the web? Baldwin's tutorial was nice, as were others.

Some mailing list or IRC channel etc? You so far are the only mailing
list.=20

Some person near you? No one near me, although I have created a yahoo
egroup for folks that want to learn python for the purposes I do, which
is to apply the scripts in graphical chat room.

Something else? If you think python has gone places so far, wait til you
see what WE have in mind for it!=20


As experienced programmers, we can look at different
tutorials and form an opinion about their usefulness,
but it's really difficult to see something with the
eyes of a beginner when you have years of python
experience... I mean: I can see if a tutorial is correct,
and in some sense well written, but I can't really see
how helpful it would be for a complete newbie...

Obviously, we're all slightly different... Both in the
way we approach problems and in what previous experience
we have. I don't think there is one way of learning to
program that fits everybody, but real world experiences
would still be interesting.



--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor





From Jmllr891@cs.com  Fri Oct 25 21:21:00 2002
From: Jmllr891@cs.com (Jmllr891@cs.com)
Date: Fri Oct 25 20:21:00 2002
Subject: [Tutor] Binding Keys to Events?
Message-ID: <2f.2ee7cd56.2aeb3991@cs.com>

--part1_2f.2ee7cd56.2aeb3991_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

I was wondering if it's possible to bind certain keys (such as the return or 
escape keys) to other events or functions. I know how do bind key presses to 
events and functions in Tk, but is there any way to do this without using Tk?

--part1_2f.2ee7cd56.2aeb3991_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 was wondering if it's possible to bind certain keys (such as the return or escape keys) to other events or functions. I know how do bind key presses to events and functions in Tk, but is there any way to do this without using Tk?</FONT></HTML>

--part1_2f.2ee7cd56.2aeb3991_boundary--


From ajs@ix.netcom.com  Sat Oct 26 09:58:02 2002
From: ajs@ix.netcom.com (Arthur)
Date: Sat Oct 26 08:58:02 2002
Subject: [Tutor] Did you learn to program with Python???
Message-ID: <003c01c27cee$d1767fe0$9865fea9@arthur>

>Are there any people on this mailing list for whom Python was the first
programming language, or perhaps even better,
>not the first they tried, but the first that worked? :)

Yes..

I had tried Java first. Gave up.  But I did learn some things in that effort
that eventually came into play in learning to program with Python.  And
after getting the concepts of OOP under my belt through Python went back to
Java, which I was then in a position to handle.  And then came back to
Python, because it was simply a lot more fun.

>How did you learn Python?

Time and work.  There were specific reasons I wanted to learn to program (I
am about 45 years old when I get this notion). Most had to do with having
become fascinated with 3d graphics - things like Povray.  I wanted to
understand what made them tick.  But I had a lot else to learn other than
programming - matrice algebra and geometry, for example.  So I just set out
to kill a number of birds with one stone - developed a concept for a program
that would help me learn the geometry, and put to use the algebra and
programming skills I developed, as I was able to develop them.

Lots of experimentation at the command line, before "committing" things to
the program I was trying to write.

And I got hooked, real bad.  Enormous learning experience.

But I think the thing to understand is the fact that it consumed a good deal
of my free time, was hard work and frustrating at times.

I think we can make a mistake by emphasizing how "easy" Python is.  It is a
full-featured, multi-paradigm programming language.  I would call it
"friendly", without hesitation.  But I think folks coming to it with the
idea that it is "easy" will go away frustrated.

>What resource was most helpful?

The command line together with the standard tutorial.

And since my project used Numeric, I relied heavily on the Numeric docs and
tutorial.  A lot of the math was new to me and in some ways harder for me to
absorb than the programming concepts - so a lot of my book budget went to
math and geometry books rather than programming books.

Another thing I found *enormously* helpful - taking advantage of Open Source
resources.  There was a lot of great graphics related Open Source resources
out there - in all kinds of languages - C, C++, Java, etc.  I found it
enormously helpful to simply try to translate code from another language
into Python.  Helped me understand something about programming languages in
general, and limited the problem domain.  Someone else had already done the
hard work of making this particular tick-tock.  My problem was limited to
one of understanding that code well enough to be able to translate it into
Python, and Python well enough to understand how to do that.

>Some person near you?

No. But periodically I have been near desperate to find someone to hold my
hand a bit.  In the end I might well end up paying a Python consultant to
critique my code and steering a course for me as to some of the issues with
which I still need to contend - documentation, cross-platform distribution
issues, a GUI with a more professional look and feel, etc, and etc.  Things
professions have *much* more expereince with than I.

Nonetheless, I am quite proud of how far I have gotten, as a lone hacker.

Art





From kp87@lycos.com  Sat Oct 26 10:39:01 2002
From: kp87@lycos.com (kevin parks)
Date: Sat Oct 26 09:39:01 2002
Subject: [Tutor] Re: chill monkey!
Message-ID: <OOEICGLGELADDBAA@mailcity.com>

> This message is in MIME format.

Ughh!


------_=_NextPart_001_01C27BA2.02557AB0
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">


More ughh!


THIS LIST EXISTS IN A DIGEST FORM AS WELL. TO ALL OF YOU
WHO JUST GOT YOUR COMPUTER YESTERDAY OR WHO USUALLY
DON'T GIVE A RAT'S BEHIND ABOUT OTHERS, PLEASE JUST
SEND YOUR QUERIES AS PLAIN TEXT TO THE LIST.

I will never understand in a million years why folks who
are smart enough to choose and use python seem to have
not even the slightest clue how to use thier mail programs.

Also, Don't quote the whole darned post (or worse 
the whole digest) either.

People who do this things are only a smidge better than
child molesters, politicians, and spammers in my book.

I love to read this list, but it has become almost
unreadable due to the amount of folks who simply refuse
to set their mail programs right and are too lazy to erase
unnecessary quoting.

I really wish that folks who excessively quote or send
anything but plain texts to the list would have their
messages rejected. Impossible i know, but a dream.
What if folks all simply refused to answer anyone who
send HTML mail to the list? Maybe that would work.

Happy Happy Happy

-kp--

PS. i know that this message will make little or no difference, but to hell with it, it really gets on my nerves. If some fool can quote the whole digest
over and over and over and the attach some HTML mail
to boot, well then, you(s) can all put up with me 
shovelling some crap 'gainst the tide.




____________________________________________________________
Get 250 full-color business cards FREE right now!
http://businesscards.lycos.com 


From op73418@mail.telepac.pt  Sat Oct 26 11:14:01 2002
From: op73418@mail.telepac.pt (=?iso-8859-1?Q?Gon=E7alo_Rodrigues?=)
Date: Sat Oct 26 10:14:01 2002
Subject: [Tutor] Did you learn to program with Python???
References: <5.1.0.14.0.20021025133553.02b11008@www.thinkware.se>
Message-ID: <001801c27cfa$a5bf6f90$0b130dd5@violante>

From: "Magnus Lycka" <magnus@thinkware.se>

>Are there any people on this mailing list for whom Python
>was the first programming language, or perhaps even better,
>not the first they tried, but the first that worked? :)
>(Are there any counter examples?)

I am not a professional programmer and in what I do (mathematics) I hardly
program at all - unless you call LaTeX programming.

Still, I was always fascinated with programming and programming languages. I
started learning with BASIC in a ZX Spectrum 48K (Ah, those were the
days...) at a tender age, and from then on I "learned" C, Pascal,
Mathematica, Java. Now, I wrote learned between "" because even though I
knew the principles and the rules of the game I never actually played it,
that is, I never have actually done anything useful (if you leave out the
assignments when I was an undergraduate - in Pascal or Mathematica). This is
certainly due to my temperament (lack of self-discipline, patience, ...)
but, with what I know today, this is also due to the hurdles that the use of
those languages posed. There was always a lot of detail that you had to pay
attention to, that sidetracked you from the main issue, just to get simple
things working. The result was almost inevitably frustration - I would soak,
throw the toy away and turn my attention somewhere else.

And then came Python. I first heard about Python in a forum about MUDs. I
like MUDs a lot, but one of the things I like most is that you can program
little scripts to automate things away and generally just make your mudding
life easier - hell, you can even program entire bots to do the mudding for
you! Anyway, MUD clients usually come with their own special-purpose
language (usually a TinTin clone) which I was finding progressively
difficult to use. The problems I wanted to solve were progressively more
difficult, and the scripting language was just not powerful enough to tackle
them. So I thought of learning yet another language, and in some
distant-chimaerical future use it in mudding.

And what I can say is that Python was/is the first language that worked,
that is, with which I did something useful and not totally trivial. Besides
numberless little utilities to manage my windoze system, some recipes in
ActiveState's cookbook, I have done a special-purpose accounting program for
my own personal use connecting to Excel via COM and with a wxPython Gui on
top, and a small semi-professional app connecting to a Jet database, also
via COM, to do data laundering. So much so, that I have embarked on a more
serious personal project. And, let me stress this again, all this was done
in the little spare time I can afford - and no, I am not a workaholic or
even a fast worker by any standards, although I do suffer from insomnias.

The reason? Well, I think the main reason is that Python, and I am quoting
someone else whose name I can't remember, just gets out of your way. The
amount of cruft is kept to a minimum so that the bare essentials can come
out - having fun programming! Uniformity, regularity and elegance are the
other qualities that I would name.

>How did you learn Python?

>What resource was most helpful?

I basically grabbed everything available on the Net and, usually in insomnia
nights, studied it.

>Some book?

I have four Python books on my shelf, all very good. But it was the second
one I bought, M. Lutz's Programming Python, from where I learned the most.
It was very important to me, because it helped me to understand some
higher-level design issues.

>Some tutorial on the web?

>Some mailing list or IRC channel etc?

comp.lang.py has also been invaluable in this respect. The average quality
of the posts, the speed and knowledge and <insert here your favourite
characteristic>
with which my questions were answered has been a very strong reason for
keeping my interest in programming alive.

With my best regards (and with my appologies for the excessive verbosity),
Gonçalo Rodrigues



From magnus@thinkware.se  Sat Oct 26 11:34:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat Oct 26 10:34:01 2002
Subject: [Tutor] Did you learn to program with Python???
In-Reply-To: <003c01c27cee$d1767fe0$9865fea9@arthur>
Message-ID: <5.1.0.14.0.20021026162813.042b7a38@www.thinkware.se>

At 08:54 2002-10-26 -0400, Arthur wrote:
>I think we can make a mistake by emphasizing how "easy" Python is.  It is a
>full-featured, multi-paradigm programming language.  I would call it
>"friendly", without hesitation.  But I think folks coming to it with the
>idea that it is "easy" will go away frustrated.

Right. I guess Python is easy, but understanding the
concepts of programming isn't so easy. In other words,
python is easy to learn for people who already know how
to program, and perhaps easier than other options for
those who don't...

I'm very enthusiastic about Python, but I do get a bit
hesitant when I hear people claim things like ten-fold
productivity improvements. I think it's generally better
to understate slightly than to overstate things grossly.

   [Python is] "the most efficient language I've ever used.
   It's 10 times better than any of the other tools I have
   used. It's free, it's object-oriented, it adapts to
   everything, it runs on everything. There is almost an
   indescribable, 'quality without a name' attraction on my
   part".
      --Bruce Eckel in Dr Dobbs Journal.

For instance, my current customer had read this (I think),
and while he is fairly happy with our development, I think
he has slightly high expectations on Python, trying to do
advanced development himself, without having any significant
programming experience.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From rlegge@tc3net.com  Sat Oct 26 13:06:01 2002
From: rlegge@tc3net.com (Ray Leggett)
Date: Sat Oct 26 12:06:01 2002
Subject: [Tutor] msgbox: phantom library?
Message-ID: <200210261204.26948.rlegge@tc3net.com>

Ok, this is really puzzling me.  Based on some code i found on the web, i=
=20
wrote a quick python app that would check my email and pop up a message b=
ox=20
if i had any.  Thats not the puzzling part.  The puzzling part is, i used=
 the=20
'msgbox' library in my app, as in:

import msgbox

at the top of my code.  I wanted to take a look at msgbox to see what oth=
er=20
useful functions there are...but I can't find the dang thing on my system=
=2E  I=20
looked in /usr/lib/python, i did find /usr/lib/python -name msgbox.  I op=
ened=20
up a python console and did "import msgbox" and it told me their is no mo=
dule=20
named msgbox.  I looked at the docs at python.org and theres no mention o=
f a=20
msgbox library in the modules reference.  What is going on?  Oh yeah, the=
 app=20
works just fine with the phantom library.

Ray


From rlegge@tc3net.com  Sat Oct 26 13:39:02 2002
From: rlegge@tc3net.com (Ray Leggett)
Date: Sat Oct 26 12:39:02 2002
Subject: [Tutor] oops :) nm
Message-ID: <200210261237.53795.rlegge@tc3net.com>

Ok, nevermind my previous message.  I learned something really useful abo=
ut=20
python...it doesn't just check /usr/lib/python for modules. :)


From dyoo@hkn.eecs.berkeley.edu  Sat Oct 26 16:14:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat Oct 26 15:14:01 2002
Subject: [Tutor] Re: chill monkey!  [How to turn off MIME email]
In-Reply-To: <OOEICGLGELADDBAA@mailcity.com>
Message-ID: <Pine.LNX.4.44.0210261159470.19551-100000@hkn.eecs.berkeley.edu>


> I love to read this list, but it has become almost unreadable due to the
> amount of folks who simply refuse to set their mail programs right and
> are too lazy to erase unnecessary quoting.

Hi Kevin,

I don't think it's laziness by choice --- rather, I think it's simply the
lack of awareness about how inconvenient it is to get HTML email.


Everyone, there's a great web site that explains how to set up your email
programs so that they do plain text instead:

    http://expita.com/nomime.html

That page contains step-by-step instructions for turning on plain-text
mode for the major email programs.  If you're running anything like Eudora
or Outlook, it would be great to double check and make sure that things
are set to plain text.

This makes it easier for other people on the list to read your Python
questions.  Since plain-text is often significantly smaller, switching
over will also help make it easier for digested Tutor members to download
their daily Tutor messages.


I hope this helps!



From dyoo@hkn.eecs.berkeley.edu  Sat Oct 26 16:19:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat Oct 26 15:19:01 2002
Subject: [Tutor] oops :) nm   [where do modules go?]
In-Reply-To: <200210261237.53795.rlegge@tc3net.com>
Message-ID: <Pine.LNX.4.44.0210261215440.19551-100000@hkn.eecs.berkeley.edu>


On Sat, 26 Oct 2002, Ray Leggett wrote:

> Ok, nevermind my previous message.  I learned something really useful
> about python...it doesn't just check /usr/lib/python for modules. :)

Hmmm!  Just out of curiosity, can you tell us where you found it?  I
haven't heard of the msgbox module myself, and can't find it in the
standard library either.

Best of wishes!



From magnus@thinkware.se  Sat Oct 26 17:16:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sat Oct 26 16:16:01 2002
Subject: [Tutor] Re: chill monkey!  [How to turn off MIME email]
In-Reply-To: <Pine.LNX.4.44.0210261159470.19551-100000@hkn.eecs.berkeley
 .edu>
References: <OOEICGLGELADDBAA@mailcity.com>
Message-ID: <5.1.0.14.0.20021026214213.042b70a0@www.thinkware.se>

At 12:11 2002-10-26 -0700, kevin parks wrote:
 > I love to read this list, but it has become almost unreadable due to the
 > amount of folks who simply refuse to set their mail programs right and
 > are too lazy to erase unnecessary quoting.

I don't think this list is worse than others that I read. (I
do use a mail client that won't show HTML mail as junk though...)

I do think that it could be better though, here as well as in other
lists. Please follow Danny Yoo's advice on disabling HTML in email,
and please take the time to read http://www.dtcc.edu/cs/rfc1855.html
At least sections 2.1.1, 3.1.1 and 3.1.2. It will make your presence
on the list (and elsewhere) much more appreciated, and that will be
to your own benefit.

I can understand that people don't quite understand the technical
aspects of their email programs, but the excessive quoting is worse.
I don't know if people just don't think, or if they actually think
that the mailing list subscribers prefer to receive the same texts
over and over again.

Please don't include more of previous mails in replies than
needed to make the context of the reply clear. It's NOT A SERVICE
to receive the same message over and over. If people have thrown
away the original question, they were probably not interested, and
if they change their mind, they can check the archives on the web.

If people ask questions or post replies on this list, it should
be because they want help, or because they want to be helpful. In
either case it's important to think through how the message they
send will be received.


-- 
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 emile@fenx.com  Sun Oct 27 09:47:02 2002
From: emile@fenx.com (Emile van Sebille)
Date: Sun Oct 27 09:47:02 2002
Subject: [Tutor] Re: Did you learn to program with Python???
References: <003c01c27cee$d1767fe0$9865fea9@arthur> <5.1.0.14.0.20021026162813.042b7a38@www.thinkware.se>
Message-ID: <apgu4b$47t$1@main.gmane.org>

Magnus:
> For instance, my current customer had read this (I think),
> and while he is fairly happy with our development, I think
> he has slightly high expectations on Python, trying to do
> advanced development himself, without having any significant
> programming experience.

Aahhh.. CP4E in action.  ;-)


--

Emile van Sebille
emile@fenx.com

---------





From kyle@sent.com  Sun Oct 27 11:21:02 2002
From: kyle@sent.com (Kyle Babich)
Date: Sun Oct 27 11:21:02 2002
Subject: [Tutor] Sounds
Message-ID: <000501c27dd4$b326d300$f94795ac@chuck>

Dumb question, how do I play a sound (wav, wma, or mp3) or display an image
(gif, bmp, jpg, jpeg)  from the command line?

Thank you,
Kyle Babich



From magnus@thinkware.se  Sun Oct 27 12:07:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Sun Oct 27 12:07:01 2002
Subject: [Tutor] Re: Did you learn to program with Python???
In-Reply-To: <apgu4b$47t$1@main.gmane.org>
References: <003c01c27cee$d1767fe0$9865fea9@arthur>
 <5.1.0.14.0.20021026162813.042b7a38@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021027162511.02ab8f48@www.thinkware.se>

At 06:45 2002-10-27 -0800, Emile van Sebille wrote:
>Magnus:
> > For instance, my current customer had read this (I think),
> > and while he is fairly happy with our development, I think
> > he has slightly high expectations on Python, trying to do
> > advanced development himself, without having any significant
> > programming experience.
>
>Aahhh.. CP4E in action.  ;-)

He he...

I think it's a very worthy goal to make Python available
for non-programmers as a useful tool. Just as it should be
possible to write letters without being a Pulitzer prize
class author, and just as it should be possible to fix
small problems in your car without being a professional
mechanic with a first rate workshop, it's reasonable that
a tool like Python could be one of the tools they use in
their computer, along with Excel, a web browser and
whatever...

My wife cuts my son's hair, but wouldn't propose to
cut mine. My sister cuts mine, but would certainly not
offer fix the hair for a bride before a wedding. I just
repaired the zipper in a laundry bag, but I know my
limitations as a tailor... Most people are capable of
performing limited tasks in all sorts of fields, but it
helps if we know our limitations.

Programming and computers is still fairly new areas. I
imagine it took decades before people really understood
how to commincate effectively on the phone, and I think
you have heard about the chaos Orson Welles cause with
his radio play based on H.G. Wells "The War of the Worlds".
Today, people do't react like that.

I certainly remember the boost of home computers in the
early 80's, when everybody was supposed to learn BASIC and
housewives should write programs to store their recipes.
That was silly, and today people certainly know that being
a computer user and being a programmer is not the same thing.
(But really, the big difference is that such a plethora of
ready made programs are widely available at a very low cost
today. Then you needed to program to get anything useful out
of your C-64 or whatever.)

As a professional programmer, I sometimes notice that management
people think that they can swap professional compentence for a
tool or a process. This would save money I guess. Sure, competence
requirements change. You don't need electronic engineers and
scientists in white coats to create an advanced IT system today.
As programs gets easier to work with, less knowledge of hardware
is needed (even though it always helps). People can be useful in
creating software without knowing machine language or how processors
work internally.

But people still need to understand a lot about problem solving,
algorithms and how systems works from a mathematical and physical
point of view to be able to create working complex systems--software
based or not. Since people adapt, react and break rules when they
have to do that, a people-based system might work despite a poor
design. For software this is not true, and it won't be for a long
time. Maybe self-improving and self-repairing software will evolve,
but that's another decade...

I just hope people will understand what the can and can't do. I
think Python can help, if used wisely.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From mongo57a@comcast.net  Sun Oct 27 15:09:02 2002
From: mongo57a@comcast.net (andy surany)
Date: Sun Oct 27 15:09:02 2002
Subject: [Tutor] Absolute and relative window sizes
Message-ID: <001201c27df4$dbd5a860$2502a8c0@emily.ewndsr01.nj.comcast.net>

This is a multi-part message in MIME format.

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

Hi all,

I've created a GUI (Tk) that uses a single frame. The application starts with just a menu (menubar). Without any size controls, the initial display is very small and the menu is "word wrapped" based on available space. I experimented with expand and fill options to no avail, and was finally forced to give the window absolute size controls, as in:

 Frame.__init__(self,  parent, width=700, height=500)

Now this worked great! - that is, until now. I've augmented the application with a scrolled list where the contents exceed my hard coded dimensions. The result is a huge "gray space" where the menu is located, and then a correctly sized widget (listbox). I tried changing the initial hard dimensions to accommodate this listbox, but it just is not working.

Now I know that I have controls set to make the widget expand based on the data (expand=YES, fill=BOTH) - and I would like to continue to use relative (data based) window sizes - rather than from an absolute perspective. All of my Listbox applications work great using relative size/position controls - but the menubar doesn't seem to abide by these rules.....

Anybody recommend how I should handle this situation?

TIA.



--Boundary_(ID_CosFbZKXNYz43HGGZT8Tfw)
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 all,</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>I've created a GUI (Tk) that uses a single frame. The 
application starts with just a menu (menubar). Without any size controls, the 
initial display is very small and the menu is "word wrapped" based on available 
space. I experimented with expand and fill options to no avail, and was finally 
forced to give the window absolute size controls, as in:</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>&nbsp;Frame.__init__(self,&nbsp; parent, width=700, 
height=500)</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Now this worked great! - that is, until now. I've augmented 
the application with a scrolled list where the contents exceed my hard coded 
dimensions. The result is a huge "gray space" where the menu is located, and 
then a correctly sized widget (listbox). I tried changing the initial hard 
dimensions to accommodate this listbox, but it just is not working.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Now I know that I have controls set to make the widget expand 
based on the data (expand=YES, fill=BOTH) - and I would like to continue to use 
relative (data based)&nbsp;window sizes - rather than from an absolute 
perspective. All of my Listbox applications work great using relative 
size/position controls - but the menubar doesn't seem to abide by these 
rules.....</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Anybody recommend how I should handle this 
situation?</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>TIA.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV></BODY></HTML>

--Boundary_(ID_CosFbZKXNYz43HGGZT8Tfw)--


From dyoo@hkn.eecs.berkeley.edu  Sun Oct 27 16:40:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun Oct 27 16:40:01 2002
Subject: [Tutor] Sounds   [pygame]
In-Reply-To: <000501c27dd4$b326d300$f94795ac@chuck>
Message-ID: <Pine.LNX.4.44.0210271324070.24370-100000@hkn.eecs.berkeley.edu>


On Sun, 27 Oct 2002, Kyle Babich wrote:

> Dumb question, how do I play a sound (wav, wma, or mp3) or display an
> image (gif, bmp, jpg, jpeg)  from the command line?

Hi Kyle; it's nice to hear from you again!


We can handle the sound and image part with the Pygame module:

    http://pygame.org/
    http://pygame.org/docs/ref/Sound.html


I think pygame can handle mp3 and wav's, but I'm not so sure about wma's.
For that, you probably need to do something Windows-specific.  Try asking
on the python-win32 list, and I'm sure someone there might know how to get
wma files to play.

    http://mail.python.org/mailman/listinfo/python-win32


For the image part, you can probably yank out components of Pygame's
'chimp' tutorial:

    http://www.pygame.org/docs/tut/ChimpLineByLine.html

replace the 'chimp' image loading with your own image.


I hope this helps!



From gus.tabares@verizon.net  Sun Oct 27 18:17:01 2002
From: gus.tabares@verizon.net (Gus Tabares)
Date: Sun Oct 27 18:17:01 2002
Subject: [Tutor] Question
Message-ID: <3DBC7382.7020608@verizon.net>

Hello all,

    I'm trying to write a script that, when prompted by 'Password: ', 
could automatically enter the password itself. Any lead in the right 
direction would be greatly appreciated. Thanks


Gus



From dyoo@hkn.eecs.berkeley.edu  Sun Oct 27 20:06:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun Oct 27 20:06:01 2002
Subject: [Tutor] Question
In-Reply-To: <3DBC7382.7020608@verizon.net>
Message-ID: <Pine.LNX.4.44.0210271657330.4523-100000@hkn.eecs.berkeley.edu>


On Sun, 27 Oct 2002, Gus Tabares wrote:

>     I'm trying to write a script that, when prompted by 'Password: ',
> could automatically enter the password itself. Any lead in the right
> direction would be greatly appreciated. Thanks

Hi Gus,

Traditionally, Unix admin would use a a utility called 'expect' to
automate this kind of password entry.  Expect is written in Tk, and
doesn't have a special relationship with Python.


However, there is a project that's a port of Expect to Python called
'pexpect':

    http://sourceforge.net/projects/pexpect/

The pexpect project page appears to be down at the moment.  Drats.
However, Google has it cached at the moment.  Here's an example that's on
the cached Google page:


###
# This connects to the openbsd ftp site and
# downloads the recursive directory listing.
import pexpect
child = pexpect.spawn ('ftp ftp.openbsd.org')
child.expect ('Name .*: ')
child.sendline ('anonymous')
child.expect ('Password:')
child.sendline ('my@email.com')
child.expect ('ftp> ')
child.sendline ('cd pub')
child.expect('ftp> ')
child.sendline ('get ls-lR.gz')
child.expect('ftp> ')
child.sendline ('bye')
###


So pexpect looks like something that might help you with your program.

I hope this helps!



From python <python@inkedmn.net>  Sun Oct 27 20:15:01 2002
From: python <python@inkedmn.net> (python)
Date: Sun Oct 27 20:15:01 2002
Subject: Re[2]: [Tutor] Question
In-Reply-To: <Pine.LNX.4.44.0210271657330.4523-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.44.0210271657330.4523-100000@hkn.eecs.berkeley.edu>
Message-ID: <47248325533.20021027171903@inkedmn.net>

the getpass module is used to get passwords without echoing the text
back to the console.  like this:

password = getpass.getpass("Password: ")

DY> On Sun, 27 Oct 2002, Gus Tabares wrote:

>>     I'm trying to write a script that, when prompted by 'Password: ',
>> could automatically enter the password itself. Any lead in the right
>> direction would be greatly appreciated. Thanks

DY> Hi Gus,

DY> Traditionally, Unix admin would use a a utility called 'expect' to
DY> automate this kind of password entry.  Expect is written in Tk, and
DY> doesn't have a special relationship with Python.


DY> However, there is a project that's a port of Expect to Python called
DY> 'pexpect':

DY>     http://sourceforge.net/projects/pexpect/

DY> The pexpect project page appears to be down at the moment.  Drats.
DY> However, Google has it cached at the moment.  Here's an example that's on
DY> the cached Google page:


DY> ###
DY> # This connects to the openbsd ftp site and
DY> # downloads the recursive directory listing.
DY> import pexpect
DY> child = pexpect.spawn ('ftp ftp.openbsd.org')
DY> child.expect ('Name .*: ')
DY> child.sendline ('anonymous')
DY> child.expect ('Password:')
DY> child.sendline ('my@email.com')
child.expect ('ftp>> ')
DY> child.sendline ('cd pub')
child.expect('ftp>> ')
DY> child.sendline ('get ls-lR.gz')
child.expect('ftp>> ')
DY> child.sendline ('bye')
DY> ###


DY> So pexpect looks like something that might help you with your program.

DY> I hope this helps!


DY> _______________________________________________
DY> Tutor maillist  -  Tutor@python.org
DY> http://mail.python.org/mailman/listinfo/tutor



From emile@fenx.com  Mon Oct 28 00:25:02 2002
From: emile@fenx.com (Emile van Sebille)
Date: Mon Oct 28 00:25:02 2002
Subject: [Tutor] Re: Question
References: <3DBC7382.7020608@verizon.net> <Pine.LNX.4.44.0210271657330.4523-100000@hkn.eecs.berkeley.edu>
Message-ID: <apigdf$kf9$1@main.gmane.org>

Danny Yoo:
> However, there is a project that's a port of Expect to Python called
> 'pexpect':
>
>     http://sourceforge.net/projects/pexpect/
>
> The pexpect project page appears to be down at the moment.  Drats.


You might also want to check out
http://sourceforge.net/projects/expectpy/

--

Emile van Sebille
emile@fenx.com

---------





From angie477@yahoo.com  Mon Oct 28 08:23:02 2002
From: angie477@yahoo.com (angela blank)
Date: Mon Oct 28 08:23:02 2002
Subject: [Tutor] Sounds   [pygame]
In-Reply-To: <Pine.LNX.4.44.0210271324070.24370-100000@hkn.eecs.berkeley.edu>
Message-ID: <20021028132209.68287.qmail@web11708.mail.yahoo.com>

--- Danny Yoo <dyoo@hkn.eecs.berkeley.edu> wrote:
> 
> 
> On Sun, 27 Oct 2002, Kyle Babich wrote:
> 
> > Dumb question, how do I play a sound (wav, wma, or
> mp3) or display an
> > image (gif, bmp, jpg, jpeg)  from the command
> line?
> 
> Hi Kyle; it's nice to hear from you again!
> 
> 
> We can handle the sound and image part with the
> Pygame module:
> 
>     http://pygame.org/
>     http://pygame.org/docs/ref/Sound.html
> 
> 
> I think pygame can handle mp3 and wav's, but I'm not
> so sure about wma's.
> For that, you probably need to do something
> Windows-specific.  Try asking
> on the python-win32 list, and I'm sure someone there
> might know how to get
> wma files to play.
> 
>    
> http://mail.python.org/mailman/listinfo/python-win32
> 
> 
> For the image part, you can probably yank out
> components of Pygame's
> 'chimp' tutorial:
> 
>    
> http://www.pygame.org/docs/tut/ChimpLineByLine.html
> 
> replace the 'chimp' image loading with your own
> image.
> 
> 
> I hope this helps!
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



What about with MacPython? I am teaching MacPython at
the High School level so we must use Macs, with MacOS
9 or less. I would love to intergrate some sound and
graphics at this point.  Thanks,  Angela

=====
Angela Blank
Home: 763-576-1431
Cell: 612-810-9769

820 west main street apt 325
anoka mn 55303

__________________________________________________
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site
http://webhosting.yahoo.com/


From magnus@thinkware.se  Mon Oct 28 09:42:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Mon Oct 28 09:42:02 2002
Subject: [Tutor] Limit Quoting please!
Message-ID: <5.1.0.14.0.20021028152859.02af13e8@www.thinkware.se>

I think excessive quoting is getting worse here...

Could the tutor posters please, please, pretty
please follow the well established netiquette
for mailing lists.

Don't include quotations that aren't needed to
understand your question or answer. I'm not
going to reply to such email, and I doubt that
many others will bother. I'm sure no harm is
intended, but why should I have to scroll down
page after page to find a question? Why should
internet searches be obscured by quotes of the
same messages occuring time over time? Harm is
being done by the excessive quoting.

If you don't get replies from this helpful mailing
list, please ask yourself: "Am I doing something
wrong?" Then please read something like
http://www.fau.edu/netiquette/net/dis.html
or http://www.dtcc.edu/cs/rfc1855.html

I'm sure it will help you in your future electronic
communication.

List Admin: Is it possible to bounce emails
with more than say 75% quotations?


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From francois.granger@free.fr  Mon Oct 28 11:16:01 2002
From: francois.granger@free.fr (Fran=?ISO-8859-1?B?5w==?=ois Granger)
Date: Mon Oct 28 11:16:01 2002
Subject: [Tutor] Sounds   [pygame]
In-Reply-To: <20021028132209.68287.qmail@web11708.mail.yahoo.com>
Message-ID: <B9E320EC.5B11F%francois.granger@free.fr>

on 28/10/02 14:22, angela blank at angie477@yahoo.com wrote:
> --- Danny Yoo <dyoo@hkn.eecs.berkeley.edu> wrote:
>> 
>> We can handle the sound and image part with the
>> Pygame module:
>>     http://pygame.org/
>>     http://pygame.org/docs/ref/Sound.html
> 
> What about with MacPython? I am teaching MacPython at
> the High School level so we must use Macs, with MacOS
> 9 or less. I would love to intergrate some sound and
> graphics at this point.

I think that Pygames run on Mac ?

Anyway, you have access to QuickTIme, and in the :Mac:Demo folder there are:
- imgbrowse
- quicktime
- sound....
(I used or tested none of them)

You can also use AppleEvent to drive any other reader available on your Mac.
I have successfully used the OSAm module in :Mac:Contrib:osam for handling
other apps through AppleEvent.

-- 
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 mongo57a@comcast.net  Mon Oct 28 11:59:03 2002
From: mongo57a@comcast.net (andy surany)
Date: Mon Oct 28 11:59:03 2002
Subject: [Tutor] Killing Buttons! (in Tk)
Message-ID: <001501c27ea3$952cb7a0$2502a8c0@emily.ewndsr01.nj.comcast.net>

This is a multi-part message in MIME format.

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

Now that I have buttons created - and working, how do I get rid of them? In the application, the buttons change based on the function. Do I just destroy the widget? If so, how? Or do I have to disable and hide the buttons? Anyone have an example??

Thanks.



--Boundary_(ID_p+Jf5egVow3CuwDTyNP4Pw)
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>Now that I have buttons created - and working, how do I get 
rid of them? In the application, the buttons change based on the function. Do I 
just destroy the widget? If so, how? Or do I have to disable and hide the 
buttons? Anyone have an example??</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Thanks.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV></BODY></HTML>

--Boundary_(ID_p+Jf5egVow3CuwDTyNP4Pw)--


From aschmidt@nvcc.edu  Mon Oct 28 12:00:04 2002
From: aschmidt@nvcc.edu (Schmidt, Allen J.)
Date: Mon Oct 28 12:00:04 2002
Subject: [Tutor] Highlighting Searched-for text
Message-ID: <47BCBF3251382B45893950D07804082475B321@novamail.nv.cc.va.us>

I will be using this in either Python Scripts or External Methods in Zope if
that makes any difference to the answers...

I have a form field on a web page. The user types in a word, words or word
fragments. The results page is then displayed with matching
entries...usually pulled from a db.

How can I then highlight (change font to red or something) the search text
on the resulting page display. I have seen this in other online systems but
want to do it in Python/Zope but have not found a way. I have basic, general
Python experience.

Thanks!!!

-Allen


From magnus@thinkware.se  Mon Oct 28 12:29:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Mon Oct 28 12:29:01 2002
Subject: [Tutor] Highlighting Searched-for text
In-Reply-To: <47BCBF3251382B45893950D07804082475B321@novamail.nv.cc.va.u
 s>
Message-ID: <5.1.0.14.0.20021028183019.02b36ec0@www.thinkware.se>

At 10:36 2002-10-25 -0400, Schmidt, Allen J. wrote:
>How can I then highlight (change font to red or something) the search text
>on the resulting page display. I have seen this in other online systems but
>want to do it in Python/Zope but have not found a way. I have basic,=
 general
>Python experience.

A na=EFve implementation would be:

 >>> a =3D "This is a text with a word we search for (text) appearing"
 >>> def highlight(text, word, colour=3D"#FF0000"):
...     start =3D '<font colour=3D"%s">' % colour
...     end =3D '</font>'
...     return text.replace(word, start+word+end)
...
 >>> highlight(a, 'text')
'This is a <font colour=3D"#FF0000">text</font> with a word we search for=20
(<font colour=3D"#FF0000">text</font>) appearing'

I think this would work if we know that the string
we make the replacement in is plain text. But if
we do this in HTML we might get into trouble. If
someone would search for "href" in an HTML file
we'll mess up the href tags with this implementation.

Maybe it can somehow be used in conjunction with
a HTML parser or something like that...


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From kp8@mac.com  Mon Oct 28 12:35:29 2002
From: kp8@mac.com (kevin parks)
Date: Mon Oct 28 12:35:29 2002
Subject: [Tutor] Sounds & images on MacPython
In-Reply-To: <20021028170012.16760.77464.Mailman@mail.python.org>
Message-ID: <6D9D58DA-EA9B-11D6-854D-003065555ABC@mac.com>

> What about with MacPython?

>  I would love to intergrate some sound and
> graphics at this point.  Thanks,  Angela


Perhaps better to ask this over at the pythonmac SIG (special interest 
group)
There is a link off of www.python.org
Folks there are (much like this list) smart and helpful. Mac is in a 
great state
of flux now with the UNIX and Mac Pythons merging for OS X, but the 
newest
distributions still support OS 9 and i think that some of the things 
that you might
will be there like img and sound modules and (for sound) look into 
something called
snack if you need fancy sound stuff, but i am not so sure you need to 
go so far.


best wishes

-kevin





From jeff@ccvcorp.com  Mon Oct 28 13:22:01 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Mon Oct 28 13:22:01 2002
Subject: [Tutor] Limit Quoting please!
References: <5.1.0.14.0.20021028152859.02af13e8@www.thinkware.se>
Message-ID: <3DBD8005.936AC85B@ccvcorp.com>


Magnus Lycka wrote:

> List Admin: Is it possible to bounce emails
> with more than say 75% quotations?

Even if possible, I'm not sure this would be a good idea (however
tempting).  Sometimes it's necessary to quote a few lines of text in
order to be clear just what you're answering, but the needed answer is
only a very short single line.  Or, if you're helping someone "fix"
their code, you might have a number of lines of code quoted, with only
one or two "new" lines.

Programatically determining excessive quoting is tricky...  which is
why it's all that much more important for humans to be a bit more
careful about it.

Jeff Shannon
Technician/Programmer
Credit International







From James.Alexander.McCarney@Cognicase.com  Mon Oct 28 16:14:01 2002
From: James.Alexander.McCarney@Cognicase.com (McCarney, James Alexander)
Date: Mon Oct 28 16:14:01 2002
Subject: [Tutor] OT: Notion of persistence in Python
Message-ID: <23FD7B1A77E8D211BCB900001D108C02023FCA99@camelot>

If this is terribly OT, I apologize. I've been googling the web for
information on persistence. On the one hand I've come up with hits galore,
but on the other hand no one seems to be explaining what it is and its use.
Is this a notion that is not Pythonic, wrt the use of the language? Or is it
more of a functional Scheme type thing? 

Any insights and clear explanations appreciated.

Thank you.

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 shalehperry@attbi.com  Mon Oct 28 16:40:31 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Mon Oct 28 16:40:31 2002
Subject: [Tutor] OT: Notion of persistence in Python
In-Reply-To: <23FD7B1A77E8D211BCB900001D108C02023FCA99@camelot>
References: <23FD7B1A77E8D211BCB900001D108C02023FCA99@camelot>
Message-ID: <200210281338.36119.shalehperry@attbi.com>

On Monday 28 October 2002 13:13, McCarney, James Alexander wrote:
> If this is terribly OT, I apologize. I've been googling the web for
> information on persistence. On the one hand I've come up with hits galo=
re,
> but on the other hand no one seems to be explaining what it is and its =
use.
> Is this a notion that is not Pythonic, wrt the use of the language? Or =
is
> it more of a functional Scheme type thing?
>

"persistence" is a way to create some data/thing in a language and have i=
t=20
exist between executions of a program.  So if you have a program which ha=
s a=20
list of sports teams and scores and stored them in a persistent object ev=
ery=20
time the program loads it could simply pick back up where it left off. =20
Without persistence you would dump the list to a file (perhaps) and then=20
parse the file on the next program run.

Sometimes this approach makes sense, sometimes it doesn't.  It is not a P=
ython=20
or Scheme specific idea though.


From James.Alexander.McCarney@Cognicase.com  Mon Oct 28 16:50:01 2002
From: James.Alexander.McCarney@Cognicase.com (McCarney, James Alexander)
Date: Mon Oct 28 16:50:01 2002
Subject: [Tutor] OT: Notion of persistence in Python
Message-ID: <23FD7B1A77E8D211BCB900001D108C02023FCA9C@camelot>

Thanks Sean,

> >>"persistence" is a way to create some data/thing in a 
> >>language and have it 
> >>exist between executions of a program.  

So here is where things like "pickle" and "shelve" come into play I guess?
Taking objects and saving data in them. Is this more advisable than reading
from and writing to an RDBMS? Time saving issues...


From francois.granger@free.fr  Mon Oct 28 17:07:01 2002
From: francois.granger@free.fr (=?iso-8859-1?Q?Fran=E7ois?= Granger)
Date: Mon Oct 28 17:07:01 2002
Subject: [Tutor] Limit Quoting please!
In-Reply-To: <3DBD8005.936AC85B@ccvcorp.com>
References: <5.1.0.14.0.20021028152859.02af13e8@www.thinkware.se>
 <3DBD8005.936AC85B@ccvcorp.com>
Message-ID: <a0510030cb9e348535d5f@[192.168.1.11]>

At 10:20 -0800 28/10/02, in message Re: [Tutor] Limit Quoting 
please!, Jeff Shannon wrote:
>
>Even if possible, I'm not sure this would be a good idea

And education of new users don't work well with error messages but 
rather through clear messages like the one from Magnus....
-- 
Le courrier électronique 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://minilien.com/?IXZneLoID0 - 
http://marc.herbert.free.fr/mail/ http://expita.com/nomime.html


From aschmidt@fredericksburg.com  Mon Oct 28 17:08:02 2002
From: aschmidt@fredericksburg.com (Allen Schmidt)
Date: Mon Oct 28 17:08:02 2002
Subject: [Tutor] Highlighting Searched-for text
References: <5.1.0.14.0.20021028183019.02b36ec0@www.thinkware.se>
Message-ID: <000f01c27ece$42994960$03000000@swl001>

Ok, that sorta works...

I forgot to mention that the keywords field is coming in from the form
defined as 'tokens' so that it is a list as it gets to Python.

This is what I did with your code below in a Python script in Zope:
colour=3D"#FF0000"


start =3D '<font colour=3D"%s">' % colour
end =3D '</font>'
if keywords:
  for words in keywords:
    return adtext.replace(words, start+words+end)
else:
  return adtext


If the adtext is "This is a fish dish day." and the keyword is "is", this=
 is
what I get:

Th<font colour=3D"#FF0000">i</font>s <font colour=3D"#FF0000">i</font>s a=
 f<font
colour=3D"#FF0000">i</font>sh d<font colour=3D"#FF0000">i</font>sh day.


Its just finding the first letter of the keyword. So do I need to inform
Python that keywords is a list?? How does it know if its just a single wo=
rd?

Probably obvious things but I am a PyNewbie...more or less...

Thanks!

Allen
----- Original Message -----
From: "Magnus Lycka" <magnus@thinkware.se>
To: "Schmidt, Allen J." <aschmidt@nvcc.edu>; "'Python Tutor'"
<tutor@python.org>
Sent: Monday, October 28, 2002 12:35 PM
Subject: Re: [Tutor] Highlighting Searched-for text


> At 10:36 2002-10-25 -0400, Schmidt, Allen J. wrote:
> >How can I then highlight (change font to red or something) the search
text
> >on the resulting page display. I have seen this in other online system=
s
but
> >want to do it in Python/Zope but have not found a way. I have basic,
general
> >Python experience.
>
> A na=EFve implementation would be:
>
>  >>> a =3D "This is a text with a word we search for (text) appearing"
>  >>> def highlight(text, word, colour=3D"#FF0000"):
> ...     start =3D '<font colour=3D"%s">' % colour
> ...     end =3D '</font>'
> ...     return text.replace(word, start+word+end)
> ...
>  >>> highlight(a, 'text')
> 'This is a <font colour=3D"#FF0000">text</font> with a word we search f=
or
> (<font colour=3D"#FF0000">text</font>) appearing'
>
> I think this would work if we know that the string
> we make the replacement in is plain text. But if
> we do this in HTML we might get into trouble. If
> someone would search for "href" in an HTML file
> we'll mess up the href tags with this implementation.
>
> Maybe it can somehow be used in conjunction with
> a HTML parser or something like that...
>
>
> --
> Magnus Lyck=E5, Thinkware AB
> =C4lvans v=E4g 99, SE-907 50 UME=C5
> tel: 070-582 80 65, fax: 070-612 80 65
> http://www.thinkware.se/  mailto:magnus@thinkware.se
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



From shalehperry@attbi.com  Mon Oct 28 17:09:02 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Mon Oct 28 17:09:02 2002
Subject: [Tutor] OT: Notion of persistence in Python
In-Reply-To: <23FD7B1A77E8D211BCB900001D108C02023FCA9C@camelot>
References: <23FD7B1A77E8D211BCB900001D108C02023FCA9C@camelot>
Message-ID: <200210281408.24257.shalehperry@attbi.com>

On Monday 28 October 2002 13:49, McCarney, James Alexander wrote:
> Thanks Sean,
>
> > >>"persistence" is a way to create some data/thing in a
> > >>language and have it
> > >>exist between executions of a program.
>
> So here is where things like "pickle" and "shelve" come into play I gue=
ss?
> Taking objects and saving data in them. Is this more advisable than rea=
ding
> from and writing to an RDBMS? Time saving issues...
>

the real advantage of an rdbms is the interface not the storage.

let's use sql as an example:

select * where last_name =3D "Perry"

also you can put all that data in a RDBMS and then write a billion differ=
ent=20
clients to read it.  web access, desktop program access, cell phones,=20
whatever.

shelve, pickle, etc are really only useful to the program that created th=
em or=20
perhaps to another python program which knows the secrets.  This does not=
=20
make them bad it is simply a matter of what you need.


From magnus@thinkware.se  Mon Oct 28 17:12:09 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Mon Oct 28 17:12:09 2002
Subject: [Tutor] OT: Notion of persistence in Python
In-Reply-To: <23FD7B1A77E8D211BCB900001D108C02023FCA9C@camelot>
Message-ID: <5.1.0.14.0.20021028231558.02a252f0@www.thinkware.se>

At 16:49 2002-10-28 -0500, McCarney, James Alexander wrote:
>So here is where things like "pickle" and "shelve" come into play I guess?
>Taking objects and saving data in them. Is this more advisable than reading
>from and writing to an RDBMS? Time saving issues...

People use words in different ways, but I'd say
that anything that preserves state between program
runs is a persistence mechanism, whether it's pickle
or Oracle. ZODB is a nice Python solution. It also
provides transaction handling and undo/versioning.


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From francois.granger@free.fr  Mon Oct 28 17:34:02 2002
From: francois.granger@free.fr (=?iso-8859-1?Q?Fran=E7ois?= Granger)
Date: Mon Oct 28 17:34:02 2002
Subject: [Tutor] OT: Notion of persistence in Python
In-Reply-To: <23FD7B1A77E8D211BCB900001D108C02023FCA99@camelot>
References: <23FD7B1A77E8D211BCB900001D108C02023FCA99@camelot>
Message-ID: <a05100311b9e35fadd9e3@[192.168.1.11]>

At 16:13 -0500 28/10/02, in message [Tutor] OT: Notion of persistence 
in Python, McCarney, James Alexander wrote:
>If this is terribly OT, I apologize. I've been googling the web for
>information on persistence. On the one hand I've come up with hits galore,
>but on the other hand no one seems to be explaining what it is and its use.
>Is this a notion that is not Pythonic, wrt the use of the language? Or is it
>more of a functional Scheme type thing?
>
>Any insights and clear explanations appreciated.

I am not a language specialist.

For me, persistence is when the language takes care of saving the 
data for you. Hypercard and Frontier on Macintosh, ToolBook on 
Windows were the best exemple of this.

Python does not do this as most programming languages. But it gives 
you the tools to implement it if you wish.

-- 
Le courrier électronique 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://minilien.com/?IXZneLoID0 - 
http://marc.herbert.free.fr/mail/ http://expita.com/nomime.html


From rickp@telocity.com  Mon Oct 28 17:36:02 2002
From: rickp@telocity.com (Rick Pasotto)
Date: Mon Oct 28 17:36:02 2002
Subject: [Tutor] Highlighting Searched-for text
In-Reply-To: <000f01c27ece$42994960$03000000@swl001>
References: <5.1.0.14.0.20021028183019.02b36ec0@www.thinkware.se> <000f01c27ece$42994960$03000000@swl001>
Message-ID: <20021028223533.GU29905@tc.niof.net>

On Mon, Oct 28, 2002 at 05:06:25PM -0500, Allen Schmidt wrote:
> Ok, that sorta works...
> 
> I forgot to mention that the keywords field is coming in from the form
> defined as 'tokens' so that it is a list as it gets to Python.
> 
> This is what I did with your code below in a Python script in Zope:
> colour="#FF0000"
> 
> 
> start = '<font colour="%s">' % colour
> end = '</font>'
> if keywords:
>   for words in keywords:
>     return adtext.replace(words, start+words+end)
> else:
>   return adtext
> 
> 
> If the adtext is "This is a fish dish day." and the keyword is "is", this is
> what I get:
> 
> Th<font colour="#FF0000">i</font>s <font colour="#FF0000">i</font>s a f<font
> colour="#FF0000">i</font>sh d<font colour="#FF0000">i</font>sh day.

You really ought to surround the keyword with

<span id=color1>keyword</span>

and then have a style sheet that sets the color1 id to whatever you
want.

-- 
"Of all the sexual aberrations, perhaps the most peculiar is chastity."
		-- Remy de Gourmont
    Rick Pasotto    rickp@telocity.com    http://www.niof.net


From magnus@thinkware.se  Mon Oct 28 18:40:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Mon Oct 28 18:40:01 2002
Subject: [Tutor] Limit Quoting please!
In-Reply-To: <a0510030cb9e348535d5f@[192.168.1.11]>
References: <3DBD8005.936AC85B@ccvcorp.com>
 <5.1.0.14.0.20021028152859.02af13e8@www.thinkware.se>
 <3DBD8005.936AC85B@ccvcorp.com>
Message-ID: <5.1.0.14.0.20021029003710.02a78e18@www.thinkware.se>

At 21:03 2002-10-28 +0100, Fran=E7ois Granger wrote:
>And education of new users don't work well with error messages but rather=
=20
>through clear messages like the one from Magnus....

But I don't like to play strict teacher. :( And usually
I read this mailing list so late in the evening (I'm in
Europe and still on US evening time if you noticed) so
I'm often not as nice and polite as I would like to be,
being a bit tired...

I don't want anyone to get discouraged, just that they
understand how to best use this mailing list (and other
mainling lists as well).

An advantage with an automatic reply from a piece of
software is that it's hard to take it personal. :)

Maybe some subscription confirmation or monthly reminder
should hint about netiquette. In this friendly list we
never see flame wars or spam, and rarely off topic
questions or big attachements, so HTML-mail and too much
quotations seem to be the things to point at...


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From magnus@thinkware.se  Mon Oct 28 19:12:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Mon Oct 28 19:12:01 2002
Subject: [Tutor] Highlighting Searched-for text
In-Reply-To: <000f01c27ece$42994960$03000000@swl001>
References: <5.1.0.14.0.20021028183019.02b36ec0@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021029004642.02a6aca0@www.thinkware.se>

Oops Allen, you forgot to edit out the pieces of the
message you replied to that wasn't needed to understand
your reply. (100% in this case! ;) Please do the hard
work of marking and deleting such text in the future.
We do the hard work of typing long replies to your
questions...

At 17:06 2002-10-28 -0500, Allen Schmidt wrote:
>if keywords:
>   for words in keywords:
>     return adtext.replace(words, start+words+end)
>else:
>   return adtext
>
>If the adtext is "This is a fish dish day." and the keyword is "is", this=
 is
>what I get:
>
>Th<font colour=3D"#FF0000">i</font>s <font colour=3D"#FF0000">i</font>s a=
 f<font
>colour=3D"#FF0000">i</font>sh d<font colour=3D"#FF0000">i</font>sh day.

Ok, it's not so strange. The for loop assumes a sequence of
words, right? But you don't call it with a list, you call
it with a string. Instead of looping over words it loops
over characters in words, the first being 'i'.

If you want to have a loop, you need to send a list of words,,
even if it's just one word.

 >>> for i in "Hello":
...     print i
...
H
e
l
l
o
 >>> for i in ["Hello"]:
...     print i
...
Hello

See? It you have a string with whitespace separated
words, use split to make it into a list. Like this:

 >>> "if then go".split()
['if', 'then', 'go']
 >>> "if".split()
['if']

Secondly, you have a return statement in the for loop.
This means that you always exit from the function on
the first pass through the loop. Right? You should return
the string after the loop, not in the middle of it.

Thirdly, a loop over an empty sequence does nothing,
so you don't need the if-else when the return is moved
out of the loop.

Then we get:

for word in keywords.split():
     adtext =3D adtext.replace(word, start+word+end)
return adtext

Shorter and better! Right?

Notice that with this code 'is' will match the second
half of 'this', which might not be what you want. The
visual indication should match how the search works.

Maybe you can use the same function as in the actual
search? Or at least share some code, so that search
criteria and display will always match?

You can use " "+word+" ", but that would miss "is." etc.
Also note that .replace() is case sensitive. For more
advanced search and replace, have a look at the re module
in the library reference. That's not the first thing to
approach as a beginner though.

/Magnus


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From aschmidt@fredericksburg.com  Mon Oct 28 19:50:02 2002
From: aschmidt@fredericksburg.com (Allen Schmidt)
Date: Mon Oct 28 19:50:02 2002
Subject: [Tutor] Highlighting Searched-for text
References: <5.1.0.14.0.20021028183019.02b36ec0@www.thinkware.se> <5.1.0.14.0.20021029004642.02a6aca0@www.thinkware.se>
Message-ID: <000f01c27ee4$e2f97e00$03000000@swl001>

Wonderful! Thanks so much for the tips!  (Sorry for making you work harder!)

I get it now....makes sense. If my Zope form sets it to be :tokens while my
Python script see it as a real list? Or just space-separated strings? I will
experiment some more...

Thanks again! I really appreciate all  the help! Sorry again for the
blunder...

Allen



From aschmidt@fredericksburg.com  Mon Oct 28 20:35:02 2002
From: aschmidt@fredericksburg.com (Allen Schmidt)
Date: Mon Oct 28 20:35:02 2002
Subject: [Tutor] Highlighting Searched-for text
References: <5.1.0.14.0.20021028183019.02b36ec0@www.thinkware.se> <5.1.0.14.0.20021029004642.02a6aca0@www.thinkware.se>
Message-ID: <003901c27eeb$2e0e5220$03000000@swl001>

Works great! Here is what I did:

keywords is defined as on my Zope form as <INPUT ... NAME=keywords:tokens
... >
So, a single word or many, keywords is always a list. Cool...


for words in keywords:
    adtext=adtext.replace(words, start+words+end)
return adtext

But, as you noted, its case sensitive. Is there a way to handle the
conversion without actually converting the data in adtext sent back? Like
just check for lower.keywords in lower.adtext? That type of thing??

Thanks


Allen



From mongo57a@comcast.net  Tue Oct 29 00:04:01 2002
From: mongo57a@comcast.net (andy surany)
Date: Tue Oct 29 00:04:01 2002
Subject: [Tutor] Killing Buttons! (in Tk)
Message-ID: <007e01c27f08$beea7ea0$2502a8c0@emily.ewndsr01.nj.comcast.net>

Well, after 6 hours of research and trying different things, I'm able to
answer my own question. This may not mean much to you experienced folks
on the list, but for us beginners, the following might prove useful.

I was using the Tk button function directly, as such:

    Button(self, text='aaa', command=self.x).pack(side=LEFT)

which was correct - but incorrect. (I remember that someone on the list
warned of this type of packing).

I needed to split the command and make an assignment:

    self.Button_1 = Button(self, text='aaa', command=self.x)
    self.Button_1.pack(side=LEFT)

Now I could delete the button:

    self.Button_1.destroy()

HTH
  -----Original Message-----
  From: andy surany <mongo57a@comcast.net>
  To: tutor@python.org <tutor@python.org>
  Date: Monday, October 28, 2002 11:59 AM
  Subject: [Tutor] Killing Buttons! (in Tk)


  Now that I have buttons created - and working, how do I get rid of
them? In the application, the buttons change based on the function. Do I
just destroy the widget? If so, how? Or do I have to disable and hide
the buttons? Anyone have an example??

  Thanks.





From francois.granger@free.fr  Tue Oct 29 04:28:02 2002
From: francois.granger@free.fr (=?iso-8859-1?Q?Fran=E7ois?= Granger)
Date: Tue Oct 29 04:28:02 2002
Subject: [Tutor] Limit Quoting please!
In-Reply-To: <5.1.0.14.0.20021029003710.02a78e18@www.thinkware.se>
References: <3DBD8005.936AC85B@ccvcorp.com>
 <5.1.0.14.0.20021028152859.02af13e8@www.thinkware.se>
 <3DBD8005.936AC85B@ccvcorp.com>
 <5.1.0.14.0.20021029003710.02a78e18@www.thinkware.se>
Message-ID: <a05100313b9e3e9e15263@[192.168.1.11]>

At 0:45 +0100 29/10/02, in message Re: [Tutor] Limit Quoting please!, 
Magnus Lycka wrote:
>At 21:03 2002-10-28 +0100, François Granger wrote:
>>And education of new users don't work well with error messages but 
>>rather through clear messages like the one from Magnus....
>
>But I don't like to play strict teacher.

I understand this. I was just trying to introduce some american 
"think positive" in your remark ;-)
I try to educate the french people I communicate with by providing 
them links to french translation of netiquette in my sig...

>(I'm in
>Europe and still on US evening time if you noticed) so
>I'm often not as nice and polite as I would like to be,
>being a bit tired...

Thanks for your efforts at that time of the day !

>An advantage with an automatic reply from a piece of
>software is that it's hard to take it personal. :)

This is right.

>Maybe some subscription confirmation or monthly reminder
>should hint about netiquette.

Nobody read these...


-- 
Le courrier électronique 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://minilien.com/?IXZneLoID0 - 
http://marc.herbert.free.fr/mail/ http://expita.com/nomime.html


From thomi@thomi.imail.net.nz  Tue Oct 29 04:57:02 2002
From: thomi@thomi.imail.net.nz (Thomi Richards)
Date: Tue Oct 29 04:57:02 2002
Subject: [Tutor] Limit Quoting please!
In-Reply-To: <a05100313b9e3e9e15263@[192.168.1.11]>
References: <3DBD8005.936AC85B@ccvcorp.com>
 <5.1.0.14.0.20021028152859.02af13e8@www.thinkware.se>
 <3DBD8005.936AC85B@ccvcorp.com>
 <5.1.0.14.0.20021029003710.02a78e18@www.thinkware.se>
 <a05100313b9e3e9e15263@[192.168.1.11]>
Message-ID: <20021029225640.0c90103d.thomi@thomi.imail.net.nz>

> >Maybe some subscription confirmation or monthly reminder
> >should hint about netiquette.
> 
> Nobody read these...

Still, if it's there, more people are going to read it than if it's not,
right?? I mean, how many people are on this list? at least one of them
will look at their reminder, and thing "gee, these guys are really
serious about this", and hopefully, they will make an effort. i know i
could do to be told this once in a while.

-- 
Thomi Richards
thomi@imail.net.nz
http://ddmodd.sourceforge.net/
Thomi Richards,
thomi@imail.net.nz


From lumbricus@gmx.net  Tue Oct 29 05:02:01 2002
From: lumbricus@gmx.net (lumbricus@gmx.net)
Date: Tue Oct 29 05:02:01 2002
Subject: [Tutor] Re: Question
References: <apigdf$kf9$1@main.gmane.org>
Message-ID: <2240.1035885641@www31.gmx.net>

Hi!

For ftp:
man netrc

HTH, J"o!

-- 
Wir beschliessen etwas, stellen das dann in
den Raum und warten dann einige Zeit ab, was
passiert. Wenn es dann kein grosses Geschrei
gibt und keine Aufstaende, weil die meisten
gar nicht begreifen, was da beschlossen
wurde, dann machen wir weiter - Schritt fuer
Schritt, bis es kein Zurueck mehr gibt. 
   -- J-C Juncker

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



From francois.granger@free.fr  Tue Oct 29 06:18:02 2002
From: francois.granger@free.fr (Fran=?ISO-8859-1?B?5w==?=ois Granger)
Date: Tue Oct 29 06:18:02 2002
Subject: [Tutor] Limit Quoting please!
In-Reply-To: <20021029225640.0c90103d.thomi@thomi.imail.net.nz>
Message-ID: <B9E42CB1.5B1E8%francois.granger@free.fr>

on 29/10/02 10:56, Thomi Richards at thomi@thomi.imail.net.nz wrote:

>>> Maybe some subscription confirmation or monthly reminder
>>> should hint about netiquette.
>> 
>> Nobody read these...
> 
> Still, if it's there, more people are going to read it than if it's not,
> right?? I mean, how many people are on this list?

1654 according to:

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

-- 
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 sannukujur@hotmail.com  Tue Oct 29 07:00:03 2002
From: sannukujur@hotmail.com (Sannu Kujur)
Date: Tue Oct 29 07:00:03 2002
Subject: [Tutor] Need book recommendation...
Message-ID: <F1846pgEBzDrvnGq8E8000076a0@hotmail.com>

I have decided to start learning programming with Python. I need to know 
which book would be best suited for me - a complete novice. I am looking for 
no prerequisites, a very basic beginning (like syntax etc.) which builds up 
to advance levels, and lots of real-world examples.





_________________________________________________________________
Surf the Web without missing calls! Get MSN Broadband.  
http://resourcecenter.msn.com/access/plans/freeactivation.asp



From charlie@begeistert.org  Tue Oct 29 08:03:02 2002
From: charlie@begeistert.org (Charlie Clark)
Date: Tue Oct 29 08:03:02 2002
Subject: [Tutor] Re: Learning to program with Python
In-Reply-To: <20021028170012.16760.77464.Mailman@mail.python.org>
References: <20021028170012.16760.77464.Mailman@mail.python.org>
Message-ID: <20021029140820.864.7@gormenghast.1035893541.fake>

On 2002-10-28 at 17:00:12 [+0000], you wrote:
> He he...
> 
> I think it's a very worthy goal to make Python available
> for non-programmers as a useful tool.
...
> their computer, along with Excel, a web browser and
> whatever...
Indeed actually I think sensible use of Python can limit the apparent 
dependency on the over-complicated software (including Excel) cluttering 
our computers which prevents us from getting our job done.

Python is the first programming language I've successfully done anything 
with despite coming from a computer-based background: my dad has been 
working with computers since the early (19)sixties. I found "Learning 
Python" a very good introduction. I think the online documentation and 
stuff isn't so good: there are not enuff examples and stuff to copy and 
change in order to really grasp how things work. It took me 2 whole days to=
 
suss the library HTML-parser and that was with the help of my neighbour and=
 
the list, particularly Danny Yoo. This list is wonderful: some great people=
 
with a lot of patience and not too much traffic. The newsgroup is really 
interesting but far too much traffic. And Python users: patient, literate 
and focussed on problem-solving rather than algorithms and technical 
schnick-schnack (except when required). I've also really enjoyed and 
benefitted from the comparisons with other languages: syntax issues, when 
to optimise, typing issues (static typing !=3D strong typing), backwards 
compatbility and other areas where I have been able to understand the 
issues even if the implementations were way over my head.
 
>... I think
> you have heard about the chaos Orson Welles cause with
> his radio play based on H.G. Wells "The War of the Worlds".
> Today, people do't react like that.
They do actually. The film "Wag the dog" illustrates this very well. This 
is not intended to offend but the events around the 11th September 2001 
highlighted our susceptibility to the media: "9.11: Emergency in New York"

> I certainly remember the boost of home computers in the
> early 80's, when everybody was supposed to learn BASIC and
> housewives should write programs to store their recipes.
> That was silly, and today people certainly know that being
> a computer user and being a programmer is not the same thing.
> (But really, the big difference is that such a plethora of
> ready made programs are widely available at a very low cost
> today. Then you needed to program to get anything useful out
> of your C-64 or whatever.)
The idea of people writing their own software to solve their problem is 
pure marketing. It's very seductive and it's become somewhat of a religion 
on which the computer industry is based. A lot of people have tried it, 
given up and bought an expensive package to do the job instead. And because=
 
they're frustrated and possibly under pressure they're also more tolerant 
of lower quality: we've come to *accept* buggy software as normal. Things 
will get better in the next release. Nobody would do this with a fridge or 
a car. The old joke of getting the car to start by closing the windows and 
opening them again.

Computers have got more and more complex and feature creep is a great way 
of not solving problems. 80 / 20 rule: only 20% of the installed software 
is used and only 20% of the features of that 20% is used. These figures are=
 
conservative - the real situation is probably more extreme. I mean look at 
stupid things like text-formatting in e-mails: people don't know it's 
there, don't know it's not standard and wouldn't dream of using HTML after 
their first 10 nightmare pages.

There are occasional figures which highlight the fact that the massive 
spending on IT since the 70s has not been reflected in increased 
productivity across our economies. There have been notable advances in many=
 
areas but many of the costs due to increased complexity have been ignored

> As a professional programmer, I sometimes notice that management
> people think that they can swap professional compentence for a
> tool or a process. This would save money I guess. Sure, competence
> requirements change. You don't need electronic engineers and
> scientists in white coats to create an advanced IT system today.
Well, you need people who can think clearly and you don't save money with 
IT. It quite often costs a lot more than people-based stuff. We need good 
people and good technology but especially good people.
 
> But people still need to understand a lot about problem solving,
Indeed. I think this is the crucial point. It is now becoming possible for 
customers to take a bigger role in specifying their solution: programmers 
often *cannot* identify nor understand the problem. Finding the problem is 
often the greatest challenge and one at which programmers are generally not=
 
very good in my experience. Python has some great tools to help on this: 
clean syntax, indenting, namespaces, sensible library names, modular 
development. Being able to rely on the libraries and do interactive 
development is also a big plus: working closely with customers to produce 
their solutions is great for all involved when it works properly. It's also=
 
reassuring to know you can change functions later on without too much 
difficulty. Python helps you find and scratch an itch quickly. And when 
solutions can't solve all the problems it's really great to be able to 
offer Python as tool for user extensions. I know of several products which 
have decided to use Python as their scripting language based on user 
acceptance.

I've recently had to do some work with databases and was lent "Practical 
issues in database management" by Fabian Pascal. It covered a lot of 
similar issues with regard to relational databases and repeatedly made the 
point that declarative work makes programming easier and safer. Pascal 
insists on quality and points out that until customers insist on quality 
from vendors they will continue to focus on features. So drawing 
non-programmers into the argument can be a two-edged sword as it is often 
easier to undestand and, therefore, accept the marketing rather than 
technical arguments.

Charlie
-- 
Charlie Clark
Helmholtzstr. 20
D=1Asseldorf
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226


From David Lawrence" <dlphone@bellsouth.net  Tue Oct 29 08:28:01 2002
From: David Lawrence" <dlphone@bellsouth.net (David Lawrence)
Date: Tue Oct 29 08:28:01 2002
Subject: [Tutor] Re: chill monkey!  [How to turn off MIME email]
References: <20021027170003.27298.80112.Mailman@mail.python.org>
Message-ID: <001201c27f4e$e668ce00$6900a8c0@dlawrencex>

My apologies to all!
Thank you Magnus Lycka and Danny Yoo for informing (or reminding) us
about netiquette rules and where to find them. Evidently I was violating
most of the key rules. Hopefully my posts will be shorter & easier to
read from now on.

Dave
----------------
David Lawrence
dlphone@bellsouth.net





From kyle@sent.com  Tue Oct 29 09:18:03 2002
From: kyle@sent.com (Kyle Babich)
Date: Tue Oct 29 09:18:03 2002
Subject: [Tutor] Bug in my program
Message-ID: <001901c27f55$e70d2020$6115a8ac@chuck>

Could someone please help me fix this?  I didn't include the full program
because it is too large but I have several blocks like this:

            try:
                ReadNum = file('C:/Documents and Settings/All
Users/Documents/TimeTrack/logs/beg_log.dat', 'r')
                content = ReadNum.xreadlines()
                last = string.split(content[len(content) - 1], ':')
                num = last[0]
                ReadNum.close()
            except:
                num = 'error reading num'

            BegTime = time.strftime('%I:%M:%S%p %Z',
time.localtime(time.time()))
            BegLog = file('C:/Documents and Settings/All
Users/Documents/TimeTrack/logs/beg_log.dat', 'a')
            BegLog.write(num + ':  ' + name + ' requested to sleep for one
hour starting at ' + BegTime + '\n')
            BegLog.close()

that keep giving me this:

Traceback (most recent call last):
  File "C:\Documents and Settings\Kyle\My
Documents\Programs\TimeTrack\TimeTrackOne.py", line 96, in ?
    BegLog = file('C:/Documents and Settings/All
Users/Documents/TimeTrack/logs/beg_log.dat', 'a')
TypeError: 'list' object is not callable

I have 2.2.1 installed on XP Home.
Any help is greatly appreciated, thank you!

- Kyle




From James.Alexander.McCarney@Cognicase.com  Tue Oct 29 09:19:02 2002
From: James.Alexander.McCarney@Cognicase.com (McCarney, James Alexander)
Date: Tue Oct 29 09:19:02 2002
Subject: [Tutor] Need book recommendation...
Message-ID: <23FD7B1A77E8D211BCB900001D108C02023FCA9E@camelot>

I would suggest Alan Gauld's tutorial (among others)... Check out
http://www.python.org/doc/Newbies.html

 >>
> >>I have decided to start learning programming with Python. I 
> >>need to know 
> >>which book would be best suited for me - a complete novice. 
>
> >>


From emile@fenx.com  Tue Oct 29 09:37:01 2002
From: emile@fenx.com (Emile van Sebille)
Date: Tue Oct 29 09:37:01 2002
Subject: [Tutor] Re: Bug in my program
References: <001901c27f55$e70d2020$6115a8ac@chuck>
Message-ID: <apm6al$29j$1@main.gmane.org>

Kyle Babich
> Traceback (most recent call last):
>   File "C:\Documents and Settings\Kyle\My
> Documents\Programs\TimeTrack\TimeTrackOne.py", line 96, in ?
>     BegLog = file('C:/Documents and Settings/All
> Users/Documents/TimeTrack/logs/beg_log.dat', 'a')
> TypeError: 'list' object is not callable
> 
> I have 2.2.1 installed on XP Home.
> Any help is greatly appreciated, thank you!

There it is -- IIRC, file became usable this way
in 2.2.

You've probably used file as a label as well, replacing its
normal meaning.  Look for something like:

Python 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> x = file(r'c:\test.dat')
>>> file = []
>>> x = file(r'c:\test.dat')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: 'list' object is not callable
>>>


HTH,


--

Emile van Sebille
emile@fenx.com

---------





From kyle@sent.com  Tue Oct 29 10:17:01 2002
From: kyle@sent.com (Kyle Babich)
Date: Tue Oct 29 10:17:01 2002
Subject: [Tutor] Re: Bug in my program
Message-ID: <007101c27f5e$2082c690$6115a8ac@chuck>

--------------------
Kyle Babich
> Traceback (most recent call last):
>   File "C:\Documents and Settings\Kyle\My
> Documents\Programs\TimeTrack\TimeTrackOne.py", line 96, in ?
>     BegLog = file('C:/Documents and Settings/All
> Users/Documents/TimeTrack/logs/beg_log.dat', 'a')
> TypeError: 'list' object is not callable
>
> I have 2.2.1 installed on XP Home.
> Any help is greatly appreciated, thank you!

There it is -- IIRC, file became usable this way
in 2.2.

You've probably used file as a label as well, replacing its
normal meaning.  Look for something like:

Python 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> x = file(r'c:\test.dat')
>>> file = []
>>> x = file(r'c:\test.dat')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: 'list' object is not callable
>>>

----------------------------------------------
Actually I searched the entire program and I have no lists at all besides
lists like:
if x in [1, 2, 3]
and I don't have any variables by that name either.
(All variables:
name
response
ran
content
last
num
ReadNumBeg
BegTime
BegLog
ReadNumFull
EndTime
log
command
tts
ClearFull
ClearBeg)



From magnus@thinkware.se  Tue Oct 29 10:43:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Oct 29 10:43:01 2002
Subject: [Tutor] Re: Bug in my program
In-Reply-To: <007101c27f5e$2082c690$6115a8ac@chuck>
Message-ID: <5.1.0.14.0.20021029164436.098372d8@www.thinkware.se>

At 10:16 2002-10-29 -0500, Kyle Babich wrote:
> > Traceback (most recent call last):
> >   File "C:\Documents and Settings\Kyle\My
> > Documents\Programs\TimeTrack\TimeTrackOne.py", line 96, in ?
> >     BegLog =3D file('C:/Documents and Settings/All
> > Users/Documents/TimeTrack/logs/beg_log.dat', 'a')
> > TypeError: 'list' object is not callable

put the following just above the problem line (96):

     print file

It should print "<type 'file'>", but I guess it will
print a list. Hopefully you will se what it is.

Is there not a single instance of "file =3D" in your
program?


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From aicolburn@yahoo.com  Tue Oct 29 11:54:05 2002
From: aicolburn@yahoo.com (Alan Colburn)
Date: Tue Oct 29 11:54:05 2002
Subject: [Tutor] Tkinter Question
Message-ID: <00f701c27f6b$b4074a00$cae68b86@fo5132>

Hi all--

I have a Tkinter frame with multiple Entry boxes. Users enter information in
each Entry box, perhaps moving from one to the next via the Tab key, before
clicking a button to store the information. A second button closes the
window, because sometimes users will be inputting multiple sets of
information.

Here's what I'm looking for help on ... I'd like the user to be able to fill
out the first Entry and move to the next via the Return key. I'm not talking
about just binding the information in the Entry box to the <Return>
keystroke; I'd like the cursor to actually move to the next Entry box. The
idea, of course, is to make it very fast and easy to enter all the
information.

As always, I appreciate your help :-)

Al C.



From James.Alexander.McCarney@Cognicase.com  Tue Oct 29 11:59:01 2002
From: James.Alexander.McCarney@Cognicase.com (McCarney, James Alexander)
Date: Tue Oct 29 11:59:01 2002
Subject: [Tutor] Tkinter Question
Message-ID: <23FD7B1A77E8D211BCB900001D108C02023FCAA0@camelot>

>From a pure GUI design and usability perspective, I don't know if it's such
a good idea. I think most users would expect to input and tab to the next
field, reserving <Return> for the final input of fields.

Just my $0.02 CAN. 

"""
Here's what I'm looking for help on ... I'd like the user to be able to fill
out the first Entry and move to the next via the Return key. I'm not talking
about just binding the information in the Entry box to the <Return>
keystroke; I'd like the cursor to actually move to the next Entry box. The
idea, of course, is to make it very fast and easy to enter all the
information.
"""


From magnus@thinkware.se  Tue Oct 29 12:00:06 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Oct 29 12:00:06 2002
Subject: [Tutor] Re: Bug in my program
In-Reply-To: <007801c27f63$bc229cb0$6115a8ac@chuck>
References: <5.1.0.14.0.20021029164436.098372d8@www.thinkware.se>
Message-ID: <5.1.0.14.0.20021029174834.00bcde90@www.thinkware.se>

At 10:56 2002-10-29 -0500, Kyle Babich wrote:
>I guess it has to be there because it returns a blank list []
>But I can't find it anywhere, so I did a little experimenting.  Eventually=
 I
>got all the way to the very top of the file and doing this:
>
>#! c:\python22\python

This pound-bang trick doesn't work in Windows, does it?
But it sholdn't matter. Windows uses the extension .py
to find the interpreter. This is just a comment to Python.


>print file
>
>still returns this:
>
>[]

Really? You can get away from the problem by
adding "file=3Dopen" in the beginning of the file
I guess, but this should certainly not happen.

There isn't even any import before your print file?

What if you open the python interpreter and
type

 >>> print file

in interactive mode? Same there?


You didn't need to quote all below... ;)
>----- Original Message -----
...



--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se



From dyoo@hkn.eecs.berkeley.edu  Tue Oct 29 12:46:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue Oct 29 12:46:01 2002
Subject: [Tutor] Re: Bug in my program  [finding when a variable's being
 bound too many times]
In-Reply-To: <007101c27f5e$2082c690$6115a8ac@chuck>
Message-ID: <Pine.LNX.4.44.0210290925180.5420-100000@hkn.eecs.berkeley.edu>


>>> Traceback (most recent call last):
>>>   File "C:\Documents and Settings\Kyle\My
>>> Documents\Programs\TimeTrack\TimeTrackOne.py", line 96, in ?
>>>     BegLog = file('C:/Documents and Settings/All
>>> Users/Documents/TimeTrack/logs/beg_log.dat', 'a')
>>> TypeError: 'list' object is not callable
>
>
>> You've probably used file as a label as well, replacing its
>> normal meaning.
>
>
> Actually I searched the entire program and I have no lists at all besides
> lists like:
> if x in [1, 2, 3]
> and I don't have any variables by that name either.



Hi Kyle,


Hmmm... Another source of hidden variables may be in a 'from foo import
*'.  Do you use any 'from *' statements in your program?




If it helps, we can trace down exactly where we lose the real definition
of file with a little trickery:

###
"""
BindingWrapper.py

This is a small program that allows us to see when something is accidently
unbounded.

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

import inspect
from sys import stderr

class BindingWrapper:
    def __init__(self, obj):
        self.obj = obj

    def __call__(self, *args, **kwargs):
        self.obj(*args, **kwargs)

    def __getattr__(self, attr):
        return getattr(self.obj, attr)

    def __del__(self):
        stderr.write("Help!  I'm (%s) being repressed!\n" %
                     repr(self.obj))
        stderr.write("Somewhere in line %d\n" %
                     inspect.currentframe().f_back.f_lineno)


if __name__ == '__main__':
    file = BindingWrapper(file)
    print "Let's see what happens when we accidently rebind file."
    file = 42
    print "oops."
###





So you can try doing this at the top of your program:

###
from BindingWrapper import BindingWrapper
file = BindingWrapper(file)
###

and run your program again.  When your 'file' variable gets redirected to
that list, we should be able to see exactly what line number this occurs
in.




Hope this helps!



From max_ig@yahoo.com  Tue Oct 29 12:46:15 2002
From: max_ig@yahoo.com (MIG)
Date: Tue Oct 29 12:46:15 2002
Subject: [Tutor] Tkinter Question
In-Reply-To: <00f701c27f6b$b4074a00$cae68b86@fo5132>
Message-ID: <20021029174544.64565.qmail@web11307.mail.yahoo.com>

Alan,

Have you tried with focusNext(). I don't remmember properly but I've
seen something doing what you want with bind and focusNext. It should
work.

Bye,

Max

PS: if you don't get it just email me again. I'll look for the code. I
can't do it now because I'm not with my own computer.


--- Alan Colburn <aicolburn@yahoo.com> wrote:
> Hi all--
> 
> I have a Tkinter frame with multiple Entry boxes. Users enter
> information in
> each Entry box, perhaps moving from one to the next via the Tab key,
> before
> clicking a button to store the information. A second button closes
> the
> window, because sometimes users will be inputting multiple sets of
> information.
> 
> Here's what I'm looking for help on ... I'd like the user to be able
> to fill
> out the first Entry and move to the next via the Return key. I'm not
> talking
> about just binding the information in the Entry box to the <Return>
> keystroke; I'd like the cursor to actually move to the next Entry
> box. The
> idea, of course, is to make it very fast and easy to enter all the
> information.
> 
> As always, I appreciate your help :-)
> 
> Al C.
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


__________________________________________________
Do you Yahoo!?
HotJobs - Search new jobs daily now
http://hotjobs.yahoo.com/


From dfinner@Kollsman.com  Tue Oct 29 13:23:02 2002
From: dfinner@Kollsman.com (dfinner@Kollsman.com)
Date: Tue Oct 29 13:23:02 2002
Subject: [Tutor] Limit Quoting please!
Message-ID: <85256C61.0065592C.00@Notes.kollsman.com>


I'm enjoying this thread quite a bit.  I am an active member of the Lotus Notes
user community and, quite some time ago, created a special society for folks who
have reached the stage of 'Please ask a new question' and 'Use the Search -
Luke'.

DQSfN.NFSRPaP (Don Quixote Society for Notes.Net Frequent Skulkers, Readers,
Posters, and Participants)
We're a naive and well meaning bunch. Find a windmill and tilt and we will
change the world.


At the risk of being repetitive, I offer a new society for this list:

MPSftiSotHGWEIYQ (Monty Python Society for those in Search of the Holy Grail -
What Exactly IS Your Quest?)

Funny, in _every_ volunteer organization I've belonged to _ever_, those folks
who give the most finally hit the wall.  The good ones work through the
frustration.  The rest give up and go away (I have, belonged to both groups).

Hang in, you can't change everything, but your participation in this endeavor
DOES make the world a better place.

Take care.

Doug

<snip>

I don't want anyone to get discouraged, just that they
understand how to best use this mailing list (and other
mainling lists as well).

An advantage with an automatic reply from a piece of
software is that it's hard to take it personal. :)






From dyoo@hkn.eecs.berkeley.edu  Tue Oct 29 17:11:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue Oct 29 17:11:02 2002
Subject: [Tutor] Limit Quoting please!  [how to keep helpers happy?]
In-Reply-To: <85256C61.0065592C.00@Notes.kollsman.com>
Message-ID: <Pine.LNX.4.44.0210291336200.12265-100000@hkn.eecs.berkeley.edu>


On Tue, 29 Oct 2002 dfinner@Kollsman.com wrote:

> Funny, in _every_ volunteer organization I've belonged to _ever_, those
> folks who give the most finally hit the wall.  The good ones work
> through the frustration.  The rest give up and go away (I have, belonged
> to both groups).


This has echoes of ESR's "How To Ask Questions The Smart Way":

    http://www.tuxedo.org/~esr/faqs/smart-questions.html

Much of the advice ESR gives out about this is specifically tailored to
keep helpers from getting burnt out.  Humans can get tired and cranky;  I
think that's something that's at the heart of this thread.

So if we sound like grumpy old men, chalk it up to a bad hair day or
something like that.



> An advantage with an automatic reply from a piece of software is that
> it's hard to take it personal. :)

But the disadvantage is that the receiver of the reply knows (or thinks)
that the sender didn't take the effort to actually read the question.
I'd feel a bit depressed myself if all I got out of a question was a RTFM.


But I think we're all here on Tutor so that we don't get automatic
replies!  If we wanted automated replies, we could effectively use Google.
Personally, I know that I'm here for the human contact: the 'Python' part
of this is only a peripheral goal.

We've been going at this thread from the point of view of the tutors.
But just as all the helpers here are human, I think we should also
sympathize with the people who tread warily in unfamiliar territory.



Best of wishes!



From alan.gauld@bt.com  Tue Oct 29 18:13:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Oct 29 18:13:01 2002
Subject: [Tutor] Absolute and relative window sizes
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB21840C6E5@mbtlipnt02.btlabs.bt.co.uk>

>  I've created a GUI (Tk) that uses a single frame.  

> ...my Listbox applications work great using relative size/position 
> controls - but the menubar doesn't seem to abide by these rules.....

Frames are your friend.
Try putting the menubar inside a frame and all the other controls 
inside another frame, then put both frames inside the application 
frame.

Make sure the frames can expand/fill.

That should now work as you expect...

Alan g


From alan.gauld@bt.com  Tue Oct 29 18:13:17 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Oct 29 18:13:17 2002
Subject: [Tutor] OT: Notion of persistence in Python
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB21840C6E7@mbtlipnt02.btlabs.bt.co.uk>

> If this is terribly OT, I apologize. I've been googling the web for
> information on persistence. 

In its most geneal sense persistence refers to maintaining state beyond 
a program's lifetime. More commonly nowadays it refers to persisting object
state beyond an objects lifetime. In Python that is most easily achieved 
using the pickle module.

The next step up is to use the shelve module and then you move into 
the realm of databases.

> Is this a notion that is not Pythonic, wrt the use of the 
> language? 

Its supported in Python as described above and is a valid concern 
in any language, but especially OOP ones.

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


From alan.gauld@bt.com  Tue Oct 29 18:13:31 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Oct 29 18:13:31 2002
Subject: [Tutor] Killing Buttons! (in Tk)
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB21840C6E6@mbtlipnt02.btlabs.bt.co.uk>

> Now that I have buttons created - and working, how do I get rid of them? 
> In the application, the buttons change based on the function. 

The normal GUI practice for this kind of thing is to build GUI 
applets within frames. Usually encapsulating them as objects.

Then you can hide or show whole sets of controls as needed by just 
packing/unpacking the objects(or frames). This also means you only 
have the relatively slow process of building the control sets once,
usually at the start of your program.

As I said in another post, frames are your friend.

Alan g


From alan.gauld@bt.com  Tue Oct 29 18:13:48 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue Oct 29 18:13:48 2002
Subject: [Tutor] OT: Notion of persistence in Python
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB21840C6E8@mbtlipnt02.btlabs.bt.co.uk>

BTW Sorry for the lag between posting and replying - I'm on a trainng 
course being "assimilated" by the Siebel corporation machine... :-) 
I only get email during a one off per day synching phone call!

> Taking objects and saving data in them. Is this more 
> advisable than reading from and writing to an RDBMS? 

Depends on what you want. Pickling an oject will not preserve 
the relationships between them in the way that an RDBMS can. Neither 
will it easily allow selective restoration of required objects. If 
you have millions of possible object instances of which only a few 
need to exist at vany instant then a database is the way to 
go, if you only have a few that all need to live in memory 
simultaneously then pickle will likely be better.

Alan G.


From Gillisai@btinternet.com  Tue Oct 29 18:25:35 2002
From: Gillisai@btinternet.com (Alex Gillis)
Date: Tue Oct 29 18:25:35 2002
Subject: [Tutor] What uni course to do?
Message-ID: <004601c27fa1$3d43a220$3f5d063e@oemcomputer>

This is a multi-part message in MIME format.

------=_NextPart_000_0043_01C27FA1.3C170900
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I'm on a gap year at the moment, coz i got cold feet about the =
theoretical physics course i was gonna do.  I thought I'd ask you advice =
on what course you'd recommend coz you're a bunch of technically minded =
people who have probably been through it. =20

Anyway basically I want to do something with a lot of problem solving =
eg. maths, physics, programming.  I get bored easily and then won't work =
then but on the flip side if something interests me I'll stay up all =
night learning/playing with it.  I lose interest if I'm supposed to use =
something without understanding it or practicing something a lot which =
I'm never going to use outside of a test.  I also like graphics though I =
wouldn't go out my way to include this in a course.. =20

Finding a uni where i can tailor my course sounds good, that way i can =
cut out the mass amount of context in society and theory crap they teach =
on some courses and also keep up with all the areas that interests me.  =
I don't really agree with the hard edge definitions between programming, =
maths and physics, they're kinda like the trinity (ponder that one if =
you will).

Any help/advice would be much appreciated and very useful.

------=_NextPart_000_0043_01C27FA1.3C170900
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 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I'm on a gap year at the moment, coz i =
got cold=20
feet about the theoretical physics course i was gonna do.&nbsp; I =
thought I'd=20
ask you advice on what course you'd recommend coz you're a bunch of =
technically=20
minded people who have probably been through it.&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Anyway basically I want to do something =
with a lot=20
of problem solving eg. maths, physics, programming.&nbsp; I get bored =
easily and=20
then won't work then but on the flip side if something interests me I'll =
stay up=20
all night learning/playing with it.&nbsp; I lose interest if I'm =
supposed to use=20
something without understanding it or practicing something a lot which =
I'm never=20
going to use outside of a test.&nbsp; I also like graphics though I =
wouldn't go=20
out my way to include this in a course..&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Finding a uni where i can tailor my =
course sounds=20
good, that way i can cut out the mass amount of context in society and =
theory=20
crap they teach on some courses and also keep up with all the areas that =

interests me.&nbsp; I don't really agree with the hard edge definitions =
between=20
programming, maths and physics, they're kinda like the trinity (ponder =
that one=20
if you will).</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Any help/advice would be much =
appreciated and very=20
useful.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0043_01C27FA1.3C170900--



From gus.tabares@verizon.net  Tue Oct 29 19:14:01 2002
From: gus.tabares@verizon.net (Gus Tabares)
Date: Tue Oct 29 19:14:01 2002
Subject: [Tutor] IDLE in Linux
Message-ID: <3DBF23C1.8000201@verizon.net>

Hello,

    I was trying to find a doc on installing IDLE under Linux. 
Python.org only seems to mention that it is in the /Tools/idle of the 
sourceball. I assumed to run setup.py within that directory but nothing 
seems to happen when I execute it (blinking cursor on newline). Are 
there any docs out there I could be looking at? Thanks..


Gus



From dylan.belsey@baesystems.com  Tue Oct 29 19:57:00 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Tue Oct 29 19:57:00 2002
Subject: [Tutor] What uni course to do?
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B98D2B01@wtntex1.baea.com.au>

    I'll be the first to admit that it can be very tedious but fortunately,
some of the context in society and theory crap helps to give me a more
rounded and objective view on what it is we are actually doing and realise
the broader picture.
 
    [Stepping off the soap box....] I'm not sure if we can give you
specifics as to the courses you could do, with the subscribers being from
all around the globe (cool isn't it!), however, in my experience I have
found that a few of the "applied" subjects/modules tend to bring together
programming, maths and physics.  Most applied mathematics and physics
modules ultimately end up using some kind of programming to carry out
mathematical computations or repetitive tasks to achieve an end result or
demonstrate a theory (often within certain bounds).  Some of these topics
included Signal Theory, Financial Mathematics and Quantum Mechanics (I'm
sure you are aware of these types of modules, realising that you are at the
stage of considering taking theoretical physics).
 
    I have an electrical eng background and I found that many of the
elective courses, offered the blend you may be looking for.  Such topics as
data, voice and video codecs/filtering/compression (from memory) could be
included in this area.  The trick, as I'm sure you know, is that you have to
do all the boring foundation subjects to get to the interesting ones.
 
    Anyway, I don't know if I've been of much help, but to sum up, have a
look at the syllabuses of the "applied" subjects that are available to you.
Electrical Eng offers the chance to apply computing/mathematics/physics etc
in the real world (I do have an obvious bias here).  Even Computer Eng or
Computer Science courses may offer what you are looking for (inc. the chance
to develop your own projects around mathematical or physics
principles/theory).
    
    Good luck,
        Dylan


From magnus@thinkware.se  Tue Oct 29 20:04:03 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Tue Oct 29 20:04:03 2002
Subject: [Tutor] IDLE in Linux
In-Reply-To: <3DBF23C1.8000201@verizon.net>
Message-ID: <5.1.0.14.0.20021030020805.02b75428@www.thinkware.se>

At 19:11 2002-10-29 -0500, Gus Tabares wrote:
>   I was trying to find a doc on installing IDLE under Linux. Python.org 
> only seems to mention that it is in the /Tools/idle of the sourceball. I 
> assumed to run setup.py within that directory but nothing seems to happen 
> when I execute it (blinking cursor on newline). Are there any docs out 
> there I could be looking at? Thanks..

How do you run setup?

python setup.py install

is probably what you want.

BTW, the IDLE-fork version is better in my opinion.
http://idlefork.sourceforge.net/


-- 
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 i812@softhome.net  Tue Oct 29 20:38:01 2002
From: i812@softhome.net (Rob McGee)
Date: Tue Oct 29 20:38:01 2002
Subject: [Tutor] IDLE in Linux
In-Reply-To: <3DBF23C1.8000201@verizon.net>
References: <3DBF23C1.8000201@verizon.net>
Message-ID: <20021030013733.GH4022@hal.1984.lan>

On Tue, Oct 29, 2002 at 07:11:45PM -0500, Gus Tabares wrote:
>    I was trying to find a doc on installing IDLE under Linux. 
> Python.org only seems to mention that it is in the /Tools/idle of the 
> sourceball. I assumed to run setup.py within that directory but nothing 
> seems to happen when I execute it (blinking cursor on newline). Are 
> there any docs out there I could be looking at? Thanks..

You don't "install" it. Just go to the idle directory and run
  ./idle.py &
There's a README.txt in the idle directory which tells you this. The "&"
is in case you don't want to lose the use of your xterm, it's optional
(it tells bash to run the command as a background job.)

For convenience you might want to configure a shortcut of some sort in
whatever window manager / desktop environment you use. The command is
simply "/full-path-to/idle.py" ("full-path-to" varies depending on where
you have your Python.)

    Rob - /dev/rob0


From nano@intermatik.co.id  Tue Oct 29 23:04:01 2002
From: nano@intermatik.co.id (nano)
Date: Tue Oct 29 23:04:01 2002
Subject: [Tutor] development tools
Message-ID: <1035949024.4224.101.camel@jrwd.internal.intermatik.com>

Hi guys,

I need some advice. In near future I want to develop some applications,
majorly it will be web-based aplications for business-related service. 
I want to use development tools, (like Webware,Twisted,etc); but confuse
to make a choice. Actually I have some criteria for the tools(priority
order):
* compatible with Python and/or C
* have a good ability/facility/features
* supporting newest technology/standard: like xml,etc
* multi os(win/linux)
* easyly to be learned
* easily to be updated
* flexible (example: Webware is more flexible than Zope)
* fast-development
I need your advice here, since I don't have enough experience in Python
(4 months for Python, in my one year programming experience), evenmore
in using development tools.

One more, can you gave me some example for using C/C++ module in Python?

I'm not very good in explaining something in English, sorry for that.

TIA

nano'



From magnus@thinkware.se  Wed Oct 30 05:13:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Oct 30 05:13:01 2002
Subject: [Tutor] development tools
In-Reply-To: <1035949024.4224.101.camel@jrwd.internal.intermatik.com>
Message-ID: <5.1.0.14.0.20021030102358.02a90508@www.thinkware.se>

At 11:00 2002-10-30 +0700, nano wrote:
>One more, can you gave me some example for using C/C++ module in Python?

I'm not sure if you mean when to use it or how to use it.

If when: Don't use C or C++ unless you need to!
It's a much less productive development environment,
and it will make maintenance of the code harder.
Typically you use it either to improve performance
or to interface with some other code written in
C or C++. If you need to interface with a standard
product written in C ot C++, chances are good that
there is already an interface, but if not, you might
have to write that. If the interface is for a piece
of software which is publically available, consider
making the python interface available on the net, so
that others can use it and help maintain it.

If you have performance problems, profile your
code. The profiling will probably point of some
small part of your code as taking up more than
half of the execution time, maybe much more. Look
closely at this, and not only on the details but
also from a helicopter perspective. Is there some
simple coding changes you can do? Can you restructure
your program, or solve the problem from a different
angle? If none of these things work, you can consider
to rewrite portions in C or C++. Before you write
extension modules you canhave a look at psyco, pyrex
or weave to see if they can fix your problem.

If how, a full answer would be long... It depends very
much on how big it is, whether you need to access
python data from C/C++ etc. There are two standard
manuals for this (Extending & Embedding and Python C/API),
and a number of tools. For C, SWIG is commonly used,
and for C++ Boost might be best. See
http://www.thinkware.se/cgi-bin/thinki.cgi/UsingPythonWithOtherLanguages

The interfaces for SQL databases such as PostgreSQL,
MySQL or Oracle are partly written in C. wxPython is
mainly a wrapper for a C++ toolkit (using SWIG). Look
at the sources for something like this to see how to
do things, but be aware that code might be generated
by SWIG etc.

Concerning toolkits, I won't recommend any product.
I don't have enough experience of either. I am curious
about Twisted, and was never impressed by WebWare, but
I don't know either of them well.

Personally, I'd probably make sure that my business logic
ran as pure, independent python modules, that I could
test and run without the web, and I'd try to hide the
persistence mechanism, SQL interface or whatever, from the
business logic as well. I find this separation of presentation,
logic and storage to be very useful for several reasons:
  * Easier to reuse code.
  * Easier to adapt to business changes.
  * Easier to test.
  * Easier to understand the code.
  * Easier to change toolkit or framework if need be.

Of course, the disadvantage might be that you don't use
all the features in the framework or toolkit you have.
You might duplicate some functionality to achieve this
freedom. Whether it's worth it is a judgement call. You
must do that based on your situation.



-- 
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 Gillisai@btinternet.com  Wed Oct 30 06:00:02 2002
From: Gillisai@btinternet.com (Alex Gillis)
Date: Wed Oct 30 06:00:02 2002
Subject: [Tutor] destroy object in Vpython
Message-ID: <001501c28002$42cfcdc0$382b7ad5@oemcomputer>

This is a multi-part message in MIME format.

------=_NextPart_000_0012_01C28002.41A334A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Does anyone know what the function to destroy an object (eg.sphere) in =
Vpython is assuming there is one.  I want to create objects and later =
destroy them at variuos points in space. =20

PS.  Is this another one of those really beginner questions?

------=_NextPart_000_0012_01C28002.41A334A0
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 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Does anyone know what the function to =
destroy an=20
object (eg.sphere) in Vpython is assuming there is one.&nbsp;&nbsp;I =
want to=20
create objects and later destroy them at variuos points in space.&nbsp;=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>PS.&nbsp; Is this another one of those =
really=20
beginner questions?</FONT></DIV></BODY></HTML>

------=_NextPart_000_0012_01C28002.41A334A0--



From gus.tabares@verizon.net  Wed Oct 30 06:18:01 2002
From: gus.tabares@verizon.net (Gus Tabares)
Date: Wed Oct 30 06:18:01 2002
Subject: [Tutor] IDLE in Linux
In-Reply-To: <5.1.0.14.0.20021030020805.02b75428@www.thinkware.se>
References: <5.1.0.14.0.20021030020805.02b75428@www.thinkware.se>
Message-ID: <3DBFBF95.8020801@verizon.net>

Magnus Lycka wrote:

> At 19:11 2002-10-29 -0500, Gus Tabares wrote:
>
>>   I was trying to find a doc on installing IDLE under Linux. 
>> Python.org only seems to mention that it is in the /Tools/idle of the 
>> sourceball. I assumed to run setup.py within that directory but 
>> nothing seems to happen when I execute it (blinking cursor on 
>> newline). Are there any docs out there I could be looking at? Thanks..
>
>
> How do you run setup?
>
> python setup.py install
>
> is probably what you want.
>
> BTW, the IDLE-fork version is better in my opinion.
> http://idlefork.sourceforge.net/
>
>
Worked, thanks. I will check out IDLE-fork while I'm at it. Thanks again


Gus



From Gillisai@btinternet.com  Wed Oct 30 10:50:02 2002
From: Gillisai@btinternet.com (Alex Gillis)
Date: Wed Oct 30 10:50:02 2002
Subject: [Tutor] IGNORE destroy object in Vpython
Message-ID: <001801c2802a$d0bca180$f53f7ad5@oemcomputer>

This is a multi-part message in MIME format.

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

Sorry just answered my own question.  Though while my crediblity is low =
I'll ask how to use the zeros function in Numeric, I import it fine but =
it won't recognise the parameters.  I want to create an empty array of =
variable length with content integers.

------=_NextPart_000_0015_01C2802A.CF5C2720
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 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Sorry just answered my own =
question.&nbsp; Though=20
while my crediblity is low I'll ask how to use the zeros function in =
Numeric, I=20
import it fine but it won't recognise the parameters.&nbsp; I want to =
create an=20
empty array of variable length with content =
integers.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0015_01C2802A.CF5C2720--



From abarker@xminc.com  Wed Oct 30 12:22:06 2002
From: abarker@xminc.com (Anthony Barker)
Date: Wed Oct 30 12:22:06 2002
Subject: [Tutor] Distributed Python module similar to Distributed Ruby
Message-ID: <24337.198.96.180.245.1035999583.squirrel@www.xminc.com>

Is anyone aware of a module similar to Distributed Ruby - DRB?

http://www.rubycentral.com/articles/drb.html

It looks much nicer/easier than anything I have seen like
corba/com/xpcom/uno(uno gets close)

Anthony




From dyoo@hkn.eecs.berkeley.edu  Wed Oct 30 13:11:02 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed Oct 30 13:11:02 2002
Subject: [Tutor] How to use Numeric.zeros() / Resizing an array
In-Reply-To: <001801c2802a$d0bca180$f53f7ad5@oemcomputer>
Message-ID: <Pine.LNX.4.44.0210300959380.8149-100000@hkn.eecs.berkeley.edu>


On Wed, 30 Oct 2002, Alex Gillis wrote:

> I'll ask how to use the zeros function in Numeric, I import it fine but
> it won't recognise the parameters.  I want to create an empty array of
> variable length with content integers.

Hi Alex,

Can you show us what you tried?  We may be able to help you interpret the
error messages so that they make more sense.



The shape of Numeric arrays is fixed at construction time:

###
>>> import Numeric
>>>
>>> Numeric.zeros
<built-in function zeros>
>>>
>>> Numeric.zeros.__doc__
"zeros((d1,...,dn),typecode='l',savespace=0) will return a new array of
shape (d1,...,dn) and type typecode with all it's entries initialized to
zero.  If savespace is nonzero the array will be a spacesaver array."
>>>
>>> Numeric.zeros([10,10])
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
###



so unlike Python lists, Numeric arrays don't expand automatically.
Instead, an array can be resize()d:

    http://www.pfdubois.com/numpy/html2/numpy-6.html#pgfId-68290


###
>>> z = Numeric.zeros([5, 5])
>>> z
array([[0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0]])
>>> z2 = Numeric.resize(z, (3,3))
>>> z
array([[0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0]])
>>> z2
array([[0, 0, 0],
       [0, 0, 0],
       [0, 0, 0]])
###


Is this what you're looking for?



Good luck!



From magnus@thinkware.se  Wed Oct 30 13:34:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Oct 30 13:34:02 2002
Subject: [Tutor] Distributed Python module similar to Distributed
 Ruby
In-Reply-To: <24337.198.96.180.245.1035999583.squirrel@www.xminc.com>
Message-ID: <5.1.0.14.0.20021030190305.02c57fe0@www.thinkware.se>

At 12:39 2002-10-30 -0500, Anthony Barker wrote:
>Is anyone aware of a module similar to Distributed Ruby - DRB?

I've never user DRB, but there is a number of modules for
distributed operation in Python.

xmlrpclib is included in the standard library and might
be the simplest choice. That's obviously a standard thingie
that is fairly wide spread and can be used to communicate
with non-python stuff.

There are a number of options listed in
http://www.thinkware.se/cgi-bin/thinki.cgi/UsingPythonWithOtherLanguages

There are both SOAP, CORBA, COM solutions and
more unique Python things such as PYRO and DOPY.


-- 
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 mark.brown@rogers.com  Wed Oct 30 19:15:02 2002
From: mark.brown@rogers.com (Mark Brown)
Date: Wed Oct 30 19:15:02 2002
Subject: [Tutor] Just Learning Python
Message-ID: <1036023353.1491.18.camel@localhost.localdomain>

I'm just learning Python and found a simple program that I'm trying to
convert to using 'class'.

The main program is 'runit2.py':

#!/usr/bin/env python

from runit2ui import *

app1 = App1()
app1.mainloop()

The user interface program is 'runit2ui.py':

#!/usr/bin/env python

from Tkinter import *
from os import system
from sys import exit

class App1:
	def __init__(self):
            root = Tk()
            root.title('PyRun')
            label = Label(root, text="Run")
            label.pack(side=LEFT)
            entry = Entry(root, takefocus=TRUE)
            entry.pack(side=LEFT, fill=X, expand=TRUE)
            entry.bind('<Key-Return>', runit)
            entry.focus()

        def runit(event):
            text = entry.get()
            command = "%s &" % text
            system(command)
            exit(0)

When 'runit2.py' is run the following error is reported:

Traceback (most recent call last):
  File "/home/mark/Projects/project2/runit2.py", line 5, in ?
    app1 = App1()
  File "/home/mark/Projects/project2/runit2ui.py", line 15, in __init__
    entry.bind('<Key-Return>', runit)
NameError: global name 'runit' is not defined


What needs to be changed to get by this error?
Thanks
Mark




From dylan.belsey@baesystems.com  Wed Oct 30 19:19:01 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Wed Oct 30 19:19:01 2002
Subject: [Tutor] Just Learning Python
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B98D2B09@wtntex1.baea.com.au>


Dylan Belsey,
Software Engineer,
AEW&C, GSS, SV&VE, MCIS,
Air 5077 (Wedgetail).
BAE SYSTEMS

Address:
              LIFF,
              Williamtown Drive,
              Williamtown, 
              NSW, 2318.
E-mail: dylan.belsey@baesystems.com
Phone: +61-2-4928 9241


-----Original Message-----
From: Mark Brown [mailto:mark.brown@rogers.com]
Sent: Thursday, 31 October 2002 11:16
To: tutor@python.org
Subject: [Tutor] Just Learning Python


I'm just learning Python and found a simple program that I'm trying to
convert to using 'class'.

The main program is 'runit2.py':

#!/usr/bin/env python

from runit2ui import *

app1 = App1()
app1.mainloop()

The user interface program is 'runit2ui.py':

#!/usr/bin/env python
Hi Mark,
	You need to tell the interpreter where t



_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


From dylan.belsey@baesystems.com  Wed Oct 30 19:24:01 2002
From: dylan.belsey@baesystems.com (BELSEY, Dylan)
Date: Wed Oct 30 19:24:01 2002
Subject: [Tutor] Just Learning Python
Message-ID: <86C3892A0C52D411AF5000A0C9EAA3B98D2B0A@wtntex1.baea.com.au>

Apologies to everyone....technical difficulties with the mail program

Hi Mark,
	The interpreter needs to know where the function exists.  Because
you have not told it that it lives in the class namespace it attempts to
look for it globally and cannot find it.
	To tell it that it is a method of the class, you need to prefix
these calls with  "self." just as you do for attributes of the class i.e.
"self.runit"

	HTH,
		Dylan


From magnus@thinkware.se  Wed Oct 30 20:03:02 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Wed Oct 30 20:03:02 2002
Subject: [Tutor] Just Learning Python
In-Reply-To: <1036023353.1491.18.camel@localhost.localdomain>
Message-ID: <5.1.0.14.0.20021031015940.02b27b78@www.thinkware.se>

At 19:15 2002-10-30 -0500, Mark Brown wrote:
>class App1:
>         def __init__(self):
>             root = Tk()
>             root.title('PyRun')
>             label = Label(root, text="Run")
>             label.pack(side=LEFT)
>             entry = Entry(root, takefocus=TRUE)
>             entry.pack(side=LEFT, fill=X, expand=TRUE)
>             entry.bind('<Key-Return>', runit)

change "runit" to "self.runit"

>             entry.focus()
>
>         def runit(event):

Change to "def runit(self, event):

>             text = entry.get()
>             command = "%s &" % text
>             system(command)
>             exit(0)

(Haven't tested. This is just what I saw right away.)

You always have to provide an instance object to a method.
This is by convention called "self" in Python.

So, with

class A:
     def set_x(self, x):
         self.x = x

a = A()

The following lines are equivalent:
a.set_x(5)
A.set_x(a, 5)

Typically we use the first, but it's really just
a short form of the first. After all, the method
is in the class object, not in the instance object...

Remember to do

 >>> import this

in your python interpreter

Explicit is better than implicit.



-- 
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 cwyglendowski@greenville.edu  Wed Oct 30 23:46:02 2002
From: cwyglendowski@greenville.edu (Christian Wyglendowski)
Date: Wed Oct 30 23:46:02 2002
Subject: [Tutor] Location of object instance in a list
Message-ID: <sdc06036.012@gwprimary.greenville.edu>

Hi everyone.  Ok, here it is...my first real question for the list.

I am trying to learn about object oriented design with python.  I have =
decided to make a computer based boardgame or something like one.  So far, =
I have a class for the board that looks like this (very basic):

class Board:
    def __init__(self, width=3D10, height=3D10):
        self.width =3D width
        self.height =3D height
        self.surface =3D []
        for eachY in range(self.height):
            self.surface.append([])
            for eachX in range(self.width):
                self.surface[eachY].append([])

    def __str__(self):
        s =3D ''
        for row in range(self.height):
            for column in range(self.width):
                s =3D s + str(self.surface[row][column])
            if len(s) > 0: s =3D s + '\n'
        return s

So I have a board that I can access with x/y coordinates...

>>> test =3D Board()
>>> test.surface[0][0].append('Cool object instance')

Now, let's say that I actually did append a 'Cool object instance' to =
test.surface[0][0] and not just a string by the same name.  Is there =
anyway the said object instance can have knowledge of its place in the =
list of lists (test.surface[x][y])?  If so, I can then give the objects =
the ability to move around the Board.surface[x][y] fairly easily.

I was able to create a method for Board that allowed me to move the =
contents of the [x][y] lists around, but if they are to contain object =
instances - it just seems that the instances themselves should have the =
ability to move, and not have the board pushing them around...

class GamePiece:
    pass

Also, if I am heading in the completely wrong direction with all of this, =
let me know!

Thanks,

Christian


From emile@fenx.com  Thu Oct 31 02:00:02 2002
From: emile@fenx.com (Emile van Sebille)
Date: Thu Oct 31 02:00:02 2002
Subject: [Tutor] Re: Location of object instance in a list
References: <sdc06036.012@gwprimary.greenville.edu>
Message-ID: <apqk9t$hnl$1@main.gmane.org>

Hi Christian,

I saw your question and although I've never tried to write a game like
this, I was interested to see how it might work out, so I played around
a bit and came up with something.  It certainly feels like a class
GamePiece is moving in the right direction to me.  Note that I
initialize the board with Square instances that know their location, and
that the assignments (eg b[1,2]='1,2') could just as easily be
b[1,2]=GamePiece('Pawn').  Anyway, perhaps you'll find some ideas to
help you along.


class Square:
    def __init__(self, ww, hh):
        self.ww = ww
        self.hh = hh
        self.name = '...'
    def __str__(self):
        return self.name
    __repr__=__str__
    def __call__(self, val):
        self.name = val

class Board1:
    def __init__(self, width=10, height=10):
        self.width = width
        self.height = height
        self.surface = [ [Square(hh,ww) for hh in range(height)] for ww
in range(width)]
    def __str__(self):
        return '\n'.join([' '.join([`col` for col in row]) for row in
b.surface])
    def __setitem__(self, ky, val):
        ww,hh = ky
        self.surface[ww][hh](val)

b = Board1()
print b
b[1,2]='1,2'
b[3,5]='3,5'
b[6,8]='6,8'
print b


--

Emile van Sebille
emile@fenx.com

---------





From magnus@thinkware.se  Thu Oct 31 04:55:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu Oct 31 04:55:01 2002
Subject: [Tutor] Location of object instance in a list
In-Reply-To: <sdc06036.012@gwprimary.greenville.edu>
Message-ID: <5.1.0.14.0.20021031095502.031c3e70@www.thinkware.se>

At 22:41 2002-10-30 -0600, Christian Wyglendowski wrote:
>Now, let's say that I actually did append a 'Cool object instance' to 
>test.surface[0][0] and not just a string by the same name.  Is there 
>anyway the said object instance can have knowledge of its place in the 
>list of lists (test.surface[x][y])?  If so, I can then give the objects 
>the ability to move around the Board.surface[x][y] fairly easily.

Not by itself, no. An object knows what it has, but
it doesn't know where there are references to it.
This is the way we want things. It's part of the
separation of concern that we want to achieve in
computer programs.

If we want a two-directional "awareness" about
relations, we have to make this explicit.

One way to solve this, is to make the board an
attribute of the CoolObject, and to let the board
handle moves.

class CoolObject:
     def __init__(self, board, name):
         self.board = board
         self.name = name
     def move(self, direction):
         self.board.move(direction, self)

Then in the Board class you could do:

     test.surface[0][0].append(CoolObject(self, 'Black Queen'))

and have the method:
     def move(self, direction, pawn):
         directions = {'up': (0,-1), 'down': (0,1),
                       'left': (-1,0), 'right': (1,0)}
         assert direction in directions.keys()
         x,y = self.findPawn(pawn) # Left to you...
         newX, newY = x + directions[direction][0], \
                      y + directions[direction][1]
         if self.availableLocation(newX, newY):
             self.surface[x,y].remove(pawn)
             self.surface[newX,newY].append(pawn)

Of course, it you only have one board, the board instance
could be a global variable, but I think you have memory
enough in your compute to keep a reference in every pawn...

Anyway, built like this, the only thing the CoolObject
class needs to know about movement are which directions
there is, and that's fairly simple to change. This means
that you can change a lot in the design and implementation
of the Board without having to change the CoolObject class.

Depending on the game, it might turn out that the CoolObject
needs to know a lot about it's surroundings to be able to
decide its moves. But is should then be able to get this
information in a generic fashion from public methods and
attributes in the Board class.

Another option would be to have a separate "controller"
object handle the movements, but I don't really like
that style of programming. Mr UseCase, Ivar Jacobson
of Rational, RUP and UML fame advocates this style
with separate controller and entity objects, but I feel
that this separation usually leads to a style of
programming which fails to bring out the advantage of
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 alan.gauld@bt.com  Thu Oct 31 12:41:03 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu Oct 31 12:41:03 2002
Subject: [Tutor] Just Learning Python
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9EF@mbtlipnt02.btlabs.bt.co.uk>

 
> class App1:
> 	def __init__(self):
>             root = Tk()
...
>             entry = Entry(root, takefocus=TRUE)

And since you access entry within runit you need to store it as a 
class variable, hence use self.entry
 
>             entry.bind('<Key-Return>', runit)

You need to bind self.runit. Otherwise Python is looking for a function
in the global namespace called runit...

>         def runit(event):

As a method this must have a patrameter referencing the class instance
first, thus you need:

          def runit(self, event):

>             text = entry.get()

And since entry is a class variable(see above) you need to access it as
self.entry

>             command = "%s &" % text
>             system(command)

Personally I'd probably just do:

             system(self.entry.get() + ' &')

and miss out the other stuff.
However if you might start adding arguments to the command then your 
approach is better...

> NameError: global name 'runit' is not defined

Thats the lack of self in front of the runit refeence.
But you need to fix the other bits too...

Alan g.


From alan.gauld@bt.com  Thu Oct 31 12:53:38 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu Oct 31 12:53:38 2002
Subject: [Tutor] Location of object instance in a list
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9F0@mbtlipnt02.btlabs.bt.co.uk>

> I am trying to learn about object oriented design with 
> python.  I have decided to make a computer based boardgame 


> >>> test = Board()
> >>> test.surface[0][0].append('Cool object instance')

Actually this won't work since you have defined surface to 
be a one dimensional list!

However better still would be to hide the surface completely
and provide a place() method, say, that did it for you:

test.place(piece, x, y)

which places a piece object at x,y.

> same name.  Is there anyway the said object instance can have 
> knowledge of its place in the list of lists 

It shouldn't know that. Otherwise it becomes tightly coupled to the 
representation of the board - which is bad OOD.

> (test.surface[x][y])?  If so, I can then give the objects the 
> ability to move around the Board.surface[x][y] fairly easily.

So pass the board to the piece which can then ask it to place itself...

class Piece:
   def move(self, board):
       board.place(self, newX, newY)

Or maybe the board should have a move method to move pieces...

   def move(self, piece, x, y):
       oldX, oldY = self.locate(piece)
       self.place(None, oldX, oldY)
       self.place(piece, x, y)

> instances themselves should have the ability to move, and not 
> have the board pushing them around...

It depends. Do the pieces know what kind of board they are on?
OTOH Does the board know the rules of movement?
Or are they controlled by another object - a Game say?
But maybe if the pieces can only be used for one game type 
your idea is OK - probably true for chess pieces, but not 
for checkers or Ludo counters say...

The question you must answer is what are the responsibilities of 
the piece and board respectively? Which one is responsible for 
knowing about movement, location etc. There is no absolute answer 
to this but hopefully the principles shown above might help...

HTH,

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


From magnus@thinkware.se  Thu Oct 31 13:26:37 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu Oct 31 13:26:37 2002
Subject: [Tutor] Just Learning Python
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9EF@mbtlipnt02.btlabs
 .bt.co.uk>
Message-ID: <5.1.0.14.0.20021031190606.0322be30@www.thinkware.se>

At 17:37 2002-10-31 +0000, alan.gauld@bt.com wrote:
> >             command = "%s &" % text
> >             system(command)
>
>Personally I'd probably just do:
>
>              system(self.entry.get() + ' &')

Experienced C and C++ programmers (at least) often avoid this
type of doing several things on the same line, and perfer the
longer approach shown in the top. This is because it's often
difficult to figure out what compiler warnings or error mesasges
refer to if several things happen on the same line.

With the splendid tracebacks and clearer error messages in
python, this is much less of a problem there, and you often
see the construct Alan suggests. I certainly write like that
as well, unless it leads to very long lines, or unclear code.

Sometimes an extra variable name can make it easier to
understand the code.

Which version is easier to understnd is a matter of taste.
In general, I feel that it's usually easier to understand a
shorter program than a larger, even it the same amount of
operations are performed. At least in python.

Also, these kinds of choices might have some performance
impact in Python, since the code is not optimized and
compiled as in C or C++. Don't be certain that shorter
is faster 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 alan.gauld@bt.com  Thu Oct 31 13:34:01 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu Oct 31 13:34:01 2002
Subject: [Tutor] Location of object instance in a list
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C9F1@mbtlipnt02.btlabs.bt.co.uk>

> Another option would be to have a separate "controller"
> object handle the movements, but I don't really like
> that style of programming. Mr UseCase, Ivar Jacobson
> of Rational, RUP and UML fame advocates this style

Controller objects are useful but there is a real danger 
of abusing them. They are a useful aid to managing a usecase
but they are not needed in every usecase (as Jacobsen himself 
stresses) only where sequencing behaviour would otherwise 
wind up in an inappropriate place.

> with separate controller and entity objects, but I feel
> that this separation usually leads to a style of
> programming which fails to bring out the advantage of
> an object-oriented approach.

If abused it can lead to a terrible style of programming
which combines the worst of procedural and OO in one package!
Use controllers with care and have them delegate as much as 
possible to the interface and entity objects. If controllers 
have many state variables then you probably got something wrong!

A good example of a use for a controller would be in a 
transaction requiring a multi phase commit. The controller 
monitors each phase of the transaction (each being carried out 
by its own object and then applies the commit/rollback to 
each and reports success or failure to the initiating object.

In that way the only thing that knows about the complexity 
of the particular transaction is the controller all other 
objects (including the initiator object) are potentially reusable.
Controllers are inherently bespoke, non reusable and are there 
to improve reusability of the other objects.

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


From africom@africaonline.co.ke  Thu Oct 31 14:54:32 2002
From: africom@africaonline.co.ke (Tom)
Date: Thu Oct 31 14:54:32 2002
Subject: [Tutor] infor
Message-ID: <000d01c280f6$4e3261b0$1101a8c0@africomlink16>

This is a multi-part message in MIME format.

------=_NextPart_000_000A_01C280B3.3D843110
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

i would like all information you can give me on the python =
language(books, cds websites, other members) to help me learn the =
language.
postal adress:     rufus m maina,
                         p. o. box 3070
                         nakuru
                         kenya
email:suxcon@yahoo.com

------=_NextPart_000_000A_01C280B3.3D843110
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.2920.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>i would like all information you can =
give me on the=20
<U>python </U>language(books, cds websites, other members) to help me =
learn the=20
language.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>postal adress: &nbsp;&nbsp;&nbsp; rufus =
m=20
maina,</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;=20
p. o. box 3070</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;nakuru</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp;&nbsp; kenya</FONT></DIV>
<DIV><FONT face=3DArial size=3D2><A=20
href=3D"mailto:email:suxcon@yahoo.com">email:suxcon@yahoo.com</A></FONT><=
/DIV></BODY></HTML>

------=_NextPart_000_000A_01C280B3.3D843110--




From SWidney@ci.las-vegas.nv.us  Thu Oct 31 15:06:02 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Thu Oct 31 15:06:02 2002
Subject: [Tutor] Just Learning Python
Message-ID: <0E5508EBA1620743B409A2B8365DE16FDC8212@sovereign.ci.las-vegas.nv.us>

> The main program is 'runit2.py':
> 
> #!/usr/bin/env python
> 
> from runit2ui import *
> 
> app1 = App1()
> app1.mainloop()

I'm pretty sure that "app1.mainloop()" should be just "mainloop()" since you
import "runit2ui" into the global namespace. At least that's what I had to
do to get it to run under WXP....


Scott


From python <python@inkedmn.net>  Thu Oct 31 15:15:02 2002
From: python <python@inkedmn.net> (python)
Date: Thu Oct 31 15:15:02 2002
Subject: [Tutor] infor
In-Reply-To: <000d01c280f6$4e3261b0$1101a8c0@africomlink16>
References: <000d01c280f6$4e3261b0$1101a8c0@africomlink16>
Message-ID: <12648950689.20021031120458@inkedmn.net>

www.python.org/doc

T> i would like all information you can give me on the python language(books, cds websites, other members) to help me learn the language.
T> postal adress:     rufus m maina,
T>                          p. o. box 3070
T>                          nakuru
T>                          kenya
T> email:suxcon@yahoo.com



From dyoo@hkn.eecs.berkeley.edu  Thu Oct 31 15:23:15 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu Oct 31 15:23:15 2002
Subject: [Tutor] A hypothetical module system for Useless Python?
Message-ID: <Pine.LNX.4.44.0210311129210.13285-100000@hkn.eecs.berkeley.edu>

Hi everyone,


I've been thinking of writing something to make it easier to submit and
grab programs from Useless Python.  Let me paint out a hypothetical
utility: I'd like suggestions if this is a good idea or not?  Make believe
can be pretty powerful... *grin*


Let's pretend that we've written some neat program that we'd like to share
with others on Useless.  Let's call this program "hello.py".  Then we
could imagine some sort of utility called 'useless' that would let us
submit this program to Useless Python:



######
$ useless submit hello.py

Hello <dyoo@hkn.eecs.berkeley.edu>; I will submit

    hello.py

to Useless Python.

Do you want to attach a version number to this program?  If not, I'll just
attach a new version number to the program.

[1.0] >>> 1.0

Please give a one-liner description of your program below:

>>> This is your standard hello world program.

Here's a quick summary of what I'm about to submit to Useless:

******
Program: hello.py
Version: 1.0
Submitter: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
Description: This is your standard hello world program.
******

Does this look ok?

[y/n?] >>> y

Sending...

Ok, I've sent your file to Useless Python.  You can check the status of
your submission online at http://uselesspython.org.  You can check the
status of your program by visiting your page on Useless, or query for it
with the command:

    useless info limbo/dyoo@hkn.eecs.berkeley.edu/hello.py

Bye!




$ useless info dyoo@hkn.eecs.berkeley.edu
Real name: Danny Yoo

Programs written:
    limbo/dyoo@hkn.eecs.berkeley.edu/hello.py [1.0]
    This is your standard hello world program.

Bye!




$ useless info hello.py
There are 3 programs with the name 'hello.py'.
    limbo/dyoo@hkn.eecs.berkeley.edu/hello.py/1.0
        This is your standard hello world program.

    simple/rob@uselesspython.com/hello.py/1.0
        This is another hello world program.

    simple/rob@uselesspython.com/hello.py/2.0
        This is another hello world program, with a different version
        number.

Bye!



$ useless info limbo

There is 1 program in the 'limbo' category.
    limbo/dyoo@hkn.eecs.berkeley.edu/hello.py/1.0
        This is your standard hello world program.

Bye!




$ useless get limbo/dyoo@hkn.eecs.berkeley.edu/hello.py
Automatically choosing the highest version of hello.py [1.0].

I am about to download:

    limbo/dyoo@hkn.eecs.berkeley.edu/hello.py/1.0
        This is your standard hello world program.

Downloading 'hello.py' into current directory... done!

Bye!
######



This is something that's been floating in my head for a while.  I want to
know if this is something that might be useful for Useless.  *grin*



From James.Alexander.McCarney@Cognicase.com  Thu Oct 31 15:29:36 2002
From: James.Alexander.McCarney@Cognicase.com (McCarney, James Alexander)
Date: Thu Oct 31 15:29:36 2002
Subject: [Tutor] A hypothetical module system for Useless Python?
Message-ID: <23FD7B1A77E8D211BCB900001D108C02023FCAB0@camelot>

As good as freshly made Spam and Pickle sandwiches with Cherry Kool-Aid! ;-)

-->
-->I've been thinking of writing something to make it easier to 
-->submit and
-->grab programs from Useless Python.  Let me paint out a hypothetical
-->utility: I'd like suggestions if this is a good idea or not? 
--> Make believe
-->can be pretty powerful... *grin*
-->


From CCampbell@ede.org  Thu Oct 31 15:48:10 2002
From: CCampbell@ede.org (Colin Campbell)
Date: Thu Oct 31 15:48:10 2002
Subject: [Fwd: RE: [Tutor] A hypothetical module system for Useless Python?]
Message-ID: <3DC194F5.4040501@ede.org>

AOL!!!

-------- Original Message --------
Subject: RE: [Tutor] A hypothetical module system for Useless Python?
Date: Thu, 31 Oct 2002 15:28:13 -0500
From: McCarney, James Alexander <James.Alexander.McCarney@Cognicase.com>
To: 'Danny Yoo' <dyoo@hkn.eecs.berkeley.edu>, Tutor <tutor@python.org>

As good as freshly made Spam and Pickle sandwiches with Cherry Kool-Aid! ;-)

-->
-->I've been thinking of writing something to make it easier to
-->submit and
-->grab programs from Useless Python.  Let me paint out a hypothetical
-->utility: I'd like suggestions if this is a good idea or not?
--> Make believe
-->can be pretty powerful... *grin*
-->


-- 
What this country needs is more free speech worth listening to.
   -- Hansell B. Duckett, Associate Chief Justice, US Supreme Court



From Ulrich Wisser <u.wisser@publisher.de>  Thu Oct 31 17:28:02 2002
From: Ulrich Wisser <u.wisser@publisher.de> (Ulrich Wisser)
Date: Thu Oct 31 17:28:02 2002
Subject: [Tutor] compute class name
Message-ID: <16449291856.20021031232657@publisher.de>

Hello,

I would like to create new object instances, but compute the
class name. Simple example

name = "ExampleClass"
obj = name()

obj should now be an instance of Class ExampleClass.
Of course it doesn't work this way, but which?

Thanks

Ulrich



From magnus@thinkware.se  Thu Oct 31 18:56:36 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu Oct 31 18:56:36 2002
Subject: [Tutor] compute class name
In-Reply-To: <16449291856.20021031232657@publisher.de>
Message-ID: <5.1.0.14.0.20021101005533.03221bd8@www.thinkware.se>

At 23:26 2002-10-31 +0100, Ulrich Wisser wrote:
>I would like to create new object instances, but compute the
>class name. Simple example
>
>name = "ExampleClass"
>obj = name()

 >>> class X:
...     def __init__(self):
...             print "An X created"
...
 >>> name = 'X'
 >>> a = eval(name+'()')
An X created
 >>> a
<__main__.X instance at 0x00FA6908>

I'm not entirely sure this is the best way to solve
whatever problem you have though... Also note that:

 >>> class Odd:
...     pass
...
 >>> class Even:
...     pass
...
 >>> x = 3
 >>> if x % 2:
...     klass = Odd
... else:
...     klass = Even
...
 >>> x = klass()
 >>> print x
<__main__.Odd instance at 0x01757FF8>

Classes are first class objects, just like functions,
modules, integers, lists, strings or whatever...

So why take the detour to go via a string?


-- 
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  Thu Oct 31 20:05:04 2002
From: kyle@sent.com (Kyle Babich)
Date: Thu Oct 31 20:05:04 2002
Subject: [Tutor] pausing time and perform on exit
Message-ID: <000a01c28142$a96c31e0$06e5a8ac@chuck>

I actually have two questions--first do date I have never figured out how to
pause time.  The best of come up with is simple while loops that look for
something to happen but its fair to say I'm clueless.

timetosleep = 0
while timetosleep < 60:
    time.sleep(1)
    timetosleep += 1

Any ideas how to pause time?

Also how would I tell the program to do something when the program is exited
by having the window closed to the computer shut down (anything with the
user manually typing 'quit' into the program)?  I don't even know where to
begin with this.

Thank you agian,
Kyle Babich



From emile@fenx.com  Thu Oct 31 20:19:01 2002
From: emile@fenx.com (Emile van Sebille)
Date: Thu Oct 31 20:19:01 2002
Subject: [Tutor] Re: compute class name
References: <16449291856.20021031232657@publisher.de>
Message-ID: <apsknb$iif$1@main.gmane.org>

Ulrich Wisser:
> I would like to create new object instances, but compute the
> class name. Simple example
> 

#----test1.py----
class Test:
    pass

if __name__ == '__main__':
    name = 'Test'
    t = globals()[name]()
    print t

    # now import this module
    import test1
    t1 = test1.__dict__[name]()
    print t1
#---end---

Another thing you could try is directly using a dict:

class OptA:pass
class OptB:pass
class OptC:pass
class OptD:pass

opts = {'OptA':OptA, 'OptB':OptB, 'OptC':OptC, 'OptD':OptD,}

import random

thisclass = random.choice(opts.keys())

ineeda = opts[thisclass]()

print thisclass, ineeda


HTH,

--

Emile van Sebille
emile@fenx.com

---------





From emile@fenx.com  Thu Oct 31 20:36:01 2002
From: emile@fenx.com (Emile van Sebille)
Date: Thu Oct 31 20:36:01 2002
Subject: [Tutor] Re: pausing time and perform on exit
References: <000a01c28142$a96c31e0$06e5a8ac@chuck>
Message-ID: <apslm2$ntp$1@main.gmane.org>

Kyle Babich:
> I actually have two questions--first do date I have never figured out
how to
> pause time.  The best of come up with is simple while loops that look
for
> something to happen but its fair to say I'm clueless.
>
> timetosleep = 0
> while timetosleep < 60:
>     time.sleep(1)

easier to do time.sleep(60)  ;-)  From the docstring:

>>> print time.sleep.__doc__
sleep(seconds)

Delay execution for a given number of seconds.  The argument may be
a floating point number for subsecond precision.
>>>


> Also how would I tell the program to do something when the program is
exited
> by having the window closed to the computer shut down (anything with
the
> user manually typing 'quit' into the program)?  I don't even know
where to
> begin with this.
>

Marc Andre Lemburg speaks to this here:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=34DA199
E.FBC1C07%40uni-duesseldorf.de

The doc string from the post says:
    Singleton that manages exit functions. These function will be
    called upon system exit in reverse order of their registering.

So it sounds like you could (once could have?) queued up a number of
clean-up tasks to be performed before exitting.

HTH,

--

Emile van Sebille
emile@fenx.com

---------





From magnus@thinkware.se  Thu Oct 31 20:45:01 2002
From: magnus@thinkware.se (Magnus Lycka)
Date: Thu Oct 31 20:45:01 2002
Subject: [Tutor] pausing time and perform on exit
In-Reply-To: <000a01c28142$a96c31e0$06e5a8ac@chuck>
Message-ID: <5.1.0.14.0.20021101023103.03245e18@www.thinkware.se>

At 20:04 2002-10-31 -0500, Kyle Babich wrote:
>I actually have two questions--first do date I have never figured out how to
>pause time.

You can do this at will. As soon as you want to pause
time, it actually does that. But since this will also
pause your mental processes together with everything
else, neither you nor anyone else will ever notice! It's
just you who can do this Kyle, and noone ever notices...
What does this have to do with Python? ;)

>The best of come up with is simple while loops that look for
>something to happen but its fair to say I'm clueless.
>
>timetosleep = 0
>while timetosleep < 60:
>     time.sleep(1)
>     timetosleep += 1

Why is this better than "time.sleep(60)" ?

Can you explain a little more what you are trying to achieve?

>Also how would I tell the program to do something when the program is exited
>by having the window closed to the computer shut down (anything with the
>user manually typing 'quit' into the program)?  I don't even know where to
>begin with this.

If you write a GUI program, there will be special
close events that you can bind to a function. I'm
not sure I fully understand your question though.

There is also some general hook for exiting python
programs... Hm... Check the library reference for
sys.exitfunc() and the atexit module.

I don't think there is anything you can do to save
things when the program is being shot down with a
signal though. For a non-gui program I think this
is what happens on computer shutdown.

Or do you just want to stop your program? You have
to explain better...


-- 
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 johnca@ourpla.net  Thu Oct 31 22:53:02 2002
From: johnca@ourpla.net (John Abbe)
Date: Thu Oct 31 22:53:02 2002
Subject: [Tutor] Visiting a URL
Message-ID: <a0511171db9e7aadefbdc@[66.81.124.226]>

I've got a newbie question -- i'm looking at altering PikiePikie to 
notify weblogs.com when my weblog updates. I could get all involved 
in XML-RPC, but it's doable through a plain URL. How do i visit a URL 
in Python?

Thanks! Life,
John
-- 
   ------===>>  AbbeNormal  <<===------  |            ..:::..
    A wiki-weblog, somewhere under the   |         .:::::::*:::.
      multi-dimensional normal curve     |      ..:::::::::::::::..
       http://ourpla.net/cgi/pikie       |....::::::::::*:::::::::::*....