From idiot1@netzero.net  Fri Mar  1 02:40:26 2002
From: idiot1@netzero.net (kirk Bailey)
Date: Thu, 28 Feb 2002 21:40:26 -0500
Subject: [Tutor] path
Message-ID: <3C7EEA1A.44AD95D4@netzero.net>

ok, I want to have a program tell itself where it lives, so it can
figure out path information.
I want it to read a config file, but it has to know where it is, and
use that to read the config file, so it knows where everything else
is! 'pwd' in unix would work, and mabe a few other things, but I do
not seem to stumble over what is needed to do this. when I tell it to
just open the file 'foo.cf' it stumbles, as when it tries to open
'./foo.cf'! Clue eagerly saught, over.

-- 
 
end
	    Respectfully,
			 Kirk D Bailey


+---------------------"Thou Art Free." -Eris----------------------+
| http://www.howlermonkey.net mailto:highprimate@howlermonkey.net |
| http://www.tinylist.org  +--------+  mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking---------------------+
                           +--------+

NOTE: By sending SPAM to this address you agree to pay me a service
fee of $100 for the service of receiving,  storing,  examining, and
deleting your piece of SPAM. I am a postmaster, and take a dim view
of such.
----------------------------------------------------
Sign Up for NetZero Platinum Today
Only $9.95 per month!
http://my.netzero.net/s/signup?r=platinum&refcd=PT97


From shalehperry@attbi.com  Fri Mar  1 02:57:07 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Thu, 28 Feb 2002 18:57:07 -0800 (PST)
Subject: [Tutor] path
In-Reply-To: <3C7EEA1A.44AD95D4@netzero.net>
Message-ID: <XFMail.20020228185707.shalehperry@attbi.com>

On 01-Mar-2002 kirk Bailey wrote:
> ok, I want to have a program tell itself where it lives, so it can
> figure out path information.
> I want it to read a config file, but it has to know where it is, and
> use that to read the config file, so it knows where everything else
> is! 'pwd' in unix would work, and mabe a few other things, but I do
> not seem to stumble over what is needed to do this. when I tell it to
> just open the file 'foo.cf' it stumbles, as when it tries to open
> './foo.cf'! Clue eagerly saught, over.
> 

check out the os and os.path modules.  Lots of path handlers there.


From rickp@telocity.com  Fri Mar  1 03:13:36 2002
From: rickp@telocity.com (Rick Pasotto)
Date: Thu, 28 Feb 2002 22:13:36 -0500
Subject: [Tutor] path
In-Reply-To: <XFMail.20020228185707.shalehperry@attbi.com>
References: <3C7EEA1A.44AD95D4@netzero.net> <XFMail.20020228185707.shalehperry@attbi.com>
Message-ID: <20020301031336.GH3547@tc.niof.net>

On Thu, Feb 28, 2002 at 06:57:07PM -0800, Sean 'Shaleh' Perry wrote:
> 
> On 01-Mar-2002 kirk Bailey wrote:
> > ok, I want to have a program tell itself where it lives, so it can
> > figure out path information.  I want it to read a config file, but
> > it has to know where it is, and use that to read the config file, so
> > it knows where everything else is! 'pwd' in unix would work, and
> > mabe a few other things, but I do not seem to stumble over what is
> > needed to do this. when I tell it to just open the file 'foo.cf' it
> > stumbles, as when it tries to open './foo.cf'! Clue eagerly saught,
> > over.
> > 
> 
> check out the os and os.path modules.  Lots of path handlers there.

At least under unix the question is ill defined.

'pwd' returns the current directory, usually the directory the command
was executed in. This is not necessarily (and usually is not) where the
command program lives. And that is even less well defined. A file can
have many hard links and you can say it lives in *all* of them
simultaneously. A unix file is defined by its inode, not by its path
name.

Kirk needs to define his starting point by convention. Most unix config
file live in /etc or /usr/etc and/or $HOME.

-- 
"Once the principle of government -- judicial monopoly and the power
 to tax -- is incorrectly accepted as just, any notion of restraining
 government power and safeguarding individual liberty and property is
 illusory." -- Hans-Herman Hoppe
    Rick Pasotto    rickp@telocity.com    http://www.niof.net


From dyoo@hkn.eecs.berkeley.edu  Fri Mar  1 03:19:48 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 28 Feb 2002 19:19:48 -0800 (PST)
Subject: [Tutor] path
In-Reply-To: <3C7EEA1A.44AD95D4@netzero.net>
Message-ID: <Pine.LNX.4.21.0202281913220.4091-100000@hkn.eecs.berkeley.edu>

On Thu, 28 Feb 2002, kirk Bailey wrote:

> ok, I want to have a program tell itself where it lives, so it can
> figure out path information.

The 'sys.argv' list contains a list of arguments that have been passed to
a program... but this is not quite the whole story:

###
[dyoo@tesuque dyoo]$ cat test_argv.py

import sys
print "This is what is in my sys.argv:", sys.argv

[dyoo@tesuque dyoo]$ 
[dyoo@tesuque dyoo]$ python test_argv.py  argument1 argument2
This is what is in my sys.argv: ['test_argv.py', 'argument1', 'argument2']
###

The very first element, sys.argv[0], tells us how we called the program in
the first place.

If we've called the script from another directory, this is reflected in
sys.argv[0] as well:

###
[dyoo@tesuque dyoo]$ cd /
[dyoo@tesuque /]$ python /home/dyoo/test_argv.py 
This is what is in my sys.argv: ['/home/dyoo/test_argv.py']
###

So sys.argv[] is useful, even if we call a program without an apparent
"arguments".


There's a function in os.path called abspath():

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

and that function can help give us get an absolete path of the called
function.


Good luck!



From sheila@thinkspot.net  Fri Mar  1 03:24:11 2002
From: sheila@thinkspot.net (Sheila King)
Date: Thu, 28 Feb 2002 19:24:11 -0800
Subject: [Tutor] path
In-Reply-To: <3C7EEA1A.44AD95D4@netzero.net>
References: <3C7EEA1A.44AD95D4@netzero.net>
Message-ID: <2C266470A3E@kserver.org>

On Thu, 28 Feb 2002 21:40:26 -0500, kirk Bailey <idiot1@netzero.net>  wrote
about [Tutor] path:

> ok, I want to have a program tell itself where it lives, so it can
> figure out path information.
> I want it to read a config file, but it has to know where it is, and
> use that to read the config file, so it knows where everything else
> is! 'pwd' in unix would work, and mabe a few other things, but I do
> not seem to stumble over what is needed to do this. when I tell it to
> just open the file 'foo.cf' it stumbles, as when it tries to open
> './foo.cf'! Clue eagerly saught, over.

Here's a snippet from a script I'm currently running that works portably on
both Windows and Linux (so I can test on my home win98 machine and then
upload to my Linux web server for use).

fullpathtoscript = os.path.abspath(sys.argv[0])
scriptdirectory, scriptfile = os.path.split(fullpathtoscript)

You will need to import sys and os modules, of course.

HTH,

-- 
Sheila King
http://www.thinkspot.net/sheila/

"When introducing your puppy to an adult cat,
restrain the puppy, not the cat." -- Gwen Bailey,
_The Perfect Puppy: How to Raise a Well-behaved Dog_




From erikprice@mac.com  Fri Mar  1 03:58:57 2002
From: erikprice@mac.com (Erik Price)
Date: Thu, 28 Feb 2002 22:58:57 -0500
Subject: [Tutor] Problems with genetically engineering the Print Ogre
In-Reply-To: <LNBBLJKPBEHFEDALKOLCMEBMOAAA.tim.one@comcast.net>
Message-ID: <A7CCA228-2CC8-11D6-9C2C-00039351FE6A@mac.com>

On Thursday, February 28, 2002, at 03:49  AM, Tim Peters wrote:

> In America, students are exposed to "set builder" notation starting at 
> about
> age 12.

If that's the case, then I sure wish I could remember what the hell "set 
builder" notation was!  That was only 13 years ago for me.  :)


Erik

<tangent>
wait... did I just say 'only' ?  ...where did my life go?
</tangent>



From virketis@fas.harvard.edu  Fri Mar  1 04:52:10 2002
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Thu, 28 Feb 2002 23:52:10 -0500
Subject: [Tutor] Problems with genetically engineering the Print Ogre
References: <A7CCA228-2CC8-11D6-9C2C-00039351FE6A@mac.com>
Message-ID: <006201c1c0dc$d924cbd0$18adf78c@virketis2>

> If that's the case, then I sure wish I could remember what the hell "set
> builder" notation was!  That was only 13 years ago for me.  :)

This is what I understand set notation to be (I am sure math gurus will do
better):

A = { x in X | x < 5}

This means, "set A is composed of elements of set X, such that those
elements are strictly less than 5." So, it tells you two things: where to
get the elements from, and which ones to choose. Come to think of it, this
is like an SQL querry:" FROM X SELLECT x WHERE x<5". It's quite a nice
notation, if you ask me. :)

Cheers,

Pijus



From idiot1@netzero.net  Fri Mar  1 04:58:38 2002
From: idiot1@netzero.net (kirk Bailey)
Date: Thu, 28 Feb 2002 23:58:38 -0500
Subject: [Tutor] where am I revisited
Message-ID: <3C7F0A7E.7BCDF8@netzero.net>

OK, it is working now, and here is how.


-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-begin code
snippet-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#120                         CONFIGURATION SECTION
#                            #####################
#                       
# NOTE that this script is SUPPOSED to be installed in the web
cgi-bin!
# and the lists dir is immediately under this dir!
#                       
# ok, where am I? I just woke up!
fullpathtoscript = os.path.split(os.path.abspath(sys.argv[0]))   
print 'fullpathtoscript=',fullpathtoscript
# ok, now my config file is supposed to be RIGHT HERE with me!
#130 So let's read the thing!
f1=open(fullpathtoscript[0]+"/tinylist.cf",'r')
# Tell me little file, who am I?
localhost=string.strip(f1.readline())
f1.close()
# knowing where I am, I know that my lists are ONE FLOOR DOWN!
path=fullpathtoscript[0]         
print 'Path=',path
# ALL TinyList scripts MUST live in the web cgi-bin, and
# ALL global and list files are directly off the web cgi-bin dir in
'/lists'.
#140 that dir should be owned by the same owner and group as this
script, and
# should be chmod 766. DIR 'list' must be 766, with all Scripts 755.
# 
-=-=-=-=-=-=-=-=-=-end code
nippet=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
All it has to read is it's domain name from the tinylist.cf file. As
soon as I jam this into all the other scripts, I will wrap it up and
issue a new generation of the program.

Now, the only thing the user must insure is correct is line 1, the one
pointing to the interpeter. I read someone posting some code that
makes the server ggo FIND the interpeter, which would avoid this, but
this takes much more time to execute the script, and if you host
several busy lists, would be a serious overhead price for sake of not
doing 5 minutes of work.

Thanks for the clues folks, it helps to have people like you in the
community.












-- 
 
end
	    Respectfully,
			 Kirk D Bailey


+---------------------"Thou Art Free." -Eris----------------------+
| http://www.howlermonkey.net mailto:highprimate@howlermonkey.net |
| http://www.tinylist.org  +--------+  mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking---------------------+
                           +--------+

NOTE: By sending SPAM to this address you agree to pay me a service
fee of $100 for the service of receiving,  storing,  examining, and
deleting your piece of SPAM. I am a postmaster, and take a dim view
of such.
----------------------------------------------------
Sign Up for NetZero Platinum Today
Only $9.95 per month!
http://my.netzero.net/s/signup?r=platinum&refcd=PT97


From tim.one@comcast.net  Fri Mar  1 05:04:04 2002
From: tim.one@comcast.net (Tim Peters)
Date: Fri, 01 Mar 2002 00:04:04 -0500
Subject: [Tutor] Problems with genetically engineering the Print Ogre
In-Reply-To: <A7CCA228-2CC8-11D6-9C2C-00039351FE6A@mac.com>
Message-ID: <LNBBLJKPBEHFEDALKOLCCEGOOAAA.tim.one@comcast.net>

[Tim]
> In America, students are exposed to "set builder" notation starting at 
> about age 12.

[Erik Price]
> If that's the case, then I sure wish I could remember what the hell "set 
> builder" notation was!  That was only 13 years ago for me.  :)

You may want to look up Miss LeBrocq for remedial education:

    http://mail.python.org/pipermail/python-list/2001-March/031865.html

> <tangent>
> wait... did I just say 'only' ?  ...where did my life go?
> </tangent>

If you know about tangents, sets are a piece o' cake <wink>.


From wesc@deirdre.org  Fri Mar  1 06:48:46 2002
From: wesc@deirdre.org (wesc@deirdre.org)
Date: Thu, 28 Feb 2002 22:48:46 -0800 (PST)
Subject: [Tutor] ANN: SV-SF Bay Area Python user grp (BayPIGgies) mtg 3/13 7:30pm
Message-ID: <200203010648.WAA23404@alpha.ece.ucsb.edu>

When:  March 13, 2002, 7:30-9pm
Where: Stanford University, Palo Alto, CA
Title: BioPython

Jeffrey Chang (School of Medicine, Stanford University) founded the
BioPython project in 1999 to promote the development of shared software
infrastructure in bioinformatics.  His talk will cover the architecture
and capabilities of Biopython and also give a sneak preview of the
upcoming version. 

Click on BayPIGgies link below for more info, including driving
directions, past meetings, schedule, etc.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

"Core Python Programming", Prentice Hall PTR, © 2001
    http://starship.python.net/crew/wesc/cpp/

Silicon Valley-San Francisco Bay Area Python Users Group (BayPIGgies)
    http://deirdre.org/baypiggies

wesley.j.chun :: wesc@deirdre.org
cyberweb.consulting : henderson, nv : cyberweb@rocketmail.com
http://roadkill.com/~wesc/cyberweb/


From erikprice@mac.com  Fri Mar  1 12:53:05 2002
From: erikprice@mac.com (Erik Price)
Date: Fri, 1 Mar 2002 07:53:05 -0500
Subject: [Tutor] Problems with genetically engineering the Print Ogre
In-Reply-To: <LNBBLJKPBEHFEDALKOLCCEGOOAAA.tim.one@comcast.net>
Message-ID: <45C9433B-2D13-11D6-94CA-00039351FE6A@mac.com>

On Friday, March 1, 2002, at 12:04  AM, Tim Peters wrote:

>
>> <tangent>
>> wait... did I just say 'only' ?  ...where did my life go?
>> </tangent>
>
> If you know about tangents, sets are a piece o' cake <wink>.

ROFL -- that's the second time in two days someone's made me laugh at my 
own words!

As for myself, I spent six years in college studying social sciences, 
which is pretty far removed from math.  I had a different tangent in 
mind.  Still, this disproves the theory about old dogs and new tricks -- 
as for the -basics- of programming, I'm starting to feel comfortable!

Erik



From alan.gauld@bt.com  Fri Mar  1 14:15:00 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 1 Mar 2002 14:15:00 -0000
Subject: [Tutor] path
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C3E8@mbtlipnt02.btlabs.bt.co.uk>

> ok, I want to have a program tell itself where it lives, so it can
> figure out path information.

OK, you could use the os module commands - getcwd() I think?

BUT...

> I want it to read a config file, but it has to know where it is

I think a better approach for this is to use an Envirinment 
Variable TMCONFIG say and then use os.getenv() to read it. 
That way users have some f;exibility to put the config file 
where they want...

Alan G


From idiot1@netzero.net  Fri Mar  1 14:20:26 2002
From: idiot1@netzero.net (kirk Bailey)
Date: Fri, 01 Mar 2002 09:20:26 -0500
Subject: [Tutor] Problems with genetically engineering the Print Ogre
References: <45C9433B-2D13-11D6-94CA-00039351FE6A@mac.com>
Message-ID: <3C7F8E2A.889901FC@netzero.net>

Remember, that time you asked about, it went backwards- or did you
move FORWARDS? This is such a relativity issue... Again, I am reminded
that time flys like an arrow, while fruit flys like a bananna... also,
THE BUDDHA says that now is the only time there is, and that the TAO
is your everyday mind... or is thismy medication kicking in?
Nevermind...

Erik Price wrote:
> 
> On Friday, March 1, 2002, at 12:04  AM, Tim Peters wrote:
> 
> >
> >> <tangent>
> >> wait... did I just say 'only' ?  ...where did my life go?
> >> </tangent>
> >
> > If you know about tangents, sets are a piece o' cake <wink>.
> 
> ROFL -- that's the second time in two days someone's made me laugh at my
> own words!
> 
> As for myself, I spent six years in college studying social sciences,
> which is pretty far removed from math.  I had a different tangent in
> mind.  Still, this disproves the theory about old dogs and new tricks --
> as for the -basics- of programming, I'm starting to feel comfortable!
> 
> Erik
> 
> _______________________________________________
> 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 |
| http://www.tinylist.org  +--------+  mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking---------------------+
                           +--------+

NOTE: By sending SPAM to this address you agree to pay me a service
fee of $100 for the service of receiving,  storing,  examining, and
deleting your piece of SPAM. I am a postmaster, and take a dim view
of such.
----------------------------------------------------
Sign Up for NetZero Platinum Today
Only $9.95 per month!
http://my.netzero.net/s/signup?r=platinum&refcd=PT97


From dsh8290@rit.edu  Fri Mar  1 14:35:28 2002
From: dsh8290@rit.edu (dman)
Date: Fri, 1 Mar 2002 09:35:28 -0500
Subject: [Tutor] Problems with genetically engineering the Print Ogre
In-Reply-To: <006201c1c0dc$d924cbd0$18adf78c@virketis2>
References: <A7CCA228-2CC8-11D6-9C2C-00039351FE6A@mac.com> <006201c1c0dc$d924cbd0$18adf78c@virketis2>
Message-ID: <20020301143528.GA18664@dman.ddts.net>

On Thu, Feb 28, 2002 at 11:52:10PM -0500, Pijus Virketis wrote:
| > If that's the case, then I sure wish I could remember what the hell "set
| > builder" notation was!  That was only 13 years ago for me.  :)
| 
| This is what I understand set notation to be (I am sure math gurus will do
| better):
| 
| A = { x in X | x < 5}

Close.  If you want to use the ascii "in" for the symbol meaning
"element of", then

A = { x | x in X and x < 5 }

(if you have a utf-8 capable display, the "element of" symbol looks
like '∈')

| This means, "set A is composed of elements of set X, such that those
| elements are strictly less than 5." So, it tells you two things: where to
| get the elements from, and which ones to choose. Come to think of it, this
| is like an SQL querry:" FROM X SELLECT x WHERE x<5". It's quite a nice
| notation, if you ask me. :)

I agree.

-D

-- 

Failure is not an option.  It is bundled with the software.



From dsh8290@rit.edu  Fri Mar  1 15:03:00 2002
From: dsh8290@rit.edu (dman)
Date: Fri, 1 Mar 2002 10:03:00 -0500
Subject: [Tutor] Problems with genetically engineering the Print Ogre
In-Reply-To: <002f01c1c12f$dc12fc60$18adf78c@virketis2>
References: <A7CCA228-2CC8-11D6-9C2C-00039351FE6A@mac.com> <006201c1c0dc$d924cbd0$18adf78c@virketis2> <20020301143528.GA18664@dman.ddts.net> <002f01c1c12f$dc12fc60$18adf78c@virketis2>
Message-ID: <20020301150300.GA18857@dman.ddts.net>

[ sent back to the list so other readers will see that I've been
  corrected ]

On Fri, Mar 01, 2002 at 09:46:23AM -0500, Pijus Virketis wrote:
| > | A = { x in X | x < 5}
| >
| > Close.  If you want to use the ascii "in" for the symbol meaning
| > "element of", then
| >
| > A = { x | x in X and x < 5 }
| 
| I certainly don't want to press this point, but let's just say that in my
| set theory books lying on my lap right now (Woolf, Marsden), most instances
| of this notation are used in the manner I showed: with the source set of the
| elements specified before the "such that" dash. But then again, everyone
| seems to do everything their own way in math. :)

Well, if you have the book(s), then you must be right :-).  I didn't
open a book, so maybe I did get it wrong.  Maybe I've done too much
VDM-SL this quarter[1].  It is (quite) conceivable that I am mixing
various languages and notations together.  At least the notation is
understandable either way :-).

HAND,
-D

[1]  VDM-SL is a formal modelling language that has a strong basis in
     discrete math and set and sequence and map operations.

-- 

Even youths grow tired and weary,
    and young men stumble and fall;
but those who hope in the Lord 
    will renew their strength.
They will soar on wings like eagles;
    they will run and not grow weary,
    they will walk and not be faint.

        Isaiah 40:31



From jbauer@rubic.com  Fri Mar  1 18:33:38 2002
From: jbauer@rubic.com (Jeff Bauer)
Date: Fri, 01 Mar 2002 12:33:38 -0600
Subject: [Tutor] path
Message-ID: <3C7FC982.F223A3DF@rubic.com>

Kirk,

Here's a method:

  import os, sys
  relpath = os.path.dirname(sys.argv[0])
  abspath = os.path.abspath(relpath)
  config_file = os.path.join(abspath, 'foo.cf')

Regards,

Jeff Bauer
Rubicon Research


On 01-Mar-2002 kirk Bailey wrote:
> ok, I want to have a program tell itself where it lives, so it can
> figure out path information.
> I want it to read a config file, but it has to know where it is, and
> use that to read the config file, so it knows where everything else
> is! 'pwd' in unix would work, and mabe a few other things, but I do
> not seem to stumble over what is needed to do this. when I tell it to
> just open the file 'foo.cf' it stumbles, as when it tries to open
> './foo.cf'! Clue eagerly saught, over.


From jeff@ccvcorp.com  Fri Mar  1 18:50:02 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Fri, 01 Mar 2002 10:50:02 -0800
Subject: [Tutor] Problems with genetically engineering the Print Ogre
References: <E16gczj-0003wV-00@mail.python.org>
Message-ID: <3C7FCD5A.8FA65CC7@ccvcorp.com>

> alan.gauld@bt.com wrote:
>
> ... and in
> that case list comprehensions are far from being
> easily comprehensible!
>
> As for me, I think they are overused - like many new
> toys - and the older map/filter/reduce are often clearer
> constructs, but in the other places, where they really
> are useful I am starting to use them and grudgingly like
> them.... I just don't find the
>
> [x for x ...
>
> syntax scans well in my brain...

Well, I know nothing of set-builder notation (I probably was taught it, but that was a
*looong* time ago), but.... While I can see the point, that

[x for x in ... ]

is a little bit odd looking, the moment that you throw some other operation in x
(i.e., you're doing anything other than a pure filter), list comps seem *much* clearer
to me.

[f(x) for x in mylist if x > 10]

vs.

map(lambda x: f(x), filter( lambda x: x > 10, mylist))

I *think* -- I can't even tell if I'm doing that right.  A sure sign (to me) that the
other syntax is preferable...  While, in the degenerate case of a pure filter, using
filter() may be as intuitive as the list comp (unless it requires some big hairy
lambda to filter on), I think that once the list-comp syntax is understood for the
more complex cases, the simple case becomes easy to extrapolate.

Of course, maybe it's just a matter of taste, and what one's brain has been exposed to
first.  :)

Jeff Shannon
Technician/Programmer
Credit International





From jeff@ccvcorp.com  Fri Mar  1 19:01:49 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Fri, 01 Mar 2002 11:01:49 -0800
Subject: [Tutor] where am I, revisited
References: <E16gqPG-0006JV-00@mail.python.org>
Message-ID: <3C7FD01D.2146105E@ccvcorp.com>

>
>
> From: kirk Bailey <idiot1@netzero.net>
>
>
> fullpathtoscript = os.path.split(os.path.abspath(sys.argv[0]))
> .....
> path=fullpathtoscript[0]

This is not necessarily reliable.  os.path.abspath() does *not* specifically find a file.  It
does a simple text substitution to convert a relative path to an absolute path, based on the
current working directory, which is *not* necessarily where your script lives.  (In a cgi
environment, it may be a valid assumption, but I wouldn't rely on it.)

I think that a better option would be to use the __file__ attribute of on of your modules.
This contains the (fully qualified) path of the file that the module was loaded from.

>>> import os
>>> print os.__file__
C:\PYTHON21\lib\os.pyc
>>>

You can thus use os.path.dirname(mymodule.__file__) to get the directory that the module is
in.

Jeff Shannon
Technician/Programmer
Credit International




From kp87@lycos.com  Fri Mar  1 18:21:36 2002
From: kp87@lycos.com (kevin parks)
Date: Sat, 02 Mar 2002 03:21:36 +0900
Subject: [Tutor] Re: transposing musical sequences
Message-ID: <LFHKKGMDPNBDGBAA@mailcity.com>

Hi. I sent this message to the list a while back and Danny ways kind enough to answer. Now i have a very different question.

In computer music there are several ways to represent musical pitch. I am working with several of these. One such way is related to the bottom function. It is called octave point pitch class because the first number represents the octave followed by a dot and the next numbers represent the pitch class (there are 12: 0->11). All items (added or subtracted) are modulo 12 (%12)

7.11  # B octave 7
8.00  # C octave 8  THIS HERE IS MIDDLE C (a.k.a C4), MIDI: 60, ca.261.626 Hz....
8.01  # C#/Db octave 8
8.02  # D octave 8
.
.
.
8.11  # B octave 8
9.00  # C octave 9  (here we go again)

So my question is this. The little fucntion below works ok for the pitch class (c,c#,d,d#,e,f,g,g#,a,a#,b) part, but...
             0,1,2,3,4,5,6,7,8, 9,10,11

I now need to add a part that takes care of the octave business. so that if i go below zero (transpose down) or above 11 (transpose up) it increments or decrements the octave number. I am not sure how to add this part without doing a test on the transposition factor and calulating how many 12s fit in it, etc. In otherwords how do i do this more efficently without having lots of flags and conditionals and test on each invocation. I just know that there has to be a better way...

I suppose that the best way would be to make this a pitch class and have Xpose be a method (and add other methods, later...) musical pitch, like ratios, fractions, points (x, y), i suppose, are prime candidates for classes. But I am *just* getting to the part about objects and classes and methods in my python studies....

but i am guessing somthing like (vague & imaginary fake python code w/ syntax errors sure to follow):

>>> z=[pch(8.01), pch(8.05), pch(7.07), pch(6.00)]
>>> x = pch.xpose([1, 2, 3], 11)
>>> foo = pch.tomidi(x)
>>> bar = pch.tocps(x)

etc. & co.....is eventually where this is heading...

If you can make any heads or tails of this question, please help spoon feed this newbie an answer. OOP answers and vanilla examples both welcome, most important is getting a working engine *and* a new undertanding of how to approach the problem.

Thank you muchly for tolerating all my dumb questions over this
winter break.

best,

kevin parks
seoul, korea


>def Xpose(seq,n, oct=12, sort_flag=0):
>    ''' take a sequence and tranpose it modulo some number
>    '''
>    mylist=[]
>    for i in seq:
>        x = (i+n)%oct
>        mylist.append(x) # to append or extend?
>    if sort_flag:
>        mylist.sort() # to sort or not sort
>    return mylist
>
>#-- (i am at an internet cafe with no interpreter so there could
># be a type, but i hope not, Imaginary session follows:
>
>>>> x = [0, 2, 4, 5, 7, 9, 11]
>>>> c = Xpose(x, 4, 12, 0)
>>>> c
>[4, 6, 8, 9, 11, 1, 3]
>>>> d = Xpose(x, 4, 12, 1) # sorted now
>>>> d
>[1, 3, 4, 6, 8, 9, 11]
>
># cool. It works, and just in case you are curious i just turned a
># C major scale into E major



2,000,000,000 Web Pages--you only need 1. Save time with My Lycos.
http://my.lycos.com


From dyoo@hkn.eecs.berkeley.edu  Fri Mar  1 19:53:13 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 1 Mar 2002 11:53:13 -0800 (PST)
Subject: [Tutor] Problems with genetically engineering the Print Ogre
In-Reply-To: <3C7FCD5A.8FA65CC7@ccvcorp.com>
Message-ID: <Pine.LNX.4.21.0203011136590.20121-100000@hkn.eecs.berkeley.edu>

On Fri, 1 Mar 2002, Jeff Shannon wrote:

> *looong* time ago), but.... While I can see the point, that
> 
> [x for x in ... ]
> 
> is a little bit odd looking, the moment that you throw some other
> operation in x (i.e., you're doing anything other than a pure filter),
> list comps seem *much* clearer to me.
> 
> [f(x) for x in mylist if x > 10]
> 
> vs.
> 
> map(lambda x: f(x), filter( lambda x: x > 10, mylist))

I think this is being a little unfair to map() and filter().  *grin*


The first lambda part is redundant, because we can just pass 'f' directly
to map.  That is, instead of saying:

    "Call map with an-anonymous-function-that-calls-f(x)",

it's easier to say:

    "Call map with function f":

###
map(f, filter(lambda x: x>10, mylist))
###


If we'd like, we can also yank that second lambda outside as a separate
function:

###
def is_greater_than_ten(x):
    return x > 10

map(f, filter(is_greater_than_ten, mylist))
###


I guess I'm trying to say that map() and filter() don't have to look
weird.  *grin* Good luck!



From jeff@ccvcorp.com  Fri Mar  1 20:14:37 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Fri, 01 Mar 2002 12:14:37 -0800
Subject: [Tutor] Problems with genetically engineering the Print Ogre
References: <Pine.LNX.4.21.0203011136590.20121-100000@hkn.eecs.berkeley.edu>
Message-ID: <3C7FE12D.B21AC884@ccvcorp.com>


Danny Yoo wrote:

> On Fri, 1 Mar 2002, Jeff Shannon wrote:
>
> > map(lambda x: f(x), filter( lambda x: x > 10, mylist))
>
> I think this is being a little unfair to map() and filter().  *grin*
>
> ###
> map(f, filter(lambda x: x>10, mylist))
> ###

Duh.  Of course.  :)  I'm so used to associating map and filter with
lambdas...  and it's the lambdas that I really dislike using.


> I guess I'm trying to say that map() and filter() don't have to look
> weird.  *grin* Good luck!

Well... maybe not quite *as* weird as I was thinking....  ;)

Jeff Shannon
Technician/Programmer
Credit International




From lha2@columbia.edu  Fri Mar  1 23:46:00 2002
From: lha2@columbia.edu (Lloyd Hugh Allen)
Date: Fri, 01 Mar 2002 18:46:00 -0500
Subject: [Fwd: Re: [Tutor] Re: transposing musical sequences]
Message-ID: <3C8012B8.CABC4F05@mail.verizon.net>

From: Lloyd Hugh Allen <l.h.allen@mail.verizon.net>
Subject: Re: [Tutor] Re: transposing musical sequences
To: kp87@lycos.com

If you have notes stored as complex-valued numbers with the octave
stored as the real part of the variable and the pitch stored as the
complex part, how's this?

def normalize(complex_pitch):
	#print complex_pitch.real
	#print complex_pitch.imag
	complex_pitch = (complex_pitch + complex_pitch.imag//12) % 12j
	#print complex_pitch
	return complex_pitch

(remove the # for debugging) (if only I knew how to access the real and
imaginary components as integers without sending them through
float-land--although that shouldn't be an issue) (Also, please note that
this is Python 2.2 code--the // breaks on earlier) (the \ is only for
line continuation) (enough extra comments).

The original incarnation was 

	complex_pitch = (complex_pitch.real+complex_pitch.imag//12 + \
			 complex_pitch.imag%12 * 1j)

kevin parks wrote:
> 
> Hi. I sent this message to the list a while back and Danny ways kind enough to answer. Now i have a very different question.
> 
> In computer music there are several ways to represent musical pitch. I am working with several of these. One such way is related to the bottom function. It is called octave point pitch class because the first number represents the octave followed by a dot and the next numbers represent the pitch class (there are 12: 0->11). All items (added or subtracted) are modulo 12 (%12)
> 
> 7.11  # B octave 7
> 8.00  # C octave 8  THIS HERE IS MIDDLE C (a.k.a C4), MIDI: 60, ca.261.626 Hz....
> 8.01  # C#/Db octave 8
> 8.02  # D octave 8
> .
> .
> .
> 8.11  # B octave 8
> 9.00  # C octave 9  (here we go again)
> 
> So my question is this. The little fucntion below works ok for the pitch class (c,c#,d,d#,e,f,g,g#,a,a#,b) part, but...
>              0,1,2,3,4,5,6,7,8, 9,10,11
> 
> I now need to add a part that takes care of the octave business. so that if i go below zero (transpose down) or above 11 (transpose up) it increments or decrements the octave number. I am not sure how to add this part without doing a test on the transposition factor and calulating how many 12s fit in it, etc. In otherwords how do i do this more efficently without having lots of flags and conditionals and test on each invocation. I just know that there has to be a better way...
> 
> I suppose that the best way would be to make this a pitch class and have Xpose be a method (and add other methods, later...) musical pitch, like ratios, fractions, points (x, y), i suppose, are prime candidates for classes. But I am *just* getting to the part about objects and classes and methods in my python studies....
> 
> but i am guessing somthing like (vague & imaginary fake python code w/ syntax errors sure to follow):
> 
> >>> z=[pch(8.01), pch(8.05), pch(7.07), pch(6.00)]
> >>> x = pch.xpose([1, 2, 3], 11)
> >>> foo = pch.tomidi(x)
> >>> bar = pch.tocps(x)
> 
> etc. & co.....is eventually where this is heading...
> 
> If you can make any heads or tails of this question, please help spoon feed this newbie an answer. OOP answers and vanilla examples both welcome, most important is getting a working engine *and* a new undertanding of how to approach the problem.
> 
> Thank you muchly for tolerating all my dumb questions over this
> winter break.
> 
> best,
> 
> kevin parks
> seoul, korea
> 
> >def Xpose(seq,n, oct=12, sort_flag=0):
> >    ''' take a sequence and tranpose it modulo some number
> >    '''
> >    mylist=[]
> >    for i in seq:
> >        x = (i+n)%oct
> >        mylist.append(x) # to append or extend?
> >    if sort_flag:
> >        mylist.sort() # to sort or not sort
> >    return mylist
> >
> >#-- (i am at an internet cafe with no interpreter so there could
> ># be a type, but i hope not, Imaginary session follows:
> >
> >>>> x = [0, 2, 4, 5, 7, 9, 11]
> >>>> c = Xpose(x, 4, 12, 0)
> >>>> c
> >[4, 6, 8, 9, 11, 1, 3]
> >>>> d = Xpose(x, 4, 12, 1) # sorted now
> >>>> d
> >[1, 3, 4, 6, 8, 9, 11]
> >
> ># cool. It works, and just in case you are curious i just turned a
> ># C major scale into E major
> 
> 2,000,000,000 Web Pages--you only need 1. Save time with My Lycos.
> http://my.lycos.com
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


From rellik19@yahoo.com  Sat Mar  2 03:34:52 2002
From: rellik19@yahoo.com (Arie van Willigen)
Date: Fri, 1 Mar 2002 19:34:52 -0800 (PST)
Subject: [Tutor] (no subject)
Message-ID: <20020302033452.66735.qmail@web14908.mail.yahoo.com>

Hi I am new at programming and was wondering how do I
get more than one line of coding in??? for ex how
would I do this program:

pi = 3.14
print pi

or 

money = 1000
none = 100
print money + none

I think it has something to do with writing it into a
text file and saving it but I cant figure out how to
open it up
Thanks

=====
Me Myself And I... Oh Yeah Arie Too...

__________________________________________________
Do You Yahoo!?
Yahoo! Sports - sign up for Fantasy Baseball
http://sports.yahoo.com


From sheila@thinkspot.net  Sat Mar  2 04:30:25 2002
From: sheila@thinkspot.net (Sheila King)
Date: Fri, 01 Mar 2002 20:30:25 -0800
Subject: [Tutor] (no subject)
In-Reply-To: <20020302033452.66735.qmail@web14908.mail.yahoo.com>
References: <20020302033452.66735.qmail@web14908.mail.yahoo.com>
Message-ID: <4DDA1595F2F@kserver.org>

On Fri, 1 Mar 2002 19:34:52 -0800 (PST), Arie van Willigen
<rellik19@yahoo.com>  wrote about [Tutor] (no subject):

> Hi I am new at programming and was wondering how do I
> get more than one line of coding in??? for ex how
> would I do this program:
> 
> pi = 3.14
> print pi
> 
> or 
> 
> money = 1000
> none = 100
> print money + none
> 
> I think it has something to do with writing it into a
> text file and saving it but I cant figure out how to
> open it up
> Thanks

Are you using IDLE ? Or what system/environment/editor are you using?

If you are using IDLE, then go to the File menu, and select "New Window".

Type your code in that window (such as your examples above).
Now go to the File Menu of that new window, and save your code.
Then go to the Edit menu and choose "Run Script" (it is fairly far down the
list).

The output from your script run will appear in the IDLE Interactive Window.

Hope this helps,

-- 
Sheila King
http://www.thinkspot.net/sheila/

"When introducing your puppy to an adult cat,
restrain the puppy, not the cat." -- Gwen Bailey,
_The Perfect Puppy: How to Raise a Well-behaved Dog_



From scot@possum.in-berlin.de  Fri Mar  1 23:27:10 2002
From: scot@possum.in-berlin.de (Scot Stevenson)
Date: Sat, 2 Mar 2002 00:27:10 +0100
Subject: [Tutor] Problems with genetically engineering the Print Ogre
In-Reply-To: <20020301150300.GA18857@dman.ddts.net>
References: <A7CCA228-2CC8-11D6-9C2C-00039351FE6A@mac.com> <002f01c1c12f$dc12fc60$18adf78c@virketis2> <20020301150300.GA18857@dman.ddts.net>
Message-ID: <200203012334.g21NYAS10163@possum.cozen.org>

Hello Dman:

> [1]  VDM-SL is a formal modelling language that has a strong basis in
>      discrete math and set and sequence and map operations.

I told you list comprehensions were for a select few =8)...

Y, Scot


From idiot1@netzero.net  Sat Mar  2 05:10:54 2002
From: idiot1@netzero.net (kirk Bailey)
Date: Sat, 02 Mar 2002 00:10:54 -0500
Subject: [Tutor] path aka whereami revisited
Message-ID: <3C805EDE.186CA335@netzero.net>

If anyone wants to look at the latest version of TLpost.py with all
the latest chaos, here it is from the serv er in an SSI include in a
web page. This is the CURRENT working script itself, instantly updated
as I hammer on it.

http://www.tinylist.org/TLpost.shtml

-- 
 
end
	    Respectfully,
			 Kirk D Bailey


+---------------------"Thou Art Free." -Eris----------------------+
| http://www.howlermonkey.net mailto:highprimate@howlermonkey.net |
| http://www.tinylist.org  +--------+  mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking---------------------+
                           +--------+

NOTE: By sending SPAM to this address you agree to pay me a service
fee of $100 for the service of receiving,  storing,  examining, and
deleting your piece of SPAM. I am a postmaster, and take a dim view
of such.
----------------------------------------------------
Sign Up for NetZero Platinum Today
Only $9.95 per month!
http://my.netzero.net/s/signup?r=platinum&refcd=PT97


From dyoo@hkn.eecs.berkeley.edu  Sat Mar  2 06:11:17 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 1 Mar 2002 22:11:17 -0800 (PST)
Subject: [Tutor] (no subject)
In-Reply-To: <4DDA1595F2F@kserver.org>
Message-ID: <Pine.LNX.4.21.0203012209590.1501-100000@hkn.eecs.berkeley.edu>

On Fri, 1 Mar 2002, Sheila King wrote:

> On Fri, 1 Mar 2002 19:34:52 -0800 (PST), Arie van Willigen
> <rellik19@yahoo.com>  wrote about [Tutor] (no subject):
> 
> > Hi I am new at programming and was wondering how do I
> > get more than one line of coding in?
>
> 
> Are you using IDLE ? Or what system/environment/editor are you using?
> 
> If you are using IDLE, then go to the File menu, and select "New Window".

I have a small guide that shows what this might look like:

    http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro

Good luck!



From sheila@thinkspot.net  Sat Mar  2 07:05:23 2002
From: sheila@thinkspot.net (Sheila King)
Date: Fri, 01 Mar 2002 23:05:23 -0800
Subject: [Tutor] where am I, revisited
In-Reply-To: <3C7FD01D.2146105E@ccvcorp.com>
References: <E16gqPG-0006JV-00@mail.python.org> <3C7FD01D.2146105E@ccvcorp.com>
Message-ID: <196C994068@kserver.org>

On Fri, 01 Mar 2002 11:01:49 -0800, "Jeff Shannon" <jeff@ccvcorp.com>
wrote about Re: [Tutor] where am I, revisited:

> > fullpathtoscript = os.path.split(os.path.abspath(sys.argv[0]))
> > .....
> > path=fullpathtoscript[0]
> 
> This is not necessarily reliable.  os.path.abspath() does *not* specifically find a file.  It
> does a simple text substitution to convert a relative path to an absolute path, based on the
> current working directory, which is *not* necessarily where your script lives.  (In a cgi
> environment, it may be a valid assumption, but I wouldn't rely on it.)
> 
> I think that a better option would be to use the __file__ attribute of on of your modules.
> This contains the (fully qualified) path of the file that the module was loaded from.
> 
> >>> import os
> >>> print os.__file__
> C:\PYTHON21\lib\os.pyc
> >>>
> 
> You can thus use os.path.dirname(mymodule.__file__) to get the directory that the module is
> in.

It has taken me a while to wrap my brain around what you are saying here,
but I think I understand it now.

However, I don't think your suggested fix will work for the particular
script *I'm* running (where I got this suggestion that I made to Kirk). The
modules from the standard Python library are in a completely different
location, and I have no modules that I'm using in the same location as the
script. I get the impression that
sys.argv[0].__file__

probably doesn't work? I have to do that on an imported module? But I have
no imported module in that directory, so...

For the particular script I'm running, which is a mail filter script that
runs when it is called by Qmail, it will give me the correct working
directory. But I appreciate your caution that I cannot assume it in all
cases.

-- 
Sheila King
http://www.thinkspot.net/sheila/

"When introducing your puppy to an adult cat,
restrain the puppy, not the cat." -- Gwen Bailey,
_The Perfect Puppy: How to Raise a Well-behaved Dog_



From kp87@lycos.com  Sat Mar  2 12:08:15 2002
From: kp87@lycos.com (kevin parks)
Date: Sat, 02 Mar 2002 21:08:15 +0900
Subject: [Tutor] Re: transposing musical sequences
Message-ID: <LPPJINBFPJCENBAA@mailcity.com>

I don't have an interpreter here so i can't actually post
working code, but i know that at the heart of my problem i can
just use %12 to extract the pitch and /12 to get to the octave part

octpch is the base note (the note we are starting with, eg 8.00
n is the number of half steps we want to transpose up or down

xpose(octpch, n):
    oct = octpch # something here to separate the stuff before the dot
    pch = octpch # followed by something code here to split the part after the dot
    pch = ((pch +n) % 12/100) #update the pitch
    oct = (oct +n) /12   # update the oct part
    return (the two items joined back together

Also i am guessing that transposing down somehow involves the 12s compliment
(12-n)

maybe down is (12-n)% 12

I am at a net cafe so i have to wait till i get home to try this ideas out. The came
to me last night *after* i sent my query! (it started to perculate in my brain as i waited
to get to sleep)

Sorry for all the thinking out loud here....

cheers,

kevin


---


On Sat, 02 Mar 2002 03:21:36  
 kevin parks wrote:
>Hi. I sent this message to the list a while back and Danny ways kind enough to answer. Now i have a very different question.
>
>In computer music there are several ways to represent musical pitch. I am working with several of these. One such way is related to the bottom function. It is called octave point pitch class because the first number represents the octave followed by a dot and the next numbers represent the pitch class (there are 12: 0->11). All items (added or subtracted) are modulo 12 (%12)
>
>7.11  # B octave 7
>8.00  # C octave 8  THIS HERE IS MIDDLE C (a.k.a C4), MIDI: 60, ca.261.626 Hz....
>8.01  # C#/Db octave 8
>8.02  # D octave 8
>.
>.
>.
>8.11  # B octave 8
>9.00  # C octave 9  (here we go again)
>
>So my question is this. The little fucntion below works ok for the pitch class (c,c#,d,d#,e,f,g,g#,a,a#,b) part, but...
>             0,1,2,3,4,5,6,7,8, 9,10,11
>
>I now need to add a part that takes care of the octave business. so that if i go below zero (transpose down) or above 11 (transpose up) it increments or decrements the octave number. I am not sure how to add this part without doing a test on the transposition factor and calulating how many 12s fit in it, etc. In otherwords how do i do this more efficently without having lots of flags and conditionals and test on each invocation. I just know that there has to be a better way...
>
>I suppose that the best way would be to make this a pitch class and have Xpose be a method (and add other methods, later...) musical pitch, like ratios, fractions, points (x, y), i suppose, are prime candidates for classes. But I am *just* getting to the part about objects and classes and methods in my python studies....
>
>but i am guessing somthing like (vague & imaginary fake python code w/ syntax errors sure to follow):
>
>>>> z=[pch(8.01), pch(8.05), pch(7.07), pch(6.00)]
>>>> x = pch.xpose([1, 2, 3], 11)
>>>> foo = pch.tomidi(x)
>>>> bar = pch.tocps(x)
>
>etc. & co.....is eventually where this is heading...
>
>If you can make any heads or tails of this question, please help spoon feed this newbie an answer. OOP answers and vanilla examples both welcome, most important is getting a working engine *and* a new undertanding of how to approach the problem.
>
>Thank you muchly for tolerating all my dumb questions over this
>winter break.
>
>best,
>
>kevin parks
>seoul, korea
>
>
>>def Xpose(seq,n, oct=12, sort_flag=0):
>>    ''' take a sequence and tranpose it modulo some number
>>    '''
>>    mylist=[]
>>    for i in seq:
>>        x = (i+n)%oct
>>        mylist.append(x) # to append or extend?
>>    if sort_flag:
>>        mylist.sort() # to sort or not sort
>>    return mylist
>>
>>#-- (i am at an internet cafe with no interpreter so there could
>># be a type, but i hope not, Imaginary session follows:
>>
>>>>> x = [0, 2, 4, 5, 7, 9, 11]
>>>>> c = Xpose(x, 4, 12, 0)
>>>>> c
>>[4, 6, 8, 9, 11, 1, 3]
>>>>> d = Xpose(x, 4, 12, 1) # sorted now
>>>>> d
>>[1, 3, 4, 6, 8, 9, 11]
>>
>># cool. It works, and just in case you are curious i just turned a
>># C major scale into E major
>
>
>
>2,000,000,000 Web Pages--you only need 1. Save time with My Lycos.
>http://my.lycos.com
>


2,000,000,000 Web Pages--you only need 1. Save time with My Lycos.
http://my.lycos.com


From charlie@begeistert.org  Sat Mar  2 15:56:09 2002
From: charlie@begeistert.org (Charlie Clark)
Date: Sat, 02 Mar 2002 16:56:09 +0100
Subject: [Tutor] was no subject, getting started
In-Reply-To: <E16h8Kx-00081K-00@mail.python.org>
References: <E16h8Kx-00081K-00@mail.python.org>
Message-ID: <20020302170907.30324.14@gormenghast.AUTODIAL>

On 2002-03-02 at 13:10:03, tutor-request@python.org wrote:
 
> I think it has something to do with writing it into a
> text file and saving it but I cant figure out how to

Python programs are text files and should be edited with a text editor. 
Sheila has said how you can do this in IDLE which is a text editor with an 
interactive command line.

You run the scripts you've written by giving them to the Python interpreter 
to run. On POSIX-compliant systems this is quite easy by setting up the 
appropriate environment variable, putting #!/bin/env Python as the first 
line and making the file executable. Otherwise just enter Python in the 
command line or DOS session with the name of your script as the second word.

If you're in windows you have my sympathy.

c:\ python myscript.py

You will probably need to add the appropriate paths and actually have 
something like this

c:\ c:\python21\python c:\my documents\python\myscript.py

Windows is not really very nice for developing partly because of these 
problems.

> money = 1000
> none = 100
> print money + none

Nobody else mentioned this but "None" is a reserved word in Python: it 
stands for an object with no content so it is not the same as "0". Python 
is case sensitive so your variable "none" is different to "None". You can 
overwrite such words in Python without raising an error but this is quite 
likely to cause confusion and thus problems.

The people who write Python are careful not to create too many reserved 
words so that the chances of this happening are rare. Ones to watch out for 
are "list" and "type"

Charlie


From dsh8290@rit.edu  Sat Mar  2 16:34:27 2002
From: dsh8290@rit.edu (dman)
Date: Sat, 2 Mar 2002 11:34:27 -0500
Subject: [Tutor] was no subject, getting started
In-Reply-To: <20020302170907.30324.14@gormenghast.AUTODIAL>
References: <E16h8Kx-00081K-00@mail.python.org> <20020302170907.30324.14@gormenghast.AUTODIAL>
Message-ID: <20020302163427.GA31059@dman.ddts.net>

[ I missed the beginning of this -- messages with "(no subject)" as
  the subject are automatically dropped on my system ]

On Sat, Mar 02, 2002 at 04:56:09PM +0100, Charlie Clark wrote:
| On 2002-03-02 at 13:10:03, tutor-request@python.org wrote:
 
| > money = 1000
| > none = 100
| > print money + none
| 
| Nobody else mentioned this but "None" is a reserved word in Python: it 

It is not a reserved word.  It is a built-in name.  The difference is
evident in the following lines :

None = "yo"
for = "yo"

The former works and is totally legal.  I don't recommend it, however,
since it creates a local variable that "overshadows" the built-in
variable.

The latter doesn't work because "for" is a reserved word (aka keyword).

| stands for an object with no content so it is not the same as "0". Python 
| is case sensitive so your variable "none" is different to "None". You can 
| overwrite such words in Python without raising an error but this is quite 
| likely to cause confusion and thus problems.
| 
| The people who write Python are careful not to create too many reserved 
| words so that the chances of this happening are rare. Ones to watch out for 
| are "list" and "type"

The moral is correct, but the details are not.  "list" and "type" are
built-ins, not keywords.

-D

-- 

Stay away from a foolish man,
for you will not find knowledge on his lips.
        Proverbs 14:7



From reardon1@juno.com  Sat Mar  2 02:30:56 2002
From: reardon1@juno.com (james p REARDON)
Date: Fri, 1 Mar 2002 21:30:56 -0500
Subject: [Tutor] hello,
Message-ID: <20020301.213058.-98353881.0.reardon1@juno.com>

Hello,
        I am a beginner at programming, actually i just down loaded
python and i have no idea of what to do. I am willing to put countless
hours into learning, so will someone help me


From sheila@thinkspot.net  Sat Mar  2 22:19:57 2002
From: sheila@thinkspot.net (Sheila King)
Date: Sat, 02 Mar 2002 14:19:57 -0800
Subject: [Tutor] hello,
In-Reply-To: <20020301.213058.-98353881.0.reardon1@juno.com>
References: <20020301.213058.-98353881.0.reardon1@juno.com>
Message-ID: <10506814CE0@kserver.org>

On Fri, 1 Mar 2002 21:30:56 -0500, james p REARDON <reardon1@juno.com>
wrote about [Tutor] hello,:

> Hello,
>         I am a beginner at programming, actually i just down loaded
> python and i have no idea of what to do. I am willing to put countless
> hours into learning, so will someone help me

Have you installed it yet? If not, what operating system are you running
on? If Windows, then just click on the Python you downloaded and it should
launch a Windows installer.

If you already have it installed, then let us know what platform you are
using so that we can better advise you.

You might try browsing the Non-Programmer's Tutorial for Python, here:
http://www.honors.montana.edu/%7Ejjc/easytut/easytut/

It does have some information about installing Python and getting started.

-- 
Sheila King
http://www.thinkspot.net/sheila/

"When introducing your puppy to an adult cat,
restrain the puppy, not the cat." -- Gwen Bailey,
_The Perfect Puppy: How to Raise a Well-behaved Dog_



From dyoo@hkn.eecs.berkeley.edu  Sun Mar  3 04:16:59 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat, 2 Mar 2002 20:16:59 -0800 (PST)
Subject: [Tutor] hello,
In-Reply-To: <20020301.213058.-98353881.0.reardon1@juno.com>
Message-ID: <Pine.LNX.4.21.0203022006370.21771-100000@hkn.eecs.berkeley.edu>

On Fri, 1 Mar 2002, james p REARDON wrote:

>         I am a beginner at programming, actually i just down loaded
> python and i have no idea of what to do. I am willing to put countless
> hours into learning, so will someone help me

Hi James, welcome aboard!


You may find this page useful:

    http://python.org/doc/Newbies.html

This page collects tutorials that you might want to browse.  All of the 
tutorials there are great, so just pick on and start playing.  *grin*

You may find:

    http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro

useful for learning how to use the text editor IDLE.  IDLE makes
experimenting with Python pretty pleasant, and it's automatically bundled
along with Python, so you don't have to do anything extra to install it.


Please feel free to ask questions here on Tutor!  Good luck to you. 



From dyoo@hkn.eecs.berkeley.edu  Sun Mar  3 04:33:38 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat, 2 Mar 2002 20:33:38 -0800 (PST)
Subject: [Tutor] Re: transposing musical sequences
In-Reply-To: <LPPJINBFPJCENBAA@mailcity.com>
Message-ID: <Pine.LNX.4.21.0203022018590.21771-100000@hkn.eecs.berkeley.edu>

On Sat, 2 Mar 2002, kevin parks wrote:

> I don't have an interpreter here so i can't actually post
> working code, but i know that at the heart of my problem i can
> just use %12 to extract the pitch and /12 to get to the octave part

Yes, I think that'll should do it.


> I am at a net cafe so i have to wait till i get home to try this ideas
> out. The came to me last night *after* i sent my query! (it started to
> perculate in my brain as i waited to get to sleep)
> 
> Sorry for all the thinking out loud here....


Don't worry about it; talking out loud about it probably helped grease the
gears.  *grin*


Talk to you later!



From dyoo@hkn.eecs.berkeley.edu  Sun Mar  3 05:12:36 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat, 2 Mar 2002 21:12:36 -0800 (PST)
Subject: [Tutor] Sorting numbers in lexicographic order  [recreational programming]
Message-ID: <Pine.LNX.4.21.0203022035580.21771-100000@hkn.eecs.berkeley.edu>

Hi everyone,

I'm starting to read parts of The Art of Computer Programming, by Donald
Knuth:

    http://www-cs-faculty.stanford.edu/~knuth/taocp.html

and I've having fun trying to solve the exercises he gives.  I thought I
might share one with the people here:


"""Section 5, problem 5:  Design a binary code for all nonnegative
integers so that if n is encoded as the string p(n) we have

    m < n

if and only if p(m) is lexicographically less than p(n).  Moreover, p(m)
should not be a prefix of p(n) for any m != n.  If possible, the length of
p(n) should be at most lg(n) + O(log log n) for all large n.  (Such a code
is useful if we want to sort texts that mix words and numbers, or if we
want to map arbitrarily large alphabets into binary strings.)"""


We know that, in Python, if we try to sort strings that contain digits:

###
>>> l = ['10', '9', '4', '8', '1']
>>> l.sort()
>>> l
['1', '10', '4', '8', '9']
###

that Python will actually sort the list in dictionary "lexicographic"
order.  What the problem is asking is to figure out a way to represent a
number as a string of 1's and 0's so that lexicographic ordering actually
does the sorting right.


I worked on this problem a bit, and figured out a solution.  It's not the
best one, but it's fairly neat, I think.  *grin*


*** spoiler space ahead ***












*** spoiler space ***


Here's the solution I cooked up:

###
>>> def toBinary(n):
...     if n == 0: return '0'
...     digits = []
...     while n != 0:
...         digits.append(str(n % 2))
...         n = n >> 1
...     digits.reverse()
...     return string.join(digits, '')
...
>>> def p(n):
...     if n == 0: return '0'
...     binary_rep = toBinary(n)
...     return '1' * len(binary_rep) + '0' + binary_rep[1:]
... 
>>> p(0)
'0'
>>> p(1)
'10'
>>> p(2)
'1100'
>>> p(4)
'111000'
>>> map(p, range(10))
['0', '10', '1100', '1101', '111000', '111001', '111010', '111011',
'11110000', '11110001']
###

I noticed that the plain binary representation of a number almost works...
except that we need to tell lexicographic order that 'shorter' strings
should be considered smaller than longer strings.  My idea is to append a
small 'length' header of a bunch of '1's and a zero, so that lexicographic
order can recognize the length of the binary strings.



From randytalbot@comcast.net  Sun Mar  3 07:03:20 2002
From: randytalbot@comcast.net (Randy Talbot)
Date: Sun, 03 Mar 2002 02:03:20 -0500
Subject: [Tutor] hello,
In-Reply-To: <Pine.LNX.4.21.0203022006370.21771-100000@hkn.eecs.berkeley.edu>
Message-ID: <000001c1c281$80b1f300$5b582144@aberdn01.md.comcast.net>

If you try the website at the bottom about using IDLE remember to save
the file with a .py extension such as (firstprogram.py).
 
Get some good books on computer programming and python such as, 'How
Computer Programming Works' by Dan Appleman, 'The Quick Python Book' by
Daryl Harms, 'Python: Visual QuickStart Guide' by Chris Fehily, 'Python
How to Program' by Harvey Deitel and 'Core Python Programming' by Wesley
Chun. 
> On Fri, 1 Mar 2002, james p REARDON wrote:
> 
> >         I am a beginner at programming, actually i just down loaded
> > python and i have no idea of what to do. I am willing to put
countless
> > hours into learning, so will someone help me
> 
> Hi James, welcome aboard!
> 
> 
> You may find this page useful:
> 
>     http://python.org/doc/Newbies.html
> 
> This page collects tutorials that you might want to browse.  All of
the
> tutorials there are great, so just pick on and start playing.  *grin*
> 
> You may find:
> 
>     http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro
> 
> useful for learning how to use the text editor IDLE.  IDLE makes
> experimenting with Python pretty pleasant, and it's automatically
bundled
> along with Python, so you don't have to do anything extra to install
it.
> 
> 
> Please feel free to ask questions here on Tutor!  Good luck to you.
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From slime@vsnl.net  Sun Mar  3 16:06:07 2002
From: slime@vsnl.net (Prahlad Vaidyanathan)
Date: Sun, 3 Mar 2002 21:36:07 +0530
Subject: [Tutor] changing sys.stdin to accept keyboard input
Message-ID: <20020303160607.GA532@marvin.localdomain>

Hi,

I have a script to extract URLs from an Email by piping the mail
through it using the recently posted url_re regex (thanks Danny !).

Now, what I want to do is, after it has finished printing the links, I
want it to wait for me to enter the number corresponding to a URL, so it
can open this url using my browser, or save the link-name to a file so I
can browse later.

So, my question right now is, how do I make it wait for input from me,
even though sys.stdin here corresponds to the Email I am piping into the
script. Right now, a simple raw_input() doesn't work because of the
above reason.

Is there a way of changing sys.stdin to allow for input from the
keyboard ?

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

Your love life will be happy and harmonious.


From fal_69@plasa.com  Sun Mar  3 16:42:24 2002
From: fal_69@plasa.com (gopal anshary                                              )
Date: Sun, 03 Mar 2002 23:42:24 +0700
Subject: [Tutor] python script
Message-ID: <web-2580700@mail.plasa.com>

hi every body, my name is ifal and i from indonesia. i'm new
member of this mailing list.
i use python in order to finish my final project for my
diploma.
i have some difficulty about python script. i wanna make
some web with python as cgi script and apache as a web
server also PostgerSQL as a data base server.

my question is how to configure those three programs, to get
them connected each other,in order to run my first script?
what module that i need? did i need mod_python ?

i really appreciated for the answer, from every one

viva python!!!!


From virketis@fas.harvard.edu  Sun Mar  3 16:59:19 2002
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Sun, 3 Mar 2002 11:59:19 -0500
Subject: [Tutor] python script
References: <web-2580700@mail.plasa.com>
Message-ID: <011701c1c2d4$c2e5a610$18adf78c@virketis2>

Gopal,

> my question is how to configure those three programs, to get
> them connected each other,in order to run my first script?

Hm. Do you have Apache and PostgreSQL already up and running? Or are you
also wondering how to get/install/admin them? In the latter case, I would be
way in over my head. Moreover, you would probably get better help by mailing
the respectice lists of those apps in any case. If everything is already
running, then here's a Python CGI tutorial for you to take a look at:
http://www.devshed.com/Server_Side/Python/CGI/page1.html.

> what module that i need?

The Python-PostgreSQL interface can be found here:
http://sourceforge.net/projects/pypgsql/. They have a mailing list for
users. I did not see any documentation on the site, but there probably will
be some with the package, and all these db modules do the same thing
anyways... :)

> did i need mod_python ?

Mod_python is not necessary, unless you are going to have a lot of
simultaneous CGI scripts running (i.e., your site will be a busy one), in
which case the server will get bogged down without it.

> viva python!!!!

Indeed. :)

Cheers,

Pijus



From kalle@gnupung.net  Sun Mar  3 17:18:47 2002
From: kalle@gnupung.net (Kalle Svensson)
Date: Sun, 3 Mar 2002 18:18:47 +0100
Subject: [Tutor] changing sys.stdin to accept keyboard input
In-Reply-To: <20020303160607.GA532@marvin.localdomain>
References: <20020303160607.GA532@marvin.localdomain>
Message-ID: <20020303171847.GA6733@sandra.lysator.liu.se>

[Prahlad Vaidyanathan]
> I have a script to extract URLs from an Email by piping the mail
> through it using the recently posted url_re regex (thanks Danny !).
> 
> Now, what I want to do is, after it has finished printing the links, I
> want it to wait for me to enter the number corresponding to a URL, so it
> can open this url using my browser, or save the link-name to a file so I
> can browse later.
> 
> So, my question right now is, how do I make it wait for input from me,
> even though sys.stdin here corresponds to the Email I am piping into the
> script. Right now, a simple raw_input() doesn't work because of the
> above reason.

I guess this is OS dependent (and more), but on my GNU/Linux
workstation this seems to work:

import sys
print sys.stdin.read()
sys.stdin = open("/dev/tty")
print raw_input("Number: ")

Peace,
  Kalle
-- 
Kalle Svensson (kalle@gnupung.net) - Laziness, impatience, hubris: Pick two!
English: http://www.gnupung.net/  Svenska: http://www.lysator.liu.se/~kalle/
Stuff: ["http://www.%s.org/" % x for x in "gnu debian python emacs".split()]


From clickron@webtv.net  Sun Mar  3 19:26:54 2002
From: clickron@webtv.net (Ron)
Date: Sun, 3 Mar 2002 14:26:54 -0500 (EST)
Subject: [Tutor] round so only see 2 digits
Message-ID: <20624-3C8278FE-191@storefull-168.iap.bryant.webtv.net>

How do I round a float so I will only see 2 digits after the decimal
point or however many I want?



From shalehperry@attbi.com  Sun Mar  3 21:11:10 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Sun, 03 Mar 2002 13:11:10 -0800 (PST)
Subject: [Tutor] round so only see 2 digits
In-Reply-To: <20624-3C8278FE-191@storefull-168.iap.bryant.webtv.net>
Message-ID: <XFMail.20020303131110.shalehperry@attbi.com>

On 03-Mar-2002 Ron wrote:
> How do I round a float so I will only see 2 digits after the decimal
> point or however many I want?
> 

The % operator takes the usual printf() arguments.  0.2%f means "unlimited
before decimal, 2 after".  I belive this is documented in the python docs
somewhere near the % operator.


From dsh8290@rit.edu  Sun Mar  3 22:55:38 2002
From: dsh8290@rit.edu (dman)
Date: Sun, 3 Mar 2002 17:55:38 -0500
Subject: [Tutor] changing sys.stdin to accept keyboard input
In-Reply-To: <20020303160607.GA532@marvin.localdomain>
References: <20020303160607.GA532@marvin.localdomain>
Message-ID: <20020303225538.GA8451@dman.ddts.net>

On Sun, Mar 03, 2002 at 09:36:07PM +0530, Prahlad Vaidyanathan wrote:
| Hi,
| 
| I have a script to extract URLs from an Email by piping the mail
| through it using the recently posted url_re regex (thanks Danny !).
| 
| Now, what I want to do is, after it has finished printing the links, I
| want it to wait for me to enter the number corresponding to a URL, so it
| can open this url using my browser, or save the link-name to a file so I
| can browse later.
| 
| So, my question right now is, how do I make it wait for input from me,
| even though sys.stdin here corresponds to the Email I am piping into the
| script. Right now, a simple raw_input() doesn't work because of the
| above reason.
| 
| Is there a way of changing sys.stdin to allow for input from the
| keyboard ?

I think it would be easier to re-design it so you don't need stdin to
be connected to different sources at different times.

Anyways, vim does this somehow by reading from stderr instead of
stdin.  From the vim manpage :

(list of command line args)
       -           The file to edit is read from stdin.  Commands
                   are read from stderr, which should be a tty.

If you were to run 
    echo "yo" | vim -
you would have vim running on your console with the text "yo" in a
new, unamed buffer.

If you grok C you could take a look at vim's source to see how Bram
implemented it.  I don't have time to look now.

HTH,
-D

-- 

Whoever gives heed to instruction prospers,
and blessed is he who trusts in the Lord.
        Proverbs 16:20



From kojo@hal-pc.org  Sun Mar  3 22:51:35 2002
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Sun, 03 Mar 2002 16:51:35 -0600
Subject: [Tutor] round so only see 2 digits
In-Reply-To: <XFMail.20020303131110.shalehperry@attbi.com>
References: <20624-3C8278FE-191@storefull-168.iap.bryant.webtv.net>
Message-ID: <5.1.0.14.0.20020303164747.00b0df70@Pop3.norton.antivirus>

I've got a similar question:  How do I round a float to get rid of the 
leading zero before the decimal?  I've looked through the printf() args and 
I know how to have it print with any number of digits after the decimal, 
but I didn't find anything that dealt with removing the leading zero.

Maybe I missed it?  That's quite probable.

Thanks,

At 01:11 PM 3/3/2002 -0800, Sean 'Shaleh' Perry wrote:

>On 03-Mar-2002 Ron wrote:
> > How do I round a float so I will only see 2 digits after the decimal
> > point or however many I want?
> >
>
>The % operator takes the usual printf() arguments.  0.2%f means "unlimited
>before decimal, 2 after".  I belive this is documented in the python docs
>somewhere near the % operator.
>
>_______________________________________________
>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 dyoo@hkn.eecs.berkeley.edu  Mon Mar  4 02:40:34 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 3 Mar 2002 18:40:34 -0800 (PST)
Subject: [Tutor] round so only see 2 digits
In-Reply-To: <XFMail.20020303131110.shalehperry@attbi.com>
Message-ID: <Pine.LNX.4.21.0203031836000.3576-100000@hkn.eecs.berkeley.edu>

On Sun, 3 Mar 2002, Sean 'Shaleh' Perry wrote:

> 
> On 03-Mar-2002 Ron wrote:
> > How do I round a float so I will only see 2 digits after the decimal
> > point or however many I want?
> > 
> 
> The % operator takes the usual printf() arguments.  0.2%f means
> "unlimited before decimal, 2 after".  I belive this is documented in
> the python docs somewhere near the % operator.

Hi Ron,

Small correction: the precision format should be after the '%' part;
otherwise, Python will confuse it with something else:

###
>>> '%0.2f' % 3.1415926
'3.14'
>>> '0.2%f' % 3.1415926
'0.23.141593'
###


There's more documentation about String Formatting here:

    http://python.org/doc/current/lib/typesseq-strings.html



Good luck!



From clickron@webtv.net  Mon Mar  4 03:16:39 2002
From: clickron@webtv.net (Ron)
Date: Sun, 3 Mar 2002 22:16:39 -0500 (EST)
Subject: [Tutor] round so only see 2 digits
In-Reply-To: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>'s message of Sun, 3 Mar
 2002 18:40:34 -0800 (PST)
Message-ID: <20623-3C82E717-651@storefull-168.iap.bryant.webtv.net>

Thanks. That's what I was looking for.

Ron



From dyoo@hkn.eecs.berkeley.edu  Mon Mar  4 03:56:39 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 3 Mar 2002 19:56:39 -0800 (PST)
Subject: [Tutor] Sorting numbers in lexicographic order  [recreational
 programming]
In-Reply-To: <Pine.LNX.4.21.0203031852580.3576-100000@hkn.eecs.berkeley.edu>
Message-ID: <Pine.LNX.4.21.0203031939580.3576-100000@hkn.eecs.berkeley.edu>

Hi everyone,


By the way, here's an example that shows a practical use of the
number-to-weird-looking-string function: sorting book titles!  Normally,
if we had something like:

####
book_titles = ['The 10th Annual Python Proceedings',
               'The 9th Annual Python Proceedings',
               'The 40th Annual Python Proceedings',
               'TAOCP Volume 3: Sorting and Searching',
               'TAOCP Volume 2: Seminumerical Algorithms',
               'The Hitchhikers Guide to the Galaxy']
###

and if we tried to sort this, we'd get something weird:

###
>>> book_titles.sort()
>>> book_titles
['TAOCP Volume 2: Seminumerical Algorithms',
 'TAOCP Volume 3: Sorting and Searching',
 'The 10th Annual Python Proceedings',
 'The 40th Annual Python Proceedings',
 'The 9th Annual Python Proceedings',
 'The Hitchhikers Guide to the Galaxy']
###

THe sort messes up when it tries to compare those Python proceedings, and
this is because '1' compares lexicographically smaller than '9', even
though we as humans know that we should be actually comparing 10 vs. 9.


But we can fix this if we replace all the numbers with things that
lexicographically sort.  The code is a bit long, so I've posted it on
ChalkBoard:

    http://www.decrem.com:8080/ChalkBoard/1015218596

(As a warning, I use Knuth's published solution to the lexicographic
problem in the code above, so if you don't want to be spoiled, do not look
at the 'numberToLexi()' function.)


So this stuff can actually by useful, even it if's weird... er, even if
it's weird.  Sorry, I'm just so excited about this that my fingers are
transposing words.  *grin*


Hope this helps!



From idiot1@netzero.net  Mon Mar  4 06:42:48 2002
From: idiot1@netzero.net (kirk Bailey)
Date: Mon, 04 Mar 2002 01:42:48 -0500
Subject: [Tutor] USELESS PYTHON
Message-ID: <3C831768.7FEBC9F0@netzero.net>

I just sent acode snippet to uselesspython about how to teack a
program to fuigure out whre it lives. Thought it might be suitable
material for the site.

-- 
 
end
	    Respectfully,
			 Kirk D Bailey


+---------------------"Thou Art Free." -Eris----------------------+
| http://www.howlermonkey.net mailto:highprimate@howlermonkey.net |
| http://www.tinylist.org  +--------+  mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking---------------------+
                           +--------+

NOTE: By sending SPAM to this address you agree to pay me a service
fee of $100 for the service of receiving,  storing,  examining, and
deleting your piece of SPAM. I am a postmaster, and take a dim view
of such.
----------------------------------------------------
Sign Up for NetZero Platinum Today
Only $9.95 per month!
http://my.netzero.net/s/signup?r=platinum&refcd=PT97


From karthikg@aztec.soft.net  Mon Mar  4 08:37:31 2002
From: karthikg@aztec.soft.net (Karthik Gurumurthy)
Date: Mon, 4 Mar 2002 14:07:31 +0530
Subject: [Tutor] idle not starting up..
In-Reply-To: <Pine.LNX.4.21.0203031836000.3576-100000@hkn.eecs.berkeley.edu>
Message-ID: <NEBBJNMDEKBIBCMCNMBDCEIMDEAA.karthikg@aztec.soft.net>

installed python2.2. Tried starting idle.
This is the error am getting. It was working just fine until i had to remove
it.
Then i re-installed it today. Any idea as to what i s'd be doing to get it
to work.



D:\Python\Tools\idle>python idle.py
Traceback (most recent call last):
  File "idle.py", line 4, in ?
    PyShell.main()
  File "D:\Python\Tools\idle\PyShell.py", line 747, in main
    root = Tk(className="Idle")
  File "D:\Python\lib\lib-tk\Tkinter.py", line 1487, in __init__
    self.tk = _tkinter.create(screenName, baseName, className)
TclError: Can't find a usable init.tcl in the following directories:
    d:/ruby/tcl/lib/tcl8.3 d:/python/lib/tcl8.3 d:/lib/tcl8.3 lib/tcl8.3
lib/tcl8.3/library library ../tcl8.3/library



This probably means that Tcl wasn't installed properly.



From toodles@yifan.net  Mon Mar  4 08:20:37 2002
From: toodles@yifan.net (Andy W)
Date: Mon, 4 Mar 2002 16:20:37 +0800
Subject: [Tutor] python-win32 pointer
Message-ID: <000501c1c355$7827b830$3100a8c0@sun>

Hi,

I've just decided to get my hands dirty with the win32all package. I'm
having some woes, as I'm not experienced with Windows Messages. I've
searched for a few hours for the answer, through documentation and google...
but no luck.
Can someone please direct me to a mailing-list that is suitable to ask
questions regarding win32?

TIA,
Andy



From karthikg@aztec.soft.net  Mon Mar  4 08:58:04 2002
From: karthikg@aztec.soft.net (Karthik Gurumurthy)
Date: Mon, 4 Mar 2002 14:28:04 +0530
Subject: [Tutor] RE: idle not starting up..
In-Reply-To: <NEBBJNMDEKBIBCMCNMBDCEIMDEAA.karthikg@aztec.soft.net>
Message-ID: <NEBBJNMDEKBIBCMCNMBDOEIMDEAA.karthikg@aztec.soft.net>

got it..sorry for the trouble. Actually was my system variable
TCL_LIBRARY was pointing to the wrong folder. Now it's working fine.

thanks
karthik


-----Original Message-----
From: karthik Guru [mailto:karthikg@aztec.soft.net]
Sent: Monday, March 04, 2002 2:08 PM
To: tutor@python.org
Subject: idle not starting up..


installed python2.2. Tried starting idle.
This is the error am getting. It was working just fine until i had to remove
it.
Then i re-installed it today. Any idea as to what i s'd be doing to get it
to work.



D:\Python\Tools\idle>python idle.py
Traceback (most recent call last):
  File "idle.py", line 4, in ?
    PyShell.main()
  File "D:\Python\Tools\idle\PyShell.py", line 747, in main
    root = Tk(className="Idle")
  File "D:\Python\lib\lib-tk\Tkinter.py", line 1487, in __init__
    self.tk = _tkinter.create(screenName, baseName, className)
TclError: Can't find a usable init.tcl in the following directories:
    d:/ruby/tcl/lib/tcl8.3 d:/python/lib/tcl8.3 d:/lib/tcl8.3 lib/tcl8.3
lib/tcl8.3/library library ../tcl8.3/library



This probably means that Tcl wasn't installed properly.



From sheila@thinkspot.net  Mon Mar  4 14:16:38 2002
From: sheila@thinkspot.net (Sheila King)
Date: Mon, 04 Mar 2002 06:16:38 -0800
Subject: [Tutor] python-win32 pointer
In-Reply-To: <000501c1c355$7827b830$3100a8c0@sun>
References: <000501c1c355$7827b830$3100a8c0@sun>
Message-ID: <942AB1CCC@kserver.org>

On Mon, 4 Mar 2002 16:20:37 +0800, "Andy W" <toodles@yifan.net>  wrote
about [Tutor] python-win32 pointer:

> Can someone please direct me to a mailing-list that is suitable to ask
> questions regarding win32?

http://mail.python.org/mailman/listinfo/python-win32

Tip: All Python mailing lists (or at least a very seemly long list) are
located at:
http://mail.python.org

HTH,

-- 
Sheila King
http://www.thinkspot.net/sheila/

"When introducing your puppy to an adult cat,
restrain the puppy, not the cat." -- Gwen Bailey,
_The Perfect Puppy: How to Raise a Well-behaved Dog_



From alan.gauld@bt.com  Mon Mar  4 15:34:24 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 4 Mar 2002 15:34:24 -0000
Subject: [Tutor] was no subject, getting started
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C3F1@mbtlipnt02.btlabs.bt.co.uk>

> If you're in windows you have my sympathy.
> You will probably need to add the appropriate paths and actually have 
> something like this
> 
> c:\ c:\python21\python c:\my documents\python\myscript.py

This is the pathalogical cxase. In most situations the 
PATH etc will be set up by the installer so all you need 
to do is (in a DOS box) type:

C:\> python myscript.py

The file associations and PATH settings will do the rest...

Alternatively go to Start->Run anf type 

myscript.py

In the dialog and the file extension will automatically 
detect python as the executable.

And finally yopu can just navigate to the file and double 
click in explorer.

> Windows is not really very nice for developing partly because 
> of these problems.

Its really not that painful!
The DOS prompt is dumb and there are several other issues 
but I don't think that launching apps is a significant barrier.

Alan g.


From alan.gauld@bt.com  Mon Mar  4 17:14:11 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 4 Mar 2002 17:14:11 -0000
Subject: [Tutor] round so only see 2 digits
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C3F4@mbtlipnt02.btlabs.bt.co.uk>

> I've got a similar question:  How do I round a float to get 
> rid of the leading zero before the decimal?  

Its got nothing to do with rounding but is purely about 
formatting. However I don't know of any way to do that 
without actually manipulating the string at a character level.

Probably because its an extremely BAD thing to do 
- it makes decimal numbers very hard to read and your output 
therefore very error prone...

> Maybe I missed it?  That's quite probable.

I doubt it, I just doubt that anyone ever considered 
providing such a thing.

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


From alan.gauld@bt.com  Mon Mar  4 17:17:30 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 4 Mar 2002 17:17:30 -0000
Subject: [Tutor] python-win32 pointer
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C3F5@mbtlipnt02.btlabs.bt.co.uk>

> Can someone please direct me to a mailing-list that is suitable to ask
> questions regarding win32?

Depends on what you want to ask!

Have you tried the Microsoft Developer Network site? 
They have the answer to most things on there if you 
can only figure out what question to ask :-/

Alan G


From kojo@hal-pc.org  Mon Mar  4 17:34:35 2002
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Mon, 04 Mar 2002 11:34:35 -0600
Subject: [Tutor] round so only see 2 digits
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C3F4@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <web-5161584@mail.hal-pc.org>

Thanks for the response Alan.  I may try to manipulate the 
string at the character level.

What I'm trying to do is perform a computation on a number 
(my age) to split it into three numbers, like a software 
version number (Major.Minor.Revision).  I'd like to have 
all three numbers be seperate, and then print them, but I 
may have to just add the Minor and Revision numbers 
together.

On Mon, 4 Mar 2002 17:14:11 -0000 
  alan.gauld@bt.com wrote:
>> I've got a similar question:  How do I round a float to 
>>get 
>> rid of the leading zero before the decimal?  
>
>Its got nothing to do with rounding but is purely about 
>formatting. However I don't know of any way to do that 
>without actually manipulating the string at a character 
>level.
>
>Probably because its an extremely BAD thing to do 
>- it makes decimal numbers very hard to read and your 
>output 
>therefore very error prone...
>
>> Maybe I missed it?  That's quite probable.
>
>I doubt it, I just doubt that anyone ever considered 
>providing such a thing.
>
>Alan g.
>Author of the 'Learning to Program' web site
>http://www.freenetpages.co.uk/hp/alan.gauld

****************************
Kojo Idrissa

kojo@hal-pc.org
http://www.hal-pc.org/~kojo/
****************************


From jeff@ccvcorp.com  Mon Mar  4 17:40:36 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Mon, 04 Mar 2002 09:40:36 -0800
Subject: [Tutor] where am I, revisited
References: <E16gqPG-0006JV-00@mail.python.org> <3C7FD01D.2146105E@ccvcorp.com> <196C994068@kserver.org>
Message-ID: <3C83B194.8BA05E63@ccvcorp.com>


Sheila King wrote:

> On Fri, 01 Mar 2002 11:01:49 -0800, "Jeff Shannon" <jeff@ccvcorp.com>
> wrote about Re: [Tutor] where am I, revisited:
>
> > I think that a better option would be to use the __file__ attribute of on of your modules.
> > This contains the (fully qualified) path of the file that the module was loaded from.
> >
> > >>> import os
> > >>> print os.__file__
> > C:\PYTHON21\lib\os.pyc
> > >>>
>
> However, I don't think your suggested fix will work for the particular
> script *I'm* running (where I got this suggestion that I made to Kirk). The
> modules from the standard Python library are in a completely different
> location, and I have no modules that I'm using in the same location as the
> script. I get the impression that
> sys.argv[0].__file__
>
> probably doesn't work? I have to do that on an imported module? But I have
> no imported module in that directory, so...

I believe (though you'll want to test this out) that an unqualified __file__ refers to the file of
the currently executing module -- in other words, it's just like any other module-global attribute,
requiring qualification when you're looking for the attribute belonging to an outside (imported)
module.  However, I haven't tested this recently, so I could be mistaken.  :)

Jeff Shannon
Technician/Programmer
Credit International




From jeff@ccvcorp.com  Mon Mar  4 17:56:43 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Mon, 04 Mar 2002 09:56:43 -0800
Subject: [Tutor] python-win32 pointer
References: <E16hvq5-0003uG-00@mail.python.org>
Message-ID: <3C83B55A.D10B2389@ccvcorp.com>

> "Andy W" <toodles@yifan.net> wrote:
>
> I've just decided to get my hands dirty with the win32all package. I'm
> having some woes, as I'm not experienced with Windows Messages. I've
> searched for a few hours for the answer, through documentation and google...
> but no luck.
> Can someone please direct me to a mailing-list that is suitable to ask
> questions regarding win32?

Someone already pointed you to the python-win32 list, but I thought I'd add that, unless
you're trying to use the PythonWin MFC bindings, you really don't need to know anything
about Windows messages, per se, in order to use win32all.  There's several large
subpackages in win32all, and the MFC bindings are, for me at least, the least-used part
(I use wxPython for all my GUI needs).  And while the win32 list is a good place to ask
questions about things that are entirely win32 specific, you're also welcome to ask
questions here.  :)

Jeff Shannon
Technician/Programmer
Credit International




From alan.gauld@bt.com  Mon Mar  4 17:58:26 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 4 Mar 2002 17:58:26 -0000
Subject: [Tutor] round so only see 2 digits
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C3F6@mbtlipnt02.btlabs.bt.co.uk>

> What I'm trying to do is perform a computation on a number 
> (my age) to split it into three numbers, like a software 
> version number (Major.Minor.Revision).  

>>> def mkTriPart(a,b,c): return "%d.%d.%d" %(a,b,c)
>>> def splitTriPart(n): return map(int,n.split('.'))
>>>
>>> yrs = 42
>>> mnth = 11
>>> days = 7
>>> age = mkTriPart(yrs,mnth,days)
>>> print age
'42.11.7'
>>> y = splitTriPart(age)
>>> print "Yrs: %d  Mnths: %d  Days: %d" % (y[0],y[1],y[2])
Yrs: 42  Mnths: 11  Days: 7
>>> Maj = 2
>>> Min = 1
>>> Rev = 123
>>> vers = mkTriPart(Maj,Min,Rev)
>>> etc...

That kind of thing?

Alan g.


From dyoo@hkn.eecs.berkeley.edu  Mon Mar  4 18:30:59 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 4 Mar 2002 10:30:59 -0800 (PST)
Subject: [Tutor] USELESS PYTHON
In-Reply-To: <3C831768.7FEBC9F0@netzero.net>
Message-ID: <Pine.LNX.4.21.0203041026330.19365-100000@hkn.eecs.berkeley.edu>

On Mon, 4 Mar 2002, kirk Bailey wrote:

> I just sent acode snippet to uselesspython about how to teack a
> program to fuigure out whre it lives. Thought it might be suitable
> material for the site.

Hi Kirk,

Cool!  If you have time, can you also toss it on ChalkBoard?

ChalkBoard's URL is:

    http://www.decrem.com:8080/ChalkBoard

Maybe we can use ChalkBoard as a secondary submission area for Useless.  
I dunno; I'm just trying to think of ways of making ChalkBoard useful for
Useless.  *grin*



From kojo@hal-pc.org  Mon Mar  4 18:46:34 2002
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Mon, 04 Mar 2002 12:46:34 -0600
Subject: [Tutor] round so only see 2 digits
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C3F6@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <web-5166061@mail.hal-pc.org>

Sort of.  If you look at my web page (link in my SIG 
Block) you'll see my (out of date) version number.  I keep 
changing it by hand, but I've been meaning to write a 
program to calculate it continuously.

Here's my current code:
import time
bday=(time.time()-(3600*24*213))
age=bday/(3600*24*365.25)
print "My current age is %2.6f" %age
print 10*"*"

major=age/10
major_ver=int(major)
print "My Major Version Number is %d" %major_ver
print 10*"*"

minor=age-(major_ver*10)
minor_ver=int(minor)
print "My Minor Version Number is %d" %minor_ver
print 10*"*"

rev=minor-minor_ver
print '%(rev)2.6f' %vars()
print "My Revision Number is %.6f" %rev
print 10*"*"
minor_rev=age%10
print "My Minor + Revision Number is %.6f" %minor_rev

print "Kojo Idrissa: Version Number %d.%.6f" %(major_ver, 
minor_rev)


Here's the output:
A:\Python>version.py
My current age is 31.588722
**********
My Major Version Number is 3
**********
My Minor Version Number is 1
**********
0.588722
My Revision Number is 0.588722
**********
My Minor + Revision Number is 1.588722
Kojo Idrissa: Version Number 3.1.588722

I'm trying to get rid of the leadin "0" on the Revision 
Number.  My current "workaround" is to just add the Minor 
and Revision numbers together.  Any ideas, other than 
converting the value to a string and manipulating that?

Thanks,

On Mon, 4 Mar 2002 17:58:26 -0000
  alan.gauld@bt.com wrote:
>> What I'm trying to do is perform a computation on a 
>>number 
>> (my age) to split it into three numbers, like a software 
>> version number (Major.Minor.Revision).  
>
>>>> def mkTriPart(a,b,c): return "%d.%d.%d" %(a,b,c)
>>>> def splitTriPart(n): return map(int,n.split('.'))
>>>>
>>>> yrs = 42
>>>> mnth = 11
>>>> days = 7
>>>> age = mkTriPart(yrs,mnth,days)
>>>> print age
>'42.11.7'
>>>> y = splitTriPart(age)
>>>> print "Yrs: %d  Mnths: %d  Days: %d" % (y[0],y[1],y[2])
>Yrs: 42  Mnths: 11  Days: 7
>>>> Maj = 2
>>>> Min = 1
>>>> Rev = 123
>>>> vers = mkTriPart(Maj,Min,Rev)
>>>> etc...
>
>That kind of thing?
>
>Alan g.
>
>_______________________________________________
>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 dsh8290@rit.edu  Mon Mar  4 20:35:12 2002
From: dsh8290@rit.edu (dman)
Date: Mon, 4 Mar 2002 15:35:12 -0500
Subject: [Tutor] round so only see 2 digits
In-Reply-To: <web-5166061@mail.hal-pc.org>
References: <web-5166061@mail.hal-pc.org>
Message-ID: <20020304203512.GA17077@dman.ddts.net>

On Mon, Mar 04, 2002 at 12:46:34PM -0600, Kojo Idrissa wrote:
[talk of version numbers]

| Here's the output:
| A:\Python>version.py
| My current age is 31.588722
| **********
| My Major Version Number is 3
| **********
| My Minor Version Number is 1
| **********
| 0.588722
| My Revision Number is 0.588722
| **********
| My Minor + Revision Number is 1.588722
| Kojo Idrissa: Version Number 3.1.588722
| 
| I'm trying to get rid of the leadin "0" on the Revision 
| Number.  My current "workaround" is to just add the Minor 
| and Revision numbers together.  Any ideas, other than 
| converting the value to a string and manipulating that?

If you can guarantee that all numbers will be less than one :

rev = ("%.6f" % .588722)[1:]
print rev

or, perhaps better,

rev = '.' + ("%.6f" % .588722).split( '.' )[1]
print rev


Alternatively, use integers for everything and format the result at
the end.  Recall that version numbers are not floating point numbers,
but rather dot-separated integers.


age = (time.time()-(3600*24*213))/(3600*24*365.25)
major = int( age/10 )
minor = int( age - (major*10) )
micro = int( ( (age-(major_ver*10)) - int(minor) ) * (10**6) )

print "Age is %d.%d.%d" % (major , minor , micro)


This is effectively what you had (without the locals just to make my
email shorter).  The change is for the "micro" number, instead
left-shift by 6 decimal places before rounding/truncation to int.

HTH,
-D

-- 

For society, it's probably a good thing that engineers value function
over appearance.  For example, you wouldn't want engineers to build
nuclear power plants that only _look_ like they would keep all the
radiation inside.
    (Scott Adams - The Dilbert principle)



From dyoo@hkn.eecs.berkeley.edu  Mon Mar  4 21:36:36 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 4 Mar 2002 13:36:36 -0800 (PST)
Subject: [Tutor] RE: idle not starting up..
In-Reply-To: <NEBBJNMDEKBIBCMCNMBDOEIMDEAA.karthikg@aztec.soft.net>
Message-ID: <Pine.LNX.4.21.0203040926350.18181-100000@hkn.eecs.berkeley.edu>

On Mon, 4 Mar 2002, Karthik Gurumurthy wrote:

> got it..sorry for the trouble. Actually was my system variable
> TCL_LIBRARY was pointing to the wrong folder. Now it's working fine.

Wow, that was obscure!  Glad to hear that you found the problem.


By the way, this is the second time that I've seen something with Ruby:

>     d:/ruby/tcl/lib/tcl8.3 d:/python/lib/tcl8.3 d:/lib/tcl8.3
> lib/tcl8.3 lib/tcl8.3/library library ../tcl8.3/library

where Tk library paths have gone bizarre.  Is there a relationship to
this?



From kojo@hal-pc.org  Mon Mar  4 22:32:08 2002
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Mon, 04 Mar 2002 16:32:08 -0600
Subject: [Tutor] Time Travel?
Message-ID: <web-5180209@mail.hal-pc.org>

Ok, I got my "version" program working, but now something 
odd has popped up.

Here's the output again....


My current age is 31.589136
**********
My Major Version Number is 3
**********
My Minor Version Number is 1
**********
My Revision Number is 589135
**********
Kojo Idrissa: Version Number 3.1.589135

Notice that the Revision number in the last 2 lines should 
be the same as the decimal value in the age in the first 
line...but it's not.  Sometimes they're equal, but often 
the Age decimal's last digit is one greater than the 
Revision number's last digit.  I seem to be stepping back 
in time a fraction of a second as the program runs...

It just occurs to me as I typed this...I used int() to 
create the Revision Numbers (thanks D-Man!).  It's 
probably a function of how int() does it's "magic".

<Looks at Python Docs..."int()...conversion truncates 
towards zero">

I'll assume that's what "truncate towards zero" means. 
 So, now that I've demonstrated my ability to read the 
docs (to myself and the rest of the list), have I answered 
my own question correctly?

Once I get this done, I'll turn it into a function that 
takes your birthday as an argument, slap a nice little GUI 
on it and submit it to Useless Python...that way everyone 
can stop aging like I have and only "upgrade".  I think 
that might just be useless enough.
:-)

****************************
Kojo Idrissa

kojo@hal-pc.org
http://www.hal-pc.org/~kojo/
****************************


From dgrayshn@hotmail.com  Mon Mar  4 20:24:36 2002
From: dgrayshn@hotmail.com (Tom Horton)
Date: Mon, 4 Mar 2002 15:24:36 -0500
Subject: [Tutor] can't use floor or ceil functions in python
Message-ID: <OE53taFcFzr8cgVtu8T0000e9da@hotmail.com>

This is a multi-part message in MIME format.

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

Hi all,
I've downloaded and am practicing with Python 2.1.2 for Windows and am =
reading the book by Ivan Van Laningham titled Teach Yourself Python in =
24 hours.  I'm in the 3rd hour and can't seem to get the floor and ceil =
(or pi) functions to run.  It says these commands are not defined.  Any =
ideas?

thanks,
-Tom Horton

------=_NextPart_000_0005_01C1C390.B1B4AF00
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.2713.1100" 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>I've downloaded and am practicing with =
Python 2.1.2=20
for Windows and am reading the book by Ivan Van Laningham titled Teach =
Yourself=20
Python in 24 hours.&nbsp; I'm in the 3rd hour and can't seem to get the =
floor=20
and ceil (or pi) functions to run.&nbsp; It says these commands are not=20
defined.&nbsp; Any ideas?</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>-Tom Horton</FONT></DIV></BODY></HTML>

------=_NextPart_000_0005_01C1C390.B1B4AF00--


From dyoo@hkn.eecs.berkeley.edu  Tue Mar  5 00:02:33 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 4 Mar 2002 16:02:33 -0800 (PST)
Subject: [Tutor] Time Travel?
In-Reply-To: <web-5180209@mail.hal-pc.org>
Message-ID: <Pine.LNX.4.21.0203041557580.27026-100000@hkn.eecs.berkeley.edu>

On Mon, 4 Mar 2002, Kojo Idrissa wrote:

> Ok, I got my "version" program working, but now something 
> odd has popped up.
> 
> Here's the output again....
> 
> 
> My current age is 31.589136
> **********
> My Major Version Number is 3
> **********
> My Minor Version Number is 1
> **********
> My Revision Number is 589135
> **********
> Kojo Idrissa: Version Number 3.1.589135

*laughing* Thank you, that made my day.



> Notice that the Revision number in the last 2 lines should be the same
> as the decimal value in the age in the first line...but it's not.  
> Sometimes they're equal, but often the Age decimal's last digit is one
> greater than the Revision number's last digit.  I seem to be stepping
> back in time a fraction of a second as the program runs...

Hmmm, that's odd!


> <Looks at Python Docs..."int()...conversion truncates 
> towards zero">
> 
> I'll assume that's what "truncate towards zero" means.


>  So, now that I've demonstrated my ability to read the docs (to myself
> and the rest of the list), have I answered my own question correctly?

Possibly.  If you'd like, you can post the adjusted code, and we can see
if we can fix that moment in time.


Good luck to you!



From dsh8290@rit.edu  Tue Mar  5 00:09:00 2002
From: dsh8290@rit.edu (dman)
Date: Mon, 4 Mar 2002 19:09:00 -0500
Subject: [Tutor] can't use floor or ceil functions in python
In-Reply-To: <OE53taFcFzr8cgVtu8T0000e9da@hotmail.com>
References: <OE53taFcFzr8cgVtu8T0000e9da@hotmail.com>
Message-ID: <20020305000900.GA18965@dman.ddts.net>

On Mon, Mar 04, 2002 at 03:24:36PM -0500, Tom Horton wrote:
| Hi all,
| I've downloaded and am practicing with Python 2.1.2 for Windows and
| am reading the book by Ivan Van Laningham titled Teach Yourself
| Python in 24 hours.  I'm in the 3rd hour and can't seem to get the
| floor and ceil (or pi) functions to run.  It says these commands are
| not defined.  Any ideas?

I don't have the book so I can't see what the example shows.  Can you
post the code?  Can you post what you tried?  Just copy-n-paste from
the interactive interpreter.

My guess is that you haven't imported the "math" module, or that you
aren't qualifying the names of the functions.  Here's an example that
works :


import math
print math.pi
print math.floor( 31.58889 )
print math.ceil( 31.58889 )


HTH,
-D

-- 

The teaching of the wise is a fountain of life,
turning a man from the snares of death.
        Proverbs 13:14



From dyoo@hkn.eecs.berkeley.edu  Tue Mar  5 00:07:55 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 4 Mar 2002 16:07:55 -0800 (PST)
Subject: [Tutor] can't use floor or ceil functions in python
In-Reply-To: <OE53taFcFzr8cgVtu8T0000e9da@hotmail.com>
Message-ID: <Pine.LNX.4.21.0203041602430.27026-100000@hkn.eecs.berkeley.edu>

On Mon, 4 Mar 2002, Tom Horton wrote:

> I've downloaded and am practicing with Python 2.1.2 for Windows and am
> reading the book by Ivan Van Laningham titled Teach Yourself Python in
> 24 hours.

Cool; how is the book?


> I'm in the 3rd hour and can't seem to get the floor and ceil (or pi)
> functions to run.  It says these commands are not defined.  Any ideas?

Those functions and variables should be defined in the 'math' module, so
you may need to 'import' the math module before playing with it.  Here's
an example in the interactive interpreter:

###
>>> import math
>>> math.pi
3.1415926535897931
>>> math.ceil(math.pi)
4.0
>>> math.floor(math.pi)
3.0
###


By the way, your post may have been delayed for a few hours because you
aren't subscribed to Tutor yet; you can subscribe here:

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

and your posts shouldn't get delayed after that.

(This requirement might seem stringent, but we've chosen to do moderation
on non-subscribers because spammers try abusing us every so often.)


If you have more questions, please feel free to ask them.  Best of wishes!



From lha2@columbia.edu  Tue Mar  5 00:23:20 2002
From: lha2@columbia.edu (Lloyd Hugh Allen)
Date: Mon, 04 Mar 2002 19:23:20 -0500
Subject: [Tutor] RE: idle not starting up..
References: <Pine.LNX.4.21.0203040926350.18181-100000@hkn.eecs.berkeley.edu>
Message-ID: <3C840FF8.71FF4EBB@mail.verizon.net>

I noticed the word "ruby" in there--Ruby screws up the autoexec.bat, and
uninstalling Ruby does NOT fix the autoexec.bat. This issue has been
submitted to ruby's bug tracker, but is still in their "incoming"
folder. Maybe they need some more people to submit reports?

Danny Yoo wrote:
> 
> On Mon, 4 Mar 2002, Karthik Gurumurthy wrote:
> 
> > got it..sorry for the trouble. Actually was my system variable
> > TCL_LIBRARY was pointing to the wrong folder. Now it's working fine.
> 
> Wow, that was obscure!  Glad to hear that you found the problem.
> 
> By the way, this is the second time that I've seen something with Ruby:
> 
> >     d:/ruby/tcl/lib/tcl8.3 d:/python/lib/tcl8.3 d:/lib/tcl8.3
> > lib/tcl8.3 lib/tcl8.3/library library ../tcl8.3/library
> 
> where Tk library paths have gone bizarre.  Is there a relationship to
> this?
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


From kojo@hal-pc.org  Tue Mar  5 00:22:20 2002
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Mon, 04 Mar 2002 18:22:20 -0600
Subject: [Tutor] Time Travel?
In-Reply-To: <Pine.LNX.4.21.0203041557580.27026-100000@hkn.eecs.berkeley
 .edu>
References: <web-5180209@mail.hal-pc.org>
Message-ID: <5.1.0.14.0.20020304181917.00b0e728@Pop3.norton.antivirus>

Well, I'm glad Danny got a kick out of my "Version" scheme...

Here's the code:
import time
bday=(time.time()-(3600*24*213))
age=bday/(3600*24*365.25)
print "My current age is %2.6f" %age
print 10*"*"

major=age/10
major_ver=int(major)
print "My Major Version Number is %d" %major_ver
print 10*"*"

minor=age-(major_ver*10)
minor_ver=int(minor)
print "My Minor Version Number is %d" %minor_ver
print 10*"*"

#D-Man on Python Tutor suggested this...the "10**6" is used
#to shift the decimal point to the right, then the value is
#made into an integer...version numbers are decimal-seperated
#integers, not decimals
rev= int((minor-minor_ver)*10**6)
print "My Revision Number is %d" %rev
print 10*"*"

print "Kojo Idrissa: Version Number %d.%.d.%d" %(major_ver, minor_ver, rev)

So, is it a "int truncates to zero" deal, or have I, using only Python, 
unlocked a secret way to manipulate the space-time continuum?!?


At 04:02 PM 3/4/2002 -0800, Danny Yoo wrote:
>On Mon, 4 Mar 2002, Kojo Idrissa wrote:
>
> > Ok, I got my "version" program working, but now something
> > odd has popped up.
> >
> > Here's the output again....
> >
> >
> > My current age is 31.589136
> > **********
> > My Major Version Number is 3
> > **********
> > My Minor Version Number is 1
> > **********
> > My Revision Number is 589135
> > **********
> > Kojo Idrissa: Version Number 3.1.589135
>
>*laughing* Thank you, that made my day.
>
><snip>

****************************
Kojo Idrissa

kojo@hal-pc.org
http://www.hal-pc.org/~kojo/
****************************



From dyoo@hkn.eecs.berkeley.edu  Tue Mar  5 00:41:23 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 4 Mar 2002 16:41:23 -0800 (PST)
Subject: [Tutor] Time Travel?
In-Reply-To: <5.1.0.14.0.20020304181917.00b0e728@Pop3.norton.antivirus>
Message-ID: <Pine.LNX.4.21.0203041635520.27755-100000@hkn.eecs.berkeley.edu>

On Mon, 4 Mar 2002, Kojo Idrissa wrote:

> Well, I'm glad Danny got a kick out of my "Version" scheme...
> 
> Here's the code:
> import time
> bday=(time.time()-(3600*24*213))
> age=bday/(3600*24*365.25)
> print "My current age is %2.6f" %age


Hmmm... let me check something:

###
>>> '%0.1f' % 0.66
'0.7'
>>> '%0.2f' % 0.66
'0.66'
###

The rounding behavior of format strings might account for the discrepency
in the space-time continuum.  As you've notice, int() doesn't round, but
instead truncates --- it just drops the fractional part of a float on the
ground:

###
>>> int(-4.5)
-4
>>> int(4.5)
4
###


You might want to use a round() in the expression:

> rev= int((minor-minor_ver)*10**6)


###
rev = int(round((minor-minor_ver)*10**6))
###

and thereby repair the singularity.


Good luck!



From toodles@yifan.net  Tue Mar  5 06:41:13 2002
From: toodles@yifan.net (Andy W)
Date: Tue, 5 Mar 2002 14:41:13 +0800
Subject: [Tutor] python-win32 pointer
References: <E16hvq5-0003uG-00@mail.python.org> <3C83B55A.D10B2389@ccvcorp.com>
Message-ID: <005b01c1c410$bfef33d0$3100a8c0@sun>

> Someone already pointed you to the python-win32 list, but I thought I'd
add that, unless
> you're trying to use the PythonWin MFC bindings, you really don't need to
know anything
> about Windows messages, per se, in order to use win32all.  There's several
large
> subpackages in win32all, and the MFC bindings are, for me at least, the
least-used part
> (I use wxPython for all my GUI needs).  And while the win32 list is a good
place to ask
> questions about things that are entirely win32 specific, you're also
welcome to ask
> questions here.  :)

Thanks everyone that answered.
I'm new to Windows programming, much of the programming I've done has been
done without the need for GUIs. I don't want to create GUIs with win32all, I
also use wxPython for that :)

What I want to do is send keyboard messages to a window. I've done all this
so far, but I want to add key-modifiers (Control, Alt & Shift). I think I
send a WM_SYSKEYDOWN message, but nothing I do seems to work...
The folks at python-win32 underestimated just how new I am to the topic, I
think.

Thanks,
Andy W

>
> Jeff Shannon
> Technician/Programmer
> Credit International
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



From dgrayshn@hotmail.com  Tue Mar  5 14:19:35 2002
From: dgrayshn@hotmail.com (Tom Horton)
Date: Tue, 5 Mar 2002 09:19:35 -0500
Subject: [Tutor] can't use floor or ceil functions in python
References: <Pine.LNX.4.21.0203041602430.27026-100000@hkn.eecs.berkeley.edu>
Message-ID: <OE280LUDA1XiHY5FbEF0000dc8b@hotmail.com>

Danny and dman,
Thanks that worked like a charm...I hadn't imported the math module properly
but it works now.  I had subscribed for the list minutes after I had sent
this mail out.  The book is pretty good and I'm learning quite a bit from
it.  I have a coding guru down the hall from me whose brain i've been
picking too.  Thanks again for the help.

-Tom Horton

----- Original Message -----
From: "Danny Yoo" <dyoo@hkn.eecs.berkeley.edu>
To: "Tom Horton" <dgrayshn@hotmail.com>
Cc: <tutor@python.org>
Sent: Monday, March 04, 2002 7:07 PM
Subject: Re: [Tutor] can't use floor or ceil functions in python


> On Mon, 4 Mar 2002, Tom Horton wrote:
>
> > I've downloaded and am practicing with Python 2.1.2 for Windows and am
> > reading the book by Ivan Van Laningham titled Teach Yourself Python in
> > 24 hours.
>
> Cool; how is the book?
>
>
> > I'm in the 3rd hour and can't seem to get the floor and ceil (or pi)
> > functions to run.  It says these commands are not defined.  Any ideas?
>
> Those functions and variables should be defined in the 'math' module, so
> you may need to 'import' the math module before playing with it.  Here's
> an example in the interactive interpreter:
>
> ###
> >>> import math
> >>> math.pi
> 3.1415926535897931
> >>> math.ceil(math.pi)
> 4.0
> >>> math.floor(math.pi)
> 3.0
> ###
>
>
> By the way, your post may have been delayed for a few hours because you
> aren't subscribed to Tutor yet; you can subscribe here:
>
>     http://mail.python.org/mailman/listinfo/tutor
>
> and your posts shouldn't get delayed after that.
>
> (This requirement might seem stringent, but we've chosen to do moderation
> on non-subscribers because spammers try abusing us every so often.)
>
>
> If you have more questions, please feel free to ask them.  Best of wishes!
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>


From python_list@edsamail.com.ph  Thu Mar  7 23:46:04 2002
From: python_list@edsamail.com.ph (Python Newbie)
Date: Thu, 7 Mar 2002 15:46:04 -0800
Subject: [Tutor] Newbie problems
Message-ID: <E16iH61-0005cV-00@mail.python.org>

Hello Python gurus,

First of all, please forgive me if I have so many questions to ask.  Thank you in advance for understanding and giving time to read and probably answer my problem.

I'm starting to learn Python and I want to try to make a simple personal exercise, something like a simple file compression.  I'm just wondering how will I be able to write it in my Python code to "read" from a text file?  For example, my simple Python program will ask what file that will be compress or uncompress?  Please consider the display:

- - - < s n i p > - - -

Please enter the filename to compress:

or

Please enter the filename to uncompress:

- - - < s n i p > - - -

So, it will "read" the filename that has been entered and will look for it.  If found, it will "write" to the same filename but if not, it will just prompt: "Please try again."

Second, I don't know if this was already been posted but I want to make a simple "text menu" in order to choose what functions/sub-programs shall be executed.  My problem is, how will I "ignore" the wrong type of choices?  Please consider my simple text menu below:

- - - < s n i p > - - -

- MY SIMPLE PROGRAM -

[1] Sub-program 1
[2] Sub-program 2
[3] Sub-program 3
[4] Sub-program 4
[5] Sub-program 5
[Q/q] Exit

Please enter your choice:

- - - < s n i p > - - -

If the "choice" is any character except "Q or q", it should not supposedly "exit" from the main program but rather it will just "ignore" or will not accept the "inputted" character or probably will display first an error message something like "Wrong input. Please try again." and the cursor will go back to the "choices".

The problem with input() is it will exit from the main program and display some errors if the "inputted" choice is not an integer.  Likewise with raw_input(), the opposite of input().

Last but not the least, what is "gotoxy" of Pascal in Python?

Thank you very much...

God bless you all...

__________________________________
www.edsamail.com


From m_konermann@gmx.de  Tue Mar  5 15:44:23 2002
From: m_konermann@gmx.de (Keule)
Date: Tue, 05 Mar 2002 16:44:23 +0100
Subject: [Tutor] Tkinter entry widget question
Message-ID: <3C84E7D7.7020300@gmx.de>

Hallo !

i create a entry widgets in the following form:

from Tkinter import *
from quitter import Quitter
fields = 'Minimalwert', 
'Maximalwert','Pre-Kondition','Post-Kondition','Zeile','Spalte'

def fetch(entries):
    for entry in entries:
        print 'Input => "%s"' % entry.get()         # get text
    print 'entries=',entries
    print'entries[1]=',entries[1]

def makeform(root, fields):
    entries = []
    for field in fields:
        row = Frame(root)                           # make a new row
        lab = Label(row, width=15, text=field)       # add label, entry
        ent = Entry(row)
        row.pack(side=TOP, fill=X)                  # pack row on top
        lab.pack(side=LEFT)
        ent.pack(side=RIGHT, expand=YES, fill=X)    # grow horizontal
        entries.append(ent)
    return entries

#if __name__ == '__main__':
def variab():
    root = Tk()
    root.title('Variableneingabe')
    ents = makeform(root, fields)
    root.bind('<Return>', (lambda event, e=ents: fetch(e)))  
    Button(root, text='nächste Variable',command=(lambda e=ents: 
fetch(e))).pack(side=LEFT)
    Quitter(root).pack(side=RIGHT)
    root.mainloop()

after calling the variab() function from another menu, it´s possible to 
set the six entries ('Minimalwert', 
'Maximalwert','Pre-Kondition','Post-Kondition','Zeile','Spalte' ) in 
fields, but the print command don´t give the correct entry back, for 
example i set the six entries to: "2","3","4","5,","6","7", but the 
print command output is:

C:\Arbeit_Diplomarbeit\__Benutzerschnittstelle>python tem.py
Input => "2"
Input => "3"
Input => "4"
Input => "5"
Input => "6"
Input => "7"
entries= [<Tkinter.Entry instance at 0x008CCC20>, <Tkinter.Entry 
instance at 0x0
08CDE28>, <Tkinter.Entry instance at 0x008CE528>, <Tkinter.Entry 
instance at 0x0
08CECA0>, <Tkinter.Entry instance at 0x008CF418>, <Tkinter.Entry 
instance at 0x0
08CFC58>]
entries[1]= .9229696.9231912

So, have anyone got an idea ? How can i get back the numbers 2-7 ?
Greetings
Marcus




From wilson@isis.visi.com  Tue Mar  5 15:49:58 2002
From: wilson@isis.visi.com (Tim Wilson)
Date: Tue, 5 Mar 2002 09:49:58 -0600 (CST)
Subject: [Tutor] Python CGI and apache config
Message-ID: <Pine.GSO.4.10.10203050933350.13222-100000@isis.visi.com>

Hi everyone,

I'm planning to have the students in my programming class do some work
with CGI programming. I've got an old castoff server and I've installed
Linux on it with apache, mod_python, PostgreSQL, and other goodies. I'm
having trouble getting apache configured to run CGI scripts from users'
home directories. Each user has a /home/joeuser/public_html which is the
root for his or her personal Web page. I want
/home/joeuser/public_html/cgi-bin to be the directory for CGI scripts.
The server is running Debian if that matters.

Any hints? Here's what I've changed or added to httpd.conf

<DirectoryMatch ^/home/.*/public_html/cgi-bin>
  Options Indexes SymLinksIfOwnerMatch ExecCGI
  AllowOverride None
</DirectoryMatch>

and

AddHandler cgi-script .cgi .sh .pl .py

I'd appreciate any further pointers on this.

-Tim

--
Tim Wilson      |   Visit Sibley online:   | Check out:
Henry Sibley HS |  http://www.isd197.org   | http://www.zope.com
W. St. Paul, MN |                          | http://slashdot.org
wilson@visi.com |  <dtml-var pithy_quote>  | http://linux.com



From urnerk@qwest.net  Tue Mar  5 18:00:05 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Tue, 05 Mar 2002 10:00:05 -0800
Subject: [Tutor] Newbie problems
In-Reply-To: <E16iH61-0005cV-00@mail.python.org>
Message-ID: <4.2.0.58.20020305094208.00d13440@pop3.norton.antivirus>

>
>Second, I don't know if this was already been posted but
>I want to make a simple "text menu" in order to choose
>what functions/sub-programs shall be executed.  My problem
>is, how will I "ignore" the wrong type of choices?  Please
>consider my simple text menu below:
>
>- - - < s n i p > - - -
>
>- MY SIMPLE PROGRAM -
>
>[1] Sub-program 1
>[2] Sub-program 2
>[3] Sub-program 3
>[4] Sub-program 4
>[5] Sub-program 5
>[Q/q] Exit
>
>Please enter your choice:

Here's a simple menu template based on the above.

def mainmenu():
         switch = [f1,f2,f3,f4,f5]
         while 1:
           print """

- MY SIMPLE PROGRAM -

[1] Sub-program 1
[2] Sub-program 2
[3] Sub-program 3
[4] Sub-program 4
[5] Sub-program 5
[Q/q] Exit

"""
           userselect = raw_input("Your selection?: ")
           if userselect.upper()=="Q":
              break  #escape from loop
            else:
              try:
                  menuchoice = int(userselect)-1
              except:  # doesn't convert to integer
                  print "Please select 1-5 or Q/q
                  continue  # loop from top
          if not menuchoice>4 and not menuchoice<0:
                switch[menuchoice]()  # valid index, execute
          else:
               print "Please select 1-5 or Q/q" # out of range

If it doesn't work, please check indentation -- cut and
pasted from IDLE.

Note:  use of raw_input to get string, conversion to
integer but trapping error if it doesn't convert.

The "subprograms" (non-Python terminology) are all
top-level functions, and must already be defined for the
above to work.  I've used simple stub functions:

def f1(): print "Menu option 1"
def f2(): print "Menu option 2"
def f3(): print "Menu option 3"
def f4(): print "Menu option 4"
def f5(): print "Menu option 5"

Since Python doesn't have a switch statement, I've
initialized an array ('switch') and filled it with
pointers to (names of) these function objects.

A user selection which passes the convert-to-integer
and not-too-big-and-not-too-small tests gets to
serve as an index to this array.  But the user choice
was decremented by 1, as arrays are 0-indexed.

As these are callable function-objects, simply sticking
() after the selection (e.g. f1) causes execution thereof.

>Last but not the least, what is "gotoxy" of Pascal in Python?

Sorry, never heard of it.  Trying to position stuff on
screen?

Kirby

"You acknowledge that Software is not designed, licensed
or intended for use in the design, construction, operation
or maintenance of any nuclear facility." -- Java license
agreement



From porterh@yahoo.com  Tue Mar  5 19:19:56 2002
From: porterh@yahoo.com (Henry Porter)
Date: Tue, 5 Mar 2002 13:19:56 -0600 (CST)
Subject: [Tutor] does a variable exist?
Message-ID: <Pine.LNX.4.21.0203051317450.8597-100000@localhost.localdomain>

I want to see if a variable exists in my program.  The variable is getting
set within an 'if' statement, so sometimes it exists afterwards, but not
always.  Is there a way to check for this besides just initializing it to
something at the top of the program?

Thanks for any help,
Henry



From kauphlyn@speakeasy.org  Tue Mar  5 19:01:10 2002
From: kauphlyn@speakeasy.org (Daniel Coughlin)
Date: Tue, 5 Mar 2002 11:01:10 -0800 (PST)
Subject: [Tutor] does a variable exist?
In-Reply-To: <Pine.LNX.4.21.0203051317450.8597-100000@localhost.localdomain>
Message-ID: <Pine.LNX.4.44.0203051050170.21235-100000@grace.speakeasy.net>

Hi Henry,

One way to test whether or not your variable is set is with a try / except 
block.

for example

>>> try:
...	if a == 1:
...		print "a is 1"
...	else: print "a is not 1"
... except NameError, n:
...	print "a is not initialized"
a is not initialized

NameError is the exception that is raised when a local or global name is not 
found. n will be the be the actual exception. something like "a is not defined".
  

Hope this helps!


On Tue, 5 Mar 2002, Henry Porter wrote:

> I want to see if a variable exists in my program.  The variable is getting
> set within an 'if' statement, so sometimes it exists afterwards, but not
> always.  Is there a way to check for this besides just initializing it to
> something at the top of the program?
> 
> Thanks for any help,
> Henry
> 



From dyoo@hkn.eecs.berkeley.edu  Tue Mar  5 19:09:32 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 5 Mar 2002 11:09:32 -0800 (PST)
Subject: [Tutor] does a variable exist?
In-Reply-To: <Pine.LNX.4.21.0203051317450.8597-100000@localhost.localdomain>
Message-ID: <Pine.LNX.4.21.0203051101290.5164-100000@hkn.eecs.berkeley.edu>

On Tue, 5 Mar 2002, Henry Porter wrote:

> I want to see if a variable exists in my program.  The variable is
> getting set within an 'if' statement, so sometimes it exists
> afterwards, but not always.  Is there a way to check for this besides
> just initializing it to something at the top of the program?

It's usually safer to initialize it at the top with a special value that
you can say means "not yet defined".

Many programmers use the 'None' value for this.  You can then check to
see, after all your tests, if that variables still has the value of
'None'.  In technical terms, we're playing with a "sentinel" value, a
value that's used mostly for it's placeholder qualities.

Without the initializtion, we force ourselves to follow the program flow
to see which variables are available to us.  I think that's just a
NameError landmine just waiting to happen.  *grin*


Alternatively, if we stuff names and values within a dictionary, we can
use the has_key() method to see if there's a certain value that hasn't
been stuffed yet:

###
>>> brothers = { 'larry' : 1,
...              'curly' : 1,
...              'moe' : 1,
...              'Chico': 2 }
>>> brothers.has_key('moe')
1
>>> brothers.has_key('Flipper')
###

so perhaps a dictionary might be what you're looking for.


Good luck!



From slime@vsnl.net  Tue Mar  5 02:36:18 2002
From: slime@vsnl.net (Prahlad Vaidyanathan)
Date: Tue, 5 Mar 2002 08:06:18 +0530
Subject: [Tutor] Re: changing sys.stdin to accept keyboard input
In-Reply-To: <20020303171847.GA6733@sandra.lysator.liu.se>
References: <20020303160607.GA532@marvin.localdomain> <20020303171847.GA6733@sandra.lysator.liu.se>
Message-ID: <20020305023618.GA1834@marvin.localdomain>

Hi,

On Sun, 03 Mar 2002 Kalle Svensson spewed into the ether:
[-- snippity --]
> I guess this is OS dependent (and more), but on my GNU/Linux
> workstation this seems to work:
> 
> import sys
> print sys.stdin.read()
> sys.stdin = open("/dev/tty")
> print raw_input("Number: ")

I've got Debian here, so this works OK. Thanks !

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

"Cogito ergo I'm right and you're wrong."
		-- Blair Houghton


From dyoo@hkn.eecs.berkeley.edu  Tue Mar  5 22:49:16 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 5 Mar 2002 14:49:16 -0800 (PST)
Subject: [Tutor] Newbie problems
In-Reply-To: <4.2.0.58.20020305094208.00d13440@pop3.norton.antivirus>
Message-ID: <Pine.LNX.4.21.0203051430270.11585-100000@hkn.eecs.berkeley.edu>

On Tue, 5 Mar 2002, Kirby Urner wrote:

> 
> def mainmenu():
>          switch = [f1,f2,f3,f4,f5]
>          while 1:
>            print """

[some code cut]

> The "subprograms" (non-Python terminology) are all
> top-level functions, and must already be defined for the
> above to work.  I've used simple stub functions:
> 
> def f1(): print "Menu option 1"
> def f2(): print "Menu option 2"
> def f3(): print "Menu option 3"
> def f4(): print "Menu option 4"
> def f5(): print "Menu option 5"


Just to clarify: those functions should exist by the time we actually
execute "mainmenu()" function.  However, before we execute the function,
those f1() through f5() functions don't have to exist yet.  Python is
considered very "dynamic" because of this.


When we're declaring a function, Python actually won't even look too
closely at the body of the function; it'll look up the values of things
when we actually run the function.


This allows us do do wacky stuff like this:

###
>>> def isEven(n):
...     if n == 0:       
...         return 1
...     else:
...         return isOdd(n-1)
... 
>>> def isOdd(n):
...     if n == 0:
...         return 0
...     else:
...         return isEven(n-1)
... 
>>> isEven(1)
0
>>> isOdd(42)
0
>>> isOdd(43)
1
###

Notice that there's no real way of putting one function in "front" of the
other: they're knotted together very tightly.  We can resolve the conflict
when we see that Python won't look at function bodies until we actually
run those functions.

The above is an artificial example, of course, but there are actual cases
when we need "mutually recursive" functions that call each other, and it's
useful to know how Python handles this.





[Aside: skip this if you haven't seen C before]

This situation is very different from static languages like C or ML, where
all function names need to be known immediately.  In fact, we can't really
write isEven() and isOdd() C without contorting ourselves with function
prototypes:

/***/
/** Function prototypes */
int isEven(int n);
int isOdd(int n);

int isEven(int n) {
    if (n == 0) return 1;
    else return isOdd(n-1);
}

int isOdd(int n) {
    if (n == 0) return 0;
    else return isEven(n-1);
}
/***/

Without the function prototypes at the top, C gets totally confused and
hollers that we have no idea what we're doing.  *grin*.  This is a strong
reason why C uses function prototypes, so that C knows up front what
functions will be available.




Hope this helps!



From bembry@bembry.org  Tue Mar  5 22:47:33 2002
From: bembry@bembry.org (Bryce Embry)
Date: Tue, 05 Mar 2002 16:47:33 -0600
Subject: [Tutor] Dictionary Format
Message-ID: <5.1.0.14.0.20020305162744.00adf310@www.bembry.org>

Howdy,
I'm working on a script to help with some Windows 2000 administration and 
have run into a little dictionary glitch that confuses me.  If any of you 
folks can help, I'd really appreciate it.  I've been reading the list for a 
couple months now, but this one is new to me.

I'm using the win32 extensions to get a list of all the users in a windows 
group.  My desire is to then find out if a certain user is a faculty member 
or a student, and make adjustments to the script accordingly.  I get a list 
of users fine, but the format is odd, and I'm not able to then search the 
list to see if a user is part of the given group.

The win32net.NetGroupGetUsers() yields a list with the following dictionaries:

{'name': u'auser'}
{'name': u'buser'}
{'name': u'cuser'}
{'name': u'duser'}
{'name': u'euser'}

auser, buser, cuser, etc. are all the login user names.

I'm trying to extract just the usernames from these dictionaries, but they 
aren't exactly strings (see that goofy little u in front of the 
apostrophe).  If I use a print statement, they work fine.

for item in listofdictionaries:
         print item['name']

 >>>auser
 >>>buser
 >>>cuser

But, if I try to create a new list with just the user names I get the 
following:

[u'auser', u'buser', u'cuser', u'duser']

If I then try to ask if "auser" is in the list, the answer is no.  If I 
slice it, it just cuts off the first letter of the name:

list = []
for item in listofdictionaries:
          list.append(item['name'][1:])

 >>>[u'user', u'user', u'user']

So, what is that extra u before the string markers?   And how do I get past 
it?

Thanks for the help.

Bryce Embry


--------------------------------------------------------------------------------------------
"Lord, you establish peace for us.
All that we have accomplished
you have done for us" -- Isaiah 26:12



From lha2@columbia.edu  Wed Mar  6 00:22:41 2002
From: lha2@columbia.edu (Lloyd Hugh Allen)
Date: Tue, 05 Mar 2002 19:22:41 -0500
Subject: [Tutor] LaTeX output
Message-ID: <3C856151.6E273CB@mail.verizon.net>

Anyone know a utility to output LaTeX formatted stuff in (preferably)
Tkinter or (less preferably) wxWindows?


From urnerk@qwest.net  Wed Mar  6 00:52:27 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Tue, 05 Mar 2002 16:52:27 -0800
Subject: [Tutor] Dictionary Format
In-Reply-To: <5.1.0.14.0.20020305162744.00adf310@www.bembry.org>
Message-ID: <4.2.0.58.20020305163332.00d0f990@pop3.norton.antivirus>

At 04:47 PM 3/5/2002 -0600, Bryce Embry wrote:
>Howdy,
>I'm working on a script to help with some Windows 2000
>administration and have run into a little dictionary glitch
>that confuses me.

You're running up against the fact that user names
are being stored in unicode, vs. ascii.  This is
a manifestation of the internationalization trend.

Look in Section 3.1.3 Unicode Strings in the online
tutorial.

I'm not sure why you don't get a match when you search
a list of users for a given user:

     'auser' in [u'auser', u'buser', u'cuser', u'duser']

returns 1, even though 'auser' is an ordinary string.

Note:  in the above-mentioned tutorial section, we find
the following user-input and Python response:

   >>> u"=E4=F6=FC".encode('utf-8')   # a,o,u with double-dots above
   '\xc3\xa4\xc3\xb6\xc3\xbc'

I find this doesn't work in Windows IDLE, but does in
a DOS-based Python session.  I was previously unaware
of IDLE's limitations vis-a-vis unicode.

Kirby

"You acknowledge that Software is not designed, licensed
or intended for use in the design, construction, operation
or maintenance of any nuclear facility." -- Java license
agreement



From ponderor@lycos.com  Wed Mar  6 01:40:24 2002
From: ponderor@lycos.com (Dean Goodmanson)
Date: Tue, 05 Mar 2002 17:40:24 -0800
Subject: [Tutor] Looking for a forgiving environment
Message-ID: <HCHGGFOIGKKFOBAA@mailcity.com>

Hello!

I've spent the last half of last year lurking some Python lists, and the first few months of this year Zopin'. All with windows, some with OSX.   I'm in central WI far from any Python or Zope physical community.

I have a number of questions that aren't worthy of comp.lang.python, and that I'd rather not go down in the permanent recordbook we call "google: search: my name"...

I'm hoping that this list will be the place for those questions, or help me find a tutor for private conversations.

Examples:
Getting started...
1. Why do emails from mailman lists get annoyingly formatted when I read them from my yahoo account.  The last two or so words are wrapped--especially on reply quotes.
2. How do I connect to the Zope chat on an IRC server. I have CryptSoftware "WinBot"
3. How do I configure a newsreader to view comp.lang.python in something other than google groups?
Advocacy...
4. How can I encourage people to place a Python SOAP service on xmethods.org ?
Zope..
5. What is Zope's specialty over other products [in it's class..], and it's relationship with Radio Userland.
6. How do I get statistics from my Zope server [beyond fsCounter]?
7. Where can I go to get Python maintenance scripts for a Zope server?
(6 & 7 are examples, I haven't researched/attempted those yet.)
Community...
8. Is EDU-SIG for education developers or educators?  I'm looking for activity & discussion in the former.

Sorry for the dump, hoping examples will explain myself better.  I understand that digging on the web will usually deliver what's needed, but there comes a point when I'd like to bounce a question off a peer slightly before all resources have been exhausted...thus the need for a forgiving environment.  Did I mention that Python's shell & absence of "Classes only" enforcement along with readable syntax (examples, not just potential coding style) are the features that hooked me into enjoying the language.  
I've also been very pleased with the pleasantness of the Python/Zope community...a far cry from the chaff to sift through at Slashdot.


Best Regards,

Dean Goodmanson
http://nomad.freezope.org




2,000,000,000 Web Pages--you only need 1. Save time with My Lycos.
http://my.lycos.com


From karthikg@aztec.soft.net  Wed Mar  6 03:04:31 2002
From: karthikg@aztec.soft.net (Karthik Gurumurthy)
Date: Wed, 6 Mar 2002 08:34:31 +0530
Subject: [Tutor] Suggestions for a good book on functional programming
In-Reply-To: <3C856151.6E273CB@mail.verizon.net>
Message-ID: <NEBBJNMDEKBIBCMCNMBDAENIDEAA.karthikg@aztec.soft.net>

Since i started python, i have been fascinated by this feature. Now i find
Java very boring.
I have found some of the discussions in tutor to to be very informative.
Since most of the guys here have programmed on a pure functional
languages before, can someone suggest a good book (haskell, scheme anything
is fine)
for the same. If i have to buy one which one w'd you recommend?

Yesterday i came across a title:

Introduction to Functional Programming using Haskell
..Bird

any ideas as to whether it is good?

regards,
karthik.


From israel@lith.com  Wed Mar  6 02:54:53 2002
From: israel@lith.com (Israel Evans)
Date: Tue, 5 Mar 2002 18:54:53 -0800
Subject: [Tutor] Suggestions for a good book on functional programming
Message-ID: <AF020C5FC551DD43A4958A679EA16A15017B3FDA@abbott.lith.com>

	In a somewhat related vein, but not really, I'm interested in any
good logic programming resources.  Something along the lines of Prolog or
Mercury except using python.  I don't even know if Python has the facilities
for such an exercise, but it would be pretty neat and educational.

  Has anyone developed any sorts of Logic extensions to python?  Does python
have logic programming-like stuff? Are there any definitive books on the
subject?  Are there any less definitive but artist friendly resources out
there?

Sorry to piggy back on your post, but you reminded me of my interest. :)



~Israel~

-----Original Message-----
From: Karthik Gurumurthy [mailto:karthikg@aztec.soft.net] 
Sent: 05 March 2002 7:05 PM
To: tutor@python.org
Subject: [Tutor] Suggestions for a good book on functional programming

Since i started python, i have been fascinated by this feature. Now i find
Java very boring.
I have found some of the discussions in tutor to to be very informative.
Since most of the guys here have programmed on a pure functional
languages before, can someone suggest a good book (haskell, scheme anything
is fine)
for the same. If i have to buy one which one w'd you recommend?

Yesterday i came across a title:

Introduction to Functional Programming using Haskell
..Bird

any ideas as to whether it is good?

regards,
karthik.

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


From dyoo@hkn.eecs.berkeley.edu  Wed Mar  6 02:54:38 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 5 Mar 2002 18:54:38 -0800 (PST)
Subject: [Tutor] LaTeX output
In-Reply-To: <3C856151.6E273CB@mail.verizon.net>
Message-ID: <Pine.LNX.4.21.0203051848470.19654-100000@hkn.eecs.berkeley.edu>

On Tue, 5 Mar 2002, Lloyd Hugh Allen wrote:

> Anyone know a utility to output LaTeX formatted stuff in (preferably)
> Tkinter or (less preferably) wxWindows?

\begin{salutation}
Hello!
\end{salutation}


\begin{answer}
I did a quick search on \emph{google}, and although I haven't found
anything connected with \emph{Python} yet, I have found this:

    http://www.tm.informatik.uni-frankfurt.de/~lingnau/tkdvi/

There also appears to be a \texttt{DVI-PNG} converter:

    http://www.astro.gla.ac.uk/users/norman/star/dvi2bitmap/

so I think you should be able to use this with the
\emph{Python~Imaging`Library} to get some results.
\end{answer}


*grin* Good luck!



From dyoo@hkn.eecs.berkeley.edu  Wed Mar  6 03:00:43 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 5 Mar 2002 19:00:43 -0800 (PST)
Subject: [Tutor] Suggestions for a good book on functional programming
In-Reply-To: <NEBBJNMDEKBIBCMCNMBDAENIDEAA.karthikg@aztec.soft.net>
Message-ID: <Pine.LNX.4.21.0203051854560.19654-100000@hkn.eecs.berkeley.edu>

On Wed, 6 Mar 2002, Karthik Gurumurthy wrote:

> Since most of the guys here have programmed on a pure functional
> languages before, can someone suggest a good book (haskell, scheme
> anything is fine) for the same. If i have to buy one which one w'd you
> recommend?

I feel obligated to do the cheerleader thing for Structure and
Interpretation of Computer Programs.

    http://mitpress.mit.edu/sicp/

Rah rah rah!  It's a wonderful book, and it's online too.



Good luck!



From erikprice@mac.com  Wed Mar  6 03:35:46 2002
From: erikprice@mac.com (Erik Price)
Date: Tue, 5 Mar 2002 22:35:46 -0500
Subject: [Tutor] Looking for a forgiving environment
In-Reply-To: <HCHGGFOIGKKFOBAA@mailcity.com>
Message-ID: <3EED45C2-30B3-11D6-B45B-00039351FE6A@mac.com>

On Tuesday, March 5, 2002, at 08:40  PM, Dean Goodmanson wrote:

> I have a number of questions that aren't worthy of comp.lang.python, 
> and that I'd rather not go down in the permanent recordbook we call 
> "google: search: my name"...

Well, in that case the bad news is that most mailing lists are archived, 
and many of them are accessible from Google searches.  I just did a 
search for posts under my own name, and I'm pretty sure that at least a 
thousand of the 34,500 matching hits are mailing lists posts of mine.  
It's been over six years since I last posted to a newsgroup, but there 
are hundreds of hits from the last few months alone.

...sigh... I fondly remember sadly auctioning my Magic card collection 
on Usenet long before there was an eBay, posting new auction listings 
that had been painstakingly composed in vi, all because I was unable to 
focus on my college freshman studies.



Erik



From erikprice@mac.com  Wed Mar  6 03:54:25 2002
From: erikprice@mac.com (Erik Price)
Date: Tue, 5 Mar 2002 22:54:25 -0500
Subject: WAY OT :  Re: [Tutor] Looking for a forgiving environment
In-Reply-To: <3EED45C2-30B3-11D6-B45B-00039351FE6A@mac.com>
Message-ID: <D9DD4B9D-30B5-11D6-B45B-00039351FE6A@mac.com>

On Tuesday, March 5, 2002, at 10:35  PM, Erik Price wrote:

> I just did a search for posts under my own name, and I'm pretty sure 
> that at least a thousand of the 34,500 matching hits are mailing lists 
> posts of mine.

Nevermind, I narrowed it down some and it looks like the majority of 
these posts were for some kind of get-rich quick scheme by some guy 
named Erik Price in Jollyville, TX.  Definitely NOT me!


Erik
in Massachusetts for the last 24 years... probably for life!



From dsh8290@rit.edu  Wed Mar  6 04:55:36 2002
From: dsh8290@rit.edu (dman)
Date: Tue, 5 Mar 2002 23:55:36 -0500
Subject: [Tutor] LaTeX output
In-Reply-To: <3C856151.6E273CB@mail.verizon.net>
References: <3C856151.6E273CB@mail.verizon.net>
Message-ID: <20020306045536.GA30517@dman.ddts.net>

On Tue, Mar 05, 2002 at 07:22:41PM -0500, Lloyd Hugh Allen wrote:
| Anyone know a utility to output LaTeX formatted stuff in
| (preferably) Tkinter or (less preferably) wxWindows?

Are you looking to output the final result after running LaTeX on the
source?

If not, then
    print r'''\begin{document} Hi. \end{document}'''
is the simplest way to get LaTeX out.  :-)

If you are, then I suggest trying to integrate existing software,
though you may have to step outside of python to do so.  In particular
I'm thinking of LyX, an XForms gui-based editor that graphically shows
what the LaTeX you enter will appear as.  It does not handle all of
LaTeX, though.  Alternatively, use LaTeX to generate a DVI, then use
some tool to manipulate that until you have a format you can display.
I'm sure you're aware of using xdvi to display a DVI file, or using
dvips to convert it to PS and then using gv to display it.

With a little work you can probably integrate some of these tools
together to achieve the result you want.  What is your goal, anyways?
Sometimes, IMO, it is helpful to evaluate the goal in terms of
existing tools.  Sometimes adjusting the goal a little bit will allow
a trivial solution using existing tools, whereas the current goal
would require lots of work and reinvention.  It all depends on what
you have for input and what you want the output to be, what tools
already exist and how flexible can you be with the output and the
process.

HTH,
-D

-- 

Pride only breeds quarrels,
but wisdom is found in those who take advice.
        Proverbs 13:10



From dsh8290@rit.edu  Wed Mar  6 05:01:15 2002
From: dsh8290@rit.edu (dman)
Date: Wed, 6 Mar 2002 00:01:15 -0500
Subject: [Tutor] Newbie problems
In-Reply-To: <Pine.LNX.4.21.0203051430270.11585-100000@hkn.eecs.berkeley.edu>
References: <4.2.0.58.20020305094208.00d13440@pop3.norton.antivirus> <Pine.LNX.4.21.0203051430270.11585-100000@hkn.eecs.berkeley.edu>
Message-ID: <20020306050115.GB30517@dman.ddts.net>

On Tue, Mar 05, 2002 at 02:49:16PM -0800, Danny Yoo wrote:

[lots of good stuff]
 
| [Aside: skip this if you haven't seen C before]
 
| Without the function prototypes at the top, C gets totally confused and
| hollers that we have no idea what we're doing.  *grin*.  This is a strong
| reason why C uses function prototypes, so that C knows up front what
| functions will be available.

Just to nitpick, the C standard doesn't require prototypes.  The
compiler just assumes that you (the programmer) know what you are
doing and that you did it right.  It also assumes that functions
return 'int' if they weren't previously declared.  You may get wacky
linker errors, though, if your calls don't match the types in the
function's signatures.  There are options to gcc to make it require
the prototypes, which I think are a good idea!  In conrast, C++
requires prototypes regardless and to leave it out is a fatal error.

-D

-- 

Even youths grow tired and weary,
    and young men stumble and fall;
but those who hope in the Lord 
    will renew their strength.
They will soar on wings like eagles;
    they will run and not grow weary,
    they will walk and not be faint.

        Isaiah 40:31



From dyoo@hkn.eecs.berkeley.edu  Wed Mar  6 06:30:51 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 5 Mar 2002 22:30:51 -0800 (PST)
Subject: [Tutor] Looking for a forgiving environment
In-Reply-To: <3EED45C2-30B3-11D6-B45B-00039351FE6A@mac.com>
Message-ID: <Pine.LNX.4.21.0203052149070.22530-100000@hkn.eecs.berkeley.edu>

On Tue, 5 Mar 2002, Erik Price wrote:

> 
> On Tuesday, March 5, 2002, at 08:40  PM, Dean Goodmanson wrote:
> 
> > I have a number of questions that aren't worthy of comp.lang.python, 
> > and that I'd rather not go down in the permanent recordbook we call 
> > "google: search: my name"...
> 
> Well, in that case the bad news is that most mailing lists are archived, 
> and many of them are accessible from Google searches.  I just did a 

Hi Dean,


And it spans several years.  Google is incredibly scary.

    http://groups.google.com/groups?q=lafn+danny+yoo&hl=en&sa=N&tab=wg

I just felt extremely nostalgic reading the posts of this kid.  I was much
younger back then.  I dunno; part of me winces to see those words, but a
part of me feels awe at how much has not changed.


Forgive my self indulgence.  Anyway, to your questions:

> 1. Why do emails from mailman lists get annoyingly formatted when I
> read them from my yahoo account.  The last two or so words are
> wrapped--especially on reply quotes.

Certain email browsers don't support text justification very well.  In
Pine, I'm pressing Ctrl-J every so often to keep the document wrapped.  
I'm not sure if Yahoo's online email software provides a similar service.



> 2. How do I connect to the Zope chat on an IRC server. I have
> CryptSoftware "WinBot"

You may want to see if:

    http://www.zope.org/Members/TheJester/IrcBot

is useful.  I don't know if this will work with Zope chat, but it couldn't
hurt to give it a shot.



> 3. How do I configure a newsreader to view comp.lang.python in
> something other than google groups? Advocacy...

You may want to see if your Internet Service Provider hosts a newsserver.  
Many of them do, with names like 'smtp.foo.bar'.  



> 4. How can I encourage people to place a Python SOAP service on
> xmethods.org ?

Dunno about this one; sorry!  This may have less to do with technical
issues than social ones.  Does xmethods.org take user submissions?  It
might be possible to cook someone up and send it as a submission.



> 5. What is Zope's specialty over other products [in it's class..], and
> it's relationship with Radio Userland.

You may want to ask on the Zope mailing list on this one; I'm only a
supplicant myself, still trying to wrap my head around Zope myself.  Try:

    http://www.zope.org/Resources/MailingLists

for more information on the mailing lists.



> 6. How do I get statistics from my Zope server [beyond fsCounter]?

Zope.org itself uses Webalizer:

    http://ns1.zope.org:82/
    http://www.mrunix.net/webalizer/

Webalizer can show statistical information from Apache logs.  Perhaps it's
possible to bend Zope logs to look like apache logs, so that Webalizer can
work on it directly.



> 7. Where can I go to get Python maintenance scripts for a Zope server?
> (6 & 7 are examples, I haven't researched/attempted those yet.)
> Community...


Some people have written scripts to remotely backup Zope:

    http://www.zope.org/Members/phd/remote-backup

so many of these maintenance scripts may be listed as "Products".



> 8. Is EDU-SIG for education developers or educators?  I'm looking for
> activity & discussion in the former.

Edu-sig appears to be a mix of both.  It would be an interesting question
to ask and see the percentages.  *grin*



Best of wishes to you!



From virketis@fas.harvard.edu  Wed Mar  6 06:47:18 2002
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Wed, 6 Mar 2002 01:47:18 -0500
Subject: [Tutor] Looking for a forgiving environment
References: <Pine.LNX.4.21.0203052149070.22530-100000@hkn.eecs.berkeley.edu>
Message-ID: <00be01c1c4da$c2a2ac40$18adf78c@virketis2>

Danny,

> You may want to see if your Internet Service Provider hosts a newsserver.
> Many of them do, with names like 'smtp.foo.bar'.

I might be wrong, but shouldn't newsservers be "nntp.foo.bar"? SMTP is
"standard mail transfer protocol", unless I am mistaken.

Getting back to the original question, most universities and places of that
sort also have newsservers. Look for "Usenet" in Google, and you will find
long lists of candidates. Then, all you need is a newsreader. If you run
Linux, anything from the humble tin to the - forgive me :) - excessive Emacs
will be ready to do your bidding. If you use Windows, check out
cnet.com/downloads: you'll find one there.

Cheers,

Pijus




From dyoo@hkn.eecs.berkeley.edu  Wed Mar  6 06:48:45 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 5 Mar 2002 22:48:45 -0800 (PST)
Subject: [Tutor] Looking for a forgiving environment
In-Reply-To: <00be01c1c4da$c2a2ac40$18adf78c@virketis2>
Message-ID: <Pine.LNX.4.21.0203052248030.22530-100000@hkn.eecs.berkeley.edu>

On Wed, 6 Mar 2002, Pijus Virketis wrote:

> Danny,
> 
> > You may want to see if your Internet Service Provider hosts a newsserver.
> > Many of them do, with names like 'smtp.foo.bar'.
> 
> I might be wrong, but shouldn't newsservers be "nntp.foo.bar"? SMTP is
> "standard mail transfer protocol", unless I am mistaken.

Gaah!  Thanks, I goofed.  NNTP.  I always get those mixed up.  *grin*



From idiot1@netzero.net  Wed Mar  6 06:55:38 2002
From: idiot1@netzero.net (kirk Bailey)
Date: Wed, 06 Mar 2002 01:55:38 -0500
Subject: [Tutor] posting on chalkboard
Message-ID: <3C85BD6A.3AF5868A@netzero.net>

DEAR GAWGD! Whoever is running chalkboard, please whack it wif an ugly
stick!
That code I posted is GARBLED! IT IGNORED ends of lines, and managed
to mangle it to an unreadable state!

-- 
 
end
	    Respectfully,
			 Kirk D Bailey


+---------------------"Thou Art Free." -Eris----------------------+
| http://www.howlermonkey.net mailto:highprimate@howlermonkey.net |
| http://www.tinylist.org  +--------+  mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking---------------------+
                           +--------+

NOTE: By sending SPAM to this address you agree to pay me a service
fee of $100 for the service of receiving,  storing,  examining, and
deleting your piece of SPAM. I am a postmaster, and take a dim view
of such.
----------------------------------------------------
Sign Up for NetZero Platinum Today
Only $9.95 per month!
http://my.netzero.net/s/signup?r=platinum&refcd=PT97


From dyoo@hkn.eecs.berkeley.edu  Wed Mar  6 09:09:13 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed, 6 Mar 2002 01:09:13 -0800 (PST)
Subject: [Tutor] posting on chalkboard
In-Reply-To: <3C85BD6A.3AF5868A@netzero.net>
Message-ID: <Pine.LNX.4.21.0203060051080.26738-100000@hkn.eecs.berkeley.edu>

On Wed, 6 Mar 2002, kirk Bailey wrote:

> DEAR GAWGD! Whoever is running chalkboard.

That irresponsible administrator would be me.  *grin*


> please whack it wif an ugly stick!

Done.  It has been throttled.


> That code I posted is GARBLED! IT IGNORED ends of lines, and managed
> to mangle it to an unreadable state!

The problem is that it's not actually ignoring the line breaks... but it
does look that way.  For those input boxes, I've used a TEXTAREA with a
"wrap='virtual'" attribute, because otherwise it forces people to scroll
when they're writing long sentences.

I've made the textareas a little wider, but you're right, the interface
needs some work.  I've inherited some "features" of Squishdot, and I know
that I need to do more changes to make ChalkBoard appropriate as a
technical Python forum.


I have to apologize for being so off topic on Python-Tutor; I feel guilty
about turning people into guinea pigs.  On the other hand, at least I'm
getting feedback really quickly.  *weak grin*

For people who are testing ChalkBoard: if you have feedback, please feel
free to send it personally to me, so that I don't abuse Tutor traffic too
much.  Thank you again!



From dyoo@hkn.eecs.berkeley.edu  Wed Mar  6 09:27:37 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed, 6 Mar 2002 01:27:37 -0800 (PST)
Subject: [Tutor] Suggestions for a good book on functional programming
In-Reply-To: <AF020C5FC551DD43A4958A679EA16A15017B3FDA@abbott.lith.com>
Message-ID: <Pine.LNX.4.21.0203060109410.26738-100000@hkn.eecs.berkeley.edu>

On Tue, 5 Mar 2002, Israel Evans wrote:

> 	In a somewhat related vein, but not really, I'm interested in
> any good logic programming resources.  Something along the lines of
> Prolog or Mercury except using python.  I don't even know if Python
> has the facilities for such an exercise, but it would be pretty neat
> and educational.

I did see something in connection with a Prolog-style validity checker:

    http://www.ps.uni-sb.de/~duchier/python/continuations.html

(and... Continuations!  Gaaah!  *grin*)


Eric Raymond's CML 2 language contains a logic theorem prover and it's
written in Python:

    http://www.tuxedo.org/~esr/cml2/



And then there's the "Python Expert Systems" page:

    http://www.awaretek.com/python.html

But you may want to take its target subject matter with a small grain of
salt.  *grin* I think Ron Stevens is having a lot of fun in Python; the
rest of his page collects a LOT of Python resources.  Wow!



> Has anyone developed any sorts of Logic extensions to python?  Does
> python have logic programming-like stuff? Are there any definitive
> books on the subject?

I started to read "Prolog Programming for Artificial Intelligence", by
Ivan Bratko, and from what I've read so far, it's pretty good stuff!



> Are there any less definitive but artist friendly resources out there?

The book "Artificial Intelligence, A Modern Approach", by Stuart Russell
and Peter Norvig, is one of the definitive books on AI.  But it's a bit
dense.

Another good book by Peter Norvig is called "Paradigms of Artificial
Intelligence Programming: Studies in Common Lisp" and it covers different
types of AI/Logic/Expert systems in great detail, and I think it's a more
practical book than his book with Russell.


Good luck to you!



From alex@gabuzomeu.net  Wed Mar  6 09:49:12 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Wed, 06 Mar 2002 10:49:12 +0100
Subject: [Tutor] Suggestions for a good book on functional
 programming
In-Reply-To: <E16iSBn-0003Uu-00@mail.python.org>
Message-ID: <4.3.2.7.2.20020306104054.00b65f00@pop3.norton.antivirus>

Hello Karthik,


At 22:34 05/03/2002 -0500, you wrote:
>From: Karthik Gurumurthy <karthikg@aztec.soft.net>
>Date: Wed, 6 Mar 2002 08:34:31 +0530
>Subject: [Tutor] Suggestions for a good book on functional programming
>
>Since i started python, i have been fascinated by this feature. Now i find
>Java very boring.
>I have found some of the discussions in tutor to to be very informative.
>Since most of the guys here have programmed on a pure functional
>languages before, can someone suggest a good book (haskell, scheme anything
>is fine)
>for the same. If i have to buy one which one w'd you recommend?

(...)

I thought you might be interested in these resources, if you haven't used 
them yet:

- Functional Programming in Python

         http://gnosis.cx/publish/programming/charming_python_13.html

- Xoltar Toolkit

Utility modules for Python, including functional programming support, lazy 
expressions and data structures, and thread pools.

         http://sourceforge.net/projects/xoltar-toolkit/


Cheers.

Alexandre



From python_list@edsamail.com.ph  Sat Mar  9 06:00:09 2002
From: python_list@edsamail.com.ph (Python Newbie)
Date: Fri, 8 Mar 2002 22:00:09 -0800
Subject: [Tutor] Data Structures and Algorithms in Python
Message-ID: <E16ibvF-0004NK-00@mail.python.org>

Hello Python gurus,

Do you know where I can download a FREE book on "Data Structures and Algorithms using Python" and the like?

Thank you very much.

God bless you all...

__________________________________
www.edsamail.com


From israel@lith.com  Wed Mar  6 15:15:22 2002
From: israel@lith.com (Israel Evans)
Date: Wed, 6 Mar 2002 07:15:22 -0800
Subject: [Tutor] Aspect oriented Software Automation..
Message-ID: <AF020C5FC551DD43A4958A679EA16A15017B3FDB@abbott.lith.com>

http://telecommunity.com/TransWarp/ 

I don't know if anyone else has spied this out, but it looked pretty neat.  


A quote from the old Zope page on transwarp:

What is TransWarp?

	TransWarp is a general purpose Aspect-Oriented Programming,
Generative Programming, and CASE toolkit for Python. Its goals are to make
developing applications as simple as 1-2-3:
	1. Draw UML diagrams in the XMI-compatible tool of your choice.
	2. Write domain-specific logic, as needed.
	3. Plug in off-the-shelf (but customizable) "horizontal frameworks"
such as UI, data storage, testing code, security management, etc.

TransWarp is the likely successor to ZPatterns for Zope 3, and has a wide
variety of applications for Python programming in general. See the
VisionStatement for more information on the planned direction of the
software."




~Israel~



From fang_hui@seu.edu.cn  Wed Mar  6 15:18:36 2002
From: fang_hui@seu.edu.cn (hfang)
Date: Wed, 6 Mar 2002 23:18:36 +0800
Subject: [Tutor] how to convert other type to string type
Message-ID: <000801c1c522$300246a0$9c1277ca@lmbe>

This is a multi-part message in MIME format.

------=_NextPart_000_0005_01C1C565.3DF32C00
Content-Type: text/plain;
	charset="gb2312"
Content-Transfer-Encoding: base64

SSB1c2UgTU1USyhtb2xlY3VsYXIgbW9kdWxlIHRvb2wga2l0KSBtb2R1bGUsIEkgd2FudCB0byBj
b252ZXJ0IGF0b20gdHlwZSB0byBzdHJpbmcgdHlwZSwgaG93IGNhbiBJIGRvPyB0aGFuayB5b3Uu
DQo=

------=_NextPart_000_0005_01C1C565.3DF32C00
Content-Type: text/html;
	charset="gb2312"
Content-Transfer-Encoding: base64

PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBUcmFuc2l0aW9uYWwv
L0VOIj4NCjxIVE1MPjxIRUFEPg0KPE1FVEEgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PWdi
MjMxMiIgaHR0cC1lcXVpdj1Db250ZW50LVR5cGU+DQo8TUVUQSBjb250ZW50PSJNU0hUTUwgNS4w
MC4yOTE5LjYzMDciIG5hbWU9R0VORVJBVE9SPg0KPFNUWUxFPjwvU1RZTEU+DQo8L0hFQUQ+DQo8
Qk9EWSBiZ0NvbG9yPSNmZmZmZmY+DQo8RElWPjxGT05UIGZhY2U9QXJpYWwgc2l6ZT0yPkkgdXNl
IE1NVEsobW9sZWN1bGFyIG1vZHVsZSB0b29sIGtpdCkgbW9kdWxlLCBJIA0Kd2FudCB0byBjb252
ZXJ0IGF0b20gdHlwZSB0byBzdHJpbmcgdHlwZSwgaG93IGNhbiBJIGRvPyB0aGFuayANCnlvdS48
L0ZPTlQ+PC9ESVY+PC9CT0RZPjwvSFRNTD4NCg==

------=_NextPart_000_0005_01C1C565.3DF32C00--



From dyoo@hkn.eecs.berkeley.edu  Wed Mar  6 16:23:12 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed, 6 Mar 2002 08:23:12 -0800 (PST)
Subject: [Tutor] Data Structures and Algorithms in Python
In-Reply-To: <E16ibvF-0004NK-00@mail.python.org>
Message-ID: <Pine.LNX.4.21.0203060821001.1666-100000@hkn.eecs.berkeley.edu>

On Fri, 8 Mar 2002, Python Newbie wrote:

> Do you know where I can download a FREE book on "Data Structures and
> Algorithms using Python" and the like?

"How To Think Like A Computer Scientist" has a few chapters on data
structures:

    http://www.ibiblio.org/obp/thinkCSpy/

including Linked Lists, Stacks, and Trees.  Hope this helps!



From dyoo@hkn.eecs.berkeley.edu  Wed Mar  6 16:29:18 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed, 6 Mar 2002 08:29:18 -0800 (PST)
Subject: [Tutor] how to convert other type to string type
In-Reply-To: <000801c1c522$300246a0$9c1277ca@lmbe>
Message-ID: <Pine.LNX.4.21.0203060824060.1666-100000@hkn.eecs.berkeley.edu>

On Wed, 6 Mar 2002, hfang wrote:

> I use MMTK(molecular module tool kit) module, I want to convert atom
> type to string type, how can I do? thank you.

In many cases, doing an 'str()' on a Python object will coerse some useful
string from a Python object:

###
>>> str([1, 2, 3])
'[1, 2, 3]'
>>> str(17)
'17'
>>> str(1+1j)
'(1+1j)'
###

Using str() may be a good solution if Atom responds well to being turned
into a string.



Also, according to the MMTK documentation:

    http://starship.python.net/crew/hinsen/MMTK/Manual/MMTK_9.html

we should be able to call the fullName() method of the atom, which will
get us the get another string.  There may be several strings that can be
yanked from an Atom; it depends on what you're trying to pull out.


Good luck!



From porterh@yahoo.com  Wed Mar  6 17:41:28 2002
From: porterh@yahoo.com (Henry Porter)
Date: Wed, 6 Mar 2002 11:41:28 -0600 (CST)
Subject: [Tutor] (no subject)
Message-ID: <Pine.LNX.4.21.0203061134430.8597-100000@localhost.localdomain>

I don't really know how to word this question well at all, so pardon me.

I'm wondering why with some functions I have to type the function then the
variable I want that function to act on in parentheses after the function
(e.g. len(a)) and other functions I have to type the variable then a
period then the function (e.g. a.strip()).  

Sorry for this stupid beginner question, but I'm trying to figure out a
rhyme and reason for when to do which.

Thanks,
Henry



From mascher@crg.ha.nw.schule.de  Wed Mar  6 16:43:02 2002
From: mascher@crg.ha.nw.schule.de (Christian Mascher)
Date: Wed, 06 Mar 2002 17:43:02 +0100
Subject: [Tutor] Python-Installation on Linux
Message-ID: <3C864716.5B991A4@gmx.de>

Hello, 

I guess I just didn't find the right installation-readme, so I would
appreciate someone correcting me about the procedure I eventually came
up with.

I wanted to use Python for some simple scripts on our
Linux-(Samba)-Server and thereby noticed it was still running 1.5.2 (no
string methods). So I downloaded the Python2.2.tgz-file, moved it to a
...temp-directory and typed (that far documentation seemed to be clear)
#> tar -xvzf Python2.2-tgz
#> ./configure
#> make 
#> make clean

After some make-magic I got a whole python tree structure wrapped up in
a subdirectory .../temp/Python2.2/ 
Guess I should move that to the right place now. But where is that? 
On my (Suse6.3) box the old python-executable was located as python1.5
in /usr/lib and a symlink named /usr/lib/python was pointing to it. 

I didn't want to separate the executable from the rest  so I moved the
whole /Python2.2/-directory to /usr/lib (changed all the files owner to
root on the way) and made a symlink pointing to the interpreter:
/usr/lib/python2.2-->/usr/lib/Python2.2/python	
# not so sure about exact name of executable, writing at home (windows).
 	
Then I changed the existing symlink
/usr/lib/python-->python2.2
and python started with version 2.2. from there on.

Questions:
1. I found I hadn't used the install.sh script (what is that for)?
2. I have never set the installation directory when building. If I look
up sys.exec_prefix  in the interpreter (2.2 allright) I get
/usr/local/lib which seems to be a default I never changed in the above
process. 
3. Do I have to set any extra environment variables? I don't think I
have to, at least I can make "executable" scripts with
#!/usr/lib/python, and that uses the upgraded python.

Any comments by Linux-gurus welcome. Thank you!

Christian


From alan.gauld@bt.com  Wed Mar  6 17:08:04 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 6 Mar 2002 17:08:04 -0000
Subject: [Tutor] Suggestions for a good book on functional programming
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C408@mbtlipnt02.btlabs.bt.co.uk>

> >Subject: [Tutor] Suggestions for a good book on functional 
> programming

Its not about FP per se but does teach an FP style.

http://www.htdp.org/

Also try the Haskell web site for lots of FP stuff (mainly 
on Haskell oddly enough!) www.haskell.org

Alan g


From paulsid@shaw.ca  Wed Mar  6 17:13:48 2002
From: paulsid@shaw.ca (Paul Sidorsky)
Date: Wed, 06 Mar 2002 10:13:48 -0700
Subject: [Tutor] (no subject)
References: <Pine.LNX.4.21.0203061134430.8597-100000@localhost.localdomain>
Message-ID: <3C864E4C.FB4AF7A7@shaw.ca>

Henry Porter wrote:

> I'm wondering why with some functions I have to type the function then the
> variable I want that function to act on in parentheses after the function
> (e.g. len(a)) and other functions I have to type the variable then a
> period then the function (e.g. a.strip()).

The functions with the form obj.func() "belong" to the data type being
used.  strip() belongs to the string type, and a.strip() operates
exclusively on the variable called a in this case.

len() is a funtion that operates on any sequence data type as well as
those that provide a __len__ function, so it doesn't make much sense for
it to be attached to any single data type.  That's probably why it's a
builtin.

BTW if you've done any work with classes you'll have noticed that you
have to supply the "self" parameter to member functions.  This actually
gets passed the object in front of the period (a in your case).  So the
"internal call" to the function could be thought of as something like
this:  StringType.strip(a).  Python's syntax is just saving you some
typing.  On the inside they really aren't all that different.  :-)

> Sorry for this stupid beginner question, 

No such thing!

> but I'm trying to figure out a
> rhyme and reason for when to do which.

Chapter 2 of the Library Reference on the builtins can help answer this
question.  Pay particular attention to sections 2.1 and 2.2.6.  (2.2.8
is also important.)  Here's the link:

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

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/


From alan.gauld@bt.com  Wed Mar  6 17:14:43 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 6 Mar 2002 17:14:43 -0000
Subject: [Tutor] (no subject)
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C409@mbtlipnt02.btlabs.bt.co.uk>

> (e.g. len(a)) and other functions I have to type the variable then a
> period then the function (e.g. a.strip()).  

This is a mess at the moment because Python is kind of 
transitioning from a mixture of object oriented and procedural 
code to pure objects ala Ruby.

len(a) is the old style procedural model and a.len() is the 
more modern OO style. Most folks seem to find the original 
style easier to learn but the OO style makes for greater 
consistency and once mastered often allows more compact code
- but thats for another day...

> Sorry for this stupid beginner question, but I'm trying to 
> figure out a rhyme and reason for when to do which.

Unfortunately there's currently no consistency. In fact 
some have two valid ways like the string methods(strip, 
split etc) which are duplicated as functions in the 
string module...

Eventually everything will have methods I suspect and then
Python will look a lot more like Ruby.

Alan G.


From urnerk@qwest.net  Wed Mar  6 17:52:07 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Wed, 06 Mar 2002 09:52:07 -0800
Subject: [Tutor] (no subject)
In-Reply-To: <Pine.LNX.4.21.0203061134430.8597-100000@localhost.localdom
 ain>
Message-ID: <4.2.0.58.20020306093059.00951f00@pop3.norton.antivirus>

>
>I'm wondering why with some functions I have to type the
>function then the variable I want that function to act on
>in parentheses after the function (e.g. len(a)) and other
>functions I have to type the variable then a period then
>the function (e.g. a.strip()).

It's a good question.

Top-level functions, outside of any classes or other
functions (but inside modules), may be accessed directly,
whereas another kind of function, called a method, lives
internally to a class definition.  The difference in
code looks like:

def func(arg):
    # do stuff
    return whatever

vs.

class Myclass:

    def func(self,arg):
       # do stuff
       return whatever

In the first case, you could import the function and
go func(a), but in the second case, you need to create
an instance of Myclass and invoke its method:

    oBject = Myclass()
    oBject.func(a)

Now, in the case of strings, e.g. 'abcde', the earlier
Pythons had this model where you'd import a string module
to do stuff with strings, like strip('abcd  ').  You can
still do that.  However, the decision was made to make
most string functions invokable as methods on string
instances as well, e.g.

  >>> 'abcd '.strip()
  'abcd'

-- which looks kinda weird at first (you just have to
remember that 'abcd ' is creating a string object, and
inheriting all the functionality this entails).

To see what kind of functionality you're inheriting
by using a primitive data type, like a sequence, map,
string or number, just go dir(3) or dir({}) and see all
the methods, e.g.:

 >>> dir(3)
['__abs__', '__add__', '__and__', '__class__', '__cmp__',
'__coerce__', '__delattr__', '__div__', '__divmod__',
'__float__', '__floordiv__', '__getattribute__', '__hash__',
'__hex__', '__init__', '__int__', '__invert__', '__long__',
'__lshift__', '__mod__', '__mul__', '__neg__', '__new__',
'__nonzero__', '__oct__', '__or__', '__pos__', '__pow__',
'__radd__', '__rand__', '__rdiv__', '__rdivmod__', '__reduce__',
'__repr__', '__rfloordiv__', '__rlshift__', '__rmod__',
'__rmul__', '__ror__', '__rpow__', '__rrshift__', '__rshift__',
'__rsub__', '__rtruediv__', '__rxor__', '__setattr__',
'__str__', '__sub__', '__truediv__', '__xor__']

That means another way to negate 3 would be to invoke the
__neg__ method associated with all integers:

 >>> 3 .__neg__()
-3

(note the period separated from the number by whitespace, so
that the parser doesn't confuse this as a decimal point --
a trick I learned awhile back from one of the gurus right
here on tutor@python.org).

Finally, you can write top-level functions to invoke object
methods, if you prefer that syntax.  In other words, if
object foo has method bar (as in foo.bar()) then you can
write:

   def bar(foo):
       return foo.bar()

More concretely:

   >>> def strip(somestring):
           return somestring.strip()

   >>> strip('abc  ')
   'abc'

Except in the case of strings you might as well just
go

from string import strip

if you want the top-level function syntax.  But in other
situations, doing a top-level functional equivalent of
an instance method invocation can be useful, e.g. if
you don't like v1.cross(v2) for the cross product v1 x v2
(vector algebra), just write:

    def cross(v1,v2):
       return v1.cross(v2)

etc. etc.

Kirby

"You acknowledge that Software is not designed, licensed
or intended for use in the design, construction, operation
or maintenance of any nuclear facility." -- Java license
agreement



From idiot1@netzero.net  Wed Mar  6 18:09:10 2002
From: idiot1@netzero.net (kirk Bailey)
Date: Wed, 06 Mar 2002 13:09:10 -0500
Subject: [Tutor] jargon file data
Message-ID: <3C865B46.2DBD8B0D@netzero.net>

Also, try this:
http://www.tf.hut.fi/cgi-bin/jargon

-- 
 
end
	    Respectfully,
			 Kirk D Bailey


+---------------------"Thou Art Free." -Eris----------------------+
| http://www.howlermonkey.net mailto:highprimate@howlermonkey.net |
| http://www.tinylist.org  +--------+  mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking---------------------+
                           +--------+

NOTE: By sending SPAM to this address you agree to pay me a service
fee of $100 for the service of receiving,  storing,  examining, and
deleting your piece of SPAM. I am a postmaster, and take a dim view
of such.
----------------------------------------------------
Sign Up for NetZero Platinum Today
Only $9.95 per month!
http://my.netzero.net/s/signup?r=platinum&refcd=PT97


From urnerk@qwest.net  Wed Mar  6 18:20:30 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Wed, 06 Mar 2002 10:20:30 -0800
Subject: [Tutor] (no subject)
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C409@mbtlipnt02.btlabs
 .bt.co.uk>
Message-ID: <4.2.0.58.20020306101535.00d167f0@pop3.norton.antivirus>

>
>Eventually everything will have methods I suspect and then
>Python will look a lot more like Ruby.
>
>Alan G.

I think we'll always have top-level functions and
programmers who use those to bypass object.method()
syntax whenever they feel like it.

The idea of Python emulating Ruby sounds dissonant
in light of my recently having read the Bruce Eckel
dismissal of same:

http://www.mindview.net/Etc/FAQ.html#Ruby

"if you've used Python at all, you wouldn't give
Ruby a second glance."

Kirby


"You acknowledge that Software is not designed, licensed
or intended for use in the design, construction, operation
or maintenance of any nuclear facility." -- Java license
agreement



From blacktrash@gmx.net  Tue Mar  5 08:27:50 2002
From: blacktrash@gmx.net (Christian Ebert)
Date: Tue,  5 Mar 2002 09:27:50 +0100
Subject: [Tutor] Sorting numbers in lexicographic order  [recreational programming]
In-Reply-To: <Pine.LNX.4.21.0203022035580.21771-100000@hkn.eecs.berkeley.edu>
Message-ID: <20020306192458-r01010800-a28ef4a9-0922-0108@193.159.0.54>

Danny Yoo at 21:12 on Saturday, March 2, 2002:

> Here's the solution I cooked up:

Really useful for me (so it would be wrong on useless python
;-)

> >>> def toBinary(n):
> ....     if n == 0: return '0'
> ....     digits = []
> ....     while n != 0:
> ....         digits.append(str(n % 2))
> ....         n = n >> 1
> ....     digits.reverse()
> ....     return string.join(digits, '')

I don't know anything about binary or hexadecimal numbers
(yet), but by playing with ">>" in the interpreter I found
something without ">>" that _seems_ to return the same
results:

def numberToBinary(n):
    if n == 0: return '0'
    digits = []
    while n != 0:
        n, b = divmod(n, 2)
        digits.append(str(b))
    digits.reverse()
    return string.join(digits, '')

Am I right or was I just lucky in feeding it the right
numbers?

Christian
-- 
Hyperion in Frankfurt
www.tko.ch/blacktrash
www.schauspielfrankfurt.de


From wolf_binary@hotmail.com  Wed Mar  6 18:46:00 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Wed, 06 Mar 2002 12:46:00 -0600
Subject: [Tutor] embedding
Message-ID: <F1995y4FypKsEgJXOxJ00007bd5@hotmail.com>

Hi all,

I would just like a quick example on embedding in both directions of C++ and 
Python if you would please.  I'm trying to understand how languages interact 
with each other.

Cameron Stoner

_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx



From brian@coolnamehere.com  Wed Mar  6 19:16:24 2002
From: brian@coolnamehere.com (Brian Wisti)
Date: Wed, 6 Mar 2002 11:16:24 -0800
Subject: [Tutor] posting on chalkboard
In-Reply-To: <Pine.LNX.4.21.0203060051080.26738-100000@hkn.eecs.berkeley.edu>
References: <3C85BD6A.3AF5868A@netzero.net>
Message-ID: <3C85FA88.24715.11B8425F@localhost>

On 6 Mar 2002 at 1:09, Danny Yoo wrote:

> 
> I have to apologize for being so off topic on Python-Tutor; I feel
> guilty about turning people into guinea pigs.  On the other hand, at
> least I'm getting feedback really quickly.  *weak grin*

If folks consider it off-topic here, I suppose Chalkboard is the best 
place to discuss Chalkboard issues (including posting comments about 
desired features or deficient elements).

That's what a message board is for, right? ;-)

Later,
Brian Wisti

--
Brian Wisti 
brian@coolnamehere.com
http://www.coolnamehere.com/




From alex@gabuzomeu.net  Wed Mar  6 19:46:04 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Wed, 06 Mar 2002 20:46:04 +0100
Subject: [Tutor] (no subject)
In-Reply-To: <E16ieUN-0003oU-00@mail.python.org>
Message-ID: <4.3.2.7.2.20020306195540.00be3940@pop3.norton.antivirus>

Hello Henry,


At 11:42 06/03/2002 -0500, you wrote:
>Date: Wed, 6 Mar 2002 11:41:28 -0600 (CST)
>From: Henry Porter <porterh@yahoo.com>
>Subject: [Tutor] (no subject)
>
>I don't really know how to word this question well at all, so pardon me.
>
>I'm wondering why with some functions I have to type the function then the
>variable I want that function to act on in parentheses after the function
>(e.g. len(a)) and other functions I have to type the variable then a
>period then the function (e.g. a.strip()).

Here is some background.


1) Build-in functions
------------------------------
Some functions are called build-ins, i.e. they are part of a basic set of 
utilities that are available as soon as your open the Python interpreter. 
Example: len()

 >>> foo = "bar"
 >>> print len(foo)
3

These functions can be accessed directy because they are always part of 
your context. Actually, they belong to a module that is automatically 
imported by the interpreter when started. This module is called 
"__builtins__". To list its content, try :

 >>> dir(__builtins__)

or try this:

 >>> import pprint
 >>> pprint.pprint(dir(__builtins__))

This will prettyprint the module listing.


2) Modules
------------------
- Other functions are part of modules that need to be imported to be 
available.  Example: "string".

 >>> import string
 >>> foo = "bar"
 >>> print string.upper(foo)
BAR

Basically, you're asking the interpreter to use the "upper()" function from 
the "string" module.

- Note you can also import a function directly into the current context, 
instead of importing the complete module:

 >>> from string import upper
 >>> foo = "bar"
 >>> print upper(foo)
BAR

Here you created a direct reference to the "upper" function; thus you can 
use it directly afterwards.


3) Class methods
----------------------------
"a.strip()" is a special case: in you example, "a" is a string. A string is 
an object; hence you are calling the "strip" function (so-called "method") 
of string objects.

 >>> foo = "bar"
 >>> print foo.upper()
BAR

You will meet this case again when using classes. Classes allow you to 
create custom objects. If you haven't used classes yet, here is an example:

class Foo:

     def __init__(self):
         "Let's initialize this class."
         self.x = 3
         self.y = "bar"

     def getX(self):
         "Let's return the x attribute."
         return self.x

     def getY(self):
         return self.y

 >>> afoo = Foo()
 >>> print afoo.getX()
3
 >>> print afoo.getY()
bar


It's simpler that it sounds: (I think almost) everything is an object in 
Python. A string, a module, a function, a class are all objects. The "dot" 
notation (foo.bar) means "in" ("bar" in "foo").

>Sorry for this stupid beginner question, but I'm trying to figure out a
>rhyme and reason for when to do which.

To sum it up: you need to use the dot notation when the object you want to 
access is not already available in your current context. If you import a 
module and you want to access a specific function in this module, you need 
to use the dot notation. If you import the function directly, you don't 
need to specify its parent object. If you use build-in functions, you don't 
need either (before they have already been imported directly).

I hope I did not make you more confused than before. If I did, ask again.


Cheers.

Alexandre




From archieval49@hotmail.com  Wed Mar  6 19:59:23 2002
From: archieval49@hotmail.com (Archie)
Date: Thu, 7 Mar 2002 03:59:23 +0800
Subject: [Tutor] Python in Linux
Message-ID: <OE163CfMQffHyihcUKW00006196@hotmail.com>

Hi,

    Does anyone know the difference between the installation made with
tarball and the rpm's?    I was just wandering if I compiled the source
tarball (Python-2.2.tgz), will I have the complete installation or do I
still need to get "python2-tools-2.2-2.i386.rpm" and
"python2-tkinter-2.2-i386.rpm".
    Thanks in advance.

Archie


From brian@coolnamehere.com  Wed Mar  6 20:19:04 2002
From: brian@coolnamehere.com (Brian Wisti)
Date: Wed, 6 Mar 2002 12:19:04 -0800
Subject: [Tutor] Python in Linux
In-Reply-To: <OE163CfMQffHyihcUKW00006196@hotmail.com>
Message-ID: <3C860938.31950.11F1A363@localhost>

Hi Archie,

Compiling from source should get you the whole deal, but you'll also 
want to make sure you have Tcl/Tk installed (if you want to use 
Tkinter).

To be honest, it might be easier to go with the RPM install.  But 
that's just a lazy programmer talking ;-)

Brian Wisti

On 7 Mar 2002 at 3:59, Archie wrote:

> Hi,
> 
>     Does anyone know the difference between the installation made with
> tarball and the rpm's?    I was just wandering if I compiled the
> source tarball (Python-2.2.tgz), will I have the complete installation
> or do I still need to get "python2-tools-2.2-2.i386.rpm" and
> "python2-tkinter-2.2-i386.rpm".
>     Thanks in advance.
> 
> Archie
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--
Brian Wisti 
brian@coolnamehere.com
http://www.coolnamehere.com/




From Cobaugh.Harvey@epamail.epa.gov  Wed Mar  6 22:21:26 2002
From: Cobaugh.Harvey@epamail.epa.gov (Cobaugh.Harvey@epamail.epa.gov)
Date: Wed, 06 Mar 2002 17:21:26 -0500
Subject: [Tutor] Basic newbie questions
Message-ID: <OFF7335E13.0070A80A-ON85256B74.00757321@rtp.epa.gov>

I am just into my first 4 hours of "teach yourself Python in 24 hours"
but please forgive my impatience.  I downloaded Python ver 2.2 onto my
my Micron PC, 166Mhz, 128MB RAM, Windows 95-SR1.  I also downloaded the
WIn32all package and then went onto the Valuts of Parnassus site to
retrieve some already written programs to see how they worked and how
they were coded.  Finally I'm to the point:   I get errors when I try to
execute these programs.  I do the following:

CD\
cd python22
python tracert.py

In this example, I tried running "tracert.py" and got the following
error msg:

Traceback (most recent call last):
  File "C:\PYTHON22\tracert.py", line 96, in ?
    compress()
  File "C:\PYTHON22\tracert.py", line 84, in compress
    d=cPickle.load(open(fn))
IOError: [Errno 2] No such file or directory: 'stats.dat'

I'm not concerned about the error so much as what I am missing in terms
of things I must specify to make a program work.  Should this program
have worked, is this one of those revision bugs,  or did I not do
something??

Last question:

Where can I read or see examples of doing File I/O??   Specifically, how
to designate a drive to read a file from and how to read the file(s).
I realize I have  along way to go but I can't get passed this tracert
program not working; mentally.
I'll appreciate any help.

Thanks,
Harvey




From shalehperry@attbi.com  Wed Mar  6 22:32:10 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Wed, 06 Mar 2002 14:32:10 -0800 (PST)
Subject: [Tutor] Basic newbie questions
In-Reply-To: <OFF7335E13.0070A80A-ON85256B74.00757321@rtp.epa.gov>
Message-ID: <XFMail.20020306143210.shalehperry@attbi.com>

> 
> In this example, I tried running "tracert.py" and got the following
> error msg:
> 
> Traceback (most recent call last):
>   File "C:\PYTHON22\tracert.py", line 96, in ?
>     compress()
>   File "C:\PYTHON22\tracert.py", line 84, in compress
>     d=cPickle.load(open(fn))
> IOError: [Errno 2] No such file or directory: 'stats.dat'
> 
> I'm not concerned about the error so much as what I am missing in terms
> of things I must specify to make a program work.  Should this program
> have worked, is this one of those revision bugs,  or did I not do
> something??
> 

This is looking for a stats.dat file which should have been created by
something.  What item from parnassus gave you tracert.py?

> Last question:
> 
> Where can I read or see examples of doing File I/O??   Specifically, how
> to designate a drive to read a file from and how to read the file(s).
> I realize I have  along way to go but I can't get passed this tracert
> program not working; mentally.
> I'll appreciate any help.
> 

>>> f = open('apt.howto')
>>> f.readline()
'Apt is a suite of utilities that assist the admin in maintaining an\n'
>>> n = f.readline()
>>> print n
up-to-date system.  More in depth documentation can be found in apt(8),

>>> count = 0                 
>>> for line in f.readlines(): count = count + 1
... 
>>> print count
35
>>> f.close()



From urnerk@qwest.net  Wed Mar  6 23:27:38 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Wed, 06 Mar 2002 15:27:38 -0800
Subject: [Tutor] Basic newbie questions
In-Reply-To: <OFF7335E13.0070A80A-ON85256B74.00757321@rtp.epa.gov>
Message-ID: <4.2.0.58.20020306152638.00d1e400@pop3.norton.antivirus>

At 05:21 PM 3/6/2002 -0500, Cobaugh.Harvey@epamail.epa.gov wrote:
>I am just into my first 4 hours of "teach yourself Python in 24 hours"
>but please forgive my impatience.  I downloaded Python ver 2.2 onto my
>my Micron PC, 166Mhz, 128MB RAM, Windows 95-SR1.  I also downloaded the
>WIn32all package and then went onto the Valuts of Parnassus site to
>retrieve some already written programs to see how they worked and how
>they were coded.  Finally I'm to the point:   I get errors when I try to
>execute these programs.  I do the following:
>
>CD\
>cd python22
>python tracert.py

My recommendation is you avoid anything to do with the
win32all package while you're just learning Python.

The first question I'd ask someone 4 hours into Python
is did you get IDLE to boot?

Kirby

"You acknowledge that Software is not designed, licensed
or intended for use in the design, construction, operation
or maintenance of any nuclear facility." -- Java license
agreement



From wilson@isis.visi.com  Wed Mar  6 23:28:48 2002
From: wilson@isis.visi.com (Tim Wilson)
Date: Wed, 6 Mar 2002 17:28:48 -0600 (CST)
Subject: [Tutor] debugging CGI hints
Message-ID: <Pine.GSO.4.10.10203061727001.14415-100000@isis.visi.com>

Hi everyone,

I've got apache configured to run Python-based CGI scripts on my home
directory now. Thanks for the tips. Now that I'm working on some simple
scripts, I'm finding the debugging to be difficult. Any problems with
the scripts generate an "Internal Server Error" in the browser and I
don't get any specific error messages.

Any tips for debugging CGI scripts?

-Tim

--
Tim Wilson      |   Visit Sibley online:   | Check out:
Henry Sibley HS |  http://www.isd197.org   | http://www.zope.com
W. St. Paul, MN |                          | http://slashdot.org
wilson@visi.com |  <dtml-var pithy_quote>  | http://linux.com



From sheila@thinkspot.net  Wed Mar  6 23:43:38 2002
From: sheila@thinkspot.net (Sheila King)
Date: Wed, 06 Mar 2002 15:43:38 -0800
Subject: [Tutor] debugging CGI hints
In-Reply-To: <Pine.GSO.4.10.10203061727001.14415-100000@isis.visi.com>
References: <Pine.GSO.4.10.10203061727001.14415-100000@isis.visi.com>
Message-ID: <16EA69610E6@kserver.org>

On Wed, 6 Mar 2002 17:28:48 -0600 (CST), Tim Wilson <wilson@isis.visi.com>
wrote about [Tutor] debugging CGI hints:

> Hi everyone,
> 
> I've got apache configured to run Python-based CGI scripts on my home
> directory now. Thanks for the tips. Now that I'm working on some simple
> scripts, I'm finding the debugging to be difficult. Any problems with
> the scripts generate an "Internal Server Error" in the browser and I
> don't get any specific error messages.
> 
> Any tips for debugging CGI scripts?
> 
> -Tim

Here are a few. Mix and match to suit your preferences:

(1) Do you have access to the error logs? This should contain the error and
it is most likely a syntax error.

(2) Before running the script as a cgi, try running it from the command
line. The only difficulty with that, is that if your script requires
certain environment variables to be set, they will not be automatically set
when running from the command line, and you would have to take care to set
them. (I'm willing to go into more detail on this, if you like.) Anyhow,
running it from the command line definitely let's you see all the error
messages, and is usually much quicker than running it as a cgi and then
looking in the error logs.

(3) Try resetting stderr so that it outputs to stdout and then the error
messages will appear in your browser window. It is explained how to do
this, here:
http://www.python.org/doc/current/lib/node302.html

and I quote:

import sys
sys.stderr = sys.stdout
print "Content-Type: text/plain"
print
...your code here...


So, basically, you can add those four lines to the top of whatever code you
currently have, and the output should go to your browser window.

(4) If you are running Python 2.2, you could try the new cgitb module.
http://www.python.org/doc/current/lib/module-cgitb.html

I haven't tried it yet, but looks interesting.

(5) Write all the errors to an error log. (This is something that I do
frequently.) Basically I have a function like this near the top of my
script:

def logfileentry(exc, val, tb):
    errortime = str(asctime(localtime(time())))
    logfile = open(logfile, 'a')
    logfile.write('\n*** %s ***\n' % errortime)
    traceback.print_exception(exc, val, tb, file=logfile)
    logfile.write('\n')
    logfile.close()

( you will need to import asctime, localtime and time from the time module,
and import the traceback module )

Then, I have try/except blocks in my code:

try:
    <my code here>
except TypeOfError, errmsg:
    exc, val, tb = sys.exc_info()
    # append to the logfile
    logfileentry(exc, val, tb)
    # just to be sure there is no reference to the traceback
    del tb


So, this should give you several different approaches to try.

HTH,

-- 
Sheila King
http://www.thinkspot.net/sheila/

"When introducing your puppy to an adult cat,
restrain the puppy, not the cat." -- Gwen Bailey,
_The Perfect Puppy: How to Raise a Well-behaved Dog_



From virketis@fas.harvard.edu  Thu Mar  7 00:00:10 2002
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Wed, 6 Mar 2002 19:00:10 -0500
Subject: [Tutor] debugging CGI hints
References: <Pine.GSO.4.10.10203061727001.14415-100000@isis.visi.com>
Message-ID: <00aa01c1c56b$0d18dbb0$18adf78c@virketis2>

Tim,

> Any tips for debugging CGI scripts?

Sheila has listed many excellent options. Let me just add one more, in some
ways easier, and in some inferior to the ones suggested by her. A few days
ago, I downloaded a trial edition of the Wing IDE Lite
(http://archaeopteryx.com/support/downloads), which basically allows to do
full-blown visual debugging on remote CGI scripts. You get to see variables,
the stack, set breakpoints, the whole shebang. The configuration is somewhat
lengthy, but no particular task is dificult per se. That's the good part.
The bad part that in 30 days, you will have to shell out some cash, or stop
using Wing, and in my experience, visual debuggers tend to be addictive and
do make one lazy. :)

Cheers,

Pijus



From paulsid@shaw.ca  Thu Mar  7 00:12:08 2002
From: paulsid@shaw.ca (Paul Sidorsky)
Date: Wed, 06 Mar 2002 17:12:08 -0700
Subject: [Tutor] debugging CGI hints
References: <Pine.GSO.4.10.10203061727001.14415-100000@isis.visi.com>
Message-ID: <3C86B058.2009E20F@shaw.ca>

Tim Wilson wrote:

> I've got apache configured to run Python-based CGI scripts on my home
> directory now. Thanks for the tips. Now that I'm working on some simple
> scripts, I'm finding the debugging to be difficult. Any problems with
> the scripts generate an "Internal Server Error" in the browser and I
> don't get any specific error messages.
> Any tips for debugging CGI scripts?

CGI debugging is touchy - check the section on the cgi module in the
library reference if you haven't already, there's some tips in there.

Off the top of my head I can suggest these:

- Check the path to python on the #! line at the start.  If you're
uploading the scripts (esp. from a Windows system) make sure you do it
in text mode, otherwise the path might have an extra CR on the end which
will cause it to fail.

- Put the initial print "Content-Type..." lines ASAP, ideally right at
the start before anything else including imports.    Sometimes this will
let you get a traceback displayed in the browser, which can be immensely
helpful.  

- Also make sure there's a blank line printed after the
"Content-Type..." line.  I think Netscape will choke if you don't have
this.

- If possible, run the script from the command line (i.e. non-CGI)
first.

- Use cgi.test() to make sure your server is setup right.  (Or use
another known-to-work CGI script.)

Hope that helps - all of these have helped me fix CGI problems in the
past.  I haven't done all that much CGI work, though, so I'm sure other
people will have better ideas.

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/


From csmith@blakeschool.org  Thu Mar  7 04:23:22 2002
From: csmith@blakeschool.org (Christopher Smith)
Date: Wed, 06 Mar 2002 22:23:22 -0600
Subject: [Tutor] error in docs regarding map
Message-ID: <fc.004c4b6b008fe9bf004c4b6b008fe9bf.8fe9d9@blakeschool.org>

OK, pretty soon I'll just trust my own judgement, but would you agree that
the docs obtained when typing help(filter) are wrong--they say that the
result of filter is a list; I think it should say that the result is a
sequence (if a string is filtered, a string is returned and if a list is
filtered, a list is returned).  If this is an error, should I file this at
the SourceForge?

Python 2.2 (#126, Jan 15 2002, 21:27:18)  [CW CARBON GUSI2 THREADS GC]
Type "copyright", "credits" or "license" for more information.
MacPython IDE 1.0.1
>>> s='nlK'
>>> l=list(s)
>>> filter(lambda x:x.isupper(),s)
'K' #<-----------------------------a string, not a list
>>> filter(lambda x:x.isupper(),l)
['K']
>>> map(lambda x:x.upper(),s)
['N', 'L', 'K']
>>> map(lambda x:x.upper(),l)
['N', 'L', 'K']
>>>

BTW, are the docs obtained when typing help(filter) or help(map) hardcoded
into Python's source code?

/c



From tutor@python.org  Thu Mar  7 04:38:40 2002
From: tutor@python.org (Tim Peters)
Date: Wed, 06 Mar 2002 23:38:40 -0500
Subject: [Tutor] error in docs regarding map
In-Reply-To: <fc.004c4b6b008fe9bf004c4b6b008fe9bf.8fe9d9@blakeschool.org>
Message-ID: <LNBBLJKPBEHFEDALKOLCOEAFOCAA.tim.one@comcast.net>

[Christopher Smith]
> OK, pretty soon I'll just trust my own judgement, but would you agree
> that the docs obtained when typing help(filter) are wrong--they say that
> the result of filter is a list; I think it should say that the result is
> a sequence (if a string is filtered, a string is returned and if a list
> is filtered, a list is returned).  If this is an error, should I file
> this at the SourceForge?

You could try <wink>.  The strings produced by

    print someobject.__doc__

(which is what help() looks at) are generally meant to be memory-refreshers,
not complete documentation.  The full truth about filter() is more
complicated than you realize so far, but is fully documented in the Library
Reference Manual.  If we put a lot of words in __doc__ strings, people don't
like that either.

> ...
> BTW, are the docs obtained when typing help(filter) or help(map)
> hardcoded into Python's source code?

Indeed they are.  If you have the Python source distribution (or get the
source from public CVS), you'll find the help string for filter() in
Python/bltinmodule.c:

static char filter_doc[] =
"filter(function, sequence) -> list\n\
\n\
...

and so on.



From csmith@blakeschool.org  Thu Mar  7 04:43:06 2002
From: csmith@blakeschool.org (Christopher Smith)
Date: Wed, 06 Mar 2002 22:43:06 -0600
Subject: [Tutor] error in docs regarding map
In-Reply-To: <LNBBLJKPBEHFEDALKOLCOEAFOCAA.tim.one@comcast.net>
References: <LNBBLJKPBEHFEDALKOLCOEAFOCAA.tim.one@comcast.net>
Message-ID: <fc.004c4b6b008fea99004c4b6b008fe9bf.8fea9b@blakeschool.org>

tutor@python.org writes:
>[Christopher Smith]
>> OK, pretty soon I'll just trust my own judgement, but would you agree
>> that the docs obtained when typing help(filter) are wrong--they say that
>> the result of filter is a list; I think it should say that the result is
>> a sequence (if a string is filtered, a string is returned and if a list
>> is filtered, a list is returned).  If this is an error, should I file
>> this at the SourceForge?
>
>You could try <wink>.  The strings produced by
>
>    print someobject.__doc__
>
>(which is what help() looks at) are generally meant to be
>memory-refreshers,
>not complete documentation.  The full truth about filter() is more
>complicated than you realize so far, but is fully documented in the
>Library
>Reference Manual.  If we put a lot of words in __doc__ strings, people
>don't
>like that either.

I might suggest changing "--> list" to "--> sequence"; but if this is less
true than the initial wording (because of other complications) it's not so
bad to have "list" instead of "sequence".

/c



From alan.gauld@bt.com  Thu Mar  7 09:37:04 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 7 Mar 2002 09:37:04 -0000
Subject: [Tutor] (no subject)
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C40D@mbtlipnt02.btlabs.bt.co.uk>

> >Eventually everything will have methods I suspect and then
> >Python will look a lot more like Ruby.

> The idea of Python emulating Ruby sounds dissonant
> in light of my recently having read the Bruce Eckel
> dismissal of same:

I only meant the object syntax for everything aspects
not the 'end' block terminators or the '@' signs etc.

I think Python strikes a good balance, Ruby just tries 
too hard to be object everything... IMHO of course.

Alan G.


From kjphotog@juno.com  Thu Mar  7 12:24:29 2002
From: kjphotog@juno.com (kjphotog@juno.com)
Date: Thu, 7 Mar 2002 04:24:29 -0800
Subject: [Tutor] thanks
Message-ID: <20020307.045321.-244019.18.kjphotog@juno.com>

Another + with the Python tutor is posting our e-mail addresses. I've
been finding some tutor members are extra helpful when I've emailed them.
 

I've also discovered an awesome computer whiz resources like Erik Price. 
He seems to know a bit about everything in the programming world. And is
ever so willing to discuss, writing in detail, about python, html, css +
tons more. 

And it's tutors like that who can empower people like me, especially
since I'm a school teacher. Although, I'm not so helpful as a Python
tutor - yet. I am learning lot's of bits & pieces of stuff like html and
have been sharing what I'm learning with my students. Now they're making
simple webpages too. 

Thanks to tutor@python & other helpful folks - I'm able to expand my
computer knowledge & skills a little more each day. 

Keith Johnson

________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today!  For your FREE software, visit:
http://dl.www.juno.com/get/web/.


From pythontutor@venix.com  Thu Mar  7 14:01:01 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Thu, 07 Mar 2002 09:01:01 -0500
Subject: [Tutor] debugging CGI hints
References: <Pine.GSO.4.10.10203061727001.14415-100000@isis.visi.com>
Message-ID: <3C87729D.7050300@venix.com>

I am sure you have figured out that "Internal Server Error" means the script
could not be run - any thing from syntax error to permissions or owner problems.

I have found it helpful to keep a test script around that simply echos the parameters
that got fed in.  This comes into play when you are debugging  HTML / script
interactions.
::::::::::::::::::::::
#!/usr/local/bin/python
import cgi

print "Content-type: text/html\n"
cgi.test()
::::::::::::::::::::::

Also, you may already have been warned that
	#! /usr/local/env python
may fail if the owner of the httpd server does not have a "normal" setup.  A direct
reference to Python may be safer.  Since your cgi scripts are in known locations, it
is not too hard to change them all if Python gets moved.


Tim Wilson wrote:

> Hi everyone,
> 
> I've got apache configured to run Python-based CGI scripts on my home
> directory now. Thanks for the tips. Now that I'm working on some simple
> scripts, I'm finding the debugging to be difficult. Any problems with
> the scripts generate an "Internal Server Error" in the browser and I
> don't get any specific error messages.
> 
> Any tips for debugging CGI scripts?
> 
> -Tim
> 
> --
> Tim Wilson      |   Visit Sibley online:   | Check out:
> Henry Sibley HS |  http://www.isd197.org   | http://www.zope.com
> W. St. Paul, MN |                          | http://slashdot.org
> wilson@visi.com |  <dtml-var pithy_quote>  | http://linux.com
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582



From nixonron@yahoo.com  Thu Mar  7 16:00:21 2002
From: nixonron@yahoo.com (Ron Nixon)
Date: Thu, 7 Mar 2002 08:00:21 -0800 (PST)
Subject: [Tutor] running a script from IDLE
Message-ID: <20020307160021.10206.qmail@web20306.mail.yahoo.com>

--0-1209697855-1015516821=:10152
Content-Type: text/plain; charset=us-ascii


I've been toying around with IDLE in the interactive mode, but I can't seem to figure out how to run a script from IDLE that I've saved. When I copy to file into IDLE and hit "run script" I get a messege saying "The buffer for Python Shell is not saved. Please save it first." If I save the file to a directory, open it in IDLE and then chose "run script" I get an invalid syntax error. I've search the documention in vain(or maybe I just missed it). So could some tell me how to perfom this seemingly simple task of running a save script?

Thanks in advance



---------------------------------
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
--0-1209697855-1015516821=:10152
Content-Type: text/html; charset=us-ascii

<P>I've been toying around with IDLE in the interactive mode, but I can't seem to figure out how to run a script from IDLE that I've saved. When I copy to file into IDLE and hit "run script" I get a messege saying "The buffer for Python Shell is not saved. Please save it first." If I save the file to a directory, open it in IDLE and then chose "run script" I get an invalid syntax error. I've search the documention in vain(or maybe I just missed it). So could some tell me how to perfom this seemingly simple task of running a save script?</P>
<P>Thanks in advance</P><p><br><hr size=1><b>Do You Yahoo!?</b><br>
Try FREE <a href="$rd_url/tag/http://mail.yahoo.com/">Yahoo! Mail</a> - the world's greatest free email!
--0-1209697855-1015516821=:10152--


From tarabryan@yahoo.com  Thu Mar  7 07:31:21 2002
From: tarabryan@yahoo.com (Tara Bryan)
Date: Thu, 7 Mar 2002 12:31:21 +0500
Subject: [Tutor] (no subject)
In-Reply-To: <4.3.2.7.2.20020306195540.00be3940@pop3.norton.antivirus>
References: <4.3.2.7.2.20020306195540.00be3940@pop3.norton.antivirus>
Message-ID: <0e7275022160732FE8@mail8.nc.rr.com>

Alexandre's answer is the best so far because it's the most readable to a 
true beginner programmer (like me).  My advice to Henry is to just keep 
going--you will start to know which function format to use based on instinct. 
 In other words, as you're exposed to it, you'll absorb the rules without 
having to learn them.  (But now that Alexandre has expressed them so well, it 
has made the rules more concrete in my mind, which can't be a bad thing!)


From Doug.Shawhan@gecits.ge.com  Thu Mar  7 17:06:37 2002
From: Doug.Shawhan@gecits.ge.com (Doug.Shawhan@gecits.ge.com)
Date: Thu, 7 Mar 2002 12:06:37 -0500
Subject: [Tutor] List madness
Message-ID: <C278B8202E91D5119F4F0008C7E67E5E01851B9D@msxcvg01itscge.gecits.ge.com>

I am a little confused as to why the following works in IDLE:

---------------------------------------------
>>> for each in pungent:
	thing = re.findall('Briggs', each)
	if thing != []:
		print each

		
"Briggs, Joe
Bob","4200","Systems",,,,"ASSET00326861",,"MRV_Sys","192.168.0.20",,,,,,"",,
,"Salary","Printer_326861_4200_01-30-2002.doc"

>>> 
--------------------------------------------

Yet this happy script does not:

--------------------------------------------
import re

def findit(db, item):
	for each in db:
		thing = re.findall(item, '%s'%each)
		if thing != [] : return each 
		else:
			return '%s not found, chump.'%item


list = open('\\list.csv','r')
listed = list.readlines()
looky = raw_input('thingy to look for: ')
print findit(listed, looky)

--------------------------------------------

The script always returns "Blah not found, chump."

I stand confused!

d


From nixonron@yahoo.com  Thu Mar  7 17:19:40 2002
From: nixonron@yahoo.com (Ron Nixon)
Date: Thu, 7 Mar 2002 09:19:40 -0800 (PST)
Subject: [Tutor] running scripts in IDLE
Message-ID: <20020307171940.31818.qmail@web20305.mail.yahoo.com>

--0-904170643-1015521580=:26912
Content-Type: text/plain; charset=us-ascii


 

 

I have this script

myfile = open("c:/menu.txt", 'r')
    for line in myfile.readlines():
        print line
     myfile.close()

 

I save it and hit "run script". I get invalid syntax. What is going on? Am I not doing this right. I though in order to run a script. You wrote the script out, save it and then open it in IDLE and hit run script. Am I mistaken?



---------------------------------
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
--0-904170643-1015521580=:26912
Content-Type: text/html; charset=us-ascii

<P>&nbsp;</P>
<P>&nbsp;</P>
<P>I have this script</P>
<P>myfile = open("c:/menu.txt", 'r')<BR>&nbsp;&nbsp;&nbsp; for line in myfile.readlines():<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print line<BR>&nbsp;&nbsp;&nbsp;&nbsp; myfile.close()</P>
<P>&nbsp;</P>
<P>I save it and hit "run script". I get invalid syntax. What is going on? Am I not doing this right. I though in order to run a script. You wrote the script out, save it and then open it in IDLE and hit run script. Am I mistaken?</P><p><br><hr size=1><b>Do You Yahoo!?</b><br>
Try FREE <a href="$rd_url/tag/http://mail.yahoo.com/">Yahoo! Mail</a> - the world's greatest free email!
--0-904170643-1015521580=:26912--


From al3ashig85@hotmail.com  Thu Mar  7 10:14:06 2002
From: al3ashig85@hotmail.com (Cheese Cake)
Date: Thu, 07 Mar 2002 10:14:06 +0000
Subject: [Tutor] Want to learn
Message-ID: <F252joYAPNXRPmcarcR00005085@hotmail.com>

<html><div style='background-color:'><DIV>hi sir,</DIV>
<DIV>&nbsp;</DIV>
<DIV>i tried to learn Python Language and i understantd the Help page For Beginners but i dont know how can i see my work and i dont know how to save it .. in .exe or in .py or else .. i ask u please .. send me an complete example .. i dont mind if it small and easy .. and where should I Copy it .. in notepad program or in Python program .. at last i mean i dont know how to make my own program .. and i ask u for example ..</DIV>
<DIV>&nbsp;</DIV>
<DIV>thank you </DIV></div><br clear=all><hr>Get your FREE download of MSN Explorer at <a href='http://g.msn.com/1HM100901/p'>http://explorer.msn.com</a>.<br></html>


From leeg@sport.rr.com  Thu Mar  7 13:09:08 2002
From: leeg@sport.rr.com (Lee Gray)
Date: Thu, 7 Mar 2002 07:09:08 -0600
Subject: [Tutor] MS office data to XML w/ Python?
Message-ID: <200203071305.g27D5jVB028193@sm12.texas.rr.com>

Hello,

I have just started exploring Python and really like it so far.  I'd like to 
ask for some pointers on a project.

I chose Python because I was looking for a cross-platform language to create 
an application to store my music collection.  Currently it is in an Excel 
spreadsheet and an Access database (the original idea was to put all the 
spreadsheet data, plus more detail, into the database, but I lost interest in 
Access and never finished).  My main goal is to escape Windows and MS Office, 
but I'd still like to read the data when I have to use Windows, so I was 
going to store the data in XML (which will give me an excuse to learn that 
technology as well!). 

I originally started to write the app in VBScript using DHTML with Internet 
Explorer (as an HTA - HTML Application), simply because that's what I know 
best, then once I got my data into XML, I'd work on a new application in 
another language.  Well, I got fed up with fighting that language/technology 
combination and started looking at Python.

So... if you're still with me, my questions are:

1. Is there already a Python application out there that I can modify that 
simply stores data in XML?

2. Is there a Python app/utility that I can modify that can translate Access 
and/or Excel to XML?  (I'd rather not input all my new data by hand, but I'll 
only have to do it once, so I don't really feel like writing this part!)

3. Do you have any other suggestions for a complete Python newbie to get 
started on this?

Thanks very much,

Lee


From dyoo@hkn.eecs.berkeley.edu  Thu Mar  7 18:03:07 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 7 Mar 2002 10:03:07 -0800 (PST)
Subject: [Tutor] debugging CGI hints
In-Reply-To: <3C87729D.7050300@venix.com>
Message-ID: <Pine.LNX.4.21.0203071000500.818-100000@hkn.eecs.berkeley.edu>

On Thu, 7 Mar 2002, Lloyd Kvam wrote:

> I am sure you have figured out that "Internal Server Error" means the
> script could not be run - any thing from syntax error to permissions
> or owner problems.

Also, if we have Python 2.2, we can import the 'cgitb' module:

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

This was recently included in the standard library, and automatically
activates CGI scripts to print traceback reports if a CGI program dies.

Good luck!



From dyoo@hkn.eecs.berkeley.edu  Thu Mar  7 18:09:43 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 7 Mar 2002 10:09:43 -0800 (PST)
Subject: [Tutor] running a script from IDLE
In-Reply-To: <20020307160021.10206.qmail@web20306.mail.yahoo.com>
Message-ID: <Pine.LNX.4.21.0203071004330.818-100000@hkn.eecs.berkeley.edu>

On Thu, 7 Mar 2002, Ron Nixon wrote:

> I've been toying around with IDLE in the interactive mode, but I can't
> seem to figure out how to run a script from IDLE that I've saved. When
> I copy to file into IDLE and hit "run script" I get a messege saying
> "The buffer for Python Shell is not saved. Please save it first." If I
> save the file to a directory, open it in IDLE and then chose "run
> script" I get an invalid syntax error.

Hi Ron,

Hmmm... can you show us the SyntaxError?  Without seeing more detail, I'm
going to have to guess.  *grin*


My best guess at the moment is that there may be '>>> ' prompts accidently
copied over when saving that file.

If so, try stripping them out of your saved file.  These '>>>' prompts are
used by the interactive interpreter to show when it's ok to type, but
they're not actually real "Python" code.


If you have time, you may want to look at my IDLE tutorial:

    http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro

Best of wishes to you!



From dyoo@hkn.eecs.berkeley.edu  Thu Mar  7 18:12:41 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 7 Mar 2002 10:12:41 -0800 (PST)
Subject: [Tutor] running scripts in IDLE
In-Reply-To: <20020307171940.31818.qmail@web20305.mail.yahoo.com>
Message-ID: <Pine.LNX.4.21.0203071010030.818-100000@hkn.eecs.berkeley.edu>

On Thu, 7 Mar 2002, Ron Nixon wrote:

> I have this script
> 
> myfile = open("c:/menu.txt", 'r')
>     for line in myfile.readlines():
>         print line
>      myfile.close()

One thing about Python is that whitespace indentation is signficiant: you
probably meant:

###
myfile = open("c:/menu.txt", "r")
for line in myfile.readlines():
    print line
myfile.close()
###

That is, we indent only when we start off a new block.  It seems a little
strict at first, but if you're using IDLE, you can press the Tab button,
and it should jump to the next indentation level automatically.

Good luck!



From dyoo@hkn.eecs.berkeley.edu  Thu Mar  7 18:20:42 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 7 Mar 2002 10:20:42 -0800 (PST)
Subject: [Tutor] Want to learn
In-Reply-To: <F252joYAPNXRPmcarcR00005085@hotmail.com>
Message-ID: <Pine.LNX.4.21.0203071013310.818-100000@hkn.eecs.berkeley.edu>

On Thu, 7 Mar 2002, Cheese Cake wrote:

> i tried to learn Python Language and i understantd the Help page For
> Beginners but i dont know how can i see my work and i dont know how to
> save it .. in .exe or in .py or else .. i ask u please .. send me an
> complete example .. i dont mind if it small and easy .. and where
> should I Copy it .. in notepad program or in Python program .. at last
> i mean i dont know how to make my own program .. and i ask u for
> example ..

Hello!  If you're using Notepad, I'd recommend switching over to a text
editor called IDLE: it comes with Python, and it's much nicer for learning
Python.  I have an example of how to save and load files in the IDLE
tutorial here:

    http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro

It's small, but it might be enough to help you write your own programs.


You don't need to worry about making .exe's at the moment until you feel
more comfortable with Python.  You can just run '.py' files with Python,
and it should work ok.


There is a utility to transform .py files to .exe's:

    http://py2exe.sourceforge.net/

but making an exe is useful only if you want to send your programs to
people who don't have Python installed.


Please feel free to ask more questions on Tutor; we're here to help.  
Good luck to you!



From urnerk@qwest.net  Thu Mar  7 18:31:03 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 07 Mar 2002 10:31:03 -0800
Subject: [Tutor] running a script from IDLE
In-Reply-To: <Pine.LNX.4.21.0203071004330.818-100000@hkn.eecs.berkeley.e
 du>
References: <20020307160021.10206.qmail@web20306.mail.yahoo.com>
Message-ID: <4.2.0.58.20020307102247.00acf650@pop3.norton.antivirus>

At 10:09 AM 3/7/2002 -0800, Danny Yoo wrote:
>On Thu, 7 Mar 2002, Ron Nixon wrote:
>
> > I've been toying around with IDLE in the interactive mode,
> > but I can't > seem to figure out how to run a script from
> > IDLE that I've saved. When > I copy to file into IDLE and
> > hit "run script" I get a messege saying "The buffer for
> > Python Shell is not saved. Please save it first." If I
> > save the file to a directory, open it in IDLE and then
> > chose "run script" I get an invalid syntax error.

Also, if you write your module such that all its features
may be triggered by functions or methods, then you don't
need to run it as a script at all.  Just go:

  >>> import mymodule
  >>> mymodule.main()  # or whatever

I find this a good way to use IDLE because you can build
up your modules by "unit testing" each piece (each
function or class) as an individual unit.  This tends to
promote good habits, as your units have more standalone
integrity if they have to bear up as testable, versus
relying on global variables or side effects smeared all
over the place.  Were I to write a tutorial for newbies,
I'd focus on importing and interacting with one's files
in shell mode, and save "Run Script" for later.

The good thing about writing in "module mode" is then you
can use it like 'math' or 'string' -- all these tools are
at your elbow, and you can invoke them in various combinations,
storing results in temporary variables, sort of in "calculator
mode" (thinking of a programmable calculator).  This makes
you part of the action.  A lot of the control structures
can be left out of it, because you the user are a real
time control structure.

I think newbies unused to a shell mode waste a lot of time
writing interactive menus that give them access to the
various components of what they've done, whereas in shell
mode you already have this access, if you simply write in
that way.  This is how LISP and Scheme programmers are
encouraged to develop (using the REPL loop).  Python should
be taught the same way IMO.

Kirby


"You acknowledge that Software is not designed, licensed
or intended for use in the design, construction, operation
or maintenance of any nuclear facility." -- Java license
agreement



From dyoo@hkn.eecs.berkeley.edu  Thu Mar  7 18:33:47 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 7 Mar 2002 10:33:47 -0800 (PST)
Subject: [Tutor] List madness
In-Reply-To: <C278B8202E91D5119F4F0008C7E67E5E01851B9D@msxcvg01itscge.gecits.ge.com>
Message-ID: <Pine.LNX.4.21.0203071020500.818-100000@hkn.eecs.berkeley.edu>

On Thu, 7 Mar 2002 Doug.Shawhan@gecits.ge.com wrote:

> >>> for each in pungent:
> 	thing = re.findall('Briggs', each)
> 	if thing != []:
> 		print each

> def findit(db, item):
> 	for each in db:
> 		thing = re.findall(item, '%s'%each)
> 		if thing != [] : return each 
> 		else:
> 			return '%s not found, chump.'%item

As you've noticed, there's some wackiness involved with that 'else'
statement.  I think you meant to return '%s not found, chump' only after
all of items in 'db' have been checked.

It's like having a row of cookie jars, and after looking into the first
one, we want to continue looking at the rest of the cookie jars, even if
the first is just filled with crumbs --- we don't want to give up so fast!

###
def findit(db, item):
    for each in db:
        thing = re.findall(item, '%s'%each)
        if thing != [] : return each 
    return '%s not found, chump.'%item
###

Otherwise, we prematurely report that we couldn't find anything, even
though we've only looked at the first element in db.


If we want to collect all the cookies from all the jars and bring them all
together, we can keep a sack and just stuff in anything we can find:

###
def findAllIts(db, item):
    sack = []
    for each in db:
        sack.extend(re.findall(item, '%s' % each))
    return sack
###


Good luck!



From urnerk@qwest.net  Thu Mar  7 18:41:36 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 07 Mar 2002 10:41:36 -0800
Subject: [Tutor] List madness
In-Reply-To: <C278B8202E91D5119F4F0008C7E67E5E01851B9D@msxcvg01itscge.ge
 cits.ge.com>
Message-ID: <4.2.0.58.20020307103444.00d1e700@pop3.norton.antivirus>

What if you do the below in IDLE?  Just define the
function at a >>> prompt:


 >>> def findit(db, item):
         for each in db:
            thing = re.findall(item, '%s'%each)
            if thing != [] : return each
            else:            return '%s not found, chump.'%item

Then start doing the other lines, one by one:

   >>> list = open('\\list.csv','r')
   >>> listed = list.readlines()

Does "listed" contain what you expect after the readlines?

  >>> looky =  # just give it the string directly
  >>> print findit(listed, looky)

I'd recommend using the above interactively in
IDLE until it works, then memorialize it as a .py
file.

Kirby

"You acknowledge that Software is not designed, licensed
or intended for use in the design, construction, operation
or maintenance of any nuclear facility." -- Java license
agreement



From urnerk@qwest.net  Thu Mar  7 18:53:00 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 07 Mar 2002 10:53:00 -0800
Subject: [Tutor] List madness
In-Reply-To: <4.2.0.58.20020307103444.00d1e700@pop3.norton.antivirus>
References: <C278B8202E91D5119F4F0008C7E67E5E01851B9D@msxcvg01itscge.ge cits.ge.com>
Message-ID: <4.2.0.58.20020307105105.00cee9d0@pop3.norton.antivirus>

>
>I'd recommend using the above interactively in
>IDLE until it works, then memorialize it as a .py
>file.
>
>Kirby

Or else just rely on Danny to spot the bug immediately.
Probably the more efficient strategy.  Being able to go:

   >>> import danny
   >>> danny.askanything("blah blah...")

is one of the more useful aspects of the Standard Library. :-D

Kirby


"You acknowledge that Software is not designed, licensed
or intended for use in the design, construction, operation
or maintenance of any nuclear facility." -- Java license
agreement



From aschmidt@nv.cc.va.us  Thu Mar  7 19:31:01 2002
From: aschmidt@nv.cc.va.us (Schmidt, Allen J.)
Date: Thu, 7 Mar 2002 14:31:01 -0500
Subject: [Tutor] New book out
Message-ID: <47BCBF3251382B45893950D07804082475AEC4@novamail.nv.cc.va.us>

Has anyone seen this new Python book out? Although expensive, looks more
like a classroom training manual.

http://vig.prenhall.com/catalog/academic/product/1,4096,0130923613,00.html

Allen


From garber@centralcatholic.org  Thu Mar  7 19:31:59 2002
From: garber@centralcatholic.org (Robert Garber)
Date: Thu,  7 Mar 2002 14:31:59 -0500
Subject: [Tutor] newbie -- python apps and DOS window.
Message-ID: <200203071431.AA252641718@centralcatholic.org>

Hello All,

 I have two questions both concern the DOS window in windows 98 machines.  First how do run a python script slow enough so i can see what is going on . Seems everytime i run a script it opens a dos window executes faster then i can see it and closes. 

Next question: Is there a way to run tkinter/python script (reversie.py) with out seeing the dos window?

Thanks
Robert


From nixonron@yahoo.com  Thu Mar  7 19:35:57 2002
From: nixonron@yahoo.com (Ron Nixon)
Date: Thu, 7 Mar 2002 11:35:57 -0800 (PST)
Subject: [Tutor] running script in IDLE problem solved
Message-ID: <20020307193557.61643.qmail@web20306.mail.yahoo.com>

--0-2129434651-1015529757=:61568
Content-Type: text/plain; charset=us-ascii


Thanks to all who responded. Danny, really cool tutorial on IDLE

 

Ron



---------------------------------
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
--0-2129434651-1015529757=:61568
Content-Type: text/html; charset=us-ascii

<P>Thanks to all who responded. Danny, really cool tutorial on IDLE</P>
<P>&nbsp;</P>
<P>Ron</P><p><br><hr size=1><b>Do You Yahoo!?</b><br>
Try FREE <a href="$rd_url/tag/http://mail.yahoo.com/">Yahoo! Mail</a> - the world's greatest free email!
--0-2129434651-1015529757=:61568--


From scarblac@pino.selwerd.nl  Thu Mar  7 19:34:38 2002
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 7 Mar 2002 20:34:38 +0100
Subject: [Tutor] newbie -- python apps and DOS window.
In-Reply-To: <200203071431.AA252641718@centralcatholic.org>; from garber@centralcatholic.org on Thu, Mar 07, 2002 at 02:31:59PM -0500
References: <200203071431.AA252641718@centralcatholic.org>
Message-ID: <20020307203438.A14156@pino.selwerd.nl>

On  0, Robert Garber <garber@centralcatholic.org> wrote:
> I have two questions both concern the DOS window in windows 98 machines.
> First how do run a python script slow enough so i can see what is going on .
> Seems everytime i run a script it opens a dos window executes faster then i
> can see it and closes.

Open the DOS window first, then start the program from there, is one way. Or
you can end your program with something like raw_input("Press enter to
close...").

It *might* be possible to set some option so that the DOS window always
stays open after running a .py program, I seem to remember something like
that, but it's years since I last Windows.

> Next question: Is there a way to run tkinter/python script (reversie.py)
> with out seeing the dos window?

Name it .pyw instead of .py, iirc. Then it runs without a DOS window.

-- 
Remco Gerlich


From Nicole.Seitz@urz.uni-heidelberg.de  Thu Mar  7 18:09:10 2002
From: Nicole.Seitz@urz.uni-heidelberg.de (Nicole Seitz)
Date: Thu, 7 Mar 2002 19:09:10 +0100
Subject: [Tutor] running scripts in IDLE
In-Reply-To: <20020307171940.31818.qmail@web20305.mail.yahoo.com>
References: <20020307171940.31818.qmail@web20305.mail.yahoo.com>
Message-ID: <02030719091001.00714@utopia>

Am Donnerstag,  7. M=E4rz 2002 18:19 schrieb Ron Nixon:
> I have this script
>
> myfile =3D open("c:/menu.txt", 'r')
>     for line in myfile.readlines():
>         print line
>      myfile.close()

As far as I can see, you get "invalid syntax" because you didn't indent=20
correctly.
So, the following should work:

myfile =3D open("c:/menu.txt", 'r')
for line in myfile.readlines():
     print line
myfile.close()

Best wishes,

Nicole
>
>
>
> I save it and hit "run script". I get invalid syntax. What is going on?=
 Am
> I not doing this right. I though in order to run a script. You wrote th=
e
> script out, save it and then open it in IDLE and hit run script. Am I
> mistaken?
>
>
>
> ---------------------------------
> Do You Yahoo!?
> Try FREE Yahoo! Mail - the world's greatest free email!

----------------------------------------
Content-Type: text/html; charset=3D"us-ascii"; name=3D"Anhang: 1"
Content-Transfer-Encoding: 7bit
Content-Description:=20
----------------------------------------


From Doug.Shawhan@gecits.ge.com  Thu Mar  7 19:07:17 2002
From: Doug.Shawhan@gecits.ge.com (Doug.Shawhan@gecits.ge.com)
Date: Thu, 7 Mar 2002 14:07:17 -0500
Subject: [Tutor] List madness
Message-ID: <C278B8202E91D5119F4F0008C7E67E5E01851B9F@msxcvg01itscge.gecits.ge.com>

Works fine in my interpreter:
-----------------------

>>> import yoo()
>>> dir(yoo)
['_YooType_','__builtins__','__name__','_helpful','_patience','python','dims
um','pizza','theladies','smallfurrythingswithgoogleeyes','amok_bookstore','l
ime_soda', 'bagels', 'propeller_beanie']
>>> yoo.pizza()
Yes, please.
>>>
----------------------

What version are you using?



-----Original Message-----
From: Kirby Urner [mailto:urnerk@qwest.net]
Sent: Thursday, March 07, 2002 12:53 PM
To: tutor@python.org
Cc: Shawhan, Doug (CAP, ITS, US)
Subject: Re: [Tutor] List madness



>
>I'd recommend using the above interactively in
>IDLE until it works, then memorialize it as a .py
>file.
>
>Kirby

Or else just rely on Danny to spot the bug immediately.
Probably the more efficient strategy.  Being able to go:

   >>> import danny
   >>> danny.askanything("blah blah...")

is one of the more useful aspects of the Standard Library. :-D

Kirby


"You acknowledge that Software is not designed, licensed
or intended for use in the design, construction, operation
or maintenance of any nuclear facility." -- Java license
agreement


From Doug.Shawhan@gecits.ge.com  Thu Mar  7 18:47:36 2002
From: Doug.Shawhan@gecits.ge.com (Doug.Shawhan@gecits.ge.com)
Date: Thu, 7 Mar 2002 13:47:36 -0500
Subject: [Tutor] List madness
Message-ID: <C278B8202E91D5119F4F0008C7E67E5E01851B9E@msxcvg01itscge.gecits.ge.com>

Make sense! The final doo dad:

---------------------------------------
import re

def findit(db, item):
	for each in db:
		thing = re.findall('%s'%item, each)
		if thing != [] : 
			return each 
	return '%s not found'%item


list = open('\\list.csv','r')
pungent = list.readlines()
looky = raw_input('thingy to look for: ')
print findit(pungent, looky)

---------------------------------------

Works like I thought it would! :-)


Thanks for filling the cookie jar! 

-----Original Message-----
From: Danny Yoo [mailto:dyoo@hkn.eecs.berkeley.edu]
Sent: Thursday, March 07, 2002 12:34 PM
To: Shawhan, Doug (CAP, ITS, US)
Cc: tutor@python.org
Subject: Re: [Tutor] List madness


On Thu, 7 Mar 2002 Doug.Shawhan@gecits.ge.com wrote:

> >>> for each in pungent:
> 	thing = re.findall('Briggs', each)
> 	if thing != []:
> 		print each

> def findit(db, item):
> 	for each in db:
> 		thing = re.findall(item, '%s'%each)
> 		if thing != [] : return each 
> 		else:
> 			return '%s not found, chump.'%item

As you've noticed, there's some wackiness involved with that 'else'
statement.  I think you meant to return '%s not found, chump' only after
all of items in 'db' have been checked.

It's like having a row of cookie jars, and after looking into the first
one, we want to continue looking at the rest of the cookie jars, even if
the first is just filled with crumbs --- we don't want to give up so fast!

###
def findit(db, item):
    for each in db:
        thing = re.findall(item, '%s'%each)
        if thing != [] : return each 
    return '%s not found, chump.'%item
###

Otherwise, we prematurely report that we couldn't find anything, even
though we've only looked at the first element in db.


If we want to collect all the cookies from all the jars and bring them all
together, we can keep a sack and just stuff in anything we can find:

###
def findAllIts(db, item):
    sack = []
    for each in db:
        sack.extend(re.findall(item, '%s' % each))
    return sack
###


Good luck!


From max_ig@yahoo.com  Thu Mar  7 20:19:23 2002
From: max_ig@yahoo.com (ichazo maximiliano)
Date: Thu, 7 Mar 2002 12:19:23 -0800 (PST)
Subject: [Tutor] Python and MySQL
Message-ID: <20020307201923.44394.qmail@web11301.mail.yahoo.com>

I'm planning to work with Python and MySql so I would like to know
where on the net I can obtain some info.

If you can give me a clue, I'll be more than pleased.

Thank you,

Max

__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/


From SWidney@ci.las-vegas.nv.us  Thu Mar  7 20:29:18 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Thu, 7 Mar 2002 12:29:18 -0800
Subject: [Tutor] Re: transposing musical sequences
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F59DE@SOVEREIGN>

> xpose(octpch, n):
>     oct = octpch  # something here to separate the stuff before the dot
>     pch = octpch  # followed by something here to split the part 
>                     after the dot
>     pch = (pch +n) % 12 / 100  # update the pitch
>     oct = (oct +n) / 12        # update the oct part
>     return (the two items joined back together)
> 
> Also i am guessing that transposing down somehow involves the 
> 12s compliment
> (12-n)
> 
> maybe down is (12-n)% 12

Just thinking out loud....
What happens if n is a negative number? Since adding a negative number is
the same as subtracting a positive, does this have the effect of transposing
down? Or does it do something else that ought to be avoided?

Scott


From virketis@fas.harvard.edu  Thu Mar  7 20:42:19 2002
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Thu, 7 Mar 2002 15:42:19 -0500
Subject: [Tutor] Python and MySQL
References: <20020307201923.44394.qmail@web11301.mail.yahoo.com>
Message-ID: <000d01c1c618$93510600$18adf78c@virketis2>

Hi Max,

> I'm planning to work with Python and MySql so I would like to know
> where on the net I can obtain some info.

Check out http://sourceforge.net/projects/mysql-python/ for the MySQLdb
module. Then, have a look at http://www.python.org/sigs/db-sig/, the special
interest group devoted to DB programming in Python. Finally, there is quite
a bit of code at Useless Python and the Vaults of Parnassus showing all
kinds of neat things you might do with Python and MySQL.

Cheers,

Pijus



From SWidney@ci.las-vegas.nv.us  Thu Mar  7 21:22:46 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Thu, 7 Mar 2002 13:22:46 -0800
Subject: [Tutor] RE: idle not starting up..
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F59DF@SOVEREIGN>

> By the way, this is the second time that I've seen something 
> with Ruby:
> 
> >     d:/ruby/tcl/lib/tcl8.3 d:/python/lib/tcl8.3 d:/lib/tcl8.3
> > lib/tcl8.3 lib/tcl8.3/library library ../tcl8.3/library
> 
> where Tk library paths have gone bizarre.  Is there a relationship to
> this?

The RubyWin Installer doesn't clean up after itself (not unlike my
children...which would be funny if it weren't so true....heh).

Most modern Installers will keep a log of:  1) what files were added, 2)
what files were updated (often with an option to backup the older version),
and 3) what changes were made to initialisation files and registry entries.
The well-behaved Installers will revert completely, changing the entries to
their previous values and returning the backed-up files (if specified) to
their original locations. Unfortunately, the Ruby Installer is not
well-behaved. I just uninstalled it from my W2K system, and it left all of
the environment variables untouched; also, there's still an entry in the
registry.

Looking at it further, it looks like the installer may be a roll-your-own
app. That might explain the lack of features.

Scott


From urnerk@qwest.net  Thu Mar  7 21:37:08 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 07 Mar 2002 13:37:08 -0800
Subject: [Tutor] New book out
In-Reply-To: <47BCBF3251382B45893950D07804082475AEC4@novamail.nv.cc.va.u
 s>
Message-ID: <4.2.0.58.20020307133205.00acfbb0@pop3.norton.antivirus>

At 02:31 PM 3/7/2002 -0500, Schmidt, Allen J. wrote:
>Has anyone seen this new Python book out? Although
>expensive, looks more like a classroom training manual.
>
>http://vig.prenhall.com/catalog/academic/product/1,4096,0130923613,00.html
>
>Allen

Yeah, I was one of the technical reviewers, as was Alan.
It has exercises at the end of each chapter.  Pretty
comprehensive treatment of topics, though even in that
many pages you can't go too deep.  Has stuff on Alice
(multimedia), Pygame (uses it to make a CD player, which
I found innovative), talking to MySQL via CGI, and lots
on XML, including 3rd party Python tools for parsing
XML files.

There's a certain format characteristic of all books in
the series that has its drawbacks (as well as its pluses).
Sometimes the line-by-line analysis paragraphs can be
pretty dense, but if you're willing to concentrate...

I CD comes with Apache, Alice, other stuff (which you
can also get on the web of course).

It costs a lot, but you get a lot.  It's an OK survey
(GUI programming, some stuff on threads), a good way to
get your feet wet on a lot of topics, using a very
learnable language (Python).  As such, it's a jumping
off point for getting into specific topics in more
depth.

Kirby


"You acknowledge that Software is not designed, licensed
or intended for use in the design, construction, operation
or maintenance of any nuclear facility." -- Java license
agreement



From Bruce Gollng" <bwgolling@attbi.com  Thu Mar  7 16:43:10 2002
From: Bruce Gollng" <bwgolling@attbi.com (Bruce Gollng)
Date: Thu, 7 Mar 2002 16:43:10 -0000
Subject: [Tutor] if __name__=='__main__'  test
Message-ID: <003e01c1c5f7$2b3879c0$5523e30c@attbi.com>

This is a multi-part message in MIME format.

------=_NextPart_000_003B_01C1C5F7.2ADCEC40
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Help please.  I've been studying several books and online tutorials and =
have been consistently stumped with the  ..  if __name__ =3D=3D =
'__main__': test.  No matter when I check __name__ always eq __main__.  =
So why is this a programming benefit?
tks
Bruce Golling (bwgolling@attbi.com)


------=_NextPart_000_003B_01C1C5F7.2ADCEC40
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.4807.2300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>
<DIV><FONT face=3DArial size=3D2>Help please.&nbsp; I've been studying =
several books=20
and online tutorials and have been consistently stumped with=20
the&nbsp;&nbsp;..&nbsp; if __name__ =3D=3D '__main__': test.&nbsp; No =
matter when I=20
check __name__ always eq __main__.&nbsp; So why is this a programming=20
benefit?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>tks</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Bruce Golling (<A=20
href=3D"mailto:bwgolling@attbi.com">bwgolling@attbi.com</A>)</FONT></DIV>=

<DIV>&nbsp;</DIV></DIV></BODY></HTML>

------=_NextPart_000_003B_01C1C5F7.2ADCEC40--



From urnerk@qwest.net  Thu Mar  7 21:46:28 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 07 Mar 2002 13:46:28 -0800
Subject: [Tutor] RE: idle not starting up..
In-Reply-To: <D4EB5574F4A7D2119C9E00A0C9EA408D059F59DF@SOVEREIGN>
Message-ID: <4.2.0.58.20020307133852.00ace460@pop3.norton.antivirus>

>
>The RubyWin Installer doesn't clean up after itself (not unlike my
>children...which would be funny if it weren't so true....heh).

Note: *many* Windows programs don't undo stuff they do in
your AUTOEXEC, even via their uninstallers -- this is in no
way all that unusual.

>The well-behaved Installers will revert completely, changing the
>entries to their previous values and returning the backed-up files
>(if specified) to their original locations.

With AUTOEXEC, this could be a problem, as many programs alter
it and make a backup.  If the Ruby uninstaller went back and
restored AUTOEXEC.RUBY, from the time it installed, you could
be in big trouble, given all the interim changes to AUTOEXEC
that might have happened in the meantime.  The only way the
uninstaller could work would be to parse the file and remove
parts of it.  A very well-behaved program will (a) tell you
what it plans on doing and (b) show you what the changes would
look like ahead of time.  Very few bother.

I just went through a long session purging my AUTOEXEC of
unwanted path subdirectories this morning.  Some kept
reappearing, I think because of stuff in the registry.
The AUTOEXEC would actually change, even after I'd edit
it -- even after I write-protected it even.

>Unfortunately, the Ruby Installer is not well-behaved.

I think you should let go of blaming the Ruby Installer
-- it's your responsibility, at the end of the day, to
clean up the AUTOEXEC file.  Uninstallers only do so much.
They'll also leave DLLs behind, or tell you they *seem*
to be unused by other programs but you might want to
leave them just in case -- no help at all to the user,
as no one keeps all these dependencies in their heads,
or even written down.

>I just uninstalled it from my W2K system, and it left all of
>the environment variables untouched; also, there's still
>an entry in the registry.

Which would be enough to mess with the AUTOEXEC on
Windows ME.  I'd purge all mention of D:\PROGRA~1\ACCPAC\RUNTIME
yet there it'd be, on the very next boot, until I scoured
the registry.

Kirby

"You acknowledge that Software is not designed, licensed
or intended for use in the design, construction, operation
or maintenance of any nuclear facility." -- Java license
agreement



From ponderor@lycos.com  Thu Mar  7 21:18:18 2002
From: ponderor@lycos.com (Dean Goodmanson)
Date: Thu, 07 Mar 2002 13:18:18 -0800
Subject: [Tutor] New book out
Message-ID: <COBGLPNEDPCBIBAA@mailcity.com>

 It was discussed on the newsgroup comp.lang.python:

http://groups.google.com/groups?hl=en&threadm=873czdnmqp.fsf%40tleepslib.sk.tsukuba.ac.jp&prev=/groups%3Fnum%3D25%26hl%3Den%26group%3Dcomp.lang.python%26start%3D50

--

On Thu, 7 Mar 2002 14:31:01   
 Schmidt, Allen J. wrote:
>Has anyone seen this new Python book out? Although expensive, looks more
>like a classroom training manual.
>
>http://vig.prenhall.com/catalog/academic/product/1,4096,0130923613,00.html
>
>Allen
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>


2,000,000,000 Web Pages--you only need 1. Save time with My Lycos.
http://my.lycos.com


From shalehperry@attbi.com  Thu Mar  7 22:04:05 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Thu, 07 Mar 2002 14:04:05 -0800 (PST)
Subject: [Tutor] if __name__=='__main__'  test
In-Reply-To: <003e01c1c5f7$2b3879c0$5523e30c@attbi.com>
Message-ID: <XFMail.20020307140405.shalehperry@attbi.com>

On 07-Mar-2002 Bruce Gollng wrote:
> Help please.  I've been studying several books and online tutorials and have
> been consistently stumped with the  ..  if __name__ == '__main__': test.  No
> matter when I check __name__ always eq __main__.  So why is this a
> programming benefit?
> tks
> Bruce Golling (bwgolling@attbi.com)
> 

the __name__ of a module is set to one of two things.  '__main__' means the
modules is run as a .py script by python.  Otherwise it is set to the module's
name.

one:/tmp$ python foo.py
I am running
one:/tmp$ python
Python 2.1.2 (#1, Jan 18 2002, 18:05:45) 
[GCC 2.95.4  (Debian prerelease)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import foo
>>> foo.whereami()
foo
>>>

foo.py is simply:

def whereami():
  print __name__

if __name__ == '__main__':
  print "I am running"



From sheila@thinkspot.net  Thu Mar  7 22:17:28 2002
From: sheila@thinkspot.net (Sheila King)
Date: Thu, 07 Mar 2002 14:17:28 -0800
Subject: [Tutor] if __name__=='__main__'  test
In-Reply-To: <003e01c1c5f7$2b3879c0$5523e30c@attbi.com>
References: <003e01c1c5f7$2b3879c0$5523e30c@attbi.com>
Message-ID: <1AC451F2C68@kserver.org>

On Thu, 7 Mar 2002 16:43:10 -0000, "Bruce Gollng" <bwgolling@attbi.com>
wrote about [Tutor] if __name__=='__main__'  test:

> Help please.  I've been studying several books and online tutorials and have been consistently stumped with the  ..  if __name__ == '__main__': test.  No matter when I check __name__ always eq __main__.  So why is this a programming benefit?
> tks
> Bruce Golling (bwgolling@attbi.com)

What I find to be the best feature of the main-name test, is that you can
write a module that is meant to be imported into other programs, but
include a test-suite in it, so that if want to test the module, you run it
as a program itself instead of importing it as a module. In this case, the
__name__ attribute of the module will be '__main__' and it will execute the
testing code. Otherwise, when it is imported as a module, it's name will
not be __main__ and so it will not execute the testing code.

It's just kind of convenient to be able to distribute a module with the
test code built right in that way.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/



From SWidney@ci.las-vegas.nv.us  Thu Mar  7 22:50:41 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Thu, 7 Mar 2002 14:50:41 -0800
Subject: [Tutor] [OT] Rogue installers
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F59E1@SOVEREIGN>

> Note: *many* Windows programs don't undo stuff they do in
> your AUTOEXEC, even via their uninstallers -- this is in no
> way all that unusual.

I agree that it's the norm. I've been in Tech Support some fifteen years
now, and it has almost always been the case that the vendors leave the
mopping up for janitors like me.  *grin*

> With AUTOEXEC, this could be a problem, as many programs alter
> it and make a backup.  If the Ruby uninstaller went back and
> restored AUTOEXEC.RUBY, from the time it installed, you could
> be in big trouble, given all the interim changes to AUTOEXEC
> that might have happened in the meantime.  The only way the
> uninstaller could work would be to parse the file and remove
> parts of it.  A very well-behaved program will (a) tell you
> what it plans on doing and (b) show you what the changes would
> look like ahead of time.  Very few bother.

That's all true. Just because that's the norm, though, doesn't mean we
should find it acceptable. We should feel fine with pointing out something
that's been missed, we should not feel guilty for expecting and/or
requesting more, and these experiences should make us all the more sensitive
to the quality of our own work, especially if we're going to be releasing it
into the wild.

> I just went through a long session purging my AUTOEXEC of
> unwanted path subdirectories this morning.  Some kept
> reappearing, I think because of stuff in the registry.
> The AUTOEXEC would actually change, even after I'd edit
> it -- even after I write-protected it even.

Ah, yes. I've become quite adept at grooming the registry ("Where angels
fear to tread..."). It's a necessary skill in the Windows world. I make it a
point to review my registry after installations specifically to see what the
Installer has done.

> I think you should let go of blaming the Ruby Installer
> -- it's your responsibility, at the end of the day, to
> clean up the AUTOEXEC file.  Uninstallers only do so much.
> They'll also leave DLLs behind, or tell you they *seem*
> to be unused by other programs but you might want to
> leave them just in case -- no help at all to the user,
> as no one keeps all these dependencies in their heads,
> or even written down.

Actually, I agree fully with you that it is the individual's responsibility.
It's the same as changing your car's oil or getting it tuned up. I wasn't so
much blaming the Installer, as identifying it as the culprit. Having done
that, I still left it up to the user to clean up after it. And here's where
I'm headed.

Why should we do that manually? We can use Python to examine our
AUTOEXEC.BAT and CONFIG.SYS files before and after an install. Then store
the changes in a log file. Then we can back out one install without
affecting the others. We can even use Python to do the parse-and-rollback.
And using the Win32 extensions we can do the same thing with the Registry.
In the interest of full disclosure, there are also commercial utilities that
do these same things, if you don't want to roll your own.

Kirby, I wasn't trying to point fingers or start a blame-fest. I was
suggesting a first place to start mopping up the mess...with the unspoken
acknowledgement that it's the PC user that has to do the mopping.

Scott


From SWidney@ci.las-vegas.nv.us  Thu Mar  7 23:10:34 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Thu, 7 Mar 2002 15:10:34 -0800
Subject: [Tutor] Data Structures and Algorithms in Python
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F59E2@SOVEREIGN>

> Do you know where I can download a FREE book on "Data 
> Structures and Algorithms using Python" and the like?

A HUGE resource is NIST's Dictionary of Algorithms and Data Structures:

http://www.nist.gov/dads/

I know, it's not a book, and it doesn't use any one programming language in
particular (They prefer pseudo-code, with links to language-specific
implementations). Still it's good to know about.

Scott


From SWidney@ci.las-vegas.nv.us  Fri Mar  8 00:32:47 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Thu, 7 Mar 2002 16:32:47 -0800
Subject: [Tutor] Suggestions for a good book on functional programming
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F59E3@SOVEREIGN>

> Since i started python, i have been fascinated by this 
> feature. Now i find
> Java very boring.
> I have found some of the discussions in tutor to to be very 
> informative.
> Since most of the guys here have programmed on a pure functional
> languages before, can someone suggest a good book (haskell, 
> scheme anything
> is fine)
> for the same. If i have to buy one which one w'd you recommend?
> 
> Yesterday i came across a title:
> 
> Introduction to Functional Programming using Haskell
> ..Bird
> 
> any ideas as to whether it is good?
> 
> regards,
> karthik.

This page is titled "Tutorial Papers in Functional Programming":

http://www.cs.chalmers.se/~rjmh/tutorials.html

Lots of links. The FAQ for comp.lang.functional might be helpful, too.

http://www.cs.nott.ac.uk/~gmh//faq.html

You should also check out Scheme (You're welcome, Danny!) if you want some
insight into functional concepts:

http://www.schemers.org/

There are some gentle introductions available there, and if you're going to
read SICP or HTDP, you're going to need a Scheme interpreter anyways. I'd
suggest PLT Scheme from Rice as good starter.

Scott


From SWidney@ci.las-vegas.nv.us  Fri Mar  8 00:52:04 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Thu, 7 Mar 2002 16:52:04 -0800
Subject: [Tutor] Suggestions for a good book on functional programming
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F59E4@SOVEREIGN>

> 	In a somewhat related vein, but not really, I'm 
> interested in any
> good logic programming resources.  Something along the lines 
> of Prolog or
> Mercury except using python.  I don't even know if Python has 
> the facilities
> for such an exercise, but it would be pretty neat and educational.
> 
>   Has anyone developed any sorts of Logic extensions to 
> python?  Does python
> have logic programming-like stuff? Are there any definitive 
> books on the
> subject?  Are there any less definitive but artist friendly 
> resources out
> there?
> 
> Sorry to piggy back on your post, but you reminded me of my 
> interest. :)
> 
> 
> 
> ~Israel~

I don't know what stage it's in, but PyProlog seeks to *embed* a Prolog
interpreter into Python:

http://sourceforge.net/projects/pyprolog/

Although unrelated to Python, Schelog is a blending of Scheme and Prolog.
You might find some useful info on their sight:

http://www.ccs.neu.edu/home/dorai/schelog/schelog.html

Note to Danny: apparently embedding Schelog relied heavily on call/cc and
continuations (ouch!) *grin*

Scott


From kp87@lycos.com  Fri Mar  8 08:09:07 2002
From: kp87@lycos.com (kevin parks)
Date: Fri, 08 Mar 2002 17:09:07 +0900
Subject: [Tutor] timing functions
Message-ID: <PDNJLKHHOOMDIBAA@mailcity.com>

Can anyone tell me what i am doing wrong here. I am trying to time two functions so that i can see which one is faster. I have this code which looks ok to me, but when i run it i get an error on the call to apply(). I am not sure what this means and what i am doing wrong. 

cheers,
kevin

-----------------Da error:

Traceback (most recent call last):
  File "sys:Desktop Folder:ftimer.py", line 32, in ?
    do_timing(100, (makezeros.lots_of_appends, makezeros.one_multiply))
  File "sys:Desktop Folder:ftimer.py", line 23, in do_timing
    apply(func)
TypeError: 'tuple' object is not callable
>>> 

------------------Da code:

# file makezeros.py

# def lots_of_appends():
#     zeros = []
#     for i in range(10000):
#         zeros.append(0)
# 
# def one_multiply():
#     zeros = [0] * 10000

# file timings.py

import time, makezeros

def do_timing(num_times, *funcs):
    totals = {}
    for func in funcs: totals[func] = 0.0
    for x in range(num_times):
        for func in funcs:
            starttime = time.time()         # record starting time
            apply(func)
            stoptime = time.time()          # record ending time
            elapsed = stoptime-starttime    # difference yields time elapsed
            totals[func] = totals[func] + elapsed
    for func in funcs:
        print "Running %s %d times took %.3f seconds" % (func.__name__,
                                                         num_times,
                                                         totals[func])

do_timing(100, (makezeros.lots_of_appends, makezeros.one_multiply))

# ftimer.do_timing(100, (ftimer.lots_of_appends, ftimer.one_multiply))


# csh> python timings.py
# Running lots_of_appends 100 times took 7.891 seconds
# Running one_multiply 100 times took 0.120 seconds
# 
# 
# >>> import profile
# >>> from timings import *
# >>> from makezeros import *
# >>> profile.run('do_timing(100, (lots_of_appends, one_multiply))')
# Running lots_of_appends 100 times took 8.773 seconds
# Running one_multiply 100 times took 0.090 seconds
# ...
# 




2,000,000,000 Web Pages--you only need 1. Save time with My Lycos.
http://my.lycos.com


From lha2@columbia.edu  Fri Mar  8 10:57:08 2002
From: lha2@columbia.edu (Lloyd Hugh Allen)
Date: Fri, 08 Mar 2002 05:57:08 -0500
Subject: [Tutor] timing functions
References: <PDNJLKHHOOMDIBAA@mailcity.com>
Message-ID: <3C889904.E870A6B0@mail.verizon.net>

The * in *funcs is being used improperly. Try the following:

def myfunc(arg1, *restofargs):
    print arg1
    print restofargs

you are telling myfunc to put the first argument in arg1 and any
remaining argument in a tuple named restofargs. So if you were to send
to myfunc

myfunc('arg1', 'arg2', 'arg3')

you should get the output

arg1
('arg2', 'arg3')

if on the other hand you send

myfunc('arg1',('arg2','arg3'))

you would get the output

arg1
(('arg2', 'arg3'),)

indicating that your tuple is being placed by the *notation into another
tuple. Not what you want.

The problem line in your code is 

> do_timing(100, (makezeros.lots_of_appends, makezeros.one_multiply))

replace this with 

do_timing(100, makezeros.lots_of_appends, makezeros.one_multiply)

if you want to send an arbitrary number of functions to do_timing.
Alternatively, if you DO want to send a tuple (that was a tuple in the
outer program) to do_timing, remove the * from the function definition.

If that makes any sense.

-Lloyd



kevin parks wrote:
> 
> Can anyone tell me what i am doing wrong here. I am trying to time two functions so that i can see which one is faster. I have this code which looks ok to me, but when i run it i get an error on the call to apply(). I am not sure what this means and what i am doing wrong.
> 
> cheers,
> kevin
> 
> -----------------Da error:
> 
> Traceback (most recent call last):
>   File "sys:Desktop Folder:ftimer.py", line 32, in ?
>     do_timing(100, (makezeros.lots_of_appends, makezeros.one_multiply))
>   File "sys:Desktop Folder:ftimer.py", line 23, in do_timing
>     apply(func)
> TypeError: 'tuple' object is not callable
> >>>
> 
> ------------------Da code:
> 
> # file makezeros.py
> 
> # def lots_of_appends():
> #     zeros = []
> #     for i in range(10000):
> #         zeros.append(0)
> #
> # def one_multiply():
> #     zeros = [0] * 10000
> 
> # file timings.py
> 
> import time, makezeros
> 
> def do_timing(num_times, *funcs):
>     totals = {}
>     for func in funcs: totals[func] = 0.0
>     for x in range(num_times):
>         for func in funcs:
>             starttime = time.time()         # record starting time
>             apply(func)
>             stoptime = time.time()          # record ending time
>             elapsed = stoptime-starttime    # difference yields time elapsed
>             totals[func] = totals[func] + elapsed
>     for func in funcs:
>         print "Running %s %d times took %.3f seconds" % (func.__name__,
>                                                          num_times,
>                                                          totals[func])
> 
> do_timing(100, (makezeros.lots_of_appends, makezeros.one_multiply))
> 
> # ftimer.do_timing(100, (ftimer.lots_of_appends, ftimer.one_multiply))
> 
> # csh> python timings.py
> # Running lots_of_appends 100 times took 7.891 seconds
> # Running one_multiply 100 times took 0.120 seconds
> #
> #
> # >>> import profile
> # >>> from timings import *
> # >>> from makezeros import *
> # >>> profile.run('do_timing(100, (lots_of_appends, one_multiply))')
> # Running lots_of_appends 100 times took 8.773 seconds
> # Running one_multiply 100 times took 0.090 seconds
> # ...
> #
> 
> 2,000,000,000 Web Pages--you only need 1. Save time with My Lycos.
> http://my.lycos.com
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


From toodles@yifan.net  Fri Mar  8 11:15:24 2002
From: toodles@yifan.net (Andy W)
Date: Fri, 8 Mar 2002 19:15:24 +0800
Subject: [Tutor] timing functions
References: <PDNJLKHHOOMDIBAA@mailcity.com>
Message-ID: <000b01c1c692$8ca4cce0$3100a8c0@sun>

Hi Kevin

The code breaks, because of the arguments it expects. You can do one of two
[simple] things to fix it.
The function is defined to receive the arguments (num_times, *funcs)

*funcs accepts any arguments after num_times.
So the first solution would be to change the function call:
      do_timing(100, makezeros.lots_of_appends, makezeros.one_multiply)
      #note that the functions aren't in a tuple anymore. *funcs is a tuple
of all the arguments after num_times

The second solution would be to change the function definition, and keep the
function call the same.
Like so:
      def do_timing(num_times, funcs):
      #Now the functions must be in a sequence

HTH
Andy W

> import time, makezeros
>
> def do_timing(num_times, *funcs):
>     totals = {}
>     for func in funcs: totals[func] = 0.0
>     for x in range(num_times):
>         for func in funcs:
>             starttime = time.time()         # record starting time
>             apply(func)
>             stoptime = time.time()          # record ending time
>             elapsed = stoptime-starttime    # difference yields time
elapsed
>             totals[func] = totals[func] + elapsed
>     for func in funcs:
>         print "Running %s %d times took %.3f seconds" % (func.__name__,
>                                                          num_times,
>                                                          totals[func])
>
> do_timing(100, (makezeros.lots_of_appends, makezeros.one_multiply))
>
> # ftimer.do_timing(100, (ftimer.lots_of_appends, ftimer.one_multiply))
>
>
> # csh> python timings.py
> # Running lots_of_appends 100 times took 7.891 seconds
> # Running one_multiply 100 times took 0.120 seconds
> #
> #
> # >>> import profile
> # >>> from timings import *
> # >>> from makezeros import *
> # >>> profile.run('do_timing(100, (lots_of_appends, one_multiply))')
> # Running lots_of_appends 100 times took 8.773 seconds
> # Running one_multiply 100 times took 0.090 seconds
> # ...
> #
>
>
>
>
> 2,000,000,000 Web Pages--you only need 1. Save time with My Lycos.
> http://my.lycos.com
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



From nicole.seitz@urz.uni-hd.de  Fri Mar  8 12:09:29 2002
From: nicole.seitz@urz.uni-hd.de (Nicole Seitz)
Date: Fri, 8 Mar 2002 13:09:29 +0100
Subject: [Tutor] this is just a test
Message-ID: <02030813092901.00716@utopia>



From erikprice@mac.com  Fri Mar  8 12:30:49 2002
From: erikprice@mac.com (Erik Price)
Date: Fri, 8 Mar 2002 07:30:49 -0500
Subject: [Tutor] thanks
In-Reply-To: <20020307.045321.-244019.18.kjphotog@juno.com>
Message-ID: <529D48C4-3290-11D6-9A36-00039351FE6A@mac.com>

On Thursday, March 7, 2002, at 07:24  AM, kjphotog@juno.com wrote:

> I've also discovered an awesome computer whiz resources like Erik Price.
> He seems to know a bit about everything in the programming world. And is
> ever so willing to discuss, writing in detail, about python, html, css +
> tons more.

<sheepish face="red">

Thanks Keith!  If only to hang on to my ego, I have to say that I really 
am a novice myself when it comes to most things, especially Python!  
Nonetheless, if it's a subject I can help with, I'll try as best I can 
anytime.  (I feel somewhat more useful on the PHP mailing list, as I 
have a little bit more experience with that language...)

For the record, I've been helped by others on this list far more times 
than I've been able to help back!

</sheepish>


Erik



From erikprice@mac.com  Fri Mar  8 12:42:58 2002
From: erikprice@mac.com (Erik Price)
Date: Fri, 8 Mar 2002 07:42:58 -0500
Subject: [Tutor] running a script from IDLE
In-Reply-To: <4.2.0.58.20020307102247.00acf650@pop3.norton.antivirus>
Message-ID: <04D211CF-3292-11D6-9A36-00039351FE6A@mac.com>

On Thursday, March 7, 2002, at 01:31  PM, Kirby Urner wrote:

> I find this a good way to use IDLE because you can build
> up your modules by "unit testing" each piece (each
> function or class) as an individual unit.  This tends to
> promote good habits, as your units have more standalone
> integrity if they have to bear up as testable, versus
> relying on global variables or side effects smeared all
> over the place.

So instead of global variables, it's good form for functions to simply 
use arguments and act upon those?  If this is what you're saying, I can 
see that, since it makes the code more reuseable in scripts that don't 
provide these same [global] variables.

Isn't using a globalized varible just a way to save time/space by not 
having to declare it as an argument?

Always curious about good style,

Erik



From erikprice@mac.com  Fri Mar  8 12:51:31 2002
From: erikprice@mac.com (Erik Price)
Date: Fri, 8 Mar 2002 07:51:31 -0500
Subject: [Tutor] New book out
In-Reply-To: <4.2.0.58.20020307133205.00acfbb0@pop3.norton.antivirus>
Message-ID: <36B8F6B8-3293-11D6-9A36-00039351FE6A@mac.com>

On Thursday, March 7, 2002, at 04:37  PM, Kirby Urner wrote:

> Has stuff on Alice
> (multimedia), Pygame (uses it to make a CD player, which
> I found innovative), talking to MySQL via CGI, and lots
> on XML, including 3rd party Python tools for parsing
> XML files.

I like the sound of all that, but golly!*  $74.00 !!  and no Amazon 
discount to boot!
I have too many Python books I haven't finished yet to go spending bucks 
like that (Python Web Programming, Quick Python Book).

Speaking of which, I like the Quick Python Book a lot, since it is very 
simply written, contains a lot of example code (but not needlessly long 
samples), and assumes that you already know another language 
(appropriate for me, not for every Python beginner).  But it's a little 
old -- I picked up David Beazley's Python Essential Reference for Python 
2.x, in hopes that this would clear up any changes to the new Python.  
Was this a safe assumption?

Erik



* an underused expression



From rob@jam.rr.com  Fri Mar  8 14:08:07 2002
From: rob@jam.rr.com (Rob Andrews)
Date: Fri, 08 Mar 2002 08:08:07 -0600
Subject: [Tutor] Re: New book out
References: <E16j8Me-0000QK-00@mail.python.org>
Message-ID: <3C88C5C7.6090303@jam.rr.com>

I also got to do some technical reviewing of the book (They spelled my 
name right and mentioned Useless Python! woohoo!), and I liked it. It's 
not without issue, of course, but it does introduce a wide range of 
different (and relevant) topics in a manner that could be quite handy.

peace,
Rob
http://www.lowerstandard.com/python
(I promise to get that update finished soon!)


> 
> Yeah, I was one of the technical reviewers, as was Alan.
> It has exercises at the end of each chapter.  Pretty
> comprehensive treatment of topics, though even in that
> many pages you can't go too deep.  Has stuff on Alice
> (multimedia), Pygame (uses it to make a CD player, which
> I found innovative), talking to MySQL via CGI, and lots
> on XML, including 3rd party Python tools for parsing
> XML files.
> 
> There's a certain format characteristic of all books in
> the series that has its drawbacks (as well as its pluses).
> Sometimes the line-by-line analysis paragraphs can be
> pretty dense, but if you're willing to concentrate...
> 
> I CD comes with Apache, Alice, other stuff (which you
> can also get on the web of course).
> 
> It costs a lot, but you get a lot.  It's an OK survey
> (GUI programming, some stuff on threads), a good way to
> get your feet wet on a lot of topics, using a very
> learnable language (Python).  As such, it's a jumping
> off point for getting into specific topics in more
> depth.
> 
> Kirby




From James.Alexander.McCarney@Cognicase.com  Fri Mar  8 15:13:00 2002
From: James.Alexander.McCarney@Cognicase.com (McCarney, James Alexander)
Date: Fri, 8 Mar 2002 10:13:00 -0500
Subject: [Tutor] Restoring IDLE
Message-ID: <23FD7B1A77E8D211BCB900001D108C02018B2A03@camelot>

Hi Pythonistas...

My computer was rudely interfered with and my settings are now f.u.b.a.r.
(translation for non native English-language speakers--not in a state of
grace or normalcy). Does anyone know how to restore IDLE as the editor of
choice? I know how to associate filetypes with executables, but is IDLE an
executable or is it Python.exe itself?

Platform: Windows 2000; Py 2.2

Grrr a pox on fu-lish fubarinos!


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 huangjianli@yahoo.com  Fri Mar  8 16:22:40 2002
From: huangjianli@yahoo.com (jianli Huang)
Date: Fri, 8 Mar 2002 08:22:40 -0800 (PST)
Subject: [Tutor] A new comer
Message-ID: <20020308162240.95104.qmail@web20906.mail.yahoo.com>

Dear All,

I am a new comer of python. I am a c++ programmer,
what can I do with python?

Thank you.

__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/


From bobx@linuxmail.org  Fri Mar  8 16:11:30 2002
From: bobx@linuxmail.org (Bob X)
Date: Sat, 09 Mar 2002 00:11:30 +0800
Subject: [Tutor] searching out keywords...
Message-ID: <20020308161130.7553.qmail@linuxmail.org>

I have to monitor some hefty (min 40MB) log files. I have a list of keywords that I want to search for and then write those lines out to a different file. Basically I want to do this.

1. run the py file with the log file as an ARG on the command line.
2. have it search that file for keywords
3. insert the lines that the keywords appears on into a different file

>From looking around a bit I have this...but:

import sys, string

# open the file to read
inp = open(sys.argv[1],"r")
outp = open("badwords.txt","w")

# create a keyword list
kw = ["sex","teen"]

# read the file in and search for keywords
for kw in inp.readlines():
  outp.write(line)   # needs to go to outp file
print "finished text processing"

# close em up
inp.close()
outp.close()

Help would be appreciated...I am learning wxPython as well and will put a gui on it once this is done.

Bob


-- 

Get your free email from www.linuxmail.org 


Powered by Outblaze


From shalehperry@attbi.com  Fri Mar  8 17:07:45 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Fri, 08 Mar 2002 09:07:45 -0800 (PST)
Subject: [Tutor] searching out keywords...
In-Reply-To: <20020308161130.7553.qmail@linuxmail.org>
Message-ID: <XFMail.20020308090745.shalehperry@attbi.com>

On 08-Mar-2002 Bob X wrote:
> I have to monitor some hefty (min 40MB) log files. I have a list of keywords
> that I want to search for and then write those lines out to a different file.
> Basically I want to do this.
> 
> 1. run the py file with the log file as an ARG on the command line.
> 2. have it search that file for keywords
> 3. insert the lines that the keywords appears on into a different file
> 
>>> import string
>>> def contains_word(line, word):
...   return (string.find(line, word) != -1)
>>> contains_word('Sean "Shaleh" Perry', 'Perry')
1
>>> contains_word('Sean "Shaleh" Perry', 'Mom')

Then the question becomes whether or not partial matches are ok.

"This line of text has bluetooth connectivity" and we search for blue which
matches.  If this is not what you want then changing the string.find() to a
regex may work better.  re.search(r'\b%s\b' % word, line) seems like a good
start.  string.find () is likely faster though.

for word in words:
  if contains_word(line, word):
    print line
    break



From shalehperry@attbi.com  Fri Mar  8 17:09:02 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Fri, 08 Mar 2002 09:09:02 -0800 (PST)
Subject: [Tutor] A new comer
In-Reply-To: <20020308162240.95104.qmail@web20906.mail.yahoo.com>
Message-ID: <XFMail.20020308090902.shalehperry@attbi.com>

On 08-Mar-2002 jianli Huang wrote:
> Dear All,
> 
> I am a new comer of python. I am a c++ programmer,
> what can I do with python?
> 

try browsing http://www.python.org.  Asking 'what can I do with python' is like
asking 'what can I write with C++'.  The answer is "just about anything if you
spend the time".


From vodine@direct.ca  Fri Mar  8 17:24:02 2002
From: vodine@direct.ca (Virginia)
Date: Fri, 8 Mar 2002 09:24:02 -0800
Subject: [Tutor] Restoring IDLE
References: <23FD7B1A77E8D211BCB900001D108C02018B2A03@camelot>
Message-ID: <005701c1c6c6$0c00fc60$808242d8@w98sysrec>

This is a multi-part message in MIME format.

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

If you go to Start, Programs, then find your Python/Idle Shortcut, and =
right click it, it points to the exe file you need.
  ----- Original Message -----=20
  From: McCarney, James Alexander=20
  To: Python Tutor (E-mail)=20
  Sent: Friday, March 08, 2002 7:13 AM
  Subject: [Tutor] Restoring IDLE


  Hi Pythonistas...

  My computer was rudely interfered with and my settings are now =
f.u.b.a.r.
  (translation for non native English-language speakers--not in a state =
of
  grace or normalcy). Does anyone know how to restore IDLE as the editor =
of
  choice? I know how to associate filetypes with executables, but is =
IDLE an
  executable or is it Python.exe itself?

  Platform: Windows 2000; Py 2.2

  Grrr a pox on fu-lish fubarinos!


  James Alexander McCarney, technical writer, (450) 928-3386 x2262=20
  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

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


------=_NextPart_000_0054_01C1C682.FC434640
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.3019.2500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>If you go to Start, Programs, then find your =
Python/Idle=20
Shortcut, and right click it, it points to the exe file you =
need.</FONT></DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A href=3D"mailto:James.Alexander.McCarney@Cognicase.com"=20
  title=3DJames.Alexander.McCarney@Cognicase.com>McCarney, James =
Alexander</A>=20
  </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
href=3D"mailto:tutor@python.org"=20
  title=3Dtutor@python.org>Python Tutor (E-mail)</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Friday, March 08, 2002 =
7:13=20
AM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Tutor] Restoring =
IDLE</DIV>
  <DIV><BR></DIV>Hi Pythonistas...<BR><BR>My computer was rudely =
interfered with=20
  and my settings are now f.u.b.a.r.<BR>(translation for non native=20
  English-language speakers--not in a state of<BR>grace or normalcy). =
Does=20
  anyone know how to restore IDLE as the editor of<BR>choice? I know how =
to=20
  associate filetypes with executables, but is IDLE an<BR>executable or =
is it=20
  Python.exe itself?<BR><BR>Platform: Windows 2000; Py 2.2<BR><BR>Grrr a =
pox on=20
  fu-lish fubarinos!<BR><BR><BR>James Alexander McCarney, technical =
writer,=20
  (450) 928-3386 x2262 <BR>Cognicase-M3i <A=20
  href=3D"http://www.m3isystems.com">http://www.m3isystems.com</A><BR><A =

  =
href=3D"mailto:James.Alexander.McCarney@Cognicase.com">mailto:James.Alexa=
nder.McCarney@Cognicase.com</A><BR>1111=20
  Saint-Charles Avenue West, 11th Floor, East Tower, Longueuil, =
Quebec,<BR>J4K=20
  5G4 =
Canada<BR><BR>_______________________________________________<BR>Tutor=20
  maillist&nbsp; -&nbsp; <A=20
  href=3D"mailto:Tutor@python.org">Tutor@python.org</A><BR><A=20
  =
href=3D"http://mail.python.org/mailman/listinfo/tutor">http://mail.python=
.org/mailman/listinfo/tutor</A><BR></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0054_01C1C682.FC434640--



From urnerk@qwest.net  Fri Mar  8 17:35:25 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Fri, 08 Mar 2002 09:35:25 -0800
Subject: [Tutor] running a script from IDLE
In-Reply-To: <04D211CF-3292-11D6-9A36-00039351FE6A@mac.com>
References: <4.2.0.58.20020307102247.00acf650@pop3.norton.antivirus>
Message-ID: <4.2.0.58.20020308075629.00acf8a0@pop3.norton.antivirus>

At 07:42 AM 3/8/2002 -0500, Erik Price wrote:

>So instead of global variables, it's good form for
>functions to simply use arguments and act upon those?

One use of global variables that's not controversial
is to fix them to constant values and consult them
in functions, e.g. start at the top by going

PHI = (1 + math.sqrt(5))/2

But that's a constant more than a variable (still
global), the kind of thing many languages handle at
compile time with #DEFINE statements and the like
(using all caps for constants is a holdover from
those languages -- a stylistic flag).

>If this is what you're saying, I can see that, since
>it makes the code more reuseable in scripts that don't
>provide these same [global] variables.

It's actually a sort of deep question how to make
use of globals.  Writing a module and testing the
functions as you add them doesn't actually prevent
weird constructs -- it only makes them less likely.

>Isn't using a globalized varible just a way to save
>time/space by not having to declare it as an argument?
>
>Always curious about good style,
>
>Erik

It's when you start burying changes to shared variables
deep in code that's ostensibly focused on something else,
that your readers (which includes yourself) get lost.

This might mean passing more arguments and returning
altered contents, rather than changing contents as a
side effect.

Giving your functions a kind of standalone integrity,
makes your code more robust overall.

However, there's a tradeoff.  A very generic coding
style can be too abstract for the problem at hand.
A language as easy to use as Python places less
premium on writing these absolutely generic utilities
at every turn -- which has the effect of making the
results look less "academic" (e.g. less like LISP).

Kirby



From python.tutorial@jarava.org  Fri Mar  8 17:43:53 2002
From: python.tutorial@jarava.org (Javier JJ)
Date: Fri, 8 Mar 2002 18:43:53 +0100
Subject: [Tutor] searching out keywords...
References: <20020308161130.7553.qmail@linuxmail.org>
Message-ID: <006501c1c6c8$d2ac7180$931304d5@uno>

First of all, I'm far from being an expert in ... well, anything, but much
less in what I'm going to say :) So take my words with a huge grain of
salt...

A few comments:



> I have to monitor some hefty (min 40MB) log files. I have a list of
keywords that I want to search for and then write those lines out to a
different file. Basically I want to do this.
>
> 1. run the py file with the log file as an ARG on the command line.
> 2. have it search that file for keywords
> 3. insert the lines that the keywords appears on into a different file
>
> From looking around a bit I have this...but:
>
> import sys, string
>
> # open the file to read
> inp = open(sys.argv[1],"r")
> outp = open("badwords.txt","w")
>
> # create a keyword list
> kw = ["sex","teen"]
>
> # read the file in and search for keywords
> for kw in inp.readlines():
>   outp.write(line)   # needs to go to outp file
> print "finished text processing"

This won't work. When you do "for kw in inp.readlines" what you do is that
you are assigning the lines in the log file to the "kw" variable ..

This is a (rogugh, probably very wrong and simple) way to do it that
works....

>>> for i in inp.readlines():    # read in all the log file and go line by
line
...  for j in kw:                            # for each of the keywords
...   if i.find(j) <>-1:                # See if the keyword is part of the
line. It has the advantage of also
                                                # finding it if it's a part
of a word
...    print i                            # Or whatever

Probably it'd be a good idea to do j.lower() and i.lower() to avoid "caps
mismatch" ...

> # close em up
> inp.close()
> outp.close()
>
> Help would be appreciated...I am learning wxPython as well and will put a
gui on it once this is done.
>
> Bob

A couple of notes on performance:

inp.readlines() does read all the file into memory; if the log is big, that
is quite a performance it. So it'd probably be better to use a read()
loop...

So, if performance is important, I'd say you'd be better off using something
as simple as (on a command line)

 cat log_fie | grep keyword > badwords_file

This is much faster :-)

But now I'll crawl back under the stone and let the real experts speak :-)

    Javier
----

Windows N'T: as in Wouldn't, Couldn't, and Didn't.




From alan.gauld@bt.com  Fri Mar  8 17:42:59 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 8 Mar 2002 17:42:59 -0000
Subject: [Tutor] running a script from IDLE
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C41A@mbtlipnt02.btlabs.bt.co.uk>

> >On Thu, 7 Mar 2002, Ron Nixon wrote:
> > > IDLE that I've saved. When > I copy to file into IDLE and
> > > hit "run script" I get a messege saying "The buffer for
> > > Python Shell is not saved. Please save it first." 

Nobody seems to have caught this bit yet...

You are trying to paste your code into the Python Shell 
window - it has the >>> prompt in it. You shouldn't do that.

Instead you need to start IDLE, then do File | New to 
open a new blank window. 
Paste your program into that window.
Then do File|Save As to save the program as a file ending .py.
Finally use Edit|Run to run the program, the output will be 
in the original Python Shell window.

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


From alan.gauld@bt.com  Fri Mar  8 17:46:08 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 8 Mar 2002 17:46:08 -0000
Subject: [Tutor] New book out
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C41B@mbtlipnt02.btlabs.bt.co.uk>

> Has anyone seen this new Python book out? Although expensive, 
> looks more like a classroom training manual.
> 
> http://vig.prenhall.com/catalog/academic/product/1,4096,013092
> 3613,00.html

There's been some discussion earlier and also on the 
comp.lang.python newsgroup. Try a search on google and/or 
Activestate...

Alan g.


From alan.gauld@bt.com  Fri Mar  8 17:54:10 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 8 Mar 2002 17:54:10 -0000
Subject: [Tutor] New book out
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C41C@mbtlipnt02.btlabs.bt.co.uk>

> It costs a lot, but you get a lot.  It's an OK survey
> (GUI programming, some stuff on threads), a good way to
> get your feet wet on a lot of topics, using a very
> learnable language (Python).  As such, it's a jumping
> off point for getting into specific topics in more
> depth.

Couldn't summarize better.

I'd add that some of the pages are excess baggage. For 
example the appendices on XHTML and HTML are almost word 
for word identical. A single annex could have covered 
both IMHO...

But its probably the widest ranging book for close 
to absolute beginner on the market at the moment.
For a school text you'd probably want to be fairly 
selective in which chapters you use.

Alan G.


From kjphotog@juno.com  Fri Mar  8 17:51:37 2002
From: kjphotog@juno.com (kjphotog@juno.com)
Date: Fri, 8 Mar 2002 09:51:37 -0800
Subject: [Tutor] Re: Deitel Book info
Message-ID: <20020308.095140.-4008351.20.kjphotog@juno.com>

I have a copy of the Deitel book too & find that it's pretty easy to
follow and understand. Readers are prompted in outline form on what
they're about to read. Then you jump into tackle samples & examples and
there's "homework" at the end of each chapter. 

The books authors even replied to an e-mail & offer to answer questions
via e-mail, but they've yet to follow up on that offer.  

In addition to the extensive Python info & tutorials there's a host of
other useful info like xml & css. By the way, the contents are easy on
the eyes to read too & no coding in microscopic text. In fact, Dietels py
coding is in color. I'm a newbie but feel the book is worthy. Public
libraries may have a copy, so check it out. 

Keith

________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today!  For your FREE software, visit:
http://dl.www.juno.com/get/web/.


From urnerk@qwest.net  Fri Mar  8 18:03:16 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Fri, 08 Mar 2002 10:03:16 -0800
Subject: [Tutor] searching out keywords...
In-Reply-To: <20020308161130.7553.qmail@linuxmail.org>
Message-ID: <4.2.0.58.20020308093831.00d2b9e0@pop3.norton.antivirus>

>
> From looking around a bit I have this...but:
>
>import sys, string
>
># open the file to read
>inp = open(sys.argv[1],"r")
>outp = open("badwords.txt","w")
>
># create a keyword list
>kw = ["sex","teen"]
>
># read the file in and search for keywords
>for kw in inp.readlines():
>   outp.write(line)   # needs to go to outp file
>print "finished text processing"
>
># close em up
>inp.close()
>outp.close()

As written, this won't do what you want.

    for kw in inp.readlines():
      outp.write(line)   # needs to go to outp file

is going to make kw be each of the lines in
your 40MB log file, which overwrites what you set
it before.  The variable 'line' is not being
defined at all.

Closer to what you want is:

    kw = ["sex","teen"]

    for line in inp.readlines():
       for badword in kw:  # loop through list
          if line.find(badword) > -1: # found!
             outp.write(line)
             break

This is a loop in a loop, with the outer loop progressing
through lines of text, the inner loop searching for each
element in kw, with a break as soon as it finds one --
no need to keep checking the same line once one offense
is counted.

As mentioned above, this algorithm is going to give false
positives on words like Middlesex and canteen.

But the more immediate challenge is to properly accomodate
40MB files.  inp.readlines() will bring all 40MB into
RAM and/or virtual memory which may or may not be a
problem.  Let's assume that it is.

One way around this is to provide a sizehint in as your
argument to readlines(), which will limit the size of
what's brought in.  Rewritting to include this:

    kw = ["sex","teen"]

    while 1:
       chunk = inp.readlines(1024)  # get some lines
       if len(chunk)==0:            # quit if no more
           break
       for line in chunk:           # do the loop-de-loop
          for badword in kw:        # loop through list
             if line.find(badword) > -1: # found!
                outp.write(line)
                break

Probably you'll want to add some feedback to the user
that indicates how far the analysis has progressed.
You could use a counter and trigger a print every
time hit a multiple of 100 or something.

Kirby



From alan.gauld@bt.com  Fri Mar  8 18:02:56 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 8 Mar 2002 18:02:56 -0000
Subject: [Tutor] running a script from IDLE
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C41D@mbtlipnt02.btlabs.bt.co.uk>

> So instead of global variables, it's good form for functions 
> to simply use arguments and act upon those?  

Absolutely. In fact this is one of the cornerstones of whats 
known as "Functional Programming" - along with having functions 
that always return a value.

> Isn't using a globalized varible just a way to save time/space 
> by not having to declare it as an argument?

Its oftehn used out of laziness yes but has several disadvantages.
First, its very hard to know which function made the changes 
which caused a fault (a phenomenon known as a 'side effect' 
- when a function changes a value outside of itself). 

Second, its very hard to debug functions in isolation because 
they rely on the existence of the global vars

Third, if you want to multi thread your functions its impossible 
coz every thread will call the function which, modifies the same 
variable.

Avoiding globals usially leads to more maintainable, more 
reliable and more reusable code - isn't that wporth a little 
extra typing and a few bytes of RAM?

HTH,

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


From urnerk@qwest.net  Fri Mar  8 18:08:51 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Fri, 08 Mar 2002 10:08:51 -0800
Subject: [Tutor] searching out keywords...
In-Reply-To: <006501c1c6c8$d2ac7180$931304d5@uno>
References: <20020308161130.7553.qmail@linuxmail.org>
Message-ID: <4.2.0.58.20020308100739.00d2d9f0@pop3.norton.antivirus>

At 06:43 PM 3/8/2002 +0100, Javier JJ wrote:

>So, if performance is important, I'd say you'd be better off using something
>as simple as (on a command line)
>
>  cat log_fie | grep keyword > badwords_file
>
>This is much faster :-)

That's a good point.  If you have an OS that already includes
a lot of utilities like this, you don't have to code up a
Python thing, let alone slap a GUI over it.  Life at the
OS command line is sooo much simpler.

Kirby



From alan.gauld@bt.com  Fri Mar  8 18:06:08 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 8 Mar 2002 18:06:08 -0000
Subject: [Tutor] Restoring IDLE
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C41E@mbtlipnt02.btlabs.bt.co.uk>

> Does anyone know how to restore IDLE as 
> the editor of choice? I know how to associate 
> filetypes with executables, but is IDLE an executable 
> or is it Python.exe itself?

Heres the shortcut in Start|Programs|Python

D:\Python20\pythonw.exe D:\PYTHON20\Tools\idle\idle.pyw

Substitute your own install dir of course...

Alan G./


From SWidney@ci.las-vegas.nv.us  Fri Mar  8 17:51:04 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Fri, 8 Mar 2002 09:51:04 -0800
Subject: [Tutor] global vars vs. func args
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F59E8@SOVEREIGN>

On Friday, March 08, 2002 at 4:43 AM, Erik Price wrote:
> On Thursday, March 7, 2002, at 01:31  PM, Kirby Urner wrote:
> 
> > I find this a good way to use IDLE because you can build
> > up your modules by "unit testing" each piece (each
> > function or class) as an individual unit.  This tends to
> > promote good habits, as your units have more standalone
> > integrity if they have to bear up as testable, versus
> > relying on global variables or side effects smeared all
> > over the place.
> 
> So instead of global variables, it's good form for functions 
> to simply use arguments and act upon those?  If this is what
> you're saying, I can see that, since it makes the code more
> reusable in scripts that don't provide these same [global] 
> variables.
> 
> Isn't using a globalized variable just a way to save time/space 
> by not having to declare it as an argument?
> 
> Always curious about good style,
> 
> Erik

The term that Kirby mentioned, "side effects", is mentioned all over the
place in Functional Programming land. Functions should not have
side-effects; which is to say that functions should receive data, operate on
that data, and return the results. The function shouldn't touch anything
outside of this scope. The idea behind it is not unique to FP though; and,
as you can see, there are several Tutors on this list that encourage this
philosophy in Python programming, too. [You'll really reap the rewards when
you start fiddling with objects: encapsulation relies on effective
partitioning.]

So, yes, the idea is to pass as arguments everything that a function needs
to do its thing. And there are drawbacks to using globals. Foremost in my
mind is: how do you keep track of which functions are reading/modifying it?
Especially in a large project? Data integrity and data access is a real
concern.

One big benefit of avoiding side effects is that you can remain confident
that these functions won't mess with any of your structures and/or data
without explicit permission.

Of course, having said all that, there are those rare times when using a
global makes sense. "The most important thing about knowing the rules is
knowing when to break them."


Scott


From shalehperry@attbi.com  Fri Mar  8 18:13:25 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Fri, 08 Mar 2002 10:13:25 -0800 (PST)
Subject: [Tutor] searching out keywords...
In-Reply-To: <4.2.0.58.20020308100739.00d2d9f0@pop3.norton.antivirus>
Message-ID: <XFMail.20020308101325.shalehperry@attbi.com>

On 08-Mar-2002 Kirby Urner wrote:
> At 06:43 PM 3/8/2002 +0100, Javier JJ wrote:
> 
>>So, if performance is important, I'd say you'd be better off using something
>>as simple as (on a command line)
>>
>>  cat log_fie | grep keyword > badwords_file
>>
>>This is much faster :-)
> 
> That's a good point.  If you have an OS that already includes
> a lot of utilities like this, you don't have to code up a
> Python thing, let alone slap a GUI over it.  Life at the
> OS command line is sooo much simpler.
> 

True, although you then lose flexibility.  Like your idea of printing a status
every few 100 lines.


From alan.gauld@bt.com  Fri Mar  8 18:13:17 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 8 Mar 2002 18:13:17 -0000
Subject: [Tutor] A new comer
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C41F@mbtlipnt02.btlabs.bt.co.uk>

> I am a new comer of python. I am a c++ programmer,
> what can I do with python?

Pretty much what you could do in C++ but faster.
(ie you spend less time writing code)

Look at the Python advocacy pages on the python.org 
web site...

http://www.python.org/doc/Intros.html

Then try the Instant Python 6 page tutor to get a 
flavor of it.

Then work through the tutorial that comes with the 
documentation. As a C++ programmer you should have few 
problems bar a slight culture shift as you get used 
to dynamic typing and heterogenous collections.
Oh yes and no public/private/protected sections 
- don't worry its not as dangerous as you might think! 

Any questions, we're right here to help :-)

Alan g.


From shalehperry@attbi.com  Fri Mar  8 18:25:46 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Fri, 08 Mar 2002 10:25:46 -0800 (PST)
Subject: [Tutor] A new comer
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C41F@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <XFMail.20020308102546.shalehperry@attbi.com>

> 
> Then work through the tutorial that comes with the 
> documentation. As a C++ programmer you should have few 
> problems bar a slight culture shift as you get used 
> to dynamic typing and heterogenous collections.
> Oh yes and no public/private/protected sections 
> - don't worry its not as dangerous as you might think! 
> 

the other big thing that catches people is in C++ the variable *this is
implicit and you almost never see it.  Python requires you to use the variable
to do most of the class work (it is called 'self' in python).

class Foo:
  def __init__(self): # constructor
    self.bar = 0

  def getBar(self):
    return self.bar

f = Foo()
print f.getBar()

as you can see, self is a needed part of class access.

class Foo {
public:
  Foo(void): bar(0) {}

  int getBar(void) const { return bar; }

private:
  int bar;
};

Foo f;
cout << f.getBar() << '\n';


From alan.gauld@bt.com  Fri Mar  8 18:26:29 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 8 Mar 2002 18:26:29 -0000
Subject: [Tutor] searching out keywords...
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C420@mbtlipnt02.btlabs.bt.co.uk>

> I have to monitor some hefty (min 40MB) log files. I have a 
> list of keywords that I want to search for and then write 
> those lines out to a different file. Basically I want to do this.

Its always fun writing stuff in Python, but I'd have thought 
the easiest and fastest way to do this was egrep...

C:\> egrep 'keyword1|kywrd2' logfile.txt > results.txt

Just a thought...

Alan g.


From James.Alexander.McCarney@Cognicase.com  Fri Mar  8 18:29:35 2002
From: James.Alexander.McCarney@Cognicase.com (McCarney, James Alexander)
Date: Fri, 8 Mar 2002 13:29:35 -0500
Subject: [Tutor] Restoring IDLE
Message-ID: <23FD7B1A77E8D211BCB900001D108C02018B2A09@camelot>

Thanks Alan and Virginia! I am happily idling again.

-----Original Message-----
From: alan.gauld@bt.com [mailto:alan.gauld@bt.com]
Sent: Friday, March 08, 2002 1:06 PM
To: James.Alexander.McCarney@Cognicase.com; tutor@python.org
Subject: RE: [Tutor] Restoring IDLE


> Does anyone know how to restore IDLE as 
> the editor of choice? I know how to associate 
> filetypes with executables, but is IDLE an executable 
> or is it Python.exe itself?

Heres the shortcut in Start|Programs|Python

D:\Python20\pythonw.exe D:\PYTHON20\Tools\idle\idle.pyw

Substitute your own install dir of course...

Alan G./


From alan.gauld@bt.com  Fri Mar  8 18:33:28 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 8 Mar 2002 18:33:28 -0000
Subject: [Tutor] searching out keywords...
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C421@mbtlipnt02.btlabs.bt.co.uk>

> >  cat log_fie | grep keyword > badwords_file
> >
> >This is much faster :-)
> 
> That's a good point.  If you have an OS that already includes
> a lot of utilities like this

GNU grep is available for most OSs and native in Unix/Linux and
now on MacOS X too.

On DOS there is the very similar (but less powerful) FIND command
or download the GNU grep.

VMS has its own equally powerful FIND tool.
(As does MVS if it matters!...)

Alan g.


From aschmidt@nv.cc.va.us  Fri Mar  8 18:56:33 2002
From: aschmidt@nv.cc.va.us (Schmidt, Allen J.)
Date: Fri, 8 Mar 2002 13:56:33 -0500
Subject: [Tutor] New book out
Message-ID: <47BCBF3251382B45893950D07804082475AEC7@novamail.nv.cc.va.us>

Thanks Alan! -- even though you spell your name wrong...  <8^)   

I told my fifteen year old son about it and he wants me to get it. He is
teaching my other 3 kids Python as part of their Home schooling regimen. The
are having a great time with it. (Incentive for first 'major' program is a
new Palm IIIxe)

He printed a tutorial he found somewhere and has been teaching from that.
He's moving into Zope now with his Python knowledge and is preparing for a
very-possible summer job build Zope/Python products.

Anyway, thanks for the book info. I thought for sure that ANYTHING new
covering Python would show up here first so that is why I was a bit curious
when I saw it on the shelf at Microcenter yesterday.

Cheers!

Allen

-----Original Message-----
From: alan.gauld@bt.com [mailto:alan.gauld@bt.com]
Sent: Friday, March 08, 2002 12:46 PM
To: aschmidt@nv.cc.va.us; tutor@python.org
Subject: RE: [Tutor] New book out



> Has anyone seen this new Python book out? Although expensive, 
> looks more like a classroom training manual.
> 
> http://vig.prenhall.com/catalog/academic/product/1,4096,013092
> 3613,00.html

There's been some discussion earlier and also on the 
comp.lang.python newsgroup. Try a search on google and/or 
Activestate...

Alan g.


From urnerk@qwest.net  Fri Mar  8 19:22:08 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Fri, 08 Mar 2002 11:22:08 -0800
Subject: [Tutor] running a script from IDLE
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C41D@mbtlipnt02.btlabs
 .bt.co.uk>
Message-ID: <4.2.0.58.20020308111222.00d32590@pop3.norton.antivirus>

At 06:02 PM 3/8/2002 +0000, alan.gauld@bt.com wrote:

> > So instead of global variables, it's good form for functions
> > to simply use arguments and act upon those?
>
>Absolutely. In fact this is one of the cornerstones of whats
>known as "Functional Programming" - along with having functions
>that always return a value.

Seems to me the OO model is somewhat at odds with the
FP model, as objects manage state, and you often want
to change an instance's state without returning a copy
of that instance, i.e. the state change is "destructive"
(in the sense that the old version is no longer around).

   object.setproperty(value)

is inherently destructive, unless you want your method
to make a [deep] copy of self, manipulate that copy, and
return a new instance.

For example, an icosahedron object might contain 12 point
objects defining its vertices.

   icosa.rotate(axis,degrees)

would alter the orientation of said instance, rotating it
about some axis.  But if I want to leave icosa as is, and
return the rotated icosa, then I have to copy icosa
internally, and if the points are themselves point objects
in a list, deepcopy to get copies of those.

I don't always need to go to this kind of trouble, and
the OO model doesn't seem to insist that I should.
Instances are the termini, and, being objects, it makes
plenty of sense to change their state.  When I move a
pencil on my desk,  it's the pencil that moves, not
some clone of the pencil, such that now I have two.

The whole object metaphor encourages "destructive"
changes to objects (in the sense that no "original"
remains, and therefore nothing need be returned).

So whereas mylist.sort() appears "non-FP" in the sense
that None is returned and mylist is destructively
altered, from an OO standpoint (and mylist is an
instance of the list class, after all), it's sort of
business as usual.

Doubtless this is not a new insight.  Some FP purists
probably fight the encroachment of OO thinking into
their space as a result.

Kirby



From pythontutor@venix.com  Fri Mar  8 19:40:13 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Fri, 08 Mar 2002 14:40:13 -0500
Subject: [Tutor] running a script from IDLE
References: <4.2.0.58.20020308111222.00d32590@pop3.norton.antivirus>
Message-ID: <3C89139D.2040104@venix.com>

http://www.paulgraham.com/langdes.html

The tail end of this Paul Graham article gives a good idea of a Lisp
programmer's view of OO.  I agree with him.  OO is extremely useful
sometimes, but I don't like getting pushed into using it when it
doesn't fit or it gets in the way...

Kirby Urner wrote:

> At 06:02 PM 3/8/2002 +0000, alan.gauld@bt.com wrote:
> 
>> > So instead of global variables, it's good form for functions
>> > to simply use arguments and act upon those?
>>
>> Absolutely. In fact this is one of the cornerstones of whats
>> known as "Functional Programming" - along with having functions
>> that always return a value.
> 
> 
> Seems to me the OO model is somewhat at odds with the
> FP model, as objects manage state, and you often want
> to change an instance's state without returning a copy
> of that instance, i.e. the state change is "destructive"
> (in the sense that the old version is no longer around).
> 
>   object.setproperty(value)
> 
> is inherently destructive, unless you want your method
> to make a [deep] copy of self, manipulate that copy, and
> return a new instance.
> 
> For example, an icosahedron object might contain 12 point
> objects defining its vertices.
> 
>   icosa.rotate(axis,degrees)
> 
> would alter the orientation of said instance, rotating it
> about some axis.  But if I want to leave icosa as is, and
> return the rotated icosa, then I have to copy icosa
> internally, and if the points are themselves point objects
> in a list, deepcopy to get copies of those.
> 
> I don't always need to go to this kind of trouble, and
> the OO model doesn't seem to insist that I should.
> Instances are the termini, and, being objects, it makes
> plenty of sense to change their state.  When I move a
> pencil on my desk,  it's the pencil that moves, not
> some clone of the pencil, such that now I have two.
> 
> The whole object metaphor encourages "destructive"
> changes to objects (in the sense that no "original"
> remains, and therefore nothing need be returned).
> 
> So whereas mylist.sort() appears "non-FP" in the sense
> that None is returned and mylist is destructively
> altered, from an OO standpoint (and mylist is an
> instance of the list class, after all), it's sort of
> business as usual.
> 
> Doubtless this is not a new insight.  Some FP purists
> probably fight the encroachment of OO thinking into
> their space as a result.
> 
> Kirby
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582



From ainsoph3@attbi.com  Fri Mar  8 20:24:21 2002
From: ainsoph3@attbi.com (chris schwan)
Date: 08 Mar 2002 12:24:21 -0800
Subject: [Tutor] Speaking of Books..
In-Reply-To: <XFMail.20020308102546.shalehperry@attbi.com>
References: <XFMail.20020308102546.shalehperry@attbi.com>
Message-ID: <1015619061.2086.6.camel@milarepa>

Since books get discussed a bunch here, I have been wondering about Mark
Lutz's 'Programming Python- second edition'. I have read a bunch of
negatives about that book (I think the first edition), but then I have
been turning up some positive things about it.

So what do people here think? I have made my way through beginnerhood
using Alan's webpage, "Think Like a Comp Sci" (great IMHO), "Quick
Python", and list lurkin. I am still not very good at all, but I am
wondering about this book, and if it has more depth like its perl
counterpart? I like to read stuff thats a bit above my head and grow
into it.

Thanks...

C.



From jeff@ccvcorp.com  Fri Mar  8 20:13:33 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Fri, 08 Mar 2002 12:13:33 -0800
Subject: [Tutor] searching out keywords...
References: <E16jOoi-0001F0-00@mail.python.org>
Message-ID: <3C891B6C.F6282D92@ccvcorp.com>

> But the more immediate challenge is to properly accomodate
> 40MB files.  inp.readlines() will bring all 40MB into
> RAM and/or virtual memory which may or may not be a
> problem.  Let's assume that it is.
>
> One way around this is to provide a sizehint in as your
> argument to readlines(), which will limit the size of
> what's brought in.   .....

Another option, provided you're using a recent enough version of Python, is to
simply use xreadlines() :

for line in logfile.xreadlines():
    # do stuff

This will read through all lines in the file, one by one, but without loading them
all into memory.  I'm not positive what version added xreadlines(), but it's
available in 2.1 if not earlier.

Jeff Shannon
Technician/Programmer
Credit International




From urnerk@qwest.net  Fri Mar  8 20:16:06 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Fri, 08 Mar 2002 12:16:06 -0800
Subject: [Tutor] running a script from IDLE
In-Reply-To: <3C89139D.2040104@venix.com>
References: <4.2.0.58.20020308111222.00d32590@pop3.norton.antivirus>
Message-ID: <4.2.0.58.20020308120934.00cd9ca0@pop3.norton.antivirus>

At 02:40 PM 3/8/2002 -0500, Lloyd Kvam wrote:
>http://www.paulgraham.com/langdes.html
>
>The tail end of this Paul Graham article gives a good idea of a Lisp
>programmer's view of OO.  I agree with him.  OO is extremely useful
>sometimes, but I don't like getting pushed into using it when it
>doesn't fit or it gets in the way...

Thanks for that, interesting article.

I think Python follows the advice there, to not make OO the
all-encompassing paradigm whether you want to use it or not
(unlike Java, which does).

Python gives us top-level functions, and that's cool.

I think a big reason why OO is popular that the article
doesn't quite address is the idea that an object can
be written in any language, while it exports an API
that other languages can use (and maybe subclass --
maybe not).

You need functionality and state all in a single entity,
like a calendar or a chat room.  The instance.method()
or instance.property notation lends itself to that.

The server-side apps will likely make a lot of use of
such componentware, even if it runs server-side more
than client-side.  Certainly this is what MSFT is banking
on, but others too -- enterprise JavaBeans and all that.

Kirby



From pythontutor@venix.com  Fri Mar  8 20:34:20 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Fri, 08 Mar 2002 15:34:20 -0500
Subject: [Tutor] Speaking of Books..
References: <XFMail.20020308102546.shalehperry@attbi.com> <1015619061.2086.6.camel@milarepa>
Message-ID: <3C89204C.2080004@venix.com>

I like having lots of working examples that solve real life programming
problems.  The Lutz book does that while also covering the most used
modules.  The downside is the sheer size of the book and a feeling that
some of the example code could be improved.  (But that's true of my code
also... )  I usually look for examples before tackling a new kind of
program to get insights into using the modules involved.

chris schwan wrote:

> Since books get discussed a bunch here, I have been wondering about Mark
> Lutz's 'Programming Python- second edition'. I have read a bunch of
> negatives about that book (I think the first edition), but then I have
> been turning up some positive things about it.
> 
> So what do people here think? I have made my way through beginnerhood
> using Alan's webpage, "Think Like a Comp Sci" (great IMHO), "Quick
> Python", and list lurkin. I am still not very good at all, but I am
> wondering about this book, and if it has more depth like its perl
> counterpart? I like to read stuff thats a bit above my head and grow
> into it.
> 
> Thanks...
> 
> C.
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582



From urnerk@qwest.net  Fri Mar  8 20:54:28 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Fri, 08 Mar 2002 12:54:28 -0800
Subject: [Tutor] Thoughts on little lambda
In-Reply-To: <3C89204C.2080004@venix.com>
References: <XFMail.20020308102546.shalehperry@attbi.com>
 <1015619061.2086.6.camel@milarepa>
Message-ID: <4.2.0.58.20020308124016.00cc0ea0@pop3.norton.antivirus>

As Alan points out, Python's little lambda is a far cry
from the Lisp or Scheme lambda, which permit lots of
internals, like looping and branching, printing or
whathaveyou.

Lispers like to show off the power of Lisp by showing
how it can define an addn function, i.e. it returns
a *function* as a result:

; Lisp
(defun addn (n)
     #'(lambda (x)
          (+ x n)))

You can do this in Python too (but not in C):

# Python
def addn (n):
   return lambda x: x + n

Note we've got the lexical scoping going, so n binds
to the passed (n).

   >>> add1 = addn(1)
   >>> add1(2)
   3
   >>> add2 = addn(2)
   >>> add2(2)
   4

So far so good.  But what if we want the function to
do something more complicated like:  raise to rth
power and add 3 if even, raise to jth power and add
4 if odd (totally contrived, I realize).

Trying to cram all this into a single lambda expression
might be difficult, or if you can do it, think of something
even more elaborate.

Does Lisp surmount this challenge and leave Python in
the dust?

Seems to me the answer is to have a named function
inside the factory function and just return the calling
part with lambda.  Lexical scoping fixes the constants,
creating a new function each time the function factory
is called with new arguments:

    def funcfact(r,j):
	def main(x):
	   if not x%2:
	      return pow(x,j)+4
	   else:
	      return pow(x,r)+3
	return lambda x: main(x)

  >>> f = funcfact(2,3)
  >>> f(4)
  68
  >>> f(5)
  28
  >>> g = funcfact(1,2)
  >>> g(4)
  20
  >>> g(5)
  8

Kirby




From Doug.Shawhan@gecits.ge.com  Fri Mar  8 21:17:12 2002
From: Doug.Shawhan@gecits.ge.com (Doug.Shawhan@gecits.ge.com)
Date: Fri, 8 Mar 2002 16:17:12 -0500
Subject: [Tutor] Thoughts on little lambda
Message-ID: <C278B8202E91D5119F4F0008C7E67E5E01851BAA@msxcvg01itscge.gecits.ge.com>

Errr...

I tried this particular excersise and had a problem...

------------------------------------------------------
Python 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> def addn(n):
	return lambda x:x+n
SyntaxError: local name 'n' in 'addn' shadows use of 'n' as global in nested
scope 'lambda' (<pyshell#1>, line 1)
------------------------------------------------------

Am I missing something?


Kirby said:

You can do this in Python too (but not in C):

# Python
def addn (n):
   return lambda x: x + n

Note we've got the lexical scoping going, so n binds
to the passed (n).

   >>> add1 = addn(1)
   >>> add1(2)
   3
   >>> add2 = addn(2)
   >>> add2(2)
   4

So far so good.  


From m_konermann@gmx.de  Fri Mar  8 21:44:21 2002
From: m_konermann@gmx.de (Keule)
Date: Fri, 08 Mar 2002 22:44:21 +0100
Subject: [Tutor] Tkinter quit frame
Message-ID: <3C8930B5.40905@gmx.de>

Hallo ! 

In the "programming python" book i read about a quitter.py method and i want to use it for my own
, this is the code:

from Tkinter import *                          # get widget classes
from tkMessageBox import askokcancel           # get canned std dialog

class Quitter(Frame):                          # subclass our GUI
    def __init__(self, parent=None):           # constructor method
        Frame.__init__(self, parent)
        self.pack()
        widget = Button(self, text='Quit', command=self.quit)
        widget.pack(expand=YES, fill=BOTH, side=LEFT)
    def quit(self):
        ans = askokcancel('Verify exit', "Really quit?")
        if ans: Frame.quit(self)

if __name__ == '__main__':  Quitter().mainloop()


unfortunatly i get a big memory allocation error after running this script. 
had anyone else perhaps the same problem ? 

Thanks a lot for your help
Greetings
Marcus





From SWidney@ci.las-vegas.nv.us  Fri Mar  8 22:23:54 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Fri, 8 Mar 2002 14:23:54 -0800
Subject: [Tutor] Thoughts on little lambda
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F59EE@SOVEREIGN>

> Errr...
> 
> I tried this particular excersise and had a problem...
> 
> ------------------------------------------------------
> Python 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit 
> (Intel)] on win32
> Type "copyright", "credits" or "license" for more information.
> IDLE 0.8 -- press F1 for help
> >>> def addn(n):
> 	return lambda x:x+n
> SyntaxError: local name 'n' in 'addn' shadows use of 'n' as 
> global in nested
> scope 'lambda' (<pyshell#1>, line 1)
> ------------------------------------------------------
> 
> Am I missing something?

from __future__ import nested_scopes


Scott


From python@ctpdesign.com  Fri Mar  8 21:47:53 2002
From: python@ctpdesign.com (Christopher T Palmer)
Date: Fri, 08 Mar 2002 13:47:53 -0800
Subject: [Tutor] brand spankin' newbie
Message-ID: <5.1.0.14.0.20020308134108.021919f0@zeus.he.net>

Hey all,

I just started in to learning Python a day or two ago (having come from C, 
PERL, PBASIC, KSH scripting......) and have what I hope is a very simple 
question.

I am wanting to use the poplib and smtplib in a script.  I found some info 
on the modules, and at the end (of the poplib blurb, for example) it says 
"At the end of the module, there is a test section that contains a more 
extensive example of usage." which is what I am dying to get my hands on.

Where does one find the actual modules to download?  I have been looking 
everywhere (although obviously not every everywhere)

Thanks in advance,
CTP



From pythonhack@yahoo.com  Fri Mar  8 23:39:55 2002
From: pythonhack@yahoo.com (pythonhack@yahoo.com)
Date: Fri, 8 Mar 2002 15:39:55 -0800
Subject: [Tutor] brand spankin' newbie
In-Reply-To: <5.1.0.14.0.20020308134108.021919f0@zeus.he.net>
References: <5.1.0.14.0.20020308134108.021919f0@zeus.he.net>
Message-ID: <181771474071.20020308153955@yahoo.com>

Christopher,

those modules come installed by default.

you just have to import them like this:
import smtplib, poplib

check out www.python.org/doc and click module index for info on each
module.

good luck!

brett
CTP> Hey all,

CTP> I just started in to learning Python a day or two ago (having come from C, 
CTP> PERL, PBASIC, KSH scripting......) and have what I hope is a very simple 
CTP> question.

CTP> I am wanting to use the poplib and smtplib in a script.  I found some info 
CTP> on the modules, and at the end (of the poplib blurb, for example) it says 
CTP> "At the end of the module, there is a test section that contains a more 
CTP> extensive example of usage." which is what I am dying to get my hands on.

CTP> Where does one find the actual modules to download?  I have been looking 
CTP> everywhere (although obviously not every everywhere)

CTP> Thanks in advance,
CTP> CTP


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



-- 
Best regards,
 pythonhack                            mailto:pythonhack@yahoo.com


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com



From sheila@thinkspot.net  Fri Mar  8 23:47:15 2002
From: sheila@thinkspot.net (Sheila King)
Date: Fri, 08 Mar 2002 15:47:15 -0800
Subject: [Tutor] brand spankin' newbie
In-Reply-To: <5.1.0.14.0.20020308134108.021919f0@zeus.he.net>
References: <5.1.0.14.0.20020308134108.021919f0@zeus.he.net>
Message-ID: <2125BE22C66@kserver.org>

On Fri, 08 Mar 2002 13:47:53 -0800, Christopher T Palmer
<python@ctpdesign.com>  wrote about [Tutor] brand spankin' newbie:

> Hey all,
> 
> I just started in to learning Python a day or two ago (having come from C, 
> PERL, PBASIC, KSH scripting......) and have what I hope is a very simple 
> question.
> 
> I am wanting to use the poplib and smtplib in a script.  I found some info 
> on the modules, and at the end (of the poplib blurb, for example) it says 
> "At the end of the module, there is a test section that contains a more 
> extensive example of usage." which is what I am dying to get my hands on.
> 
> Where does one find the actual modules to download?  I have been looking 
> everywhere (although obviously not every everywhere)

You don't need to download the modules. They should already be installed on
the computer you are running Python on. Look in the directory where you
have installed Python (are you on a Windows or Other machine? this would
give us a bit more to go on....)

If Windows, then under the directory where you installed Python there is
probably a folder like

Python22

or 

Python21

or something like that (depending on the version number you installed).
Look inside that folder and you will find the Lib folder. Inside the Lib
folder you should find the poplib.py and smtplib.py files. Open in a text
editor (in read only mode would be good, so you don't accidentally change
the files...or make a copy and work with the copy instead).

On Linux, there is a lib folder somewhere 
(if it is installed system wide, look under
/usr/lib/python2.1
or
/usr/lib/python2.2

or something like that)

If you installed it in your own $HOME directory, it is probably under

$HOME/lib/python2.2

depending on version number. Again, inside this directory you should find
the files poplib.py and smtplib.py

HTH,

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/




From urnerk@qwest.net  Sat Mar  9 00:47:50 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Fri, 08 Mar 2002 16:47:50 -0800
Subject: [Tutor] Thoughts on little lambda
In-Reply-To: <D4EB5574F4A7D2119C9E00A0C9EA408D059F59EE@SOVEREIGN>
Message-ID: <4.2.0.58.20020308164728.00d2bcd0@pop3.norton.antivirus>

At 02:23 PM 3/8/2002 -0800, Scott Widney wrote:
>---------------------------------
> >
> > Am I missing something?
>
>from __future__ import nested_scopes

Yeah, in 2.2 we don't have to ask for that -- it's
the default.

Kirby



From SWidney@ci.las-vegas.nv.us  Sat Mar  9 01:10:10 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Fri, 8 Mar 2002 17:10:10 -0800
Subject: [Tutor] brand spankin' newbie
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F59F8@SOVEREIGN>

> Hey all,
> 
> I just started in to learning Python a day or two ago (having 
> come from C, 
> PERL, PBASIC, KSH scripting......) and have what I hope is a 
> very simple 
> question.
> 
> I am wanting to use the poplib and smtplib in a script.  
> I found some info on the modules, and at the end (of the 
> poplib blurb, for example) it says "At the end of the 
> module, there is a test section that contains a more 
> extensive example of usage." which is what I am dying to 
> get my hands on.
> 
> Where does one find the actual modules to download?  I have 
> been looking everywhere (although obviously not every 
> everywhere)
> 
> Thanks in advance,
> CTP

You don't mention which version of Python you're using, or which flavor of
OS. On mine (Python 2.1 on FreeBSD) they're under /usr/local/lib/python2.1/
as poplib.py and smtplib.py

It should be something similar to that.

Scott


From idiot1@netzero.net  Sat Mar  9 04:42:13 2002
From: idiot1@netzero.net (kirk Bailey)
Date: Fri, 08 Mar 2002 23:42:13 -0500
Subject: [Tutor] brand spankin' newbie
References: <5.1.0.14.0.20020308134108.021919f0@zeus.he.net>
Message-ID: <3C8992A5.A558C824@netzero.net>

They come with the copy of the language. When you install the current
generation of python, they are in the tarball, and when you tell it to
import smtplib, it grabs that library file and appends it to the list
of known functions and their definitions the language maintains while
running. See, python is VERY extensible, just like my joytoy FORTH, if
in a different way.

Would you like to look at the scripts I wrote to handle sending email
and reading incoming email?

http://www.tinylist.org/TLpost.shtml

(think majordomo without the headaches...)

This lists the CURRENT UP TO THE MINUTE version of TLpost.py, which is
an email list management program; this particular script receives
incoming messages, reads several headers, insures membership in the
list, and IF a member, sends the message on to the list members with
footers, a preface if used, and (listname) in [square brackets].

Christopher T Palmer wrote:
> 
> Hey all,
> 
> I just started in to learning Python a day or two ago (having come from C,
> PERL, PBASIC, KSH scripting......) and have what I hope is a very simple
> question.
> 
> I am wanting to use the poplib and smtplib in a script.  I found some info
> on the modules, and at the end (of the poplib blurb, for example) it says
> "At the end of the module, there is a test section that contains a more
> extensive example of usage." which is what I am dying to get my hands on.
> 
> Where does one find the actual modules to download?  I have been looking
> everywhere (although obviously not every everywhere)
> 
> Thanks in advance,
> CTP
> 
> _______________________________________________
> 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 |
| http://www.tinylist.org  +--------+  mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking---------------------+
                           +--------+

NOTE: By sending SPAM to this address you agree to pay me a service
fee of $100 for the service of receiving,  storing,  examining, and
deleting your piece of SPAM. I am a postmaster, and take a dim view
of such.
----------------------------------------------------
Sign Up for NetZero Platinum Today
Only $9.95 per month!
http://my.netzero.net/s/signup?r=platinum&refcd=PT97


From lha2@columbia.edu  Sat Mar  9 12:01:37 2002
From: lha2@columbia.edu (Lloyd Hugh Allen)
Date: Sat, 09 Mar 2002 07:01:37 -0500
Subject: [Tutor] LaTeX output
References: <Pine.LNX.4.21.0203051848470.19654-100000@hkn.eecs.berkeley.edu>
Message-ID: <3C89F9A1.9E6899B@mail.verizon.net>

Danny Yoo wrote:
> 
> On Tue, 5 Mar 2002, Lloyd Hugh Allen wrote:
> 
> > Anyone know a utility to output LaTeX formatted stuff in (preferably)
> > Tkinter or (less preferably) wxWindows?
> 
> \begin{salutation}
> Hello!
> \end{salutation}
> 
> \begin{answer}
> I did a quick search on \emph{google}, and although I haven't found
> anything connected with \emph{Python} yet, I have found this:
> 
>     http://www.tm.informatik.uni-frankfurt.de/~lingnau/tkdvi/
> 
> There also appears to be a \texttt{DVI-PNG} converter:
> 
>     http://www.astro.gla.ac.uk/users/norman/star/dvi2bitmap/

Thanks--these look very close to what I want. May have to get that linux
box after all.

re:dman's response:

What I want is: I am a math teacher, and would like to write some test
generating / administering programs. I could do this by using lots of
parentheses and "raised to the 1/2"s, but my HS students don't
necessarily translate "5^(1/2)" (in their TI notation) as "sqrt(5)"
automatically in their heads. I want to have properly notated
mathematical text on the screen. LaTeX is what I understand to be the
appropriate tool for that task.

A side benefit is that my school makes heavy use of Acces databases,
which I understand to be encoded in LaTeX; and if I were to write my own
questions for these, I'd like to be able to preview them before printing
them and/or to have a python program that could generate questions
within particular paramaters and then output to the screen "Does this
question look like what you want it to?" without having to print the
question to see whether it's coded correctly and whether it's a doable,
but nontrivial question.

If any of that makes sense. Sorry if I'm incoherent.


From urnerk@qwest.net  Sat Mar  9 15:49:26 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Sat, 09 Mar 2002 07:49:26 -0800
Subject: [Tutor] LaTeX output
In-Reply-To: <3C89F9A1.9E6899B@mail.verizon.net>
References: <Pine.LNX.4.21.0203051848470.19654-100000@hkn.eecs.berkeley.edu>
Message-ID: <4.2.0.58.20020309074557.00d1bbd0@pop3.norton.antivirus>

>
>A side benefit is that my school makes heavy use of Acces databases,

Do you mean Microsoft Access?  Or maybe Acces is something
very similar.  Microsoft Access makes no use of LaTeX AFAIK.

MathML (math markup language) should also do what you want
-- could preview in a browser.  Except the technology is
still not widely distributed.

Kirby



From erikprice@mac.com  Sat Mar  9 17:18:27 2002
From: erikprice@mac.com (Erik Price)
Date: Sat, 9 Mar 2002 12:18:27 -0500
Subject: [Tutor] Re: global vars vs. func args
In-Reply-To: <D4EB5574F4A7D2119C9E00A0C9EA408D059F59E8@SOVEREIGN>
Message-ID: <AB7051D0-3381-11D6-BCC5-00039351FE6A@mac.com>

On Friday, March 8, 2002, at 12:51  PM, Scott Widney wrote:

>> Isn't using a globalized variable just a way to save time/space
>> by not having to declare it as an argument?

> The term that Kirby mentioned, "side effects", is mentioned all over the
> place in Functional Programming land. Functions should not have
> side-effects; which is to say that functions should receive data, 
> operate on
> that data, and return the results. The function shouldn't touch anything
> outside of this scope. The idea behind it is not unique to FP though; 
> and,
> as you can see, there are several Tutors on this list that encourage 
> this
> philosophy in Python programming, too. [You'll really reap the rewards 
> when
> you start fiddling with objects: encapsulation relies on effective
> partitioning.]

I can see the benefits of this.  Now, my experience has been with PHP 
(though I learn far more about programming fundamentals on this Python 
list than I do anywhere else), but I assume that the lessons are the 
same.  But in my scripts, I believe I have been misusing the power of 
functions, to create something else -- which I have seen referenced as a 
"subroutine".

That is, I call a function at some point in the script, but it's not 
there so much to act upon data as to perform a certain chunk of 
decision-making that I will need to call again else-where in the 
script.  The "side-effect" of this function is that it echoes out some 
data (namely, an HTML form), but in fact I don't pass this function any 
arguments and beyond echoing some HTML, it doesn't really "act" upon any 
data.  So should I not be using functions to take this shortcut?  That's 
what I'm really wondering.  (And yes, this means that these functions 
are not terribly portable, since the echoed results are specific to the 
script that calls them.)  I have used global variables not to change the 
values of those variables, but rather to access them at all -- perhaps 
PHP is a bit different from Python, but in PHP you must globalize a 
variable if it is outside of the function's scope

... (a few minutes later)...

okay, instead of asking I just rtfm'd my Quick Python book and got my 
answer.  I was misusing the term "global variable" in the context of 
this discussion list.  In PHP, any variable outside of a function's 
[name?]space is inaccessible by the function (even if you do not intend 
to act upon it), unless you declare it global within the function.  
Thus, my database connection parameters, which I have declared at the 
beginning of all scripts, need to be declared global in all functions 
that require database connectivity.  But in Python, these variables are 
accessible, just not modifiable, without the "global" declaration.  So I 
was talking about eggs and the discussion was about chickens -- I 
apologize.  But this has been an informative thread nonetheless, because 
I've learned a bit more about Python and global variables, and that what 
we are talking about is CHANGING global variables from within a 
function, not just ACCESSING them.

The QPB also answered another question from above -- that functions can 
be used as "subroutines", only that in Python they're called 
"procedures" -- blocks of code that do not return a value.  Is this 
still legitimate coding practice in Python?  The QPB is a bit dated, but 
this seems like valid use of functions.

> One big benefit of avoiding side effects is that you can remain 
> confident
> that these functions won't mess with any of your structures and/or data
> without explicit permission.

Understood.  Thus, the term "side effect" makes perfect sense now -- 
changing a global variable from within a function is a "side effect" in 
that the function is not directly acting upon the data entered as a 
parameter to that function.  If it were, then you wouldn't need to do 
any work with the data as a global variable.  And this can lead to 
errors, since the change made to a global variable is sort of tangential 
or incidental to the function call, rather than a direct result of it.  
(Of course, that's really not what happens, because it obviously IS a 
direct result, I just don't have a better way of phrasing it.)

Thanks to all who have commented on this subject.


Erik



From erikprice@mac.com  Sat Mar  9 17:21:17 2002
From: erikprice@mac.com (Erik Price)
Date: Sat, 9 Mar 2002 12:21:17 -0500
Subject: [Tutor] running a script from IDLE
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C41D@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <10B610E4-3382-11D6-BCC5-00039351FE6A@mac.com>

On Friday, March 8, 2002, at 01:02  PM, alan.gauld@bt.com wrote:

>
>> So instead of global variables, it's good form for functions
>> to simply use arguments and act upon those?
>
> Absolutely. In fact this is one of the cornerstones of whats
> known as "Functional Programming" - along with having functions
> that always return a value.
>
>> Isn't using a globalized varible just a way to save time/space
>> by not having to declare it as an argument?
>
> Its oftehn used out of laziness yes but has several disadvantages.
> First, its very hard to know which function made the changes
> which caused a fault (a phenomenon known as a 'side effect'
> - when a function changes a value outside of itself).
>
> Second, its very hard to debug functions in isolation because
> they rely on the existence of the global vars
>
> Third, if you want to multi thread your functions its impossible
> coz every thread will call the function which, modifies the same
> variable.
>
> Avoiding globals usially leads to more maintainable, more
> reliable and more reusable code - isn't that wporth a little
> extra typing and a few bytes of RAM?


Now that I think about it, all of these are very good points!  You're 
right -- I think there's an expression for this kind of thing, but I 
can't remember what it is.  Something about a builder measuring an inch 
for every foot or something.  The point is that if you do the work ahead 
of time then you save yourself grief later on.

I'll take care not to act upon global variables unless I've really 
considered the ramifications of it.

BTW, I investigated a page on "functional programming" (posted a few 
days ago on this list, but I forget by who), and it seems to be a very 
strict method of programming.  I'm not saying that I wouldn't give it a 
try, but I think that it's something that I should come back to after 
I've had more experience just writing simple programs that don't conform 
to the functional programming dogma.

Erik



From raevsky@hotmail.com  Sat Mar  9 18:18:17 2002
From: raevsky@hotmail.com (Andrei Raevsky)
Date: Sat, 09 Mar 2002 19:18:17 +0100
Subject: [Tutor] python & bash combination
Message-ID: <F30Svux4Jf7zynrvDOv00002624@hotmail.com>

Hi!

I am total newbie at Python (I have been looking at it for a week or so) and 
I am curious as to whether and how I could combine Python and Bash commands 
in one single script.

If I begin my script with

#!/usr/bin/env python

I probably cannot suddently write:

#!/usr/bin/bash

now can I?

How could I write something combining 2-3 lines of Python, then say one Bash 
command (to for example load a string variable) and then continue with 2-3 
lines of Python?

Is this type of "expanding possible"?

Thanks,

Andrei

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.



From shalehperry@attbi.com  Sat Mar  9 18:25:04 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Sat, 09 Mar 2002 10:25:04 -0800 (PST)
Subject: [Tutor] python & bash combination
In-Reply-To: <F30Svux4Jf7zynrvDOv00002624@hotmail.com>
Message-ID: <XFMail.20020309102504.shalehperry@attbi.com>

> 
> How could I write something combining 2-3 lines of Python, then say one Bash 
> command (to for example load a string variable) and then continue with 2-3 
> lines of Python?
> 
> Is this type of "expanding possible"?
> 

No, you can not have two different scripts running at once this way.  Perhaps
if you explain what you need to do we can help you come up with a better
solution.

Imagine debugging your program.  What interpreter was running when this bug
occured?


From scarblac@pino.selwerd.nl  Sat Mar  9 18:24:35 2002
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Sat, 9 Mar 2002 19:24:35 +0100
Subject: [Tutor] python & bash combination
In-Reply-To: <F30Svux4Jf7zynrvDOv00002624@hotmail.com>; from raevsky@hotmail.com on Sat, Mar 09, 2002 at 07:18:17PM +0100
References: <F30Svux4Jf7zynrvDOv00002624@hotmail.com>
Message-ID: <20020309192435.A25975@pino.selwerd.nl>

On  0, Andrei Raevsky <raevsky@hotmail.com> wrote:
> Hi!
> 
> I am total newbie at Python (I have been looking at it for a week or so) and 
> I am curious as to whether and how I could combine Python and Bash commands 
> in one single script.
> 
> If I begin my script with
> 
> #!/usr/bin/env python
> 
> I probably cannot suddently write:
> 
> #!/usr/bin/bash
> 
> now can I?
> 
> How could I write something combining 2-3 lines of Python, then say one Bash 
> command (to for example load a string variable) and then continue with 2-3 
> lines of Python?
> 
> Is this type of "expanding possible"?

You can call bash commands from Python with os.system(), and start commands
to get their output with os.popen(), for instance.

Most of the things that bash does can be done more easily in Python though,
I think. What do you mean with 'load a string variable'?

-- 
Remco Gerlich


From python.tutorial@jarava.org  Sat Mar  9 19:04:55 2002
From: python.tutorial@jarava.org (Javier JJ)
Date: Sat, 9 Mar 2002 20:04:55 +0100
Subject: [Tutor] searching out keywords...
References: <20020308161130.7553.qmail@linuxmail.org> <4.2.0.58.20020308100739.00d2d9f0@pop3.norton.antivirus>
Message-ID: <013201c1c79d$4d4672e0$931304d5@uno>

----- Mensaje original -----
De: "Kirby Urner" <urnerk@qwest.net>
Para: "Javier JJ" <python.tutorial@jarava.org>
CC: <tutor@python.org>
Enviado: viernes, 08 de marzo de 2002 19:08
Asunto: RE: [Tutor] searching out keywords...


> At 06:43 PM 3/8/2002 +0100, Javier JJ wrote:
>
> >So, if performance is important, I'd say you'd be better off using
something
> >as simple as (on a command line)
> >
> >  cat log_fie | grep keyword > badwords_file
> >
> >This is much faster :-)
>
> That's a good point.  If you have an OS that already includes
> a lot of utilities like this, you don't have to code up a
> Python thing, let alone slap a GUI over it.  Life at the
> OS command line is sooo much simpler.

Well.. I don't know about MacOS, but apart from that, you have those
utilities on Unix by default, and on Windows you can use a port  of them

http://unxutils.sourceforge.net/

:)

Works great!!

Javier

> Kirby
>
>



From zahara@mimos.my  Fri Mar  8 03:47:11 2002
From: zahara@mimos.my (Anita Zahara)
Date: Fri, 08 Mar 2002 11:47:11 +0800
Subject: [Tutor] Progress bar
Message-ID: <3C88343F.BE985F65@mimos.my>

Hi,

I'm working on my installation-cd project
using python-gtk.

Is there any sample to install RPM
package with progress bar?

TQ
~anita~



From ctp@ctpdesign.com  Sat Mar  9 00:05:47 2002
From: ctp@ctpdesign.com (Christopher Palmer)
Date: Fri, 08 Mar 2002 16:05:47 -0800
Subject: [Tutor] brand spankin' newbie
In-Reply-To: <181771474071.20020308153955@yahoo.com>
References: <5.1.0.14.0.20020308134108.021919f0@zeus.he.net>
 <5.1.0.14.0.20020308134108.021919f0@zeus.he.net>
Message-ID: <5.1.0.14.0.20020308160245.01ea0950@zeus.he.net>

>those modules come installed by default.

Sweet!

>you just have to import them like this:
>import smtplib, poplib

I got far enough in my readings to have that import syntax, but didn't 
assume that the modules came with Python.

Thanks to all who answered!

CTP



From dyoo@hkn.eecs.berkeley.edu  Sat Mar  9 19:37:58 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat, 9 Mar 2002 11:37:58 -0800 (PST)
Subject: [Tutor] brand spankin' newbie
In-Reply-To: <5.1.0.14.0.20020308160245.01ea0950@zeus.he.net>
Message-ID: <Pine.LNX.4.21.0203091133570.20841-100000@hkn.eecs.berkeley.edu>

On Fri, 8 Mar 2002, Christopher Palmer wrote:

> >those modules come installed by default.
> 
> Sweet!

By the way, you can browse through the library documentation here when you
have more time:

    http://python.org/doc/lib

People often say that Python comes with "batteries included".  It's often
quite fun to see what kind of modules people have written.


Good luck to you!



From dyoo@hkn.eecs.berkeley.edu  Sat Mar  9 19:47:54 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat, 9 Mar 2002 11:47:54 -0800 (PST)
Subject: [Tutor] LaTeX output
In-Reply-To: <3C89F9A1.9E6899B@mail.verizon.net>
Message-ID: <Pine.LNX.4.21.0203091139260.20841-100000@hkn.eecs.berkeley.edu>

On Sat, 9 Mar 2002, Lloyd Hugh Allen wrote:

> What I want is: I am a math teacher, and would like to write some test
> generating / administering programs. I could do this by using lots of
> parentheses and "raised to the 1/2"s, but my HS students don't
> necessarily translate "5^(1/2)" (in their TI notation) as "sqrt(5)"
> automatically in their heads. I want to have properly notated
> mathematical text on the screen. LaTeX is what I understand to be the
> appropriate tool for that task.

Hmmm... if HTML is an acceptable output format, you may want to see if the
latex2html utitity might help:

    http://www.latex2html.org/

It might be possible to write a quick math previewer using latex2html with
Python.

Good luck!



From alan.gauld@bt.com  Sat Mar  9 21:11:21 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sat, 9 Mar 2002 21:11:21 -0000
Subject: [Tutor] running a script from IDLE
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C422@mbtlipnt02.btlabs.bt.co.uk>

> >known as "Functional Programming" - along with having functions
> >that always return a value.
> 
> Seems to me the OO model is somewhat at odds with the
> FP model, 

They are orthogonal.
In Smalltalk an FP style is encouraged and the default 
return value from methods is self - Thus you get a 
reference to the modified object. You can use or discard 
that reference as you like but it allows an FP approach 
if required/desired.

> is inherently destructive, unless you want your method
> to make a [deep] copy of self, manipulate that copy, and
> return a new instance.

Or just a reference to the mofified object

   myfoo = myfoo.setBar(42)

myfoo is still referencing the same object it always did
but with a new value for bar...

> about some axis.  But if I want to leave icosa as is, and
> return the rotated icosa, then I have to copy icosa
> internally, and if the points are themselves point objects
> in a list, deepcopy to get copies of those.

You need to do that anyway since the original is different 
to the rotated version. I don't see the difference?

> the OO model doesn't seem to insist that I should.

Absolutely, OO, FP and imperative programming styles are 
different in emphasis. You can combine all three by adopting 
the intersecting attributes and abandioning the unique 
features. Some people would argue that this leads to the best 
(most reliable and maintainable) programming style of all. 
But it does bring its own issues in performance and resource 
usage.

> Instances are the termini, and, being objects, it makes
> plenty of sense to change their state.  When I move a
> pencil on my desk,  it's the pencil that moves, not
> some clone of the pencil, such that now I have two.

Correct and FP is quite happy for you to return a new reference 
to the modified pencil. The point of returning values is that 
you can apply value substitution to prove the correctness of 
the solution. (The real FP afficianados wuill be screaming 
at me real soon :-) When a function performs its task without 
returning a value you lose the concept of the entire program 
being an expression that is evaluated.

> Doubtless this is not a new insight.  Some FP purists
> probably fight the encroachment of OO thinking into
> their space as a result.

On the contrary most embrace OO but practiced in an 
FP style - FP uses polymorphism heavily for example.
A few zealots would have us abandon OO for a pure FP 
approach but most see value in the encapsulation/abstraction 
that OO provides.

Alan G


From alan.gauld@bt.com  Sat Mar  9 21:31:08 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sat, 9 Mar 2002 21:31:08 -0000
Subject: [Tutor] A new comer
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C425@mbtlipnt02.btlabs.bt.co.uk>

> the other big thing that catches people is in C++ the 
> variable *this is implicit and you almost never see it.

Hmm, in my (limited(*)) experience most industrial IT departments 
have coding guidlines that insist you use this-> in front of 
every class member/method to make it obvious that its a class 
thing and not a local function name. 

eg:

class foo{
private: 
	int x,y;
public:
 doit(int p)
 { 
   int z = 0;
   z = p + this->y;
   return this->x/this->y;
 }
};

So using self is only a minor hiccup.
use of unreferenced members is one of the most confusing
features of C++ programs to a maintenance progammer, and 
a bigger source of frustration that anything else when 
dealing with deep class heirarchies!

Alan g.

(*)I've only seen 3 different company C++ standards!


From alan.gauld@bt.com  Sat Mar  9 21:37:30 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sat, 9 Mar 2002 21:37:30 -0000
Subject: [Tutor] Speaking of Books..
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C426@mbtlipnt02.btlabs.bt.co.uk>

> Lutz's 'Programming Python- second edition'. I have read a bunch of
> negatives about that book (I think the first edition), but then I have
> been turning up some positive things about it.

I thought it was a great book even in its first edition 
- but when I started on Python it was one of only two 
available and the best of those... I still turn to it 
when the online help fails to clarify things for me.

A lot of the criticism was that it wasn't as good as the 
Perl equivalent - this is true, but its not that bad. 
Now that there are lots of beginners books out the 2nd 
edition has a much more focussed approach and altho' still 
not a reference book it is pretty comprehensive in its 
coverage of more advanced topics.

Alan g


From alan.gauld@bt.com  Sat Mar  9 21:42:13 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sat, 9 Mar 2002 21:42:13 -0000
Subject: [Tutor] Thoughts on little lambda
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C427@mbtlipnt02.btlabs.bt.co.uk>

> I tried this particular excersise and had a problem...
> 
> ------------------------------------------------------
> Python 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit 
> ....
> SyntaxError: local name 'n' in 'addn' shadows use of 'n' as 
> ...
> Am I missing something?

Yes, Python 2.2

In 2.1 you need to do 

from __future__ import nested_scopes

or something similarly arcane.

Alan G


From luk108@yahoo.com  Sat Mar  9 17:45:30 2002
From: luk108@yahoo.com (Lukas Lehner)
Date: Sat, 9 Mar 2002 18:45:30 +0100
Subject: [Tutor] (no subject)
Message-ID: <00cc01c1c792$845eea10$1488543e@rakitnik>





From lha2@columbia.edu  Sun Mar 10 07:17:11 2002
From: lha2@columbia.edu (Lloyd Hugh Allen)
Date: Sun, 10 Mar 2002 02:17:11 -0500
Subject: [Tutor] LaTeX output (now OT: Acces)
References: <Pine.LNX.4.21.0203051848470.19654-100000@hkn.eecs.berkeley.edu> <4.2.0.58.20020309074557.00d1bbd0@pop3.norton.antivirus>
Message-ID: <3C8B0877.74C69313@mail.verizon.net>

Kirby Urner wrote:
> 
> >
> >A side benefit is that my school makes heavy use of Acces databases,
> 
> Do you mean Microsoft Access?  Or maybe Acces is something
> very similar.  Microsoft Access makes no use of LaTeX AFAIK.
> 
> MathML (math markup language) should also do what you want
> -- could preview in a browser.  Except the technology is
> still not widely distributed.
> 
> Kirby
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

No. I mean Acces, a dos-based program that acts as a database of math
problems. Currently one looks up the appropriate kind of problem in a
three-inch three-ring binder, selects the appropriate database, section,
and problem number, and appropriate layout options, and gets decently
formatted tests / worksheets / etc. from the printer, with answer key
that's correct 95% of the time. At the time that you select the problem,
though, there's no immediate preview. There is an option to add what I
believe to be LaTeX commands to a particular problem in order to, say,
append a graph to a problem.


From scot@possum.in-berlin.de  Sun Mar 10 11:08:38 2002
From: scot@possum.in-berlin.de (Scot Stevenson)
Date: Sun, 10 Mar 2002 12:08:38 +0100
Subject: [Tutor] Speaking of Books..
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C426@mbtlipnt02.btlabs.bt.co.uk>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C426@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <200203101115.g2ABFcS19679@possum.cozen.org>

Hello there, 

> Now that there are lots of beginners books out the 2nd
> edition has a much more focused approach and altho' still
> not a reference book it is pretty comprehensive in its
> coverage of more advanced topics.

I found Lutz's book (2nd edition) very useful after going thru "Learning 
Python" and would feel good about recommending it. My main gripe is that 
bits of code created early in the book are used all over the place later, 
which makes it harder to look up one topic later on. The reusable 
"Quitter" code on page 305 was the most annoying bit of code that kept 
getting imported again and again and again.  

I have been thru three Python books so far ("Learning Python", 
"Programming Python", and currently "Python and Tkinter programming") and 
have found that all three have two problems:

1) The rate of change to the Python language obviously outstrips the 
ability of people to write hardcopy documentation. In "Programming 
Python", for example, "assert" is covered briefly on page 1211 with no 
text on what you would want to use it for ("Assertions are mostly meant 
for debugging" is not that helpful if you are just learning how to 
program). This mutation rate is enormously frustrating if you are trying 
to learn the language; I hope that at least the core part of Python will 
stabilize soon. 

Then again, Mark Lutz probably does, too =8). 

2) A lot of time is spent explaining workarounds for Windows problems 
(like the lack of a "fork" call) that I as a Linux user couldn't care less 
about. I realize that until Linux has achieved World Domination, there 
will be people around who have these problems and who are probably upset 
about all the Unix stuff. But it does mean that when I buy one of these 
books, I'm paying for lots of information I can't use. 

Y, Scot



From arcege@speakeasy.net  Sun Mar 10 17:44:42 2002
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Sun, 10 Mar 2002 12:44:42 -0500
Subject: [Tutor] Tkinter quit frame
In-Reply-To: <3C8930B5.40905@gmx.de>; from m_konermann@gmx.de on Fri, Mar 08, 2002 at 10:44:21PM +0100
References: <3C8930B5.40905@gmx.de>
Message-ID: <20020310124442.A909@speakeasy.net>

On Fri, Mar 08, 2002 at 10:44:21PM +0100, Keule wrote:
> Hallo ! 
> 
> In the "programming python" book i read about a quitter.py method and i want to use it for my own
> , this is the code:
> 
> from Tkinter import *                          # get widget classes
> from tkMessageBox import askokcancel           # get canned std dialog
> 
> class Quitter(Frame):                          # subclass our GUI
>     def __init__(self, parent=None):           # constructor method
>         Frame.__init__(self, parent)
>         self.pack()
>         widget = Button(self, text='Quit', command=self.quit)
>         widget.pack(expand=YES, fill=BOTH, side=LEFT)
>     def quit(self):
>         ans = askokcancel('Verify exit', "Really quit?")
>         if ans: Frame.quit(self)
> 
> if __name__ == '__main__':  Quitter().mainloop()
> 
> 
> unfortunatly i get a big memory allocation error after running this script. 
> had anyone else perhaps the same problem ? 

I don't have a problem when I run it.  What system are you using and what
version of Python?

  -Arcege



From wolf_binary@hotmail.com  Sun Mar 10 19:11:58 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Sun, 10 Mar 2002 13:11:58 -0600
Subject: [Tutor] printing
Message-ID: <DAV12AeRaNgEpTX5V3G00012198@hotmail.com>

This is a multi-part message in MIME format.

------=_NextPart_000_0005_01C1C835.28DA46A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

hi all,

How do you send data to the printer?

Cameron Stoner

------=_NextPart_000_0005_01C1C835.28DA46A0
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.2713.1100" 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 do you send data to the =
printer?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Cameron =
Stoner</FONT></DIV></BODY></HTML>

------=_NextPart_000_0005_01C1C835.28DA46A0--


From urnerk@qwest.net  Mon Mar 11 03:56:50 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Sun, 10 Mar 2002 19:56:50 -0800
Subject: [Tutor] running a script from IDLE
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C422@mbtlipnt02.btlabs
 .bt.co.uk>
Message-ID: <4.2.0.58.20020310193939.00d1dc00@pop3.norton.antivirus>

At 09:11 PM 3/9/2002 +0000, alan.gauld@bt.com wrote:
> > >known as "Functional Programming" - along with having functions
> > >that always return a value.
> >
> > Seems to me the OO model is somewhat at odds with the
> > FP model,
>
>They are orthogonal.

I think in practice, yes.  Easy to take advantage of
FP constructs in an OO language.  They work together.
But the philosophies may clash, as objects are identities
with state, and you often change them without returning
anything.

>In Smalltalk an FP style is encouraged and the default
>return value from methods is self - Thus you get a
>reference to the modified object. You can use or discard
>that reference as you like but it allows an FP approach
>if required/desired.
>
> > is inherently destructive, unless you want your method
> > to make a [deep] copy of self, manipulate that copy, and
> > return a new instance.
>
>Or just a reference to the mofified object
>
>    myfoo = myfoo.setBar(42)
>
>myfoo is still referencing the same object it always did
>but with a new value for bar...

But my point was that forcing myfoo to return an object
can be expensive overhead and the OO paradigm lets me off
the hook if I don't want to do this.  A typical myfoo.setBar(42)
method in Python would just setBar and be done with it.

> > about some axis.  But if I want to leave icosa as is, and
> > return the rotated icosa, then I have to copy icosa
> > internally, and if the points are themselves point objects
> > in a list, deepcopy to get copies of those.
>
>You need to do that anyway since the original is different
>to the rotated version. I don't see the difference?

The difference is I don't have to keep the original.

     icosa = Icosa()       # create instance
     icosa.display(tofile) # output to display
     icosa.rotate('X',90)  # rotate 90 degrees around X axis
     icosa.display(tofile) # output again -- looks different

Rotating an icosa can be destructive in the same sense
that mylist.reverse() is destructive.  Internally, every
Vertex in some list got matrix-multiplied.  These vertices
were themselves objects, so I'd have needed to deepcopy
to work with a clone to return it as a new object.

> > the OO model doesn't seem to insist that I should.
>
>Absolutely, OO, FP and imperative programming styles are
>different in emphasis. You can combine all three by adopting
>the intersecting attributes and abandioning the unique
>features. Some people would argue that this leads to the best
>(most reliable and maintainable) programming style of all.
>But it does bring its own issues in performance and resource
>usage.

I tend to agree with this -- I like the cosmopolitan flavor
of Python for example, because of the synergy.  When I go
back to some of the more "strict" implementors of this or
that feature, I find I miss the easygoing facility with
the now-missing complementary features.


> > Instances are the termini, and, being objects, it makes
> > plenty of sense to change their state.  When I move a
> > pencil on my desk,  it's the pencil that moves, not
> > some clone of the pencil, such that now I have two.
>
>Correct and FP is quite happy for you to return a new reference
>to the modified pencil. The point of returning values is that
>you can apply value substitution to prove the correctness of
>the solution. (The real FP afficianados wuill be screaming
>at me real soon :-) When a function performs its task without
>returning a value you lose the concept of the entire program
>being an expression that is evaluated.

...which is how I'm contrasting object.method() calls which
change object state without returning anything.  The point
of the method is to change the internal state of the object.
Nothing is returned.


> > Doubtless this is not a new insight.  Some FP purists
> > probably fight the encroachment of OO thinking into
> > their space as a result.
>
>On the contrary most embrace OO but practiced in an
>FP style - FP uses polymorphism heavily for example.
>A few zealots would have us abandon OO for a pure FP
>approach but most see value in the encapsulation/abstraction
>that OO provides.
>
>Alan G

Here's a quote from an interesting set of pages -- not sure
exactly who to attribute it to:

   My take: functional programming is about minimizing state,
   and object orientation is about managing it. You don't want
   to do stateful objects in a side-effect-free language, but
   you can gain the AdvantagesOfFp in any language.

Kirby

[1] http://crit.org/http://c2.com/cgi/wiki?FpVsOo



From tim.one@comcast.net  Mon Mar 11 04:36:24 2002
From: tim.one@comcast.net (Tim Peters)
Date: Sun, 10 Mar 2002 23:36:24 -0500
Subject: [Tutor] error in docs regarding map
In-Reply-To: <fc.004c4b6b008fea99004c4b6b008fe9bf.8fea9b@blakeschool.org>
Message-ID: <LNBBLJKPBEHFEDALKOLCCEFBODAA.tim.one@comcast.net>

[Christopher Smith]
> OK, pretty soon I'll just trust my own judgement, but would you agree
> that the docs obtained when typing help(filter) are wrong ...

BTW, I changed the filter docstring.  In 2.3 it will say:

>>> print filter.__doc__
filter(function or None, sequence) -> list, tuple, or string

Return those items of sequence for which function(item) is true.  If
function is None, return the items that are true.  If sequence is a tuple
or string, return the same type, else return a list.
>>>

Don't let it go to your head <wink -- and thanks>.


From fal_69@plasa.com  Mon Mar 11 06:55:05 2002
From: fal_69@plasa.com (gopal anshary                                              )
Date: Mon, 11 Mar 2002 13:55:05 +0700
Subject: [Tutor] configure python with apache on mandrake 8.0
Message-ID: <web-5823806@mail.plasa.com>

hello every body
i wanna ask about how to configure python with apache on
mandrake 8.0, in order to run my script. because in
/etc/httpd/conf/httpd.conf there's only have httpd.conf.
they dont have access.conf and smr.conf .
that's all for now
i wait for your answer?
thank's


From dyoo@hkn.eecs.berkeley.edu  Mon Mar 11 07:34:55 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 10 Mar 2002 23:34:55 -0800 (PST)
Subject: [Tutor] configure python with apache on mandrake 8.0
In-Reply-To: <web-5823806@mail.plasa.com>
Message-ID: <Pine.LNX.4.21.0203102321420.24812-100000@hkn.eecs.berkeley.edu>

On Mon, 11 Mar 2002, gopal anshary                                               wrote:

> hello every body
>
> i wanna ask about how to configure python with apache on mandrake 8.0,
> in order to run my script. because in /etc/httpd/conf/httpd.conf
> there's only have httpd.conf. they dont have access.conf and smr.conf
> . that's all for now i wait for your answer?

Hi Gopal,


If you keep your scripts in the standard 'cgi-bin' directory in Apache,
you actually don't need to do much else except plop the Python scripts in
there.  You'll want to make sure that that the scripts are executable, and
that the 'magic line'

###
#!/usr/bin/python
###

is pointing toward the path where Python is installed on your system.  
Otherwise, that should be it.  *grin*

Also, be sure to use some error-trapping to make it easier to debug your
CGI scripts.  If you have Python 2.2, the 'cgitb' module might just be the
ticket:

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


If you want to allow Python scripts to be generally executable, you'll
want to make a few changes to the httpd.conf.  You'll want to mark off
directories with the 'ExecCGI' directive.

Also, you may want to tell Apache to allow '.py' as a file extension for
CGI scripts.  Look for the "AddHandler cgi-script", and add '.py' into the
list of acceptable extensions.  For example, here's what it looks like on
my laptop:

###
AddHandler cgi-script .cgi .sh .pl .py
###


There are more details on CGI's and Python here:

    http://starship.python.net/crew/davem/cgifaq/faqw.cgi?req=index


Please feel free to ask more questions about this.  Best of wishes to you!



From James.Alexander.McCarney@Cognicase.com  Mon Mar 11 14:23:44 2002
From: James.Alexander.McCarney@Cognicase.com (McCarney, James Alexander)
Date: Mon, 11 Mar 2002 09:23:44 -0500
Subject: [Tutor] Py FAQs for newbies
Message-ID: <23FD7B1A77E8D211BCB900001D108C02018B2A0D@camelot>

There are any number of truly excellent beginners' tutorials for Python
programming in particular and programming in general. I truly thsnk and doff
my cap to all those who have offered us the fruit of their knowledge. A
special 'prop' to Guido van Rossum, for another Dutch treat! ;-)

Anyway, I wonder if there is (whenever I wonder in Pythonland whatever I
wish for always seems to appear magically!) a simpler FAQ or Cookbook (even
simpler than all of the wonderful manna on Vaults of Parnassus). For
complete programming newbies, all of what goes on here might be like trying
to take a sip from a firehose.

Thank you all!

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 rob@jam.rr.com  Mon Mar 11 14:35:44 2002
From: rob@jam.rr.com (Rob Andrews)
Date: Mon, 11 Mar 2002 08:35:44 -0600
Subject: [Tutor] Py FAQs for newbies
References: <23FD7B1A77E8D211BCB900001D108C02018B2A0D@camelot>
Message-ID: <3C8CC0C0.9060803@jam.rr.com>

Did I hear someone say "Rob, please plug Useless Python"? (which I vow 
on my singing bowl will be updated soon, and I like my singing bowl a 
great deal)

http://www.lowerstandard.com/python

bowing to the awakened coder within each of you,
Rob 3;->

McCarney, James Alexander wrote:

<snip />
> 
> Anyway, I wonder if there is (whenever I wonder in Pythonland whatever I
> wish for always seems to appear magically!) a simpler FAQ or Cookbook (even
> simpler than all of the wonderful manna on Vaults of Parnassus). For
> complete programming newbies, all of what goes on here might be like trying
> to take a sip from a firehose.
> 
> Thank you all!
<snip />




From brian@coolnamehere.com  Mon Mar 11 16:46:09 2002
From: brian@coolnamehere.com (Brian Wisti)
Date: Mon, 11 Mar 2002 08:46:09 -0800 (PST)
Subject: Links and a Tangent (Re: [Tutor] Py FAQs for newbies)
In-Reply-To: <23FD7B1A77E8D211BCB900001D108C02018B2A0D@camelot>
Message-ID: <Pine.LNX.4.33.0203110822440.1933-100000@www.coolnamehere.com>

On Mon, 11 Mar 2002, McCarney, James Alexander wrote:
Hi James and Everyone Else,

> Anyway, I wonder if there is (whenever I wonder in Pythonland whatever I
> wish for always seems to appear magically!) a simpler FAQ or Cookbook (even
> simpler than all of the wonderful manna on Vaults of Parnassus). For
> complete programming newbies, all of what goes on here might be like trying
> to take a sip from a firehose.

FAQs and Cookbooks are almost obscure by tradition ;-)  I think it's so 
that people who are already comfortable with the basics of Python can find 
something specific they might have forgotten.  You'll probably want to try 
one of the masses of online tutorials, and _then_ go back to see if the 
FAQ makes more sense.

The first stop for gentle newbie Python tutorials is here:

	http://www.python.org/doc/Newbies.html

I am quite fond of Danny Yoo's guide through a single day with IDLE:

	http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html

If you want to humor an aspiring tutorial-writer, you can check out my own 
desperate attempt at a guide through the first steps with Python and IDLE.  
It's very ... how shall I say ... casual.
	
	http://www.coolnamehere.com/geekery/python/pythontut

Hope these links are kind of helpful!

Now for the tangent, which actually has more to do with the question James 
posted than the rest of what I've been writing.  Is there a resource for 
Pythonistas similar to the Perlmonks site (http://www.perlmonks.org/)?  
I've been rescued time and again by the stuff there: FAQ-ish, 
Cookbook-ish, and so on.  I'd really like to see a Pythonmonks site 
someday.  Heck, I'd figure it out myself if there was enough interest,
and those interested folks could deal with the fact that I'm working off of a 
DSL connection on an old clunker computer :-)

Back to my coffee,

Brian Wisti
brian@coolnamehere.com
http://www.coolnamehere.com/



From Doug.Shawhan@gecits.ge.com  Mon Mar 11 16:48:41 2002
From: Doug.Shawhan@gecits.ge.com (Doug.Shawhan@gecits.ge.com)
Date: Mon, 11 Mar 2002 11:48:41 -0500
Subject: [Tutor] Thoughts on little lambda
Message-ID: <C278B8202E91D5119F4F0008C7E67E5E01851BAC@msxcvg01itscge.gecits.ge.com>

>>> from __future__ import nested_scopes
>>> def addn(n):
	return lambda x:x+n
SyntaxError: local name 'n' in 'addn' shadows use of 'n' as global in nested
scope 'lambda' (<pyshell#3>, line 1)
>>> 

Fiddlesticks. Off to d/l 2.2 :-)

d

-----Original Message-----
From: Scott Widney [mailto:SWidney@ci.las-vegas.nv.us]
Sent: Friday, March 08, 2002 4:24 PM
To: Shawhan, Doug (CAP, ITS, US)
Cc: tutor@python.org
Subject: RE: [Tutor] Thoughts on little lambda


> Errr...
> 
> I tried this particular excersise and had a problem...
> 
> ------------------------------------------------------
> Python 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit 
> (Intel)] on win32
> Type "copyright", "credits" or "license" for more information.
> IDLE 0.8 -- press F1 for help
> >>> def addn(n):
> 	return lambda x:x+n
> SyntaxError: local name 'n' in 'addn' shadows use of 'n' as 
> global in nested
> scope 'lambda' (<pyshell#1>, line 1)
> ------------------------------------------------------
> 
> Am I missing something?

from __future__ import nested_scopes


Scott


From dyoo@hkn.eecs.berkeley.edu  Mon Mar 11 17:31:41 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 11 Mar 2002 09:31:41 -0800 (PST)
Subject: [Tutor] Thoughts on little lambda
In-Reply-To: <C278B8202E91D5119F4F0008C7E67E5E01851BAC@msxcvg01itscge.gecits.ge.com>
Message-ID: <Pine.LNX.4.21.0203110917100.1149-100000@hkn.eecs.berkeley.edu>

On Mon, 11 Mar 2002 Doug.Shawhan@gecits.ge.com wrote:

> >>> from __future__ import nested_scopes
> >>> def addn(n):
> 	return lambda x:x+n
> SyntaxError: local name 'n' in 'addn' shadows use of 'n' as global in nested
> scope 'lambda' (<pyshell#3>, line 1)
> >>> 
> 
> Fiddlesticks. Off to d/l 2.2 :-)

Yikes:

    http://mail.python.org/pipermail/python-list/2001-June/046708.html
    http://mail.python.org/pipermail/python-list/2001-June/046712.html

and:

    http://mail.python.org/pipermail/idle-dev/2002-January/000818.html
    http://mail.python.org/pipermail/idle-dev/2002-January/000819.html


Python 2.2's IDLE should resolve the problem.  Good luck!



From Doug.Shawhan@gecits.ge.com  Mon Mar 11 17:48:23 2002
From: Doug.Shawhan@gecits.ge.com (Doug.Shawhan@gecits.ge.com)
Date: Mon, 11 Mar 2002 12:48:23 -0500
Subject: [Tutor] Thoughts on little lambda
Message-ID: <C278B8202E91D5119F4F0008C7E67E5E01851BAF@msxcvg01itscge.gecits.ge.com>

Indeed it did. Very simple, yet brain-stretching! :-)

Are there any good examples of using python fp in zope?

d

-----Original Message-----
From: Danny Yoo [mailto:dyoo@hkn.eecs.berkeley.edu]
Sent: Monday, March 11, 2002 11:32 AM
To: Shawhan, Doug (CAP, ITS, US)
Cc: tutor@python.org
Subject: RE: [Tutor] Thoughts on little lambda


On Mon, 11 Mar 2002 Doug.Shawhan@gecits.ge.com wrote:

> >>> from __future__ import nested_scopes
> >>> def addn(n):
> 	return lambda x:x+n
> SyntaxError: local name 'n' in 'addn' shadows use of 'n' as global in
nested
> scope 'lambda' (<pyshell#3>, line 1)
> >>> 
> 
> Fiddlesticks. Off to d/l 2.2 :-)

Yikes:

    http://mail.python.org/pipermail/python-list/2001-June/046708.html
    http://mail.python.org/pipermail/python-list/2001-June/046712.html

and:

    http://mail.python.org/pipermail/idle-dev/2002-January/000818.html
    http://mail.python.org/pipermail/idle-dev/2002-January/000819.html


Python 2.2's IDLE should resolve the problem.  Good luck!


From urnerk@qwest.net  Mon Mar 11 18:37:16 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Mon, 11 Mar 2002 10:37:16 -0800
Subject: [Tutor] Thoughts on little lambda
In-Reply-To: <Pine.LNX.4.21.0203110917100.1149-100000@hkn.eecs.berkeley.
 edu>
References: <C278B8202E91D5119F4F0008C7E67E5E01851BAC@msxcvg01itscge.gecits.ge.com>
Message-ID: <4.2.0.58.20020311094139.00cda670@pop3.norton.antivirus>

>
>Python 2.2's IDLE should resolve the problem.  Good luck!

2.2 does make import from __future__ work directly in the
IDLE shell (you needn't be in a module), e.g.:

  >>> from __future__ import division
  >>> 3/2
  1.5

However, in this particular case, using the nested scopes
feature, the "fix" comes from not needing to import from
__future__ at all, because nested scopes are the default
for version 2.2 on.

Just to review the construct, I was suggesting a way to
make "function factories" (functions that build other
functions) which have internal complexity beyond lambda's
ability by itself, is to use an internal function called
with lambda.

E.g. the example below includes a print statement --
something lambda can't, by itself, invoke:

  >>> def makeadder(n):
          def main(x):
             print "Adding %s" % n
             return x + n
          return lambda x: main(x)

This is the classic case of building an "adder" e.g.:

  >>> add1 = makeadder(1)
  >>> add1(5)
  Adding 1
  6

Now it comes up in many applications that you want to
do one thing to a number if it's odd, something else
if it's even.  The template below accepts two *functions*
as inputs, and builds a "switcher" with 'em:

  >>> def evenodd(fe,fo):
         def main(x):
            if x%2:  # odd
               return fo(x)
            else:    # even
               return fe(x)
         return lambda x: main(x)

So, for example, if you'd earlier defined add0 and add1
using the makeadder() function, then here you could pass
these to function-builder evenodd() and get a function
which adds 0 to evens, 1 to odds:

  >>> switcher = evenodd(add0,add1)
  >>> switcher(3)
  Adding 1
  4
  >>> switcher(2)
  Adding 0
  2

But note that evenodd(fe,fo) is designed to accept *any*
two functions, one to execute if the input is even,
the other if odd.

I think this provides a good example of "functional
programming" in the sense of using functions to build
other functions, which in turn involves thinking of
functions as the arguments of other functions.

But my main focus was to explore ways of overcoming
little lambda's inherent limitations, by taking advantage
of nested scopes to put the real guts of a function in
some internally called construct.  The arguments to
the builder provide the static content for these guts
(variable only at the time the function is built), and
then the final lambda return statement handles what
will be the dynamic inputs to the built function.

In the case of a polynomial builder, you could have a
list of coefficients at "build time", then, presuming
it's a poly of a single variable (but it doesn't *have*
to be) pass "x" in the lambda statement:

  >>> def buildpoly(coeffs):
         def main(x):
            dim = len(coeffs)-1
            sum = 0
            for c in coeffs:
               sum += c * pow(x,dim)
               dim -= 1
            return sum
         return lambda x: main(x)

  >>> p = buildpoly([2,3,1])    # f(x) = 2x^2 + 3x + 1
  >>> p(3)
  28
  >>> 2*(3**2) + 3*(3) + 1
  >>> q = buildpoly([1,2,3,4])  # f(x) = x^3 + 2x^2 + 3x + 4
  >>> q(10)
  1234
  >>> 10**3 + 2*(10**2) + 3*10 + 4
  1234

The important thing to note here is buildpoly is
returning callable functions, which functions are then
applied to specific numbers.

Note also that the internally called construct might be
recursive.  In the example below, recursop(op) wants an
operation as input.  It builds a recursive function
which decrements the argument by 1 each time, stopping
when the argument reaches 1 (up to the user here not to
pass 1.5 or -1 -- asking for trouble [1]).

So if you import mul and add from operator, you can
use recursop to build a primitive factorial and and
triangular number cruncher.  I call it "triangular"
because 5+4+3+2+1 may be represented as a triangle:

        *
       * *
      * * *
     * * * *
    * * * * *

  >>> def recursop(op):
          def main(x):
             if x==1: return x
             else:    return apply(op,(x,main(x-1)))
          return lambda x: main(x)

  >>> factorial = recursop(mul)
  >>> factorial(5)
  120
  >>> factorial(7)
  5040
  >>> 7*6*5*4*3*2
  5040

  >>> triangular = recursop(add)
  >>> triangular(10)
  55
  >>> 10+9+8+7+6+5+4+3+2+1
  55

It's a little harder to figure what's going on with
recursive subtraction, but it works, if you import sub:

  >>> something = recursop(sub)
  >>> something(10)
  5

i.e.:

  >>> 10-(9-(8-(7-(6-(5-(4-(3-(2-1))))))))
  5

These ideas are not new to programmers.  It's the kind
of stuff you see in Scheme/LISP all the time.  I was
just wanting to see how Python's little lambda (vs. the
big honker lambda of the LISPs) isn't really a major
limitation when it comes to writing function-building
functions.

The new way of doing scoping is what adds power, as the
bindings are all local within the builder, and the lambda
is charged only with passing what will be the external
arguments to the built output functions -- expecting lots
of reuse.  The builder's calling args, on the other hand,
are the one-time definers of the product's behavior.

A natural next topic would be to explore this same
construct as a way of returning generators, i.e. functions
built around the new 'yield' keyword.

Kirby

[1] because we're using an internal function to
provide the guts, more elaborate argument checking,
including try/excepts, are certainly doable.



From jeff@ccvcorp.com  Mon Mar 11 18:35:32 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Mon, 11 Mar 2002 10:35:32 -0800
Subject: [Tutor] Thoughts on little lambda
References: <E16jSCe-0002hs-00@mail.python.org>
Message-ID: <3C8CF8F4.C4009ADD@ccvcorp.com>

Recently, Kirby Urner described a bit about the differences between Python's lambda and Lisp-ish
lambdas.  To create something that works a bit more like the Lisp-ish lambda, Kirby proposed using a
function factory like this:


>     def funcfact(r,j):
>         def main(x):
>            if not x%2:
>               return pow(x,j)+4
>            else:
>               return pow(x,r)+3
>         return lambda x: main(x)

Now, I might be missing something (wouldn't be the first time ;) ) but it seems to me that the return
statement doesn't need to create a lambda;  it should be equivalent to change it to simply

            return main

shouldn't it?  ISTM that the lambda here creates a function object that calls a function, using
exactly the arguments passed to it;  I see no benefit to encapsulating that second function object
(the main in the above example) inside of another function object (and some cost in terms of
overhead).

Jeff Shannon
Technician/Programmer
Credit International




From urnerk@qwest.net  Mon Mar 11 18:58:30 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Mon, 11 Mar 2002 10:58:30 -0800
Subject: [Tutor] Thoughts on little lambda
In-Reply-To: <3C8CF8F4.C4009ADD@ccvcorp.com>
References: <E16jSCe-0002hs-00@mail.python.org>
Message-ID: <4.2.0.58.20020311104645.01b5ed30@pop3.norton.antivirus>

You make an excellent point Jeff.  It wasn't clear to me
at first that I was moving towards such a simple lambda,
so simple, in fact, that we don't need it at all.

So the template should be revised as you've indicated:

    def builder(B_arg1,B_arg2...):
       def main(E_args):
           # statements using B_arg1,B_arg2
       return main # expecting E_args as inputs

So take all of my earlier templates and make this
change of 'return lambda x: main(x)' --> 'return main'

Thanks for the insight!

Next question:  Is there a way to associate a customized
doc string with the built function?

Kirby


>Recently, Kirby Urner described a bit about the differences between 
>Python's lambda and Lisp-ish
>lambdas.  To create something that works a bit more like the Lisp-ish 
>lambda, Kirby proposed using a
>function factory like this:
>
>
> >     def funcfact(r,j):
> >         def main(x):
> >            if not x%2:
> >               return pow(x,j)+4
> >            else:
> >               return pow(x,r)+3
> >         return lambda x: main(x)
>
>Now, I might be missing something (wouldn't be the first time ;) ) but it 
>seems to me that the return
>statement doesn't need to create a lambda;  it should be equivalent to 
>change it to simply
>
>             return main
>
>shouldn't it?  ISTM that the lambda here creates a function object that 
>calls a function, using
>exactly the arguments passed to it;  I see no benefit to encapsulating 
>that second function object
>(the main in the above example) inside of another function object (and 
>some cost in terms of
>overhead).
>
>Jeff Shannon
>Technician/Programmer
>Credit International



From alan.gauld@bt.com  Mon Mar 11 18:54:43 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 11 Mar 2002 18:54:43 -0000
Subject: [Tutor] printing
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C42E@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C1C92E.34E5F990
Content-type: text/plain; charset="ISO-8859-1"

 >  How do you send data to the printer? 
 
Theeasy way, for text is:
 
os.system('lpr foo.txt') # *nix
 
OR 
 
os.system('Print foo.txt') # DOS 
 
Or just assign stdout to prn:
 
Or open PRN: as a file
 
For fancier work you are probabluy best to generate 
an HTML file or PDF and print that using the native 
tools as above.
 
If you must do it in Windows native printing then its HARD!
You need to create a device context on the printer and 
draw the output using GDI commands. The theory is that 
the same GDI calls generate the display and the print
(hence WYSIWYG) but in pracxtice its not that simple!
 
On *nix its usually via runoff macros of some type.
 
Alan g

------_=_NextPart_001_01C1C92E.34E5F990
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=810085818-11032002><FONT 
face="Courier New" color=#0000ff>&nbsp;&gt; &nbsp;</FONT></SPAN>How do you send 
data to the printer?<SPAN class=810085818-11032002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=810085818-11032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=810085818-11032002><FONT 
face="Courier New" color=#0000ff>Theeasy way, for text 
is:</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=810085818-11032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=810085818-11032002><FONT 
face="Courier New" color=#0000ff>os.system('lpr foo.txt')&nbsp;# 
*nix</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=810085818-11032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=810085818-11032002><FONT 
face="Courier New" color=#0000ff>OR&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=810085818-11032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=810085818-11032002><FONT 
face="Courier New" color=#0000ff>os.system('Print foo.txt') # 
DOS</FONT>&nbsp;</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=810085818-11032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=810085818-11032002>Or just assign stdout to 
prn:</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=810085818-11032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=810085818-11032002>Or open PRN: as a file</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=810085818-11032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=810085818-11032002>For fancier work you are probabluy best to generate 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=810085818-11032002>an HTML file or PDF and print that using the native 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=810085818-11032002>tools as above.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=810085818-11032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=810085818-11032002>If you must do it in Windows native printing then its 
HARD!</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=810085818-11032002>You need to create a device context on the printer and 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=810085818-11032002>draw the output using GDI commands. The theory is that 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=810085818-11032002>the same GDI calls generate the display and the 
print</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=810085818-11032002>(hence WYSIWYG) but in pracxtice its not that 
simple!</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=810085818-11032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=810085818-11032002>On *nix its usually via runoff macros of some 
type.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><SPAN class=810085818-11032002><FONT face=Arial size=2>Alan 
g</FONT></SPAN></DIV></BODY></HTML>

------_=_NextPart_001_01C1C92E.34E5F990--


From alan.gauld@bt.com  Mon Mar 11 19:02:30 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 11 Mar 2002 19:02:30 -0000
Subject: [Tutor] running a script from IDLE
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C42F@mbtlipnt02.btlabs.bt.co.uk>

> >In Smalltalk an FP style is encouraged and the default
> >return value from methods is self... 
> 
> But my point was that forcing myfoo to return an object
> can be expensive overhead 

It's no more expensive to return a reference to an object 
than to return a reference to a number or string. The point 
being you don't need to create a new object, you reference 
the modified original.

> >You need to do that anyway since the original is different
> >to the rotated version. I don't see the difference?
> 
> The difference is I don't have to keep the original.

You don't have to keep the original in FP either.
You either pass in a reference to the object, modify it 
in the function then pas back the reference to the 
(same) modified object OR you pass in the original object
create a new modified object(as you would with a tuple say)
and pass back the new object. The original can now be 
left to die.

> were themselves objects, so I'd have needed to deepcopy
> to work with a clone to return it as a new object.

But you don't need to do that in FP (OK some would say you 
do but most pragmatic FP'ers don't). you just pass in the 
reference and return the same reference.

> I tend to agree with this -- I like the cosmopolitan flavor
> of Python for example, because of the synergy.  

Absolutely, the reason why I am still using Python after having 
played with Ruby. Ruby has too much of a feel of "When all 
you have is a hammer every problem looks like a nail" to it.

>    My take: functional programming is about minimizing state,

Minimizing yes, but not eliminating.

Alan g.


From jeff@ccvcorp.com  Mon Mar 11 19:20:25 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Mon, 11 Mar 2002 11:20:25 -0800
Subject: [Tutor] Thoughts on little lambda
References: <E16jSCe-0002hs-00@mail.python.org> <4.2.0.58.20020311104645.01b5ed30@pop3.norton.antivirus>
Message-ID: <3C8D0379.D37C2C40@ccvcorp.com>


Kirby Urner wrote:

>
> Next question:  Is there a way to associate a customized
> doc string with the built function?

A brief experiment in the interpreter seems to indicate that a function's
__doc__ is assignable, so it should be possible, after defining the function
but before returning it, to do

    main.__doc__ = "This function returns %s" % descripton

or something similar.

Jeff Shannon
Technician/Programmer
Credit International




From urnerk@qwest.net  Mon Mar 11 19:22:55 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Mon, 11 Mar 2002 11:22:55 -0800
Subject: [Tutor] running a script from IDLE
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C42F@mbtlipnt02.btlabs
 .bt.co.uk>
Message-ID: <4.2.0.58.20020311111654.00cfe640@pop3.norton.antivirus>

>
>But you don't need to do that in FP (OK some would say you
>do but most pragmatic FP'ers don't). you just pass in the
>reference and return the same reference.

OK, this makes sense:

    newicosa = rotate(icosa,angle,degrees)

will be a destructive operation on icosa, in the sense
that its state will change.

It's the same as going

    def rotate(icosa,angle,degrees):
        icosa.rotate(icosa,angle,degrees)
        return icosa

...which I think was your original point.  I was just
getting hung up on that fact that object methods needn't
return self or anything at all, hence the FP "wrapper"
above, making sure that you get an object back.

Then you could write:

    newicosa = rotate(icosa,angle,degrees)

no problem.

Kirby



From dyoo@hkn.eecs.berkeley.edu  Mon Mar 11 20:11:03 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 11 Mar 2002 12:11:03 -0800 (PST)
Subject: [Edu-sig] Re: [Tutor] Thoughts on little lambda
In-Reply-To: <3C8D0379.D37C2C40@ccvcorp.com>
Message-ID: <Pine.LNX.4.21.0203111210020.5849-100000@hkn.eecs.berkeley.edu>

On Mon, 11 Mar 2002, Jeff Shannon wrote:

> 
> 
> Kirby Urner wrote:
> 
> >
> > Next question:  Is there a way to associate a customized
> > doc string with the built function?
> 
> A brief experiment in the interpreter seems to indicate that a function's
> __doc__ is assignable, so it should be possible, after defining the function
> but before returning it, to do
> 
>     main.__doc__ = "This function returns %s" % descripton
> 
> or something similar.


Here's a concrete example of this:

###
>>> def makeAdder(n):
...     def function(x):
...         "This function adds %(n)s to x."
...         return n + x
...     function.__doc__ = function.__doc__ % {'n' : n}
...     return function
... 
>>> f = makeAdder(42)
>>> f.__doc__
'This function adds 42 to x.'
###



From max_ig@yahoo.com  Mon Mar 11 21:37:29 2002
From: max_ig@yahoo.com (ichazo maximiliano)
Date: Mon, 11 Mar 2002 13:37:29 -0800 (PST)
Subject: [Tutor] curses module
Message-ID: <20020311213729.12735.qmail@web11304.mail.yahoo.com>

I'm playing around with Python but I can't find a module called
"curses". This module should allow me to work with text screens in
win32.

Please show me the light and tell me where can I find it.


Thanx,

Max

__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/


From SWidney@ci.las-vegas.nv.us  Mon Mar 11 21:54:40 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Mon, 11 Mar 2002 13:54:40 -0800
Subject: [Tutor] running a script from IDLE
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F5A01@SOVEREIGN>

> >Correct and FP is quite happy for you to return a new reference
> >to the modified pencil. The point of returning values is that
> >you can apply value substitution to prove the correctness of
> >the solution. (The real FP afficianados wuill be screaming
> >at me real soon :-) When a function performs its task without
> >returning a value you lose the concept of the entire program
> >being an expression that is evaluated.
> 
> ...which is how I'm contrasting object.method() calls which
> change object state without returning anything.  The point
> of the method is to change the internal state of the object.
> Nothing is returned.

Hmmm... in Alan's example above, you could always have the function return a
boolean indicating its success or failure at performing the task. One level
up you'd have logic that would react accordingly. Now it's back to being
functional again....

Actually, Kirby's object.method() ought to do that as well. Perhaps you've
asked the method to change the object in a way that was never intended. You
could have safeguards within the methods, but reporting an error would
become a side effect. So, instead, in essence you're asking the object to
modify itself, and it's responding with either "OK, done" or "I'm sorry,
Dave, but I can't do that."

Oversimplified perhaps, but it seems as though having functions and/or
objects only report errors, while leaving it to the caller to react to the
error makes both more functional.

Scott


From urnerk@qwest.net  Mon Mar 11 22:01:14 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Mon, 11 Mar 2002 14:01:14 -0800
Subject: [Tutor] curses module
In-Reply-To: <20020311213729.12735.qmail@web11304.mail.yahoo.com>
Message-ID: <4.2.0.58.20020311140027.00d0dc40@pop3.norton.antivirus>

At 01:37 PM 3/11/2002 -0800, ichazo maximiliano wrote:
>I'm playing around with Python but I can't find a module called
>"curses". This module should allow me to work with text screens in
>win32.

It won't, unless you add a lot of other stuff to the
default windows platform.

Kirby



From urnerk@qwest.net  Mon Mar 11 22:07:37 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Mon, 11 Mar 2002 14:07:37 -0800
Subject: [Edu-sig] Re: [Tutor] Thoughts on little lambda
In-Reply-To: <Pine.LNX.4.21.0203111210020.5849-100000@hkn.eecs.berkeley.
 edu>
References: <3C8D0379.D37C2C40@ccvcorp.com>
Message-ID: <4.2.0.58.20020311140531.00cd8a20@pop3.norton.antivirus>

At 12:11 PM 3/11/2002 -0800, Danny Yoo wrote:

> > A brief experiment in the interpreter seems to indicate that a
> > function's __doc__ is assignable, so it should be possible, after
> > defining the function but before returning it, to do
> >
> >     main.__doc__ = "This function returns %s" % descripton
> >
> > or something similar.
>
>
>Here's a concrete example of this:
>
>###
> >>> def makeAdder(n):
>...     def function(x):
>...         "This function adds %(n)s to x."
>...         return n + x
>...     function.__doc__ = function.__doc__ % {'n' : n}
>...     return function
>...
> >>> f = makeAdder(42)
> >>> f.__doc__
>'This function adds 42 to x.'
>###
>

Or even just:

  >>> def makeAdder(n):
        def function(x):
            return n + x
        function.__doc__ = "This function adds %s to x." % n
        return function

  >>> add42 = makeAdder(42)
  >>> help(add42)
  Help on function function:

  function(x)
      This function adds 1 to x.

Kirby



From Felix.Toran@esa.int  Mon Mar 11 10:07:24 2002
From: Felix.Toran@esa.int (Felix.Toran@esa.int)
Date: Mon, 11 Mar 2002 11:07:24 +0100
Subject: [Tutor] Installing tkinter
Message-ID: <41256B79.003573BC.00@esahqmail3.hq.esa.int>


Hi all!

I have downloaded ActivePython and ActiveTcl for Solaris 2.6. After installing
the products, my python scripts run nice, but those containing calls to the
tkinter module present problems.

I have tried to write:  import _tkinter at python (as indicated in a FAQ in
www.python.org), and an excepcion is thrown, reporting:

Import error: ld.so.1: /usr/local/ActivePython-2.1/bin/python2.1 : fatal :
libtk8.3.so : open failed : no such file or directory


I am really new to Solaris. Please, can someone help me solving this problem?
Thanks a lot in advance.
Felix.




From SWidney@ci.las-vegas.nv.us  Mon Mar 11 22:29:46 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Mon, 11 Mar 2002 14:29:46 -0800
Subject: [Tutor] RE: global vars vs. func args
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F5A02@SOVEREIGN>

> The QPB also answered another question from above -- that 
> functions can be used as "subroutines", only that in Python 
> they're called "procedures" -- blocks of code that do not
> return a value.

Yep. Some other languages are a little more rigid with the terminology.

In one version of Beginner's All-purpose Symbolic Instruction Code, a
FUNCTION must return a value and a SUB-routine must not. So a FUNCTION is
used to generate a value that can be assigned to a variable. And a SUB is
simply used to perform a repetitive task (usually fraught with side
effects).

In another language (Pascal, I think?), a FUNCTION returns a value, and a
PROCEDURE does not. It's semantics.

In Python, when you DEFine a function, you're creating a name and
associating that name with a function object. Python is relaxed. You can
choose to return a value or not.

> Is this still legitimate coding practice in Python?  The QPB 
> is a bit dated, but this seems like valid use of functions.

Sure...use whatever you know now in whatever way is appropriate to getting
the task completed.

"Everything is permissible, but not all things are beneficial."

You can always refactor it, if it's going to be around for a while.

"The best thing about knowing the rules is knowing when to break them."

Incidentally, even when you don't specify a return value in your function
definition, it still returns a value (None). If you don't assign it to a
variable, or capture it in some other way, it just drops out.

</rambling>

Scott


From urnerk@qwest.net  Mon Mar 11 23:37:48 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Mon, 11 Mar 2002 15:37:48 -0800
Subject: [Tutor] running a script from IDLE
In-Reply-To: <D4EB5574F4A7D2119C9E00A0C9EA408D059F5A01@SOVEREIGN>
Message-ID: <4.2.0.58.20020311153249.00d16630@pop3.norton.antivirus>

>
>Hmmm... in Alan's example above, you could always have the
>function return a boolean indicating its success or failure
>at performing the task. One level up you'd have logic that
>would react accordingly. Now it's back to being functional
>again....

Well, I don't necessarily want to bypass all the try/except
syntax by trying to handle errors using return values.

But I can see writing more "helper functions" like:

    def sort(thelist):
         thelist.sort()
         return thelist

This gets around a common pitfall, when people try to
do something like:

    for i in mylist.sort():
        # etc.

because mylist.sort() returns nothing.  By wrapping it
in the above, we get the list back out, and can
then indeed do one-liners like:

  >>> a = [4,3,8,1,0]
  >>> for i in sort(a): print i,

  0 1 3 4 8

Kirby



From pythontutor@venix.com  Tue Mar 12 00:42:16 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Mon, 11 Mar 2002 19:42:16 -0500
Subject: [Tutor] running a script from IDLE
References: <D4EB5574F4A7D2119C9E00A0C9EA408D059F5A01@SOVEREIGN>
Message-ID: <3C8D4EE8.9050302@venix.com>

I think failure is best reported by raising an exception.

To my mind (based on limited FP experience) you want functions that
return useful values - even if it is only a reference the the object
that was passed into the function.  So long as the result of a function
makes sense as the argument for other functions, you have a function
that can be used as a building block.  This is easy to see with math
oriented processing.


Scott Widney wrote:

>>>Correct and FP is quite happy for you to return a new reference
>>>to the modified pencil. The point of returning values is that
>>>you can apply value substitution to prove the correctness of
>>>the solution. (The real FP afficianados wuill be screaming
>>>at me real soon :-) When a function performs its task without
>>>returning a value you lose the concept of the entire program
>>>being an expression that is evaluated.
>>>
>>...which is how I'm contrasting object.method() calls which
>>change object state without returning anything.  The point
>>of the method is to change the internal state of the object.
>>Nothing is returned.
>>
> 
> Hmmm... in Alan's example above, you could always have the function return a
> boolean indicating its success or failure at performing the task. One level
> up you'd have logic that would react accordingly. Now it's back to being
> functional again....
> 
> Actually, Kirby's object.method() ought to do that as well. Perhaps you've
> asked the method to change the object in a way that was never intended. You
> could have safeguards within the methods, but reporting an error would
> become a side effect. So, instead, in essence you're asking the object to
> modify itself, and it's responding with either "OK, done" or "I'm sorry,
> Dave, but I can't do that."
> 
> Oversimplified perhaps, but it seems as though having functions and/or
> objects only report errors, while leaving it to the caller to react to the
> error makes both more functional.
> 
> Scott
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582



From erikprice@mac.com  Tue Mar 12 01:23:19 2002
From: erikprice@mac.com (Erik Price)
Date: Mon, 11 Mar 2002 20:23:19 -0500
Subject: [Tutor] Re: global vars vs. func args
In-Reply-To: <D4EB5574F4A7D2119C9E00A0C9EA408D059F5A02@SOVEREIGN>
Message-ID: <BCB203E4-3557-11D6-945B-00039351FE6A@mac.com>

Scott,

Thanks for following up on that thread for me -- I was wondering about 
whether or not pros use procedures.

Your response raises one question though -- what's "refactor"?  I think 
the quote was "You can always refactor it later if it's going to be 
around for a while".


Thanks,

Erik



From SWidney@ci.las-vegas.nv.us  Tue Mar 12 01:47:59 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Mon, 11 Mar 2002 17:47:59 -0800
Subject: [Tutor] running a script from IDLE
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F5A04@SOVEREIGN>

> >Hmmm... in Alan's example above, you could always have the
> >function return a boolean indicating its success or failure
> >at performing the task. One level up you'd have logic that
> >would react accordingly. Now it's back to being functional
> >again....
> 
> Well, I don't necessarily want to bypass all the try/except
> syntax by trying to handle errors using return values.

OK, I can see that. So would this type of setup work:

try:
  object.method()     # Exception "raised" in method.
except derivedError:  # Derived errors being errors created
  blah_blah()         # for this particular object.

(i.e. wrap the method call in a try, as opposed to having the try/except
coded in the method)? I'm unsure if that's possible -- I don't know if
nested scopes changed this behavior or not. I'm thinking of the old LGB
acronym; in older versions of Python if things didn't happen in the Local
vicinity, Python hopped right up to Global without any regard to intervening
levels.

Scott


From SWidney@ci.las-vegas.nv.us  Tue Mar 12 02:12:48 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Mon, 11 Mar 2002 18:12:48 -0800
Subject: [Tutor] RE: global vars vs. func args
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F5A05@SOVEREIGN>

> Thanks for following up on that thread for me -- I was 
> wondering about whether or not pros use procedures.
> 
> Your response raises one question though -- what's 
> "refactor"?  I think the quote was "You can always 
> refactor it later if it's going to be around for a 
> while".
> 

Ah, refactoring! Well, to begin with, it's the title of Martin Fowler's July
'99 book. Here's a quote from him:

"Refactoring is a technique to restructure code in a disciplined way. For a
long time it was a piece of programmer lore, done with varying degrees of
discipline by experienced developers, but not passed on in a coherent way."

He even has a website for it: www.refactoring.com

At it's core, it's taking existing code and reworking it, piece by piece,
possibly using techniques that didn't exist at the time it was originally
created. Kind of a "If I knew then what I know now" thing....  It's gone on
since programming began, but now it has a Name, documented techniques,
tools, and a community.

Scott


From SWidney@ci.las-vegas.nv.us  Tue Mar 12 02:51:05 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Mon, 11 Mar 2002 18:51:05 -0800
Subject: [Tutor] running a script from IDLE
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F5A06@SOVEREIGN>

> I think failure is best reported by raising an exception.
> 
> To my mind (based on limited FP experience) you want functions that
> return useful values - even if it is only a reference the the object
> that was passed into the function.  So long as the result of a 
> function makes sense as the argument for other functions, you have a
> function that can be used as a building block.  This is easy to see
> with math oriented processing.

Just to play Devil's Advocate a little longer....

I see what you mean with the math-oriented processing, especially because in
math, functions tend to be nested (sometimes greatly so). But on the object
side...

Let's say that I'm a bit of Controller code. My user (please no Tron cracks)
has just indicated that he wants his "icosa" rotated +90 degress on the
z-plane. I'm going to call icosa.rotate(z=90) or something similar. Before I
tell the View to refresh itself, I want to be sure that the Model has
changed. How can I be sure of that? As Kirby pointed out, most method calls
that change state return None.

Returning a pointer: whether we return a pointer to the
"your-old-state-data-has-been-destroyed" instance or to a new instance, I
still don't know if the transformation took place.

There's the "return a boolean flag" thing mentioned before, which would put
all of the error handling inside the method. But it doesn't reflect *what*
was wrong. It just reports failure or success.

So I need the descriptive power that exception handling provides. Here lies
the question: where do we put that try/except? Do we wrap it around the
method call and let the method raise an error that passes out of the call?
Or does the whole shebang go in the method? Could I see some appropriate
pseudocode?

Scott


From dyoo@hkn.eecs.berkeley.edu  Tue Mar 12 03:05:06 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 11 Mar 2002 19:05:06 -0800 (PST)
Subject: [Tutor] RE: global vars vs. func args
In-Reply-To: <D4EB5574F4A7D2119C9E00A0C9EA408D059F5A02@SOVEREIGN>
Message-ID: <Pine.LNX.4.21.0203111856040.15261-100000@hkn.eecs.berkeley.edu>

On Mon, 11 Mar 2002, Scott Widney wrote:

> In Python, when you DEFine a function, you're creating a name and
> associating that name with a function object. Python is relaxed. You
> can choose to return a value or not.
> 
> > Is this still legitimate coding practice in Python?  The QPB 
> > is a bit dated, but this seems like valid use of functions.
> 
> Sure...use whatever you know now in whatever way is appropriate to
> getting the task completed.
> 
> "Everything is permissible, but not all things are beneficial."
> 
> You can always refactor it, if it's going to be around for a while.
> 
> "The best thing about knowing the rules is knowing when to break
> them."


I might as well toss out a few more relevant and funny quotes from Alan
Perlis:

###
"""If you have a procedure with ten parameters, you probably missed
some."""

"""Think of all the psychic energy expended in seeking a fundamental
distinction between "algorithm" and "program"."""

"""Interfaces keep things tidy, but don't accelerate growth: Functions
do."""
###


    http://www.cs.yale.edu/homes/perlis-alan/quotes.html

*grin*



From kalle@gnupung.net  Tue Mar 12 03:27:26 2002
From: kalle@gnupung.net (Kalle Svensson)
Date: Tue, 12 Mar 2002 04:27:26 +0100
Subject: [Tutor] Quotes (Was: global vars vs. func args)
In-Reply-To: <Pine.LNX.4.21.0203111856040.15261-100000@hkn.eecs.berkeley.edu>
References: <D4EB5574F4A7D2119C9E00A0C9EA408D059F5A02@SOVEREIGN> <Pine.LNX.4.21.0203111856040.15261-100000@hkn.eecs.berkeley.edu>
Message-ID: <20020312032726.GA25241@sandra.lysator.liu.se>

[Danny Yoo]
> I might as well toss out a few more relevant and funny quotes from Alan
> Perlis:

Well, this quote isn't relevant, but I like it very much.

  I never realized it before, but having looked that over I'm certain
  I'd rather have my eyes burned out by zombies with flaming dung sticks
  than work on a conscientious Unicode regex engine.

   -- Tim Peters, 3 Dec 1998

>From A.M. Kuchlings excellent quotations page, Python section.
http://www.amk.ca/quotations/

Peace,
  Kalle
-- 
Kalle Svensson (kalle@gnupung.net) - Laziness, impatience, hubris: Pick two!
English: http://www.gnupung.net/  Svenska: http://www.lysator.liu.se/~kalle/
Stuff: ["http://www.%s.org/" % x for x in "gnu debian python emacs".split()]


From virketis@fas.harvard.edu  Tue Mar 12 04:13:16 2002
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Mon, 11 Mar 2002 23:13:16 -0500
Subject: [Tutor] artificial agents
Message-ID: <003201c1c97c$3f7b7df0$18adf78c@virketis2>

This is a multi-part message in MIME format.

------=_NextPart_000_002F_01C1C952.5350A5A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Fellows,=20

(is this a gender-neutral form of address? I wonder :) does anyone know =
of Python code for any sort of Artificial Agents or Complex Adaptive =
Systems? I want to work on an economics simulation of the Soviet =
"shortage economy" and it would be lovely if I would not have to contort =
myself into C++. Just to make sure I give, as well as take, I have found =
one site on the subject: www.norvig.com. P. Norvig is the author of a =
well know AI book, and he is working on porting some of his LISP (eeek) =
code into Python, but the project is far from the documentation stage.:( =
Perhaps someone will find it useful/interesting.

Cheers,=20

Pijus


----------------------------
Time goes, you say? Ah no! Time stays, *we* go. -- Austin Dobson

------=_NextPart_000_002F_01C1C952.5350A5A0
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.2713.1100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Fellows, </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>(is this a gender-neutral form of =
address? I wonder=20
:) does anyone know of Python code for any sort of Artificial Agents=20
or&nbsp;Complex Adaptive Systems? I want to work on an =
economics&nbsp;simulation=20
of the Soviet "shortage economy" and it would be lovely if I would not =
have to=20
contort&nbsp;myself into C++. Just to make sure I give, as well as take, =
I have=20
found one site on the subject: <A=20
href=3D"http://www.norvig.com">www.norvig.com</A>.&nbsp;P. Norvig is=20
the&nbsp;author of a well know AI book, and he is working on porting =
some of his=20
LISP (eeek) code into Python, but the&nbsp;project is far from&nbsp;the=20
documentation stage.:( Perhaps someone will find it=20
useful/interesting.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Cheers,&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Pijus</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>----------------------------<BR>Time =
goes, you say?=20
Ah no! Time stays, *we* go. -- Austin Dobson</FONT></DIV></BODY></HTML>

------=_NextPart_000_002F_01C1C952.5350A5A0--



From idiot1@netzero.net  Tue Mar 12 05:24:18 2002
From: idiot1@netzero.net (kirk Bailey)
Date: Tue, 12 Mar 2002 00:24:18 -0500
Subject: [Tutor] TL quest for improvements and users
Message-ID: <3C8D9102.A132A3E9@netzero.net>

OK, I now have TL working with a simple config file. ALL it contains
is your domain name, it knows enough to tell where it lives. It is
easier than ever to use, and offers many features. I want to get it
known to the world, and get some people using it. Regretfully, yagoo,
and even google which it now owns, have gone mercenary, and seem to be
ignoring my efforts to get it listed there.

I need users. Anyone want to take a try at using this program?

I also bneed advice on how to get this listed without spending cash, I
already did the free submission thing to no effect.

Also, any comments and suggestions on the thing would be well
received.

-- 
 
end
	    Respectfully,
			 Kirk D Bailey


+---------------------"Thou Art Free." -Eris----------------------+
| http://www.howlermonkey.net mailto:highprimate@howlermonkey.net |
| http://www.tinylist.org  +--------+  mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking---------------------+
                           +--------+

NOTE: By sending SPAM to this address you agree to pay me a service
fee of $100 for the service of receiving,  storing,  examining, and
deleting your piece of SPAM. I am a postmaster, and take a dim view
of such.
----------------------------------------------------
Sign Up for NetZero Platinum Today
Only $9.95 per month!
http://my.netzero.net/s/signup?r=platinum&refcd=PT97


From erikprice@mac.com  Tue Mar 12 13:25:43 2002
From: erikprice@mac.com (Erik Price)
Date: Tue, 12 Mar 2002 08:25:43 -0500
Subject: [Tutor] RE: global vars vs. func args
In-Reply-To: <Pine.LNX.4.21.0203111856040.15261-100000@hkn.eecs.berkeley.edu>
Message-ID: <A7C45430-35BC-11D6-9E16-00039351FE6A@mac.com>

Whoah -- some questions about those quotes!


On Monday, March 11, 2002, at 10:05  PM, Danny Yoo wrote:

> """If you have a procedure with ten parameters, you probably missed
> some."""

Is this sarcasm, or seriousness?  I don't think I've encountered many 
functions that take more than four parameters, usually three or less.  
And I know I haven't written any.  Is it really okay to make such a 
detailed function?  (I mean, "of course you can do what you want", but 
is it the convention among programmers to do so?  Is it "expensive"?)

> """Think of all the psychic energy expended in seeking a fundamental
> distinction between "algorithm" and "program"."""

I was wondering the very same thing.  An algorithm is like a 
progam-within-a-program, isn't it?  I like this quote, if I'm 
interpeting it correctly.

> """Interfaces keep things tidy, but don't accelerate growth: Functions
> do."""

This one is a bit beyond me.  My best guess is this:  whereas an 
application (with an interface of some sort) is a neat way to let the 
user know what they can and can't do, it is not as flexible as a 
function that could accept parameters to do the same thing, since the 
function could be incorporated into a greater program.  This makes me 
think of Unix tools, with their ability to pipe and redirect standard 
input and output in a flexible way.

These are curious quotes.  Thank you for posting.


Erik



From wolf_binary@hotmail.com  Tue Mar 12 14:05:39 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Tue, 12 Mar 2002 08:05:39 -0600
Subject: [Tutor] printing
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C42E@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <DAV436AATiyhGvDpEDi0001f84c@hotmail.com>

This is a multi-part message in MIME format.

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



   >  How do you send data to the printer?=20

  Theeasy way, for text is:

  os.system('lpr foo.txt') # *nix

  OR=20

  os.system('Print foo.txt') # DOS=20

  Or just assign stdout to prn:

  Or open PRN: as a file

  For fancier work you are probabluy best to generate=20
  an HTML file or PDF and print that using the native=20
  tools as above.

  If you must do it in Windows native printing then its HARD!
  You need to create a device context on the printer and=20
  draw the output using GDI commands. The theory is that=20
  the same GDI calls generate the display and the print
  (hence WYSIWYG) but in pracxtice its not that simple!

  Alan g



  What are GDI commands?

  Cameron Stoner

------=_NextPart_000_0014_01C1C99C.B2E7C760
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.2713.1100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2></FONT><BR>&nbsp;</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D810085818-11032002><FONT=20
  face=3D"Courier New" color=3D#0000ff>&nbsp;&gt; =
&nbsp;</FONT></SPAN>How do you=20
  send data to the printer?<SPAN class=3D810085818-11032002><FONT=20
  face=3D"Courier New" =
color=3D#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN=20
  class=3D810085818-11032002></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D810085818-11032002><FONT=20
  face=3D"Courier New" color=3D#0000ff>Theeasy way, for text=20
  is:</FONT></SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN=20
  class=3D810085818-11032002></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D810085818-11032002><FONT=20
  face=3D"Courier New" color=3D#0000ff>os.system('lpr foo.txt')&nbsp;#=20
  *nix</FONT></SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN=20
  class=3D810085818-11032002></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D810085818-11032002><FONT=20
  face=3D"Courier New" =
color=3D#0000ff>OR&nbsp;</FONT></SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN=20
  class=3D810085818-11032002></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial><FONT size=3D2><SPAN =
class=3D810085818-11032002><FONT=20
  face=3D"Courier New" color=3D#0000ff>os.system('Print foo.txt') #=20
  DOS</FONT>&nbsp;</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT face=3D"Courier New" color=3D#0000ff =
size=3D2><SPAN=20
  class=3D810085818-11032002></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial><FONT face=3D"Courier New" color=3D#0000ff =
size=3D2><SPAN=20
  class=3D810085818-11032002>Or just assign stdout to=20
  prn:</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT face=3D"Courier New" color=3D#0000ff =
size=3D2><SPAN=20
  class=3D810085818-11032002></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial><FONT face=3D"Courier New" color=3D#0000ff =
size=3D2><SPAN=20
  class=3D810085818-11032002>Or open PRN: as a =
file</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT face=3D"Courier New" color=3D#0000ff =
size=3D2><SPAN=20
  class=3D810085818-11032002></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial><FONT face=3D"Courier New" color=3D#0000ff =
size=3D2><SPAN=20
  class=3D810085818-11032002>For fancier work you are probabluy best to =
generate=20
  </SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT face=3D"Courier New" color=3D#0000ff =
size=3D2><SPAN=20
  class=3D810085818-11032002>an HTML file or PDF and print that using =
the native=20
  </SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT face=3D"Courier New" color=3D#0000ff =
size=3D2><SPAN=20
  class=3D810085818-11032002>tools as above.</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT face=3D"Courier New" color=3D#0000ff =
size=3D2><SPAN=20
  class=3D810085818-11032002></SPAN></FONT></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial><FONT face=3D"Courier New" color=3D#0000ff =
size=3D2><SPAN=20
  class=3D810085818-11032002>If you must do it in Windows native =
printing then its=20
  HARD!</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT face=3D"Courier New" color=3D#0000ff =
size=3D2><SPAN=20
  class=3D810085818-11032002>You need to create a device context on the =
printer=20
  and </SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT face=3D"Courier New" color=3D#0000ff =
size=3D2><SPAN=20
  class=3D810085818-11032002>draw the output using GDI commands. The =
theory is=20
  that </SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT face=3D"Courier New" color=3D#0000ff =
size=3D2><SPAN=20
  class=3D810085818-11032002>the same GDI calls generate the display and =
the=20
  print</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial><FONT face=3D"Courier New" color=3D#0000ff =
size=3D2><SPAN=20
  class=3D810085818-11032002>(hence WYSIWYG) but in pracxtice its not =
that=20
  simple!</SPAN></FONT></FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><SPAN class=3D810085818-11032002><FONT face=3DArial size=3D2>Alan =

  g</FONT></SPAN></DIV>
  <DIV><SPAN class=3D810085818-11032002><FONT face=3DArial=20
  size=3D2></FONT></SPAN>&nbsp;</DIV>
  <DIV><SPAN class=3D810085818-11032002><FONT face=3DArial=20
  size=3D2></FONT></SPAN>&nbsp;</DIV>
  <DIV><SPAN class=3D810085818-11032002><FONT face=3DArial=20
  size=3D2></FONT></SPAN>&nbsp;</DIV>
  <DIV><SPAN class=3D810085818-11032002><FONT face=3DArial size=3D2>What =
are GDI=20
  commands?</FONT></SPAN></DIV>
  <DIV><SPAN class=3D810085818-11032002><FONT face=3DArial=20
  size=3D2></FONT></SPAN>&nbsp;</DIV>
  <DIV><SPAN class=3D810085818-11032002><FONT face=3DArial =
size=3D2>Cameron=20
  Stoner</FONT></SPAN></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0014_01C1C99C.B2E7C760--


From israel@lith.com  Tue Mar 12 14:55:08 2002
From: israel@lith.com (Israel Evans)
Date: Tue, 12 Mar 2002 06:55:08 -0800
Subject: [Tutor] artificial agents
Message-ID: <AF020C5FC551DD43A4958A679EA16A15017B3FF9@abbott.lith.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_01C1C9D5.E74D8CAD
Content-Type: text/plain

 
The links on this page might help you out:
 
http://www.awaretek.com/ailinks.html <http://www.awaretek.com/ailinks.html> 
 
 
This Russian guy (Vladimir) seems to have a lot of neat stuff!
 
http://starship.python.net/crew/gandalf/
<http://starship.python.net/crew/gandalf/> 
 
 
This is a pretty good general AI site.
 
http://www.pcai.com/ <http://www.pcai.com/> 
 
 
 
~Israel~
 
-----Original Message-----
From: Pijus Virketis [mailto:virketis@fas.harvard.edu] 
Sent: 11 March 2002 8:13 PM
To: tutor@python.org
Subject: [Tutor] artificial agents
 
Fellows, 
 
(is this a gender-neutral form of address? I wonder :) does anyone know of
Python code for any sort of Artificial Agents or Complex Adaptive Systems? I
want to work on an economics simulation of the Soviet "shortage economy" and
it would be lovely if I would not have to contort myself into C++. Just to
make sure I give, as well as take, I have found one site on the subject:
www.norvig.com <http://www.norvig.com> . P. Norvig is the author of a well
know AI book, and he is working on porting some of his LISP (eeek) code into
Python, but the project is far from the documentation stage.:( Perhaps
someone will find it useful/interesting.
 
Cheers, 
 
Pijus
 
 
----------------------------
Time goes, you say? Ah no! Time stays, *we* go. -- Austin Dobson

------_=_NextPart_001_01C1C9D5.E74D8CAD
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:st1=3D"urn:schemas-microsoft-com:office:smarttags" =
xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">


<meta name=3DProgId content=3DWord.Document>
<meta name=3DGenerator content=3D"Microsoft Word 10">
<meta name=3DOriginator content=3D"Microsoft Word 10">
<link rel=3DFile-List href=3D"cid:filelist.xml@01C1C992.D8E9E560">
<o:SmartTagType =
namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags"
 name=3D"country-region"/>
<o:SmartTagType =
namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags"
 name=3D"place"/>
<o:SmartTagType =
namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags"
 name=3D"time"/>
<o:SmartTagType =
namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags"
 name=3D"date"/>
<!--[if gte mso 9]><xml>
 <o:OfficeDocumentSettings>
  <o:DoNotRelyOnCSS/>
 </o:OfficeDocumentSettings>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:SpellingState>Clean</w:SpellingState>
  <w:GrammarState>Clean</w:GrammarState>
  <w:DocumentKind>DocumentEmail</w:DocumentKind>
  <w:EnvelopeVis/>
  <w:Compatibility>
   <w:UseFELayout/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]--><!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:PMingLiU;
	panose-1:2 2 3 0 0 0 0 0 0 0;
	mso-font-alt:\65B0\7D30\660E\9AD4;
	mso-font-charset:136;
	mso-generic-font-family:roman;
	mso-font-pitch:variable;
	mso-font-signature:3 137232384 22 0 1048577 0;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;
	mso-font-charset:0;
	mso-generic-font-family:swiss;
	mso-font-pitch:variable;
	mso-font-signature:553679495 -2147483648 8 0 66047 0;}
@font-face
	{font-family:"\@PMingLiU";
	panose-1:2 2 3 0 0 0 0 0 0 0;
	mso-font-charset:136;
	mso-generic-font-family:roman;
	mso-font-pitch:variable;
	mso-font-signature:3 137232384 22 0 1048577 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0in;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:PMingLiU;}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;
	text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
	{color:blue;
	text-decoration:underline;
	text-underline:single;}
p.MsoAutoSig, li.MsoAutoSig, div.MsoAutoSig
	{margin:0in;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";}
span.EmailStyle17
	{mso-style-type:personal-reply;
	mso-style-noshow:yes;
	mso-ansi-font-size:10.0pt;
	mso-bidi-font-size:10.0pt;
	font-family:Arial;
	mso-ascii-font-family:Arial;
	mso-hansi-font-family:Arial;
	mso-bidi-font-family:Arial;
	color:navy;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;
	mso-header-margin:.5in;
	mso-footer-margin:.5in;
	mso-paper-source:0;}
div.Section1
	{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
 /* Style Definitions */=20
 table.MsoNormalTable
	{mso-style-name:"Table Normal";
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0in 5.4pt 0in 5.4pt;
	mso-para-margin:0in;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";}
</style>
<![endif]--><!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext=3D"edit">
  <o:idmap v:ext=3D"edit" data=3D"1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body bgcolor=3Dwhite lang=3DEN-US link=3Dblue vlink=3Dblue =
style=3D'tab-interval:.5in'>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>=


<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>The links on this page might help =
you out:<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>=


<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><a
href=3D"http://www.awaretek.com/ailinks.html">http://www.awaretek.com/ai=
links.html</a><o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>=


<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>=


<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>This Russian guy (Vladimir) seems =
to have
a lot of neat stuff!<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>=


<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><a
href=3D"http://starship.python.net/crew/gandalf/">http://starship.python=
.net/crew/gandalf/</a><o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>=


<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>=


<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>This is a pretty good general AI =
site.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>=


<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><a =
href=3D"http://www.pcai.com/">http://www.pcai.com/</a><o:p></o:p></span>=
</font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>=


<div>

<p class=3DMsoAutoSig><font size=3D3 color=3Dnavy face=3D"Times New =
Roman"><span
style=3D'font-size:12.0pt;color:navy;mso-no-proof:yes'><o:p>&nbsp;</o:p>=
</span></font></p>

<p class=3DMsoAutoSig><font size=3D3 color=3Dnavy face=3D"Times New =
Roman"><span
style=3D'font-size:12.0pt;color:navy;mso-no-proof:yes'><o:p>&nbsp;</o:p>=
</span></font></p>

<p class=3DMsoAutoSig><font size=3D2 color=3Dnavy face=3D"Courier =
New"><span
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:navy;mso-no-proof:yes'>~</span></font><st1:country-region><st=
1:place><font
  size=3D2 color=3Dnavy face=3D"Courier New"><span =
style=3D'font-size:10.0pt;
  font-family:"Courier =
New";color:navy;mso-no-proof:yes'>Israel</span></font></st1:place></st1:=
country-region><font
size=3D2 color=3Dnavy face=3D"Courier New"><span =
style=3D'font-size:10.0pt;font-family:
"Courier =
New";color:navy;mso-no-proof:yes'>~<o:p></o:p></span></font></p>

</div>

<p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span =
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>=


<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D2 face=3DTa=
homa><span
style=3D'font-size:10.0pt;font-family:Tahoma'>-----Original =
Message-----<br>
<b><span style=3D'font-weight:bold'>From:</span></b> Pijus Virketis
[mailto:virketis@fas.harvard.edu] <br>
<b><span style=3D'font-weight:bold'>Sent:</span></b> =
</span></font><st1:date
Month=3D"3" Day=3D"11" Year=3D"2002"><font size=3D2 face=3DTahoma><span =
style=3D'font-size:
 10.0pt;font-family:Tahoma'>11 March 2002</span></font></st1:date><font =
size=3D2
face=3DTahoma><span style=3D'font-size:10.0pt;font-family:Tahoma'> =
</span></font><st1:time
Hour=3D"20" Minute=3D"13"><font size=3D2 face=3DTahoma><span =
style=3D'font-size:10.0pt;
 font-family:Tahoma'>8:13 PM</span></font></st1:time><font size=3D2 =
face=3DTahoma><span
style=3D'font-size:10.0pt;font-family:Tahoma'><br>
<b><span style=3D'font-weight:bold'>To:</span></b> tutor@python.org<br>
<b><span style=3D'font-weight:bold'>Subject:</span></b> [Tutor] =
artificial agents</span></font></p>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D3 =
face=3D"Times New Roman"><span
style=3D'font-size:12.0pt'><o:p>&nbsp;</o:p></span></font></p>

<div>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D2 =
face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial'>Fellows, =
</span></font><o:p></o:p></p>

</div>

<div>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D3 =
face=3D"Times New Roman"><span
style=3D'font-size:12.0pt'>&nbsp;<o:p></o:p></span></font></p>

</div>

<div>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D2 =
face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial'>(is this a gender-neutral =
form of
address? I wonder :) does anyone know of Python code for any sort of =
Artificial
Agents or&nbsp;Complex Adaptive Systems? I want to work on an =
economics&nbsp;simulation
of the Soviet &quot;shortage economy&quot; and it would be lovely if I =
would
not have to contort&nbsp;myself into C++. Just to make sure I give, as =
well as
take, I have found one site on the subject: <a =
href=3D"http://www.norvig.com">www.norvig.com</a>.&nbsp;P.
Norvig is the&nbsp;author of a well know AI book, and he is working on =
porting
some of his LISP (eeek) code into Python, but the&nbsp;project is far
from&nbsp;the documentation stage.:( Perhaps someone will find it
useful/interesting.</span></font><o:p></o:p></p>

</div>

<div>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D3 =
face=3D"Times New Roman"><span
style=3D'font-size:12.0pt'>&nbsp;<o:p></o:p></span></font></p>

</div>

<div>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D2 =
face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial'>Cheers,&nbsp;</span></font>=
<o:p></o:p></p>

</div>

<div>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D3 =
face=3D"Times New Roman"><span
style=3D'font-size:12.0pt'>&nbsp;<o:p></o:p></span></font></p>

</div>

<div>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D2 =
face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial'>Pijus</span></font><o:p></o=
:p></p>

</div>

<div>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D3 =
face=3D"Times New Roman"><span
style=3D'font-size:12.0pt'>&nbsp;<o:p></o:p></span></font></p>

</div>

<div>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D3 =
face=3D"Times New Roman"><span
style=3D'font-size:12.0pt'>&nbsp;<o:p></o:p></span></font></p>

</div>

<div>

<p class=3DMsoNormal style=3D'margin-left:.5in'><font size=3D2 =
face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial'>---------------------------=
-<br>
Time goes, you say? Ah no! Time stays, *we* go. -- Austin =
Dobson</span></font><o:p></o:p></p>

</div>

</div>

</body>

</html>

------_=_NextPart_001_01C1C9D5.E74D8CAD--


From kjphotog@juno.com  Tue Mar 12 14:18:01 2002
From: kjphotog@juno.com (kjphotog@juno.com)
Date: Tue, 12 Mar 2002 06:18:01 -0800
Subject: [Tutor] Spend a  day with Yoo
Message-ID: <20020312.072637.-187195.7.kjphotog@juno.com>

I too found Danny Yoo's tutorial guide through a single day with IDLE:
an easy read, easy to digest & understand. But some of the examples 
didn't seem to work in the Python Windows version. 

And I'm discovering that more & more, there's IDLE & then there's
Activestate. What works for one, doesn't work the same in the other
version. 

For example, saving py files? Yoo's tutorial doesn't seem to work in
Activestate. Is there some sort of windows weirdness?

In which case tutors, which version should we newbies really use? 

        http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html
 
Danny, when will you find the time to write up a Single Day #2? 
Perhaps we can offer to e-mail you large sums of cash for inspiration. 

Keith

________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today!  For your FREE software, visit:
http://dl.www.juno.com/get/web/.


From urnerk@qwest.net  Tue Mar 12 16:05:16 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Tue, 12 Mar 2002 08:05:16 -0800
Subject: [Tutor] Spend a  day with Yoo
In-Reply-To: <20020312.072637.-187195.7.kjphotog@juno.com>
Message-ID: <4.2.0.58.20020312080410.00cc4b70@pop3.norton.antivirus>

>
>And I'm discovering that more & more, there's IDLE & then there's
>Activestate. What works for one, doesn't work the same in the other
>version.

That's very true.  IDLE and the Windows-only shell you get
with ActiveState and different shells.  Danny's tutorial is
really about IDLE.

Kirby



From urnerk@qwest.net  Tue Mar 12 16:10:38 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Tue, 12 Mar 2002 08:10:38 -0800
Subject: [Tutor] RE: global vars vs. func args
In-Reply-To: <A7C45430-35BC-11D6-9E16-00039351FE6A@mac.com>
References: <Pine.LNX.4.21.0203111856040.15261-100000@hkn.eecs.berkeley.edu>
Message-ID: <4.2.0.58.20020312080524.00cc45b0@pop3.norton.antivirus>

At 08:25 AM 3/12/2002 -0500, you wrote:

>Whoah -- some questions about those quotes!
>
>
>On Monday, March 11, 2002, at 10:05  PM, Danny Yoo wrote:
>
>>"""If you have a procedure with ten parameters, you probably
>>missed some."""
>
>Is this sarcasm, or seriousness?

It's a joke.  Ten would be considered very much on the
high side, for parameters, although you can easily pass
a single list -- that contains ten (or a thousand)
elements to be modified (but probably all in the same
way).

>>"""Think of all the psychic energy expended in seeking
>>a fundamental distinction between "algorithm" and "program"."""
>
>I was wondering the very same thing.  An algorithm is like a
>progam-within-a-program, isn't it?  I like this quote, if I'm
>interpeting it correctly.

Here I think he's saying don't waste your time trying to
puzzle out a neat distinction between the two.  Life is
short.

>>"""Interfaces keep things tidy, but don't accelerate growth:
>>Functions do."""
>
>This one is a bit beyond me.  My best guess is this:  whereas
>an application (with an interface of some sort) is a neat way
>to let the user know what they can and can't do, it is not as
>flexible as a function that could accept parameters to do the
>same thing, since the function could be incorporated into a
>greater program.  This makes me think of Unix tools, with their
>ability to pipe and redirect standard input and output in a
>flexible way.

We agree on this one.  Functions package a program into
discrete units *and* promote synergy i.e. suggest ways
of reusing the same functions in new and interesting
combinations.  Interfaces (I presume he meant in the
GUI sense, not in the more arcane Java pseudo-class
sense) also help organize a program, but they tend to
impose a static, non-synergetic regime.


>These are curious quotes.  Thank you for posting.
>
>
>Erik
>

Yeah, fun.  I'm glad you chose to analyze 'em.

Kirby



From alan.gauld@bt.com  Tue Mar 12 16:58:55 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 12 Mar 2002 16:58:55 -0000
Subject: [Tutor] running a script from IDLE
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C432@mbtlipnt02.btlabs.bt.co.uk>

> >Hmmm... in Alan's example above, you could always have the
> >function return a boolean indicating its success or failure

This is possible but not really an FP style, returning 
a usable value is better.

> Well, I don't necessarily want to bypass all the try/except
> syntax by trying to handle errors using return values.

Which is another good reason not to to that...

> This gets around a common pitfall, when people try to
> do something like:
> 
>     for i in mylist.sort():
>         # etc.
> 
> because mylist.sort() returns nothing.  By wrapping it
> in the above, we get the list back out, and can
> then indeed do one-liners like:
> 
>   >>> a = [4,3,8,1,0]
>   >>> for i in sort(a): print i,


Now this is an FP style - you can prove correctness because 
sort returns a substitutional value. In traditional Python 
you get the comparatively useless None and an error.

Alan g.


From alan.gauld@bt.com  Tue Mar 12 17:02:42 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 12 Mar 2002 17:02:42 -0000
Subject: [Tutor] Re: global vars vs. func args
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C433@mbtlipnt02.btlabs.bt.co.uk>

> Your response raises one question though -- what's 
> "refactor"?  

Its harder to explain than to show.
There is an example of refactoring in the Case Study on 
my web tutor.
Look at the section where we move to a GUI - we need to 
refactor the code to remove display features from 
processing functions... 

In general refactoring code is about taking existing code 
and reshaping it(splitting small reusable functions out 
from bigger ones, combining functions that are only called 
once or are trivial in nature etc) to produce cleaner, 
more maintainable/more reusable code.

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


From alan.gauld@bt.com  Tue Mar 12 17:10:12 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 12 Mar 2002 17:10:12 -0000
Subject: [Tutor] running a script from IDLE
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C434@mbtlipnt02.btlabs.bt.co.uk>

> z-plane. I'm going to call icosa.rotate(z=90) or something 
> similar. Before I tell the View to refresh itself, I want 
> to be sure that the Model has changed. How can I be sure 


The convention for this in Smalltalk is either to return self or to return
the value being set. Thus you get back whatever the attribute value is
*after* the operation. You can compare that to either the previous value of
the new one:

fZ = foo.getZ
if foo.setZ(42) == fZ: # failed

OR

if foo.setZ(47) == 47: # success...

As an aside,
Using a variable demonstrates why pure FP doesn't want you 
changing the incoming parameter:

bar = 52
if foo.setZ(bar) == bar: # only works if setZ didn't mess with bar!

Alan g


From alan.gauld@bt.com  Tue Mar 12 17:18:51 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 12 Mar 2002 17:18:51 -0000
Subject: [Tutor] RE: global vars vs. func args
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C435@mbtlipnt02.btlabs.bt.co.uk>

> > """If you have a procedure with ten parameters, you probably missed
> > some."""
> 
> Is this sarcasm, or seriousness?  

Serious sarcasm.
Most functions should have less than 10 params. If you have 
one with 10 the likeliehood is you should rethink the design. 
If you really, really do need 10 then the chances are that you 
will need even more that you didn't realize at the time, 
hence 'you probably missed some'.

> > """Think of all the psychic energy expended in seeking a fundamental
> > distinction between "algorithm" and "program"."""
> 
> I was wondering the very same thing.  An algorithm is like a 
> progam-within-a-program, isn't it?  I like this quote, if I'm 
> interpeting it correctly.

In the early days it was true. Today many programs encompass multiple
algorithms - think Microsoft Word - is that really 'an algorithm'?
But it certainly encompasses plenty of algorithms.

But if you look at traditional batch programs then they are 
mostly single algorithm programs so there is a valid (and 
essentially worthless) debate over the semantics.

> > """Interfaces keep things tidy, but don't accelerate 
> growth: Functions do."""
> 
> This one is a bit beyond me.  

Me too, I'm interested in an explanation coz I can think of 
several(contradictory) options!

Alan g


From alan.gauld@bt.com  Tue Mar 12 17:30:31 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 12 Mar 2002 17:30:31 -0000
Subject: [Tutor] printing
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C437@mbtlipnt02.btlabs.bt.co.uk>

> > You need to create a device context on the printer and 
> > draw the output using GDI commands. 
>
> What are GDI commands?

Graphical Device Interface (I think)

They are the low level windows display primitives like:

Circle(DC, centreX, Y, radius, fillColor, borderColor)

DrawText(DC, positionX, Y, someString, font, attributes)

That type of thing. Very arcane and very painful to use.

I strongly recommend using the HTML/PDF type route!

Alan G.


From rhseabrook@mail.aacc.cc.md.us  Tue Mar 12 17:43:39 2002
From: rhseabrook@mail.aacc.cc.md.us (Seabrook, Richard)
Date: Tue, 12 Mar 2002 12:43:39 -0500
Subject: [Tutor] RE: global vars vs. func args
Message-ID: <61A1404EB0BFC04D87020AA6B71441E281300E@aacc-mail1.aacc.cc.md.us>


-----Original Message-----
From: Kirby Urner [mailto:urnerk@qwest.net]
Sent: Tuesday, March 12, 2002 11:11 AM
To: Erik Price
Cc: tutor@python.org
Subject: Re: [Tutor] RE: global vars vs. func args


At 08:25 AM 3/12/2002 -0500, you wrote:

>Whoah -- some questions about those quotes!
>
>
>On Monday, March 11, 2002, at 10:05  PM, Danny Yoo wrote:
>
>>"""If you have a procedure with ten parameters, you probably
>>missed some."""
>
>Is this sarcasm, or seriousness?

It's a joke.  Ten would be considered very much on the
high side, for parameters, although you can easily pass
a single list -- that contains ten (or a thousand)
elements to be modified (but probably all in the same
way).

-------------------------------------------------------
Actually, in OO it's considered evidence of a design problem.
A function that requires lots of arguments is said to have
a "fat" interface -- it has to know about a lot of information
elsewhere in the model in order to do its work, and is therefore
heavily dependent on the programs that create that information.
Years ago, defining a window under the MS operating system required
a function call with 11 or 12 arguments that included most of the 
window's characteristics. I did my master's work under Windows 1.0-1.3 
and it was always a pain to get them all in and in the correct order.
Perhaps this has changed now.
Fortunately, Python gives us quite a bit more flexibility to design
our own information-passing schemes.
Dick S.


From SWidney@ci.las-vegas.nv.us  Tue Mar 12 17:46:09 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Tue, 12 Mar 2002 09:46:09 -0800
Subject: [Tutor] RE: global vars vs. func args
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F5A07@SOVEREIGN>

> > > """If you have a procedure with ten parameters, you 
> > > probably missed some."""
> > 
> > Is this sarcasm, or seriousness?  
> 
> Serious sarcasm.
> Most functions should have less than 10 params. If you have 
> one with 10 the likeliehood is you should rethink the design. 
> If you really, really do need 10 then the chances are that you 
> will need even more that you didn't realize at the time, 
> hence 'you probably missed some'.

An example of something that warrants myriad parameters is Tkinter; note,
though, that most arguments have default values.

Scott


From pythonhack@yahoo.com  Tue Mar 12 17:53:04 2002
From: pythonhack@yahoo.com (pythonhack@yahoo.com)
Date: Tue, 12 Mar 2002 09:53:04 -0800
Subject: [Tutor] python and MS Access db's
Message-ID: <1311096262902.20020312095304@yahoo.com>

I need to write a cgi for our company site that will receive input and
add the supplied information to an Access database.  i've searched the
web and haven't found much on how to do this.

can anybody point me in the right direction?

thanks!

brett


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com



From dyoo@hkn.eecs.berkeley.edu  Tue Mar 12 19:46:21 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 12 Mar 2002 11:46:21 -0800 (PST)
Subject: [Tutor] python and MS Access db's
In-Reply-To: <1311096262902.20020312095304@yahoo.com>
Message-ID: <Pine.LNX.4.21.0203121140470.32546-100000@hkn.eecs.berkeley.edu>

On Tue, 12 Mar 2002 pythonhack@yahoo.com wrote:

> I need to write a cgi for our company site that will receive input and
> add the supplied information to an Access database.  i've searched the
> web and haven't found much on how to do this.
> 
> can anybody point me in the right direction?

You may want to connect Python with Access though ODBC; ODBC is a generic
interface that many databases support.  Here's a page that gives hints on
doing this:

    http://www.python.org/windows/OdbcHints.html


I don't believe that the ODBC module comes with the Standard Library, but
you can find the ODBC module bundled with the Win32 package:

    http://www.python.org/windows/win32/


There's also an mxODBC module by the same people who made mxTextTools:

    http://www.lemburg.com/files/python/mxODBC.html

though I have to admit that I haven't used it yet.


Please feel free to ask more questions.  Good luck!



From wesc@deirdre.org  Tue Mar 12 20:03:19 2002
From: wesc@deirdre.org (wesc@deirdre.org)
Date: Tue, 12 Mar 2002 12:03:19 -0800 (PST)
Subject: [Tutor] ANN: SV-SF Bay Area Python user grp (BayPIGgies) mtg 3/13 7:30pm
Message-ID: <200203122003.MAA14260@alpha.ece.ucsb.edu>

just a quick reminder about the BayPIGgies event tomorrow evening...
hope to see some of you there!

also, we are placing a call-for-talks for this monthly event.  if you
are working on a Python project and want to get the word out, or if
you are a company producing products using Python and would like to
share how Python has helped you "get it done," this is a great way to
let everyone know.  if you are interested in giving a such talk at one
of our meetings, please contact me directly.

thanks!

-wesley



When:  March 13, 2002, 7:30-9pm
Where: Stanford University, Palo Alto, CA
Title: BioPython

Jeffrey Chang (School of Medicine, Stanford University) founded the
BioPython project in 1999 to promote the development of shared software
infrastructure in bioinformatics.  His talk will cover the architecture
and capabilities of Biopython and also give a sneak preview of the
upcoming version. 

Click on BayPIGgies link below for more info, including driving
directions, past meetings, schedule, etc.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

"Core Python Programming", Prentice Hall PTR, © 2001
    http://starship.python.net/crew/wesc/cpp/

Silicon Valley-San Francisco Bay Area Python Users Group (BayPIGgies)
    http://deirdre.org/baypiggies

wesley.j.chun :: wesc at deirdre.org
cyberweb.consulting : henderson, nv : cyberweb at rocketmail.com
http://roadkill.com/~wesc/cyberweb/



From israel@lith.com  Tue Mar 12 19:00:21 2002
From: israel@lith.com (Israel Evans)
Date: Tue, 12 Mar 2002 11:00:21 -0800
Subject: [Tutor] RE: [Pythonmac-SIG] Ming on Mac OS X
Message-ID: <AF020C5FC551DD43A4958A679EA16A15017B3FFC@abbott.lith.com>

If I remember correctly, Adobe GoLive and LiveMotion do both .swf and SMIL
and SVG so you may see more Designers becoming aware of these things.



~Israel~


-----Original Message-----
From: macnerd [mailto:macnerd@realmspace.com] 
Sent: 12 March 2002 10:29 AM
To: pythonmac-SIG@python.org
Subject: RE: [Pythonmac-SIG] Ming on Mac OS X

The question is, can you get graphic design folks
to program in SMIL and SVG, especially when so
few browsers support SMIL.  Is there any movement
to make a plug-in to SMIL, or support for conversion
to and fro SWF<->SMIL?!?

I hope more cool libraries can be made available
under Python for this support. :-)

> -----Original Message-----
> From: pythonmac-sig-admin@python.org
> [mailto:pythonmac-sig-admin@python.org]On Behalf Of Jack Jansen
> Sent: Tuesday, March 12, 2002 7:10 AM
> To: macnerd@dontspam.realmspace.com
> Cc: 'Hans verschooten'; pythonmac-SIG@python.org
> Subject: Re: [Pythonmac-SIG] Ming on Mac OS X
> 
> 
> 
> On Monday, March 11, 2002, at 08:00 , macnerd wrote:
> > I still have this lurking dream for someday a W3C XML
> > standard that would support an animation format that is
> > rich as Flash.
> 
> Just a moment while I borrow Guido's time machine....
> 
> [>POOF<]
> 
> Have a look at the SVG standard. With the SMIL timing in 
> there it should 
> allow you to do most things that you can do in flash.
> --
> - Jack Jansen        <Jack.Jansen@oratrix.com>        
> http://www.cwi.nl/~jack -
> - If I can't dance I don't want to be part of your revolution -- Emma 
> Goldman -
> 
> 
> _______________________________________________
> Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig
> 

_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


From van@lindbergs.org  Tue Mar 12 19:58:42 2002
From: van@lindbergs.org (VanL)
Date: Tue, 12 Mar 2002 12:58:42 -0700
Subject: [Tutor] Dicts and classes
Message-ID: <3C8E5DF2.3030809@lindbergs.org>

Hello,

If I understand correctly, a class is more or less a dict with a little 
special sauce thrown in.

Thus, can I assign to a class like I would a dict?  Get a list of members?

For example, this doesn't seem very pythonic:

class customer:
    def __init__(self, name, lastname, address, address2, email, phone, 
areacode, fax, faxarea .....):
         self.name = name
         self.lastname = lastname
         self.address = address
         self.address= address2
[snip]
    def changename(self, name): self.name = name
    def changelastname(self, name): self.lastname = name
[snip]
     def printname(self): print self.name


I have exaggerated here, but you get the idea.
Is there any way to do this:

class customer:
    def __init__(self, info):
        for k in info.keys(): self.k = info[k]
    def change(self, name, value):
        self.name = value
    def print(self, name):
        print self.name

and even:

bob = customer({'name':'Bob', 'lastname':'Jones','phone':'555-1234'})
for member in bob.keys(): print bob.member

or finally:
print 'Customer: %(name)s %(lastname)s' % bob



From sheila@thinkspot.net  Tue Mar 12 23:22:46 2002
From: sheila@thinkspot.net (Sheila King)
Date: Tue, 12 Mar 2002 15:22:46 -0800
Subject: [Tutor] Dicts and classes
In-Reply-To: <3C8E5DF2.3030809@lindbergs.org>
References: <3C8E5DF2.3030809@lindbergs.org>
Message-ID: <86A29A7EE2@kserver.org>

On Tue, 12 Mar 2002 12:58:42 -0700, VanL <van@lindbergs.org>  wrote about
[Tutor] Dicts and classes:

> Hello,
> 
> If I understand correctly, a class is more or less a dict with a little 
> special sauce thrown in.

Well, a class needn't necessarily have anything to do with a dict, although
it may.

> Thus, can I assign to a class like I would a dict?  Get a list of members?
> 
> For example, this doesn't seem very pythonic:
> 
> class customer:
>     def __init__(self, name, lastname, address, address2, email, phone, 
> areacode, fax, faxarea .....):
>          self.name = name
>          self.lastname = lastname
>          self.address = address
>          self.address= address2
> [snip]
>     def changename(self, name): self.name = name
>     def changelastname(self, name): self.lastname = name
> [snip]
>      def printname(self): print self.name
> 

You don't have to write a function to change the name. You can just do
this:

>>> class customer:
	def __init__(self, name, lastname, address, address2, areacode):
		self.name = name
		self.lastname = lastname
		self.address = address
		self.address2 = address2
		self.areacode = areacode

		
>>> bob = customer('bob', 'smith', '1122 boulevard st', 'springfield, GA', '320')
>>> bob.areacode
'320'
>>> bob.areacode = '321'
>>> bob.areacode
'321'
>>> 

So you don't have to write a function for changing each of these values.
Just change it by an assignment statement.

As for printing...

You don't necessarily have to write a function to handle this. You can just
print out the separate values, like this:

>>> print bob.name
bob
>>> 

However, it might be nice to have a way of asking a customer to print
itself, and have it come out nicely formatted. What about this:

class customer:
    def __init__(self, name, lastname, address, address2, areacode):
        self.name = name
        self.lastname = lastname
        self.address = address
        self.address2 = address2
        self.areacode = areacode

    def __str__(self):
        mystring = "%s,%s\n%s\n%s\n%s" % \
            (self.lastname, self.name, self.address,
             self.address2, self.areacode)
        return mystring


bob = customer('Bob', 'Smith', '1122 Boulevard St.', 'Springfield, GA',\
	 '320')
print bob



When I run the above code, I get:

Smith,Bob
1122 Boulevard St.
Springfield, GA
320

> I have exaggerated here, but you get the idea.
> Is there any way to do this:
> 
> class customer:
>     def __init__(self, info):
>         for k in info.keys(): self.k = info[k]
>     def change(self, name, value):
>         self.name = value
>     def print(self, name):
>         print self.name
> 
> and even:
> 
> bob = customer({'name':'Bob', 'lastname':'Jones','phone':'555-1234'})
> for member in bob.keys(): print bob.member
> 
> or finally:
> print 'Customer: %(name)s %(lastname)s' % bob


How about this? (Although I'm not sure I prefer it to the first version
that doesn't use dicts)

class customer:
    def __init__(self, infodict):
        self.info = infodict

    def __str__(self):
        mystring = "%s,%s\n%s\n%s\n%s" % \
            (self.info['lastname'], self.info['name'],
             self.info['address'],
             self.info['address2'], self.info['areacode'])
        return mystring


bob_dict = {'name':'Bob', 'lastname':'Smith',
       'address': '1122 Boulevard St.',
       'address2': 'Springfield, GA',
       'areacode': '302'}

bob = customer(bob_dict)
print bob


When I run it, I get the same output as I showed in the previous version:

Smith,Bob
1122 Boulevard St.
Springfield, GA
302


Does this help any?

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/



From Scott Kurland" <skurland@juggler.net  Tue Mar 12 23:09:46 2002
From: Scott Kurland" <skurland@juggler.net (Scott Kurland)
Date: Tue, 12 Mar 2002 17:09:46 -0600
Subject: [Tutor] Please, why isn't this program working?
Message-ID: <000501c1ca1b$01bebe10$48905a42@emachine>

#Searching for perfect numbers

howhigh= input ("How high should I check?")
for number in range (1,howhigh):
 factorsum = 0
 halfnumber=number/2
 for checking in range (1,halfnumber):
  if number/checking == int (number/checking):
   factorsum = factorsum + checking
 if number == factorsum:
  print number
  



"Quemadmodum gladius neminem occidit, occidentis telum est." 
-- Seneca





From charlie@begeistert.org  Tue Mar 12 22:54:00 2002
From: charlie@begeistert.org (Charlie Clark)
Date: Tue, 12 Mar 2002 23:54:00 +0100
Subject: [Tutor] urllib & client side cookies
In-Reply-To: <E16kpeJ-0002jq-00@mail.python.org>
References: <E16kpeJ-0002jq-00@mail.python.org>
Message-ID: <20020313002848.1960.3@gormenghast.AUTODIAL>

s far as I've so far been able to gather, Python's cookie module only really supports server-side cookies. But my current project requires that I set a client-side cookie.

Google came up with a very good presentation by Moshe Zadke at Python 9
http://www.python9.org/p9-zadka.ppt
or in staight HTML
http://www.google.de/search?q=cache:CZr5DdjK6zwC:www.python9.org/p9-zadka.ppt

which includes a couple of examples which I've tried to learn from:

The example source is:

import urllib, string 
agent = urllib.URLopener() 
d = {
         'u':  'moshez',
         'pass': 'not my real password'
} 
u = agent.open('http://advogato.org/acct/loginsub.html',
               urllib.urlencode(d))
cookie = u.info()['set-cookie']
cookie = cookies[string.find(cookie, ';')]
agent.addheader('Cookie', cookie)
d = {
         'entry': open('entry').read(),
         'post': 'Post'
} 
u = agent.open('http://advogato.org/diary/post.html',
                         urllib.urlencode(d))

This won't run out of the box, not just because of the invalid Password but also because of typo.
line 7 should read:
cookies = u.info()['set-cookie']
line 8 had me foxed for a while as it, too
cookie = cookies[:cookie.find(';')]
this is a not so obvious slice = cookies.split(";")[0] which is more readable for me

Oh, well now that those little problems are over. Does it work?
Well, it does get my cookie for me but I don't seem to be able to use use the cookie correctly. This is great because it means I can get some work done without having to become an expert on http first.

Steve Purcell has already made the web-unit module available for working with cookies but it seems to require more detailed knowledge of http than i currently have :-(.

Here's my script

import urllib
agent = urllib.URLopener()

u = agent.open("http://localhost/login.jsp")
cookies = u.info()['set-cookie']

cookie = cookie.split(';')[0]
cookie = cookie.lower()
# need the cookie to be lowercase for some reason
print cookie
agent.addheader('Cookie', cookie)

d = {'page':'firstpage', 'password':'my_password'} 
##u = agent.open("http://localhist/login_trx.jsp",urllib.urlencode(d))
u = agent.open("http://localhist/login_trx.jsp?page=16password=my_password;" + cookie)
content = u.read()

This does get me my cookie which I was able to test in a brower session but my python script gives me the following error:

JSESSIONID=ke334pszf1
[('User-agent', 'Python-urllib/1.15')]
Traceback (most recent call last):
  File "D:\spider\cookie_test.py", line 19, in ?
    u = agent.open("http://192.168.103.26/login_trx.jsp?institution=3&kennwort=preentry;" + cookie)
  File "C:\Python21\lib\urllib.py", line 176, in open
    return getattr(self, name)(url)
  File "C:\Python21\lib\urllib.py", line 296, in open_http
    return self.http_error(url, fp, errcode, errmsg, headers)
  File "C:\Python21\lib\urllib.py", line 313, in http_error
    return self.http_error_default(url, fp, errcode, errmsg, headers)
  File "C:\Python21\lib\urllib.py", line 319, in http_error_default
    raise IOError, ('http error', errcode, errmsg, headers)
IOError: ('http error', 302, 'Found', <mimetools.Message instance at 00A6D2D4>)

I'm not quite sure what the error message means which I'm getting back. I assume I'm getting something sent back by the server which I need to process but I think I might also not quite be sending the cookie in the right form.

I'm very much appreciate any help on getting this sorted. It's all part of the usual Sisyphus work but still has to get done.

Charlie


From dyoo@hkn.eecs.berkeley.edu  Tue Mar 12 23:43:12 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 12 Mar 2002 15:43:12 -0800 (PST)
Subject: [Tutor] Dicts and classes   [Attribute access using methods]
In-Reply-To: <86A29A7EE2@kserver.org>
Message-ID: <Pine.LNX.4.21.0203121527320.5489-100000@hkn.eecs.berkeley.edu>

On Tue, 12 Mar 2002, Sheila King wrote:

> > [snip]
> >     def changename(self, name): self.name = name
> >     def changelastname(self, name): self.lastname = name
> > [snip]
> >      def printname(self): print self.name
> > 
> 
> You don't have to write a function to change the name. You can just do
> this:
> 
> >>> class customer:
> 	def __init__(self, name, lastname, address, address2, areacode):
> 		self.name = name
> 		self.lastname = lastname
> 		self.address = address
> 		self.address2 = address2
> 		self.areacode = areacode
> 
> 		
> >>> bob = customer('bob', 'smith', '1122 boulevard st', 
>                    'springfield, GA', '320')
> >>> bob.areacode
> '320'
> >>> bob.areacode = '321'
> >>> bob.areacode
> '321'


At the same time, it might be useful to touch attributes only through a
method, because that gives us the ability to do some pre-validation of the
input.  For example, if we did something like:

###
def changename(self, name): self.name = name.strip()
###

then we guarantee that, as long as we don't fiddle with the instance
attributes by hand, that all names in a customer are stripped() of
extraneous whitespace.

For simple classes, like a Customer, forcing all attributes to be accessed
through methods is a bit onerous to write.  But for more complicated
structures, we may want to make sure that instance attributes have certain
constraints that we can control.


[Side note 1:  Java concept of Javabeans is very much an agreement that
all attribute access is done through method calls.]



[Side note 2:  Python 2.2 New Style Classes actually makes this "direct
attribute access vs methods" a nonissue altogether, since attribute access
actually may trigger a method call.  See:

    http://www.python.org/2.2/descrintro.html#property

for more details on these Properties.]


Good luck!



From sheila@thinkspot.net  Wed Mar 13 00:09:41 2002
From: sheila@thinkspot.net (Sheila King)
Date: Tue, 12 Mar 2002 16:09:41 -0800
Subject: [Tutor] Dicts and classes   [Attribute access using methods]
In-Reply-To: <Pine.LNX.4.21.0203121527320.5489-100000@hkn.eecs.berkeley.edu>
References: <86A29A7EE2@kserver.org> <Pine.LNX.4.21.0203121527320.5489-100000@hkn.eecs.berkeley.edu>
Message-ID: <B1AFBD1429@kserver.org>

On Tue, 12 Mar 2002 15:43:12 -0800 (PST), Danny Yoo
<dyoo@hkn.eecs.berkeley.edu>  wrote about Re: [Tutor] Dicts and classes
[Attribute access using methods]:

> On Tue, 12 Mar 2002, Sheila King wrote:
> 
> > > [snip]
> > >     def changename(self, name): self.name = name
> > >     def changelastname(self, name): self.lastname = name
> > > [snip]
> > >      def printname(self): print self.name
> > 
> > You don't have to write a function to change the name. You can just do
> > this:

[code snip]

> > >>> bob.areacode
> > '320'
> > >>> bob.areacode = '321'
> > >>> bob.areacode
> > '321'
> 
> At the same time, it might be useful to touch attributes only through a
> method, because that gives us the ability to do some pre-validation of the
> input.  

Good point. 

> For simple classes, like a Customer, forcing all attributes to be accessed
> through methods is a bit onerous to write.  But for more complicated
> structures, we may want to make sure that instance attributes have certain
> constraints that we can control.

Yes, in fact, for more complicated access, I usually access the class
instances via methods myself. I guess I was just looking at this simple
little tutorial-style question, and thinking in much simpler and quicker
code, but the original question certainly hints at the idea of extending it
to a much bigger application. So, your comments are very appropriate here.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/



From urnerk@qwest.net  Wed Mar 13 00:23:09 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Tue, 12 Mar 2002 16:23:09 -0800
Subject: [Tutor] Dicts and classes
In-Reply-To: <3C8E5DF2.3030809@lindbergs.org>
Message-ID: <4.2.0.58.20020312161209.00d1e3d0@pop3.norton.antivirus>

>
>I have exaggerated here, but you get the idea.
>Is there any way to do this:
>
>class customer:
>    def __init__(self, info):
>        for k in info.keys(): self.k = info[k]
>    def change(self, name, value):
>        self.name = value
>    def print(self, name):
>        print self.name
>

  >>> class Myclass:
         def __init__(self, **entries):
            self.__dict__.update(entries)
         def change(self,**kw):
            self.__dict__.update(kw)
         def prn(self,name):
            print "Name: %s  Value: %s" %(name, self.__dict__[name])


  >>> obj = Myclass(joe=3,simple=1,make=[1,2])
  >>> obj.prn('joe')
  Name: joe  Value: 3
  >>> obj.change(joe=10)
  >>> obj.joe
  10
  >>> obj.change(joe=7,simple=15)
  >>> obj.simple
  15
  >>> obj.joe
  7

Kirby



From dyoo@hkn.eecs.berkeley.edu  Wed Mar 13 00:36:28 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 12 Mar 2002 16:36:28 -0800 (PST)
Subject: [Tutor] Please, why isn't this program working?
In-Reply-To: <000501c1ca1b$01bebe10$48905a42@emachine>
Message-ID: <Pine.LNX.4.21.0203121543310.5489-100000@hkn.eecs.berkeley.edu>

On Tue, 12 Mar 2002, Scott Kurland wrote:

> #Searching for perfect numbers
> 
> howhigh= input ("How high should I check?")
> for number in range (1,howhigh):
>  factorsum = 0
>  halfnumber=number/2
>  for checking in range (1,halfnumber):
>   if number/checking == int (number/checking):

Hi Scott,

Division in Python (and in other programming languages), can be a little
tricky.  In a division like:

    x / y

If 'x' and 'y' are both integers, then what comes out of the division is
truncated as an integer.  As long as either x or y are floats, Python
won't truncate the result.  Knowing this, we can fix the problem like
this:

###
if number/float(checking) == int(number/float(checking)):
###


However, it looks like you're trying to find if 'number' is divisible by
'checking'.  If so, we can do this more simply by using the remainder or
"modulus" operator:

###
## if the remainder is zero, then number is divisible by checking:
if number % checking == 0:
    ## do the stuff here
###

which is a little simpler to write.


Hopefully, that should fix those problems.  Good luck!



From SWidney@ci.las-vegas.nv.us  Wed Mar 13 01:42:54 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Tue, 12 Mar 2002 17:42:54 -0800
Subject: [Tutor] Dicts and classes
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F5A0F@SOVEREIGN>

> >class customer:
> >    def __init__(self, info):
> >        for k in info.keys(): self.k = info[k]
> >    def change(self, name, value):
> >        self.name = value
> >    def print(self, name):
> >        print self.name
> >
> 
>   >>> class Myclass:
>          def __init__(self, **entries):
>             self.__dict__.update(entries)
>          def change(self,**kw):
>             self.__dict__.update(kw)
>          def prn(self,name):
>             print "Name: %s  Value: %s" %(name, self.__dict__[name])
> 
> 
>   >>> obj = Myclass(joe=3,simple=1,make=[1,2])
>   >>> obj.prn('joe')
>   Name: joe  Value: 3
>   >>> obj.change(joe=10)
>   >>> obj.joe
>   10
>   >>> obj.change(joe=7,simple=15)
>   >>> obj.simple
>   15
>   >>> obj.joe
>   7

I once read somewhere that "everything in Python is an object", but
"everything is implemented as a dictionary". True?


Scott


From paulsid@shaw.ca  Wed Mar 13 03:43:10 2002
From: paulsid@shaw.ca (Paul Sidorsky)
Date: Tue, 12 Mar 2002 20:43:10 -0700
Subject: [Tutor] Dicts and classes
References: <3C8E5DF2.3030809@lindbergs.org> <86A29A7EE2@kserver.org>
Message-ID: <3C8ECACE.B44AE48F@shaw.ca>

Sheila King wrote:


> So you don't have to write a function for changing each of these values.
> Just change it by an assignment statement.
> 
> As for printing...
> 
> You don't necessarily have to write a function to handle this. You can just
> print out the separate values, like this:

And here we see yet another great thing about Python, and its people. 
Try making the above suggestions in the C++ or Java communities and see
what happens!  :-)

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/


From alan.gauld@bt.com  Wed Mar 13 10:53:03 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 13 Mar 2002 10:53:03 -0000
Subject: [Tutor] Please, why isn't this program working?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C43A@mbtlipnt02.btlabs.bt.co.uk>

>>> for number in range (1,howhigh):
...   factorsum = 0
...   halfnumber=number/2
...   for checking in range (1,halfnumber):
...    if (number/checking) == int (number/checking):
...     factorsum = factorsum + checking
...   print howhigh, factorsum, number, halfnumber
...   if number == factorsum:
...    print number
...
...
7 0 1 0
7 0 2 1
7 0 3 1
7 1 4 2
7 1 5 2
7 3 6 3
>>>  

Thats what it did for me. What were you expecting exactly?

BTW
When posting its a good idea to say what you expected to happen 
and what actually happened rather than just posying code and 
asking us to try it out just to see...

If there is an error trace post that too.

Alan g.


From pythontutor@venix.com  Wed Mar 13 13:36:02 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Wed, 13 Mar 2002 08:36:02 -0500
Subject: [Tutor] Dicts and classes
References: <3C8E5DF2.3030809@lindbergs.org>
Message-ID: <3C8F55C2.4030308@venix.com>

Kirby's examples are wonderfully concise, but you might have overlooked the
setattr and getattr functions which are also possible solutions.

VanL wrote:

> Is there any way to do this:
> 
> class customer:
>    def __init__(self, info):
>        for k in info.keys(): self.k = info[k]

Works if info is a dictionary.
(Again, see Kirby's examples for clever alternatives.)


>    def change(self, name, value):
>        self.name = value

	setattr(self, name, value)


>    def print(self, name):
>        print self.name

	print getattr(self, name)


> 
> and even:
> 
> bob = customer({'name':'Bob', 'lastname':'Jones','phone':'555-1234'})
> for member in bob.keys(): print bob.member

	for member in bob.__dict__.keys(): print getattr(bob, member)


> 
> or finally:
> print 'Customer: %(name)s %(lastname)s' % bob

	print 'Customer: %(name)s %(lastname)s' % bob.__dict__

-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582



From scarblac@pino.selwerd.nl  Wed Mar 13 13:49:15 2002
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 13 Mar 2002 14:49:15 +0100
Subject: [Tutor] Dicts and classes
In-Reply-To: <3C8E5DF2.3030809@lindbergs.org>; from van@lindbergs.org on Tue, Mar 12, 2002 at 12:58:42PM -0700
References: <3C8E5DF2.3030809@lindbergs.org>
Message-ID: <20020313144915.A16475@pino.selwerd.nl>

I was surprised to see a whole thread after your post, and no-one had the
simple answer to your questions... use getattr() and setattr(). 

On  0, VanL <van@lindbergs.org> wrote:
> If I understand correctly, a class is more or less a dict with a little 
> special sauce thrown in.

Sort of, yes. That is, a class instance is implemented using a dictionary.

> Thus, can I assign to a class like I would a dict?  Get a list of members?

The class' dict is in its .__dict__, but you don't want to touch that.

Your examples below work fine if you use getattr() and setattr().

I'll snip a bit...

> I have exaggerated here, but you get the idea.
> Is there any way to do this:
> 
> class customer:
>     def __init__(self, info):
>         for k in info.keys(): self.k = info[k]
>     def change(self, name, value):
>         self.name = value
>     def print(self, name):
>         print self.name

Yes, like:

class customer:
   def __init__(self, info):
      for k in info.keys(): setattr(self, k, info[k])
   def change(self, name, value):
      setattr(self, name, value)
   def print(self, name):
      print getattr(self, name)

> and even:
> 
> bob = customer({'name':'Bob', 'lastname':'Jones','phone':'555-1234'})
> for member in bob.keys(): print bob.member

Yes, with:

for member in bob.keys(): print getattr(bob, member)

> or finally:
> print 'Customer: %(name)s %(lastname)s' % bob

Yes, if you add a __getitem__ method to the class:

  def __getitem__(self, name):
     return getattr(self, name)


Instead of all of this, you can of course just store a dictionary in the
class (like self.info) as well. But this sort of thing is very easy in
Python :)

-- 
Remco Gerlich


From rickp@telocity.com  Wed Mar 13 14:17:48 2002
From: rickp@telocity.com (Rick Pasotto)
Date: Wed, 13 Mar 2002 09:17:48 -0500
Subject: [Tutor] Dicts and classes
In-Reply-To: <20020313144915.A16475@pino.selwerd.nl>
References: <3C8E5DF2.3030809@lindbergs.org> <20020313144915.A16475@pino.selwerd.nl>
Message-ID: <20020313141748.GF575@tc.niof.net>

On Wed, Mar 13, 2002 at 02:49:15PM +0100, Remco Gerlich wrote:
> I was surprised to see a whole thread after your post, and no-one had the
> simple answer to your questions... use getattr() and setattr(). 

How does doing this differ from creating a subclass of UserDict?

class MyClass(UserDict):
	pass

-- 
"If a thousand men were not to pay their tax bills, that would not be so
 violent and bloody a measure as it would be to pay them and enable the
 state to commit violence and shed innocent blood." - Henry David Thoreau
    Rick Pasotto    rickp@telocity.com    http://www.niof.net


From scarblac@pino.selwerd.nl  Wed Mar 13 14:22:21 2002
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 13 Mar 2002 15:22:21 +0100
Subject: [Tutor] Dicts and classes
In-Reply-To: <20020313141748.GF575@tc.niof.net>; from rickp@telocity.com on Wed, Mar 13, 2002 at 09:17:48AM -0500
References: <3C8E5DF2.3030809@lindbergs.org> <20020313144915.A16475@pino.selwerd.nl> <20020313141748.GF575@tc.niof.net>
Message-ID: <20020313152221.A16633@pino.selwerd.nl>

On  0, Rick Pasotto <rickp@telocity.com> wrote:
> On Wed, Mar 13, 2002 at 02:49:15PM +0100, Remco Gerlich wrote:
> > I was surprised to see a whole thread after your post, and no-one had the
> > simple answer to your questions... use getattr() and setattr(). 
> 
> How does doing this differ from creating a subclass of UserDict?
> 
> class MyClass(UserDict):
> 	pass

That's possible too, of course. But it doesn't do the same thing exactly;
if you do

x = UserDict()
x["foo"] = "bar"

Then x.foo still doesn't exist, the value has instead been added to a
dictionary that the instance holds.

If you have a class with many member variables you may well want to set them
from a loop in __init__ using setattr(), but still use them in other methods
by referring to them as self.varname, as usual. Having to use
self["varname"] everywhere would be awkward.

-- 
Remco Gerlich


From apython101@yahoo.com  Wed Mar 13 21:30:11 2002
From: apython101@yahoo.com (john public)
Date: Wed, 13 Mar 2002 13:30:11 -0800 (PST)
Subject: [Tutor] dir
Message-ID: <20020313213011.36730.qmail@web21107.mail.yahoo.com>

--0-1167446793-1016055011=:35981
Content-Type: text/plain; charset=us-ascii


I typed:

>>>dir(_builtins_)

in IDLE then hit return. I was expecting to get a list of the built in modules in python. As shown in chapter 8 on modules in learning Python. I got an error message stating that builtins were not defined. What did I do wrong?

John Q. Public



---------------------------------
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
--0-1167446793-1016055011=:35981
Content-Type: text/html; charset=us-ascii

<P>I typed:</P>
<P>&gt;&gt;&gt;dir(_builtins_)</P>
<P>in IDLE then hit return. I was expecting to get a list of the built in modules in python. As shown in chapter 8 on modules in learning Python. I got an error message stating that builtins were not defined. What did I do wrong?</P>
<P>John Q. Public</P><p><br><hr size=1><b>Do You Yahoo!?</b><br>
Try FREE <a href="$rd_url/tag/http://mail.yahoo.com/">Yahoo! Mail</a> - the world's greatest free email!
--0-1167446793-1016055011=:35981--


From shalehperry@attbi.com  Wed Mar 13 21:49:57 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Wed, 13 Mar 2002 13:49:57 -0800 (PST)
Subject: [Tutor] dir
In-Reply-To: <20020313213011.36730.qmail@web21107.mail.yahoo.com>
Message-ID: <XFMail.20020313134957.shalehperry@attbi.com>

On 13-Mar-2002 john public wrote:
> 
> I typed:
> 
>>>>dir(_builtins_)
> 
> in IDLE then hit return. I was expecting to get a list of the built in
> modules in python. As shown in chapter 8 on modules in learning Python. I got
> an error message stating that builtins were not defined. What did I do wrong?
> 

yay for meaningless anonymity (-:

it is __builtins__ (two '_' on each side).

In python one underscore means "I am a private, you should not use me".  Two of
them means "I am private to python and should probably not be used unless the
docs say to do so".


From apython101@yahoo.com  Wed Mar 13 22:00:33 2002
From: apython101@yahoo.com (john public)
Date: Wed, 13 Mar 2002 14:00:33 -0800 (PST)
Subject: [Tutor] search
Message-ID: <20020313220033.58744.qmail@web21106.mail.yahoo.com>

--0-204471641-1016056833=:58428
Content-Type: text/plain; charset=us-ascii


Is it possible to do a keyword search in the tutor archives? For say like cookies or tkinter?

John Q public 



---------------------------------
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
--0-204471641-1016056833=:58428
Content-Type: text/html; charset=us-ascii

<P>Is it possible to do a keyword search in the tutor archives? For say like cookies or tkinter?</P>
<P>John Q public&nbsp;</P><p><br><hr size=1><b>Do You Yahoo!?</b><br>
Try FREE <a href="$rd_url/tag/http://mail.yahoo.com/">Yahoo! Mail</a> - the world's greatest free email!
--0-204471641-1016056833=:58428--


From apython101@yahoo.com  Wed Mar 13 20:56:58 2002
From: apython101@yahoo.com (john public)
Date: Wed, 13 Mar 2002 12:56:58 -0800 (PST)
Subject: [Tutor] builltins
Message-ID: <20020313205658.95342.qmail@web21110.mail.yahoo.com>

--0-1902544353-1016053018=:92673
Content-Type: text/plain; charset=us-ascii


I am using python2.1.1 and when I type in 

>>> dir(_builtins_) 

in IDLE and hit return I get an error message saying that builtins is not defined.

I was expecting a list of the builtin modules as shown in chapter 8 in learning Python.

What did I do wrong?

 



---------------------------------
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
--0-1902544353-1016053018=:92673
Content-Type: text/html; charset=us-ascii

<P>I am using python2.1.1 and when I type in </P>
<P>&gt;&gt;&gt; dir(_builtins_) </P>
<P>in IDLE and hit return I get an error message saying that builtins is not defined.</P>
<P>I was expecting a list of the builtin modules as shown in chapter 8 in learning Python.</P>
<P>What did I do wrong?</P>
<P>&nbsp;</P><p><br><hr size=1><b>Do You Yahoo!?</b><br>
Try FREE <a href="$rd_url/tag/http://mail.yahoo.com/">Yahoo! Mail</a> - the world's greatest free email!
--0-1902544353-1016053018=:92673--


From dyoo@hkn.eecs.berkeley.edu  Wed Mar 13 22:37:01 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed, 13 Mar 2002 14:37:01 -0800 (PST)
Subject: [Tutor] search
In-Reply-To: <20020313220033.58744.qmail@web21106.mail.yahoo.com>
Message-ID: <Pine.LNX.4.21.0203131413360.454-100000@hkn.eecs.berkeley.edu>

On Wed, 13 Mar 2002, john public wrote:

> Is it possible to do a keyword search in the tutor archives? For say
> like cookies or tkinter?

Yes, we can use the ActiveState archives of Tutor:

    http://aspn.activestate.com/ASPN/Mail/Browse/Threaded/python-Tutor


Also, google appears to be fairly accurate if we give it the right
keywords:


    http://google.com/search?hl=en&q=python+cookies
    http://google.com/search?hl=en&q=python+tkinter

comes up with remarkably close matches.



Hope this helps!



From SWidney@ci.las-vegas.nv.us  Wed Mar 13 22:36:04 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Wed, 13 Mar 2002 14:36:04 -0800
Subject: [Tutor] builltins
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F5A14@SOVEREIGN>

> I am using python2.1.1 and when I type in 
> >>> dir(_builtins_) 
> in IDLE and hit return I get an error message saying that 
> builtins is not defined.
> I was expecting a list of the builtin modules as shown in 
> chapter 8 in learning Python.
> What did I do wrong?
> 

You should use two (2) underscores preceding and following 'builtins'. Take
a look:

PythonWin 2.1.1 (#20, Jul 26 2001, 11:38:51) [MSC 32 bit (Intel)] on win32.
Portions Copyright 1994-2001 Mark Hammond (MarkH@ActiveState.com) - see
'Help/About PythonWin' for further copyright information.
>>> dir(__builtins__)
['ArithmeticError', 'AssertionError', 'AttributeError',
'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError',
'Exception', 'FloatingPointError', 'IOError', 'ImportError',
'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt',
'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented',
'NotImplementedError', 'OSError', 'OverflowError', 'RuntimeError',
'RuntimeWarning', 'StandardError', 'SyntaxError', 'SyntaxWarning',
'SystemError', 'SystemExit', 'TabError', 'TypeError', 'UnboundLocalError',
'UnicodeError', 'UserWarning', 'ValueError', 'Warning', 'WindowsError',
'ZeroDivisionError', '__debug__', '__doc__', '__import__', '__name__',
'abs', 'apply', 'buffer', 'callable', 'chr', 'cmp', 'coerce', 'compile',
'complex', 'copyright', 'credits', 'delattr', 'dir', 'divmod', 'eval',
'execfile', 'exit', 'filter', 'float', 'getattr', 'globals', 'hasattr',
'hash', 'help', 'hex', 'id', 'input', 'int', 'intern', 'isinstance',
'issubclass', 'len', 'license', 'list', 'locals', 'long', 'map', 'max',
'min', 'oct', 'open', 'ord', 'pow', 'quit', 'range', 'raw_input', 'reduce',
'reload', 'repr', 'round', 'setattr', 'slice', 'str', 'tuple', 'type',
'unichr', 'unicode', 'vars', 'xrange', 'zip']
>>> 

Enjoy!

Scott


From arcege@speakeasy.net  Thu Mar 14 00:19:31 2002
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Wed, 13 Mar 2002 19:19:31 -0500
Subject: [Tutor] Installing tkinter
In-Reply-To: <41256B79.003573BC.00@esahqmail3.hq.esa.int>
References: <41256B79.003573BC.00@esahqmail3.hq.esa.int>
Message-ID: <20020314001931.GB1505@speakeasy.net>

On Mon, Mar 11, 2002 at 11:07:24AM +0100, Felix.Toran@esa.int wrote:
> Hi all!
> 
> I have downloaded ActivePython and ActiveTcl for Solaris 2.6. After installing
> the products, my python scripts run nice, but those containing calls to the
> tkinter module present problems.
> 
> I have tried to write:  import _tkinter at python (as indicated in a FAQ in
> www.python.org), and an excepcion is thrown, reporting:
> 
> Import error: ld.so.1: /usr/local/ActivePython-2.1/bin/python2.1 : fatal :
> libtk8.3.so : open failed : no such file or directory
> 
> 
> I am really new to Solaris. Please, can someone help me solving this problem?
> Thanks a lot in advance.
> Felix.

I have no experience with ActivePython or ActiveTcl, but it
sounds like the installations didn't get install in the default
locations.  Most things on UNIX end up going in /usr/local, not
/usr/local/ActivePython-2.1.  I think that maybe ActiveTcl would be
in /usr/local/ActiveTcl-X.X.  Find out where Tcl was installed and
set LD_LIBRARY_PATH to the directory where the *.so file is.

$ find /usr/local -name libtk8.3.so -print
/usr/local/ActiveTcl-8.3/lib/libtk8.3.so
$ env LD_LIBRARY_PATH=/usr/local/ActiveTcl-X.X/lib \
/usr/local/ActivePython-2.1/bin/python2.1
>>> import _tkinter

Good luck.
  -Arcege



From apython101@yahoo.com  Thu Mar 14 16:54:25 2002
From: apython101@yahoo.com (john public)
Date: Thu, 14 Mar 2002 08:54:25 -0800 (PST)
Subject: [Tutor] telling dir(_builtins_) from dir(__builtins__)
Message-ID: <20020314165425.84186.qmail@web21107.mail.yahoo.com>

--0-937614337-1016124865=:82886
Content-Type: text/plain; charset=us-ascii


How in the heck is a Newwbie to know  dir(_builtins_) from dir(__builtins__)?!? both look like one hypen to me. One's just longer than the other. I just assumed it was a difference between the type on my machine and the type in the O'riely book. I have been working in Alan Gaulds book and looking a bit in Learning Python and programming Python and don't recall reading about this distinction. I am sure glad I can ask you guys questions. This is exactly the kind of tedious dotting your I's and crossing your T's that drove me nuts years ago when I tried to learn basic but gave up. So far this is the first thing I have found like this in Python. I have actually been amazed at how easy it is compared to C++ which I worked at for 2 months and got relatively nowhere by comparison. I am sure glad Barry Warsaw steered me towards Python.

 THANKS BARRRRRY!!

 I can't remember how I found Barry's Web page but I am sure glad I did. Anyway if someone has a list of visually misleading things like this in Python please send me the link.

Thankzzz



---------------------------------
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage
--0-937614337-1016124865=:82886
Content-Type: text/html; charset=us-ascii

<P>How in the heck is a Newwbie to know&nbsp; dir(_builtins_) from dir(__builtins__)?!? both look like one hypen to me. One's just longer than the other. I just assumed it was a difference between the type on my machine and the type in the O'riely book. I have been working in Alan Gaulds book and looking a bit in Learning Python and programming Python and don't recall reading about this distinction. I am sure glad I can ask you guys questions. This is exactly the kind of tedious dotting your&nbsp;I's and crossing your T's that drove me nuts years ago when I tried to learn basic but gave up. So far this is the first thing I have found like this in Python. I have actually been amazed at how easy it is compared to C++ which I worked at for 2 months and got relatively nowhere by comparison. I am sure glad Barry Warsaw steered me towards Python.</P>
<P>&nbsp;THANKS BARRRRRY!!</P>
<P>&nbsp;I can't remember how I found Barry's Web page but I am sure glad I did. Anyway if someone has a list of visually misleading things like this in Python please send me the link.</P>
<P>Thankzzz</P><p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href="$rd_url/tag/http://sports.yahoo.com/">Yahoo! Sports</a> - live college hoops coverage
--0-937614337-1016124865=:82886--


From apython101@yahoo.com  Thu Mar 14 16:59:00 2002
From: apython101@yahoo.com (john public)
Date: Thu, 14 Mar 2002 08:59:00 -0800 (PST)
Subject: [Tutor] Print going off the page.
Message-ID: <20020314165900.84827.qmail@web21108.mail.yahoo.com>

--0-1962712604-1016125140=:83721
Content-Type: text/plain; charset=us-ascii


Why does my print always go off the page. I'd like to stop that.

 John



---------------------------------
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage
--0-1962712604-1016125140=:83721
Content-Type: text/html; charset=us-ascii

<P>Why does my print always go off the page. I'd like to stop that.</P>
<P>&nbsp;John</P><p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href="$rd_url/tag/http://sports.yahoo.com/">Yahoo! Sports</a> - live college hoops coverage
--0-1962712604-1016125140=:83721--


From scarblac@pino.selwerd.nl  Thu Mar 14 17:03:45 2002
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 14 Mar 2002 18:03:45 +0100
Subject: [Tutor] Print going off the page.
In-Reply-To: <20020314165900.84827.qmail@web21108.mail.yahoo.com>; from apython101@yahoo.com on Thu, Mar 14, 2002 at 08:59:00AM -0800
References: <20020314165900.84827.qmail@web21108.mail.yahoo.com>
Message-ID: <20020314180345.A23678@pino.selwerd.nl>

On  0, john public <apython101@yahoo.com> wrote:
> Why does my print always go off the page. I'd like to stop that.

Use larger pages.

Seriously, what do you mean exactly? The print command, or printing to
paper, if the latter how are you printing, etc.

-- 
Remco Gerlich


From shalehperry@attbi.com  Thu Mar 14 17:17:48 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Thu, 14 Mar 2002 09:17:48 -0800 (PST)
Subject: [Tutor] telling dir(_builtins_) from dir(__builtins__)
In-Reply-To: <20020314165425.84186.qmail@web21107.mail.yahoo.com>
Message-ID: <XFMail.20020314091748.shalehperry@attbi.com>

>  I can't remember how I found Barry's Web page but I am sure glad I did.
> Anyway if someone has a list of visually misleading things like this in
> Python please send me the link.
> 

the only other thing that jumps immediately to memory is a wart that python
recently developed.

pieces = ['My', 'name', 'is', 'Sean']
my_string = ' '.join(pieces)
print my_string
'My name is Sean'

another_string = ''.join(pieces)
print another_string
'MynameisSean'

before python 2.x we had to use:

import string
my_string = string.join(pieces) # defaults to one space delimiter
another_string = string.join(pieces, '') # glue it together, no whitespace


From dyoo@hkn.eecs.berkeley.edu  Thu Mar 14 17:41:05 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 14 Mar 2002 09:41:05 -0800 (PST)
Subject: [Tutor] telling dir(_builtins_) from dir(__builtins__)
In-Reply-To: <20020314165425.84186.qmail@web21107.mail.yahoo.com>
Message-ID: <Pine.LNX.4.21.0203140912220.22875-100000@hkn.eecs.berkeley.edu>

On Thu, 14 Mar 2002, john public wrote:

> How in the heck is a Newwbie to know dir(_builtins_) from
> dir(__builtins__)?!? both look like one hypen to me. One's just longer
> than the other. I just assumed it was a difference between the type on
> my machine and the type in the O'riely book.

Typography can be a tricky thing.  '1' and 'l' and 'i' look much too
similar, as does '0' and 'O'.  Whoever typeset the book you're looking at
should probably have made it look more visually distinctive, but, on the
other hand, double underscores already suggest tricky magic ahead...
*grin*


(By the way, newcomers really aren't expected to look into '__builtins__'
until they have more experience; it is often possible to not even know
that it exists unless we read closely into the "separate symbol table"  
mentioned in the library documentation:

    http://www.python.org/doc/lib/builtin.html)


Double underscores in Python indicate that here, in front of us, is a
variable that probably means something special to Python.  This
double-underscore convention in Python isn't a one-time special case;
Python uses it for reserved names and special variables specific to Python
itself.

Newcomers often encounter the __double_underscore__ when they try to
"overload" operators with classes.  For example, here's a class that has
some strange looking functions defined in them:

###
class ModuloNumber:
    def __init__(self, x, n):
        self.x, self.n = x%n, n

    def __str__(self):
        return '%d modulo %d' % (self.x, self.n)

    def __add__(self, some_number):
        return ModuloNumber(self.x + some_number, self.n)
###


Here's an example of what this is sorta doing:

###
>>> my_number = ModuloNumber(5, 12)
>>> str(my_number)
'5 modulo 12'
>>> for i in range(10):
...     print my_number + i
... 
5 modulo 12
6 modulo 12
7 modulo 12
8 modulo 12
9 modulo 12
10 modulo 12
11 modulo 12
0 modulo 12
1 modulo 12
2 modulo 12
###

So something sorta strange is happening here: somehow, Python is calling
the '__add__()' function when we say 'Add my_number to i'.  __str__ and
__add__ are special method names meant for its own nefarious purposes:

    http://www.python.org/doc/current/ref/specialnames.html

There aren't many other places where we'll see double underscores, but at
least they're used consistantly.


> So far this is the first thing I have found like this in Python. I
> have actually been amazed at how easy it is compared to C++ which I
> worked at for 2 months and got relatively nowhere by comparison. I am
> sure glad Barry Warsaw steered me towards Python.

When you see double underscores, think "having some special meaning to
Python itself".  I don't believe anyone wanted to make '__' to look like a
single '_', but that's probably more of a case of bad typography rather
than bad programming.  *grin*


Best of wishes to you!



From max_ig@yahoo.com  Thu Mar 14 19:47:40 2002
From: max_ig@yahoo.com (ichazo maximiliano)
Date: Thu, 14 Mar 2002 11:47:40 -0800 (PST)
Subject: [Tutor] curses module and screens on DOS
Message-ID: <20020314194740.15232.qmail@web11308.mail.yahoo.com>

I've read there is a module called curses to work with plain screens
such as DOS or any other plain-text screen. However, I couldn't find
it. I asked few day ago in here about this topic but I'm a bit
confused.

I'would appreciate your help.

Thanx,

Max


__________________________________________________
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage
http://sports.yahoo.com/


From apython101@yahoo.com  Thu Mar 14 20:38:09 2002
From: apython101@yahoo.com (john public)
Date: Thu, 14 Mar 2002 12:38:09 -0800 (PST)
Subject: [Tutor] print going of page
Message-ID: <20020314203809.22386.qmail@web21107.mail.yahoo.com>

--0-178051437-1016138289=:21345
Content-Type: text/plain; charset=us-ascii


Sorry for not being more specific.

I am writing this in my Yahoo account and when I go look at it on the archives it does not word wrap. It just keeps going to the right. Are you seeing it that way also?

John



---------------------------------
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage
--0-178051437-1016138289=:21345
Content-Type: text/html; charset=us-ascii

<P>Sorry for not being more specific.</P>
<P>I am writing this in my Yahoo account and when I go look at it on the archives it does not word wrap. It just keeps going to the right. Are you seeing it that way also?</P>
<P>John</P><p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href="$rd_url/tag/http://sports.yahoo.com/">Yahoo! Sports</a> - live college hoops coverage
--0-178051437-1016138289=:21345--


From paulsid@shaw.ca  Thu Mar 14 22:22:08 2002
From: paulsid@shaw.ca (Paul Sidorsky)
Date: Thu, 14 Mar 2002 15:22:08 -0700
Subject: [Tutor] telling dir(_builtins_) from dir(__builtins__)
References: <20020314165425.84186.qmail@web21107.mail.yahoo.com>
Message-ID: <3C912290.21EAE051@shaw.ca>

john public wrote:

> How in the heck is a Newwbie to know  dir(_builtins_) from
> dir(__builtins__)?!? both look like one hypen to me. One's just longer
> than the other. I just assumed it was a difference between the type on
> my machine and the type in the O'riely book. 

For stuff on your computer you can tell by attempting to select the
underscore(s) in question manually (i.e. by dragging your mouse over
it/them).  If you can't select a portion of a single line then it's a
single, otherwise it's got more than one.  Of course you usually have to
be expecting there to be more than one underscore before you try this. 
:-)

Not much you can do for printed material except hope that a good font is
chosen.  Though if it looks unusually long then it's probably two.  For
one you have to find a case where you know it's one and just remember
the length of the single in relation to the other characters.

(As an aside, this is one of the major reasons why I prefer the PC's
full-screen text mode.  My main text editor is still an old DOS editor
and I almost always use it full-screen.  It's virtually impossible to
make these kind of mistakes there.)

> I am sure glad
> I can ask you guys questions. This is exactly the kind of tedious
> dotting your I's and crossing your T's that drove me nuts years ago
> when I tried to learn basic but gave up. So far this is the first
> thing I have found like this in Python. 

To be blunt, that's what programming is, and why it's widely considered
to be such a difficult thing to do.  We have to be impeccably specific
because the computer can't figure out what we mean if we don't say it,
or say it wrong.  If you have difficulties being so finicky then you
will likely have great difficulty with programming.

That being said, Python certainly does have less syntactical pitfalls
and it's a lot easier to "speak" python (e.g. over the phone) than, say,
C.  So yeah, it's definitely easier to learn!  And as you said we are
here to help.

As for the choice of double-underscore, that's probably one of those
didn't-seem-like-a-problem-when-it-was-introduced-but-looking-back-
on-it-now-it-would-be-nice-if-it-were-done-differently things.  I don't
know the history of it, though.

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/


From csmith@blakeschool.org  Thu Mar 14 22:37:06 2002
From: csmith@blakeschool.org (Christopher Smith)
Date: Thu, 14 Mar 2002 16:37:06 -0600
Subject: [Tutor] islink() in macpath and directory walk
In-Reply-To: <E15Zwui-0004RY-00@mail.python.org>
References: <E15Zwui-0004RY-00@mail.python.org>
Message-ID: <fc.004c4b6b009111243b9aca00b1e2f27c.9112f5@blakeschool.org>

I was using the walk function to go through directories and change
modification times on files which, because of a daylight savings issue are
1 hour different than a backup set that I have.  I've run into two issues:

1) I don't want to follow aliases to other folders--I just want to update
files that are physically in the root folder and its subfolders.  So it
seems that I must remove aliases in the list of files that is passed to
the function that is called as walk() takes place.  I noticed that in
macpath there is an islink() function that says

def islink(s):
    """Return true if the pathname refers to a symbolic link.
    Always false on the Mac, until we understand Aliases."""

   return 0

Maybe this is just a function that hasn't been used by others and has thus
never been updated...is there any reason not to have the function do the
following return?

  return macfs.ResolveAliasFile(s)[2]

The [2]th value is 1 or 0 depending on whether or not the file specified
by s is an alias.

2) If I *do* want to follow aliases, I don't want to get trapped in an
infinite loop caused when two folders contain aliases of each other.  Is
there a clever "loop detection" algorithm for this short of keeping track
of every folder visited?  what is this condition called?  (I checked ASPN
with "loop detection", "walk detection", etc...without a lot of success.)

/c



From pythontutor@venix.com  Thu Mar 14 22:42:47 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Thu, 14 Mar 2002 17:42:47 -0500
Subject: [Tutor] telling dir(_builtins_) from dir(__builtins__)
References: <20020314165425.84186.qmail@web21107.mail.yahoo.com>
Message-ID: <3C912767.9050506@venix.com>

One thing that gets me sometimes in the documentation is that square
brackets are used for optional pieces of syntax.  Square brackets are
also used to delimit lists.  So documentation about lists (e.g. List
Comprehension syntax) can be confusing.

john public wrote:

> How in the heck is a Newwbie to know  dir(_builtins_) from 
> dir(__builtins__)?!? both look like one hypen to me. One's just longer 
> than the other. I just assumed it was a difference between the type on 
> my machine and the type in the O'riely book. I have been working in Alan 
> Gaulds book and looking a bit in Learning Python and programming Python 
> and don't recall reading about this distinction. I am sure glad I can 
> ask you guys questions. This is exactly the kind of tedious dotting 
> your I's and crossing your T's that drove me nuts years ago when I tried 
> to learn basic but gave up. So far this is the first thing I have found 
> like this in Python. I have actually been amazed at how easy it is 
> compared to C++ which I worked at for 2 months and got relatively 
> nowhere by comparison. I am sure glad Barry Warsaw steered me towards 
> Python.
> 
>  THANKS BARRRRRY!!
> 
>  I can't remember how I found Barry's Web page but I am sure glad I did. 
> Anyway if someone has a list of visually misleading things like this in 
> Python please send me the link.
> 
> Thankzzz
> 
> 
> ------------------------------------------------------------------------
> Do You Yahoo!?
> Yahoo! Sports <$rd_url/tag/http://sports.yahoo.com/> - live college 
> hoops coverage


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582



From lbergman@[nospam]abi.tconline.net  Thu Mar 14 17:01:24 2002
From: lbergman@[nospam]abi.tconline.net (Lewis Bergman)
Date: Thu, 14 Mar 2002 11:01:24 -0600
Subject: [Tutor] PostgreSQL module recommendations
Message-ID: <200203141701.g2EH1Oi08359@lewis.abi.tconline.net>

I know there are three (or more) python modules to interface to the 
PostgreSQL server. My app places an importance on Postgres feature support 
not speed. Does anyone have recommendations?
-- 
Lewis Bergman
Texas Communications
4309 Maple St.
Abilene, TX 79602-8044
915-695-6962 ext 115


From dyoo@hkn.eecs.berkeley.edu  Thu Mar 14 23:02:20 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 14 Mar 2002 15:02:20 -0800 (PST)
Subject: [Tutor] curses module and screens on DOS
In-Reply-To: <20020314194740.15232.qmail@web11308.mail.yahoo.com>
Message-ID: <Pine.LNX.4.21.0203141457180.29982-100000@hkn.eecs.berkeley.edu>

On Thu, 14 Mar 2002, ichazo maximiliano wrote:

> I've read there is a module called curses to work with plain screens
> such as DOS or any other plain-text screen. However, I couldn't find
> it. I asked few day ago in here about this topic but I'm a bit
> confused.

Hi Ichazo!

Sorry about not answering sooner; I've been a bit busy.  The curses
module, unfortunately, appears to be limited to Unix systems until someone
takes the time to make it work on Windows.  There's supposed to be a
similar module called WConio:

    http://newcenturycomputers.net/projects/wconio.html

so you may have more success with it.


There's some more information on curses here:

    http://www-106.ibm.com/developerworks/linux/library/l-python6.html

where the author casually mentions that someone had ported curses to
Windows... but doesn't mention it for the rest of the article.  *sigh*
Does anyone know more about this?


Good luck to you!



From scarblac@pino.selwerd.nl  Thu Mar 14 23:38:25 2002
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Fri, 15 Mar 2002 00:38:25 +0100
Subject: [Tutor] print going of page
In-Reply-To: <20020314203809.22386.qmail@web21107.mail.yahoo.com>; from apython101@yahoo.com on Thu, Mar 14, 2002 at 12:38:09PM -0800
References: <20020314203809.22386.qmail@web21107.mail.yahoo.com>
Message-ID: <20020315003825.A25365@pino.selwerd.nl>

On  0, john public <apython101@yahoo.com> wrote:
> I am writing this in my Yahoo account and when I go look at it on the
> archives it does not word wrap. It just keeps going to the right. Are you
> seeing it that way also?

It's all on one line. My mail client shows it on several lines with some
primitive wrapping, but in a reply like this I edit it myself so it becomes
several lines - this involves moving it from the rest of the quote, letting
my editor rewrap it, and adding several > signs. Please hit enter now and
then.

-- 
Remco Gerlich


From erikprice@mac.com  Fri Mar 15 01:54:27 2002
From: erikprice@mac.com (Erik Price)
Date: Thu, 14 Mar 2002 20:54:27 -0500
Subject: [Tutor] telling dir(_builtins_) from dir(__builtins__)
In-Reply-To: <3C912290.21EAE051@shaw.ca>
Message-ID: <954ECD48-37B7-11D6-B498-00039351FE6A@mac.com>

On Thursday, March 14, 2002, at 05:22  PM, Paul Sidorsky wrote:

> (As an aside, this is one of the major reasons why I prefer the PC's
> full-screen text mode.  My main text editor is still an old DOS editor
> and I almost always use it full-screen.  It's virtually impossible to
> make these kind of mistakes there.)

I think I'm the only person I know who actually prefers to use the 
prompt over xwindows.  So I know what you mean.  If I'm in X, then I 
feel like I need to always have a term open.  It helps that the python 
interpreter and emacs are available thru this too!  (Of course on Mac OS 
X I swear by BBEdit.)

> That being said, Python certainly does have less syntactical pitfalls
> and it's a lot easier to "speak" python (e.g. over the phone) than, say,
> C.

Or (shudder) Perl....


Erik



From erikprice@mac.com  Fri Mar 15 02:00:16 2002
From: erikprice@mac.com (Erik Price)
Date: Thu, 14 Mar 2002 21:00:16 -0500
Subject: [Tutor] telling dir(_builtins_) from dir(__builtins__)
In-Reply-To: <XFMail.20020314091748.shalehperry@attbi.com>
Message-ID: <6564D357-37B8-11D6-B498-00039351FE6A@mac.com>

On Thursday, March 14, 2002, at 12:17  PM, Sean 'Shaleh' Perry wrote:

> before python 2.x we had to use:
>

But now this is fine, right?  I use 2.2... and both methods work.
Is there a changelog or quick guide to the major differences between 1.x 
and 2.x Pythons?  I guess it doesn't matter as much as long as I'm 
always using the most recent version, but...

Thanks,

Erik



From urnerk@qwest.net  Fri Mar 15 07:12:27 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 14 Mar 2002 23:12:27 -0800
Subject: [Tutor] Fun geometry w/ Python's help
Message-ID: <4.2.0.58.20020314225220.00ce9a50@pop3.norton.antivirus>

Greetings all --

Just thought I'd share results of a project with other
Pythonistas.

Here's a POV-Ray graphic [1] I generated earlier today
using Python to write the script:

http://www.inetarena.com/~pdx4d/ocn/graphics/w1000.gif

What we're seeing are balls in a cubic close packing (ccp)
out to distance sqrt(1000) from the origin.  Color coding
indicates different distances, with orange balls being
at maximum distance.[3]

Source code is here:
http://www.inetarena.com/~pdx4d/ocn/python/ccp.py

Note I'm also importing modules coords.py (a vector
implementation) and povray.py (used to write vectors in
coords to POV-Ray).  Both are available at same URL.[2]

Kirby

[1] Re POV-Ray:  http://www.povray.org

[2] related info and more graphics at:
     http://www.inetarena.com/~pdx4d/ocn/wgraphics.html

[3] background on povray.py and coords.py is at
     http://www.inetarena.com/~pdx4d/ocn/numeracy0.html ff




From idiot1@netzero.net  Fri Mar 15 08:34:03 2002
From: idiot1@netzero.net (kirk Bailey)
Date: Fri, 15 Mar 2002 03:34:03 -0500
Subject: [Tutor] 1.2.0 is ready for downloading
Message-ID: <3C91B1FB.CD7CE45B@netzero.net>

1.2.0 Tinylist release is ready. Now is able to locate itself, reads
it's domain name from a super simple config file, even beter training
wheels, and improvements in the documentation unto verboseness.

http://www.tinylist.org

-- 
 
end
	    Respectfully,
			 Kirk D Bailey


+---------------------"Thou Art Free." -Eris----------------------+
| http://www.howlermonkey.net mailto:highprimate@howlermonkey.net |
| http://www.tinylist.org  +--------+  mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking---------------------+
                           +--------+

NOTE: By sending SPAM to this address you agree to pay me a service
fee of $100 for the service of receiving,  storing,  examining, and
deleting your piece of SPAM. I am a postmaster, and take a dim view
of such.
----------------------------------------------------
Sign Up for NetZero Platinum Today
Only $9.95 per month!
http://my.netzero.net/s/signup?r=platinum&refcd=PT97


From apython101@yahoo.com  Fri Mar 15 13:44:42 2002
From: apython101@yahoo.com (john public)
Date: Fri, 15 Mar 2002 05:44:42 -0800 (PST)
Subject: [Tutor] tinylist is it something I can down load?
Message-ID: <20020315134442.25731.qmail@web21103.mail.yahoo.com>

--0-1034481579-1016199882=:22182
Content-Type: text/plain; charset=us-ascii


Where do I down load it. Since it is heavily commented and friendly to Newbies I'd like to look at it even if it is over my head.

John



---------------------------------
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage
--0-1034481579-1016199882=:22182
Content-Type: text/html; charset=us-ascii

<P>Where do I down load it. Since it is heavily commented and friendly to Newbies I'd like to look at it even if it is over my head.</P>
<P>John</P><p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href="$rd_url/tag/http://sports.yahoo.com/">Yahoo! Sports</a> - live college hoops coverage
--0-1034481579-1016199882=:22182--


From idiot1@netzero.net  Fri Mar 15 17:01:06 2002
From: idiot1@netzero.net (kirk Bailey)
Date: Fri, 15 Mar 2002 12:01:06 -0500
Subject: [Tutor] tinylist is it something I can down load?
References: <20020315134442.25731.qmail@web21103.mail.yahoo.com>
Message-ID: <3C9228D2.3269CBC2@netzero.net>

Sure thing. Zip and .tar.gz formats are available at the website.

http://www.tinylist.org/

In the download area, click on the ling for the archive file format of
our choice. LOTS of stuff there to read about it, using it, intresting
tech stuff on how to get it right. feel free to write me off list with
questions.


john public wrote:
> 
> Where do I down load it. Since it is heavily commented and friendly
> to Newbies I'd like to look at it even if it is over my head.
> 
> John
> 
> --------------------------------------------------------------------
> Do You Yahoo!?
> Yahoo! Sports - live college hoops coverage

-- 
 
end
	    Respectfully,
			 Kirk D Bailey


+---------------------"Thou Art Free." -Eris----------------------+
| http://www.howlermonkey.net mailto:highprimate@howlermonkey.net |
| http://www.tinylist.org  +--------+  mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking---------------------+
                           +--------+

NOTE: By sending SPAM to this address you agree to pay me a service
fee of $100 for the service of receiving,  storing,  examining, and
deleting your piece of SPAM. I am a postmaster, and take a dim view
of such.
----------------------------------------------------
Sign Up for NetZero Platinum Today
Only $9.95 per month!
http://my.netzero.net/s/signup?r=platinum&refcd=PT97


From bobx@linuxmail.org  Fri Mar 15 18:44:20 2002
From: bobx@linuxmail.org (Bob X)
Date: Sat, 16 Mar 2002 02:44:20 +0800
Subject: [Tutor] Parsing a file
Message-ID: <20020315184420.671.qmail@linuxmail.org>

I have this:

# import the libs
import sys

inp = open(sys.argv[1],"r") 
outp = open(sys.argv[2],"w") 

kw = ["tony","bob","chris"] # build list of keywords

# loop through the kw list and print the lines to a file
for line in inp.readlines():
	for badword in kw:
		if line.find(badword) > -1:
			print line
			outp.write(line)
			break 

# close the files
inp.close()
outp.close()			

# let me know when it's done doing its thang
print "Finished processing file..."

Which works great. Can I change "print line" to "print kw + line" to get the keyword it found plus the line it found it on or is it harder than that?

Bob
-- 

Get your free email from www.linuxmail.org 


Powered by Outblaze


From adam@switchedonsoftware.com  Thu Mar 14 23:55:25 2002
From: adam@switchedonsoftware.com (Adam Eijdenberg)
Date: Fri, 15 Mar 2002 10:55:25 +1100
Subject: [Tutor] Re: [Pythonmac-SIG] islink() in macpath and directory walk
In-Reply-To: <fc.004c4b6b009111243b9aca00b1e2f27c.9112f5@blakeschool.org>
Message-ID: <F439AED5-37A6-11D6-8D2C-0030656E8732@switchedonsoftware.com>

> Maybe this is just a function that hasn't been used by others and has 
> thus
> never been updated...is there any reason not to have the function do the
> following return?
>
>   return macfs.ResolveAliasFile(s)[2]

Can't answer that one for you, but...

> 2) If I *do* want to follow aliases, I don't want to get trapped in an
> infinite loop caused when two folders contain aliases of each other.  Is
> there a clever "loop detection" algorithm for this short of keeping 
> track
> of every folder visited?  what is this condition called?  (I checked 
> ASPN
> with "loop detection", "walk detection", etc...without a lot of 
> success.)

This is more of a general programming question. One method I have used 
for similar projects, is start with two empty lists, say TO_PROCESS and 
DONE.

Add your first job (or in this case "root" folder) to TO_PROCESS and to 
DONE and then run something like the following:

while len (TO_PROCESS) > 0:
     job = TO_PROCESS.pop ()

     ... process job, possibly getting new child jobs and adding them as 
below ....

     if not (newChildJob in DONE):
         TO_PROCESS.append (newChildJob)
         DONE.append (newChildJob)

Not sure what you would exactly call this condition, but solving it with 
queues is usually fairly simple.

Hope that helps,
Adam



From raunocastro@hotmail.com  Fri Mar 15 18:57:37 2002
From: raunocastro@hotmail.com (Rauno castro)
Date: Fri, 15 Mar 2002 12:57:37 -0600
Subject: [Tutor] Hello!!
Message-ID: <F128MPX8KYGCkLCcmUH0000338b@hotmail.com>


Hello python friends!

I'm a new in all this world of programers but I have a problem, I'm trying 
to understand all because I'm a spanish guy but i'm tinking if i could learn 
how to program I'm gonna make a Python helper for all the Spanish world but 
now I need your help... Cause I don't Know nothing!! im trying to learn all 
the comands but i didn't find a list with all the comands so please you guys 
help me with this.. and if you find a spanish progamer who can help me 
please notify me. ok.??

I hope you all guys understand what i want to mean..

Rauno Castro

Pd. Why you guys use the irc channel to lean Python for dummies like me!!... 
or make a event in a IRC channel?? it's only an idea..

_________________________________________________________________
Con MSN Hotmail súmese al servicio de correo electrónico más grande del 
mundo. http://www.hotmail.com/ES



From tutor@python.org  Fri Mar 15 19:50:52 2002
From: tutor@python.org (Alexey Rusakov)
Date: Fri, 15 Mar 2002 22:50:52 +0300
Subject: [Tutor] Hello!!
In-Reply-To: <F128MPX8KYGCkLCcmUH0000338b@hotmail.com>
References: <F128MPX8KYGCkLCcmUH0000338b@hotmail.com>
Message-ID: <20020315225052.109c6c91.cpp@userline.ru>

Hi!

> I'm a new in all this world of programers but I have a problem, I'm trying 
> to understand all because I'm a spanish guy but i'm tinking if i could learn 
> how to program I'm gonna make a Python helper for all the Spanish world but 
> now I need your help... Cause I don't Know nothing!! im trying to learn all 
> the comands but i didn't find a list with all the comands so please you guys 
> help me with this.. and if you find a spanish progamer who can help me 
> please notify me. ok.??

Well... I think Python doesn't start with 'all the commands'. As any tool, these commands should be used in a proper way.
I think you should refer to the documentation that comes with Python. The tutorial there is excellent and will help you to start programming as early as you want. In short - RTFM.

-- 
  Alexey Rusakov aka Ktirf


From dyoo@hkn.eecs.berkeley.edu  Fri Mar 15 19:32:07 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 15 Mar 2002 11:32:07 -0800 (PST)
Subject: [Tutor] Hello!!
In-Reply-To: <F128MPX8KYGCkLCcmUH0000338b@hotmail.com>
Message-ID: <Pine.LNX.4.21.0203151119560.22153-100000@hkn.eecs.berkeley.edu>

On Fri, 15 Mar 2002, Rauno castro wrote:

> I'm a new in all this world of programers but I have a problem, I'm
> trying to understand all because I'm a spanish guy but i'm tinking if
> i could learn how to program I'm gonna make a Python helper for all
> the Spanish world but now I need your help... 

No problem.


> im trying to learn all the comands but i didn't find a list with all
> the comands so please you guys help me with this.. and if you find a
> spanish progamer who can help me please notify me. ok.??

You might want to see if the Spanish resources on Python.org will be of
use:

    http://python.org/doc/NonEnglish.html#spanish

The translation of Alan Gauld's "Learning to Program", in particular, is a
great tutorial for learning programming; I think you'l like it a lot.



> Pd. Why you guys use the irc channel to lean Python for dummies like
> me!!...  or make a event in a IRC channel?? it's only an idea..

The problem is that not all of us are awake at the same time.  *grin*

There actually are some IRC channels out there for Python programming.  
The irc.openprojects.com server hosts several channels, including a
'#python' channel.  The TwistedMatrix folks also have a Wiki with Python
IRC resources:

    http://twistedmatrix.com/users/jh.twistd/python/moin.cgi/


But please feel free to ask your questions on Tutor too; we'll be glad to
help.  Good luck to you.



From dyoo@hkn.eecs.berkeley.edu  Fri Mar 15 19:41:51 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 15 Mar 2002 11:41:51 -0800 (PST)
Subject: [Tutor] Parsing a file  [print and String Formatting]
In-Reply-To: <20020315184420.671.qmail@linuxmail.org>
Message-ID: <Pine.LNX.4.21.0203151134360.22153-100000@hkn.eecs.berkeley.edu>

Hi Bob,

Your program looks good.  Let's take a look at some of the lines.


On Sat, 16 Mar 2002, Bob X wrote:

> inp = open(sys.argv[1],"r") 

Files are opened as 'read' by default if we leave off the second argument
to open, so we can write this equivalently as:

###
inp = open(sys.argv[1])
###




> # loop through the kw list and print the lines to a file
> for line in inp.readlines():
> 	for badword in kw:
> 		if line.find(badword) > -1:
> 			print line
> 			outp.write(line)
> 			break 
> 
> # close the files
> inp.close()
> outp.close()			
> 
> # let me know when it's done doing its thang
> print "Finished processing file..."
>
> Which works great. Can I change "print line" to "print kw + line" to
> get the keyword it found plus the line it found it on or is it harder
> than that?

No, actually, it should be that easy.  *grin*


Alternatively,

###
print kw, line
###

will work because Python's "print" statement tries to be nice about
things, and will even insert a space between the keyword 'kw' and the
line.


If you want finer control over how things are printed, you can take a look
at the "String Formatting" chapter on the Official Python Tutorial:

    http://www.python.org/doc/tut/node9.html

As a warning, the official tutorial is only meant to give a taste of
things, so it goes quite fast.  Please feel free to experiment and ask
questions on Tutor, and we can talk about them more slowly.

Good luck!



From tbost@ifarm.com  Fri Mar 15 21:11:17 2002
From: tbost@ifarm.com (Tracy Bost)
Date: Fri, 15 Mar 2002 15:11:17 -0600 (CST)
Subject: [Tutor] Change Directory using ftplib
Message-ID: <1016226677.3c92637555740@mail.ifarm.com>



I can't seem to find the right combination to cd "Change Directory once I 
connect using the ftplib..
have tried ftp.voidcmd('cd'), ftp.sendcmd('cd')
but not working... even took a stab at ftp.cd().. but cd is not an object..


- Tracy

------------------------------------------------------------------------------
Visit "The Most Powerful Tool on the Farm" at http://www.ifarm.com
Get the latest on Ag News, Market Reports, FREE email, and much more.




From tbost@ifarm.com  Fri Mar 15 21:14:15 2002
From: tbost@ifarm.com (Tracy Bost)
Date: Fri, 15 Mar 2002 15:14:15 -0600 (CST)
Subject: [Tutor] RE: Change Directory using ftplib
Message-ID: <1016226855.3c926427668b0@mail.ifarm.com>

Wouldn't ya know. I mess with it for an hour and as soon as I fire off the 
email, I find it.... ftp.cwd('directory') ...

 Thanks !



----- Forwarded message from Tracy Bost <tbost@ifarm.com> -----
Date: Fri, 15 Mar 2002 15:11:17 -0600 (CST)
From: Tracy Bost <tbost@ifarm.com>
Reply-To: Tracy Bost <tbost@ifarm.com>
Subject: Change Directory using ftplib
To: tutor@python.org



I can't seem to find the right combination to cd "Change Directory once I
connect using the ftplib..
have tried ftp.voidcmd('cd'), ftp.sendcmd('cd')
but not working... even took a stab at ftp.cd().. but cd is not an object..


- Tracy

------------------------------------------------------------------------------
Visit "The Most Powerful Tool on the Farm" at http://www.ifarm.com
Get the latest on Ag News, Market Reports, FREE email, and much more.



----- End forwarded message -----



- Tracy

------------------------------------------------------------------------------
Visit "The Most Powerful Tool on the Farm" at http://www.ifarm.com
Get the latest on Ag News, Market Reports, FREE email, and much more.




From paulsid@shaw.ca  Fri Mar 15 21:35:29 2002
From: paulsid@shaw.ca (Paul Sidorsky)
Date: Fri, 15 Mar 2002 14:35:29 -0700
Subject: [Tutor] Parsing a file
References: <20020315184420.671.qmail@linuxmail.org>
Message-ID: <3C926921.4E5ECF3F@shaw.ca>

Bob X wrote:

> Which works great. Can I change "print line" to "print kw + line" to get the keyword it found plus the line it found it on or is it harder than that?

Yes, except you'll actually need to print badword.  Printing kw will
print the whole list each time.  So you can use:

print badword + line

However, this will run the keyword and line together, so you might want
to put a space in there to make it nicer:

print badword + " " + line

You could also do this, which will include a space for you:

print badword, line

Lastly, the most common way to print multiple pieces of data is like
this:

print "%s %s" % (badword, line)

If you stick some formatting stuff in there you can even get them to
line up
nicely:

print "%-10s %-60s" % (badword, line)

The % syntax is probably overkill for this, though, and since it's not
all that easy to use unless you already know C (which is where it comes
from) you can probably live without it for now.

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/


From dyoo@hkn.eecs.berkeley.edu  Fri Mar 15 21:36:58 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 15 Mar 2002 13:36:58 -0800 (PST)
Subject: [Tutor] RE: Change Directory using ftplib
In-Reply-To: <1016226855.3c926427668b0@mail.ifarm.com>
Message-ID: <Pine.LNX.4.21.0203151335120.25528-100000@hkn.eecs.berkeley.edu>

On Fri, 15 Mar 2002, Tracy Bost wrote:

> Wouldn't ya know. I mess with it for an hour and as soon as I fire off
> the email, I find it.... ftp.cwd('directory') ...

*laugh* Yes, this happens a lot; don't worry about it.


I'm glad to hear you found the solution.  If you have more questions,
please feel free to ask on Tutor.



From dyoo@hkn.eecs.berkeley.edu  Fri Mar 15 21:44:42 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 15 Mar 2002 13:44:42 -0800 (PST)
Subject: [Tutor] Fun geometry w/ Python's help  [geometry and PyMol?]
In-Reply-To: <4.2.0.58.20020314225220.00ce9a50@pop3.norton.antivirus>
Message-ID: <Pine.LNX.4.21.0203151339070.25528-100000@hkn.eecs.berkeley.edu>

On Thu, 14 Mar 2002, Kirby Urner wrote:

> Here's a POV-Ray graphic [1] I generated earlier today
> using Python to write the script:
> 
> http://www.inetarena.com/~pdx4d/ocn/graphics/w1000.gif
> 
> What we're seeing are balls in a cubic close packing (ccp)
> out to distance sqrt(1000) from the origin.  Color coding
> indicates different distances, with orange balls being
> at maximum distance.[3]

Hi Kirby,

This is very cool!

By the way, during the recent BayPiggies meeting two days ago, I got my
first glance at PyMol:

    http://pymol.sourceforge.net/ 

This program allows one to build molecular models in real time.  I was
stunned to see how the program would allow me to pull and tug on the
atoms, and have the whole structure warp and stretch.  Tinker toys on a
mass scale.  I felt like a little kid again.  *grin*

Perhaps there might be something in PyMol that could be useful for the
geometrical programs that you've been working on.


Good luck to you.



From wolf_binary@hotmail.com  Fri Mar 15 22:48:59 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Fri, 15 Mar 2002 16:48:59 -0600
Subject: [Tutor] Alan Gauld's new book
Message-ID: <DAV46rczSR9AF4VoJcI00008940@hotmail.com>

This is a multi-part message in MIME format.

------=_NextPart_000_0007_01C1CC41.4DA84B20
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I remember you saying something about you making a new book.  How is it =
comming cause I have your Python one and want to try out this new one of =
yours?  Are you going to have it available online too so you can =
download it?

Cameron Stoner

------=_NextPart_000_0007_01C1CC41.4DA84B20
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.2713.1100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I remember you saying something about =
you making a=20
new book.&nbsp; How is it comming cause I have your Python one and want =
to try=20
out this new one of yours?&nbsp; Are you going to have it available =
online too=20
so you can download it?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Cameron =
Stoner</FONT></DIV></BODY></HTML>

------=_NextPart_000_0007_01C1CC41.4DA84B20--


From Cobaugh.Harvey@epamail.epa.gov  Sat Mar 16 02:30:26 2002
From: Cobaugh.Harvey@epamail.epa.gov (Cobaugh.Harvey@epamail.epa.gov)
Date: Fri, 15 Mar 2002 21:30:26 -0500
Subject: [Tutor] Harvey Cobaugh/RTP/USEPA/US is out of the office.
Message-ID: <OFF5648B6B.A7C27931-ON85256B7E.000DC628@rtp.epa.gov>

I will be out of the office starting  03/14/2002 and will not return
until 03/25/2002.

I will respond to your message when I return.



From virketis@fas.harvard.edu  Sat Mar 16 06:13:00 2002
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Sat, 16 Mar 2002 01:13:00 -0500
Subject: [Tutor] constructing tupples in 1.5.2
Message-ID: <001601c1ccb1$a0339fa0$18adf78c@virketis2>

This is a multi-part message in MIME format.

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

Dear all,=20

I am writting a MySQL script, which will be deployed on Py1.5.2. The =
call to the database made through MySQLdb module must be in the form of =
a list of tupples (e.g. [("John", 33, "M"), ("Sally", 35, "F"), ...]. =
The thing is, I need to construct these tupples on the fly: I have a =
dictionary of values (e.g. {"name": "John", "age": 33, ... }) and I want =
to put the right values in the right places in a tupple. In Py2.2 this =
is easy, because the tupple object has a handy __add__ method, which =
concatenates two tupples. Py1.5.2, unfortunately, does not support this =
method. What would be the most effective way of doing this? A workaround =
I have though of is updating the table entry-by-entry, rather than =
making one big update call, but it's obviously less efficient to run all =
these INSERT querries.

Cheers,=20

Pijus



----------------------------
Nothing is as simple as it seems at first Or as hopeless as it seems in =
the middle Or as finished as it seems in the end. - /usr/games/fortune

------=_NextPart_000_0013_01C1CC87.B70676F0
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.2713.1100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Dear all, </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I am writting a MySQL script, which =
will be=20
deployed on Py1.5.2. The call to the database made through MySQLdb =
module must=20
be in the form of a list of tupples (e.g. [("John", 33, "M"), ("Sally", =
35,=20
"F"), ...]. The thing is, I need to construct these tupples on the fly: =
I have a=20
dictionary of values (e.g. {"name": "John", "age": 33, ... }) and I want =
to put=20
the right values in the right places in a tupple. In Py2.2 this is easy, =
because=20
the tupple object has a handy __add__ method, which concatenates two =
tupples.=20
Py1.5.2, unfortunately, does not support this method. What would be the =
most=20
effective way of doing this? A workaround I have though of is updating =
the table=20
entry-by-entry, rather than making one big update call, but it's =
obviously less=20
efficient to run all these INSERT querries.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Cheers, </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Pijus</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial =
size=3D2><BR>----------------------------<BR>Nothing is as=20
simple as it seems at first Or as hopeless as it seems in the middle Or =
as=20
finished as it seems in the end. - =
/usr/games/fortune</FONT></DIV></BODY></HTML>

------=_NextPart_000_0013_01C1CC87.B70676F0--



From ricke@netidea.com  Sat Mar 16 07:16:41 2002
From: ricke@netidea.com (ricke)
Date: Fri, 15 Mar 2002 23:16:41 -0800
Subject: [Tutor] getting started on python
Message-ID: <000801c1ccba$89a415e0$7c7d35d1@oemcomputer>

This is a multi-part message in MIME format.

------=_NextPart_000_0005_01C1CC77.773633E0
Content-Type: text/plain;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

I just downloaded the python files, but have no idea how to begin.  Do I =
need other software to start?  I am using Windows 98 on a Pentium II.

Thanks,

Rick

------=_NextPart_000_0005_01C1CC77.773633E0
Content-Type: text/html;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252">
<META content=3D"MSHTML 6.00.2712.300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>I just downloaded the python files, but have no idea =
how to=20
begin.&nbsp; Do I need other software to start?&nbsp; I am using Windows =
98 on a=20
Pentium II.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Thanks,</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Rick</FONT></DIV></BODY></HTML>

------=_NextPart_000_0005_01C1CC77.773633E0--



From dave@primco.org  Sat Mar 16 07:30:25 2002
From: dave@primco.org (David Primmer)
Date: Fri, 15 Mar 2002 23:30:25 -0800
Subject: [Tutor] how to install python on unix machine if you don't have root
Message-ID: <000201c1ccbc$73990290$6401a8c0@redcloud>

You don't need root but you do need write privledges to a dir. This will
most likely be your homedir and so I use ~ in these docs. I did this
tonight on my web host http://www.webaxxs.net because they only offer
1.5.2. (newer accts get 2.1 I think) They're running redhat linux 6.2 on
intel. 

Read the README doc in the root of the tarball for more detailed info.

Get python http://python.org (I used the lynx browser to get it)

Download Python-2.2.tgz to your homedir or somewhere like that and
extract to Python-2.2 with the commands:

	tar zxf Python-2.2.tgz

	cd Python-2.2

Next, type this command to configure options for your system

	./configure

Normally you'd type 'make' in the root of Python-2.2 but if you run make
now you'll probably have some problems because this will attempt to
install everything in /usr/local/. These instructions are modified so
that python is installed into your home directory.

	make altinstall prefix=~ exec-prefix=~

'prefix=~' installs all platform-independent files in ~/lib and
'exec-prefix=~' installs all binary and other platform-specific files in
~/bin

This installs the same set of files as "make install" except it doesn't
create the hard link to "python<version>" named "python" and it doesn't
install the manual page at all.

I create a link in ~/bin with 
	
	ln -s python2.2 python

And since my system has python 1.5.2 in /usr/bin, in my .bashrc I
short-circuit that with 

	alias python='~/bin/python'

hope this helps out some newbies.

davep



From python@nzpagans.8m.com  Sat Mar 16 10:53:27 2002
From: python@nzpagans.8m.com (Grail)
Date: Sat, 16 Mar 2002 23:53:27 +1300
Subject: [Tutor] Re: getting started on python
References: <E16mAYh-0003Sn-00@mail.python.org>
Message-ID: <000b01c1ccd8$ce2ca880$0801a8c0@fugly>

I downloaded Python 2.1.2 - http://python.org/2.1.2/
(why? Because the Beginners page said to -
http://python.org/doc/Newbies.html )

A python group got installed in my Start menu, where I can go open "IDLE
(Python GUI)"

On the beginners page are links to:
One Day of IDLE Toying -
http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html
(explains how IDLE works. Simple)

And actual Python tutorials, I've started off with:
Instant Hacking - http://www.hetland.org/python/instant-hacking.php

If I can cope with that, anyone can - right?


And, hi to everyone on the list.
:)
I'm a complete newbie, unless you count a couple of weeks of PASCAL at
school, Python is *going to be* my first programming language.

Grail.

> From: "ricke" <ricke@netidea.com>
> To: <tutor@python.org>
> Date: Fri, 15 Mar 2002 23:16:41 -0800
> Subject: [Tutor] getting started on python
>
> This is a multi-part message in MIME format.
>
> ------=_NextPart_000_0005_01C1CC77.773633E0
> Content-Type: text/plain;
> charset="Windows-1252"
> Content-Transfer-Encoding: quoted-printable
>
> I just downloaded the python files, but have no idea how to begin.  Do I =
> need other software to start?  I am using Windows 98 on a Pentium II.
>
> Thanks,
>
> Rick




From python@nzpagans.8m.com  Sat Mar 16 11:21:18 2002
From: python@nzpagans.8m.com (Grail)
Date: Sun, 17 Mar 2002 00:21:18 +1300
Subject: [Tutor] Hello World.
References: <E16mAYh-0003Sn-00@mail.python.org>
Message-ID: <001301c1ccdc$b1d5e120$0801a8c0@fugly>

It says at http://www.geocities.com/SiliconValley/2072/python.htm
That all you need to type to display "Hello, World." is:
"Hello, World."
(no 'print' required)

In the python shell, this worked!
Saved as a program, it didn't.

So, why is there a difference between what you type in directly to the
Python Shell, and what you save as a program?




From pythontutor@venix.com  Sat Mar 16 14:07:57 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Sat, 16 Mar 2002 09:07:57 -0500
Subject: [Tutor] constructing tupples in 1.5.2
References: <001601c1ccb1$a0339fa0$18adf78c@virketis2>
Message-ID: <3C9351BD.20107@venix.com>

Untested code (and I do not have 1.5 to check against)
But it should be close.

Based on your message,  you probably have a list of dictionaries since
the keys are name, age and gender.  That implies one person per dictionary.

Possible working code:
insert_list = []
for d in dictionary_list:
	insert_list.append( (d[name], d[age], d[gender]) )


Pijus Virketis wrote:

> Dear all,
> 
>  
> 
> I am writting a MySQL script, which will be deployed on Py1.5.2. The 
> call to the database made through MySQLdb module must be in the form of 
> a list of tupples (e.g. [("John", 33, "M"), ("Sally", 35, "F"), ...]. 
> The thing is, I need to construct these tupples on the fly: I have a 
> dictionary of values (e.g. {"name": "John", "age": 33, ... }) and I want 
> to put the right values in the right places in a tupple. In Py2.2 this 
> is easy, because the tupple object has a handy __add__ method, which 
> concatenates two tupples. Py1.5.2, unfortunately, does not support this 
> method. What would be the most effective way of doing this? A workaround 
> I have though of is updating the table entry-by-entry, rather than 
> making one big update call, but it's obviously less efficient to run all 
> these INSERT querries.
> 
>  
> 
> Cheers,
> 
>  
> 
> Pijus
> 
>  
> 
>  
> 
> 
> ----------------------------
> Nothing is as simple as it seems at first Or as hopeless as it seems in 
> the middle Or as finished as it seems in the end. - /usr/games/fortune
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582



From pythontutor@venix.com  Sat Mar 16 14:15:58 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Sat, 16 Mar 2002 09:15:58 -0500
Subject: [Tutor] Hello World.
References: <E16mAYh-0003Sn-00@mail.python.org> <001301c1ccdc$b1d5e120$0801a8c0@fugly>
Message-ID: <3C93539E.1080200@venix.com>

In the Python Shell, results from expressions will be displayed if you
do not assign the result to a variable.  In a program, results from
an expression are simply discarded if the program does not save the
result to a variable.

A shell example:
 >>> 2+2
4
 >>> a = 2+2
 >>>

In a program, the first line
	2+2
will get python to calculate a result of 4.  HOWEVER, since the program
gives no instructions as to what to do with that result, Python will
simply discard it.  Effectively, the shell is a Python program the will
print results before the result is discarded.

Your program needs to say:
	print "Hello World"

Grail wrote:

> It says at http://www.geocities.com/SiliconValley/2072/python.htm
> That all you need to type to display "Hello, World." is:
> "Hello, World."
> (no 'print' required)
> 
> In the python shell, this worked!
> Saved as a program, it didn't.
> 
> So, why is there a difference between what you type in directly to the
> Python Shell, and what you save as a program?
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582



From alex@gabuzomeu.net  Sat Mar 16 14:32:21 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Sat, 16 Mar 2002 15:32:21 +0100
Subject: [Tutor] Uniques values in a list
Message-ID: <4.3.2.7.2.20020315190446.00c2c590@pop3.norton.antivirus>

Hello,


I wanted to filter out unique values in a list. Here is what I found (it is 
a frequent question listed in the Python FAQ) :

1) Using lists:
toto = [1, 2, 2, 4]
titi = []
for x in toto:
	if x not in titi:
		titi.append(x)
print titi
[1, 2, 4]


2) Using dictionaries:
toto = [1, 2, 2, 4]
d = {}
for x in toto:
	d[x] = 0
print d.keys()

This solution modifies the list order and only works if the list content 
can be used as a dictionary key (eg. is it "hashable").
Source : http://www.lemburg.com/files/python/lists.py.html


=> Do you know any other solution (eg. using functional programming or 
similar woodoo)?


Cheers.

Alexandre



From alex@gabuzomeu.net  Sat Mar 16 14:39:01 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Sat, 16 Mar 2002 15:39:01 +0100
Subject: [Tutor] constructing tupples in 1.5.2
In-Reply-To: <E16mAYh-0003Sh-00@mail.python.org>
Message-ID: <4.3.2.7.2.20020316152011.00b73b10@pop3.norton.antivirus>

Hello Pijus,


At 04:33 16/03/2002 -0500, you wrote:
>From: "Pijus Virketis" <virketis@fas.harvard.edu>
>To: <tutor@python.org>
>Date: Sat, 16 Mar 2002 01:13:00 -0500
>Subject: [Tutor] constructing tupples in 1.5.2

>I am writting a MySQL script, which will be deployed on Py1.5.2. The call 
>to the database made through MySQLdb module must be in the form of a list 
>of tupples (e.g. [("John", 33, "M"), ("Sally", 35, "F"), ...].
>The thing is, I need to construct these tupples on the fly: I have a
>dictionary of values (e.g. {"name": "John", "age": 33, ... })

Do you have a lot of information in these dictionaries (eg. do you need to 
store a lot of information for every person)?

>and I want  to put the right values in the right places in a tupple. In 
>Py2.2 this is easy, because the tupple object has a handy __add__ method, 
>which concatenates two tupples. Py1.5.2, unfortunately, does not support 
>this method. What would be the most effective way of doing this? A 
>workaround I have though of is updating the table entry-by-entry, rather 
>than making one big update call, but it's obviously less efficient to run all
>these INSERT querries.

Can you modify your dictionary structure if needed? Eg. could you use a 
tuple as dictionary key?

toto = {(1, "name"): "John", (2, "age"): 33, (3, "truc"): "muche"}

I haven't thought this out, but it might be useful to reconstruct the 
correct tuple order. Example:

titi = map(lambda x,y : x + (y,), toto.keys(), toto.values())
titi.sort()
[(1, 'name', 'John'), (2, 'age', 33), (3, 'truc', 'muche')]

Just a stab in the dark...


Cheers.

Alexandre



From shalehperry@attbi.com  Sat Mar 16 15:45:51 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Sat, 16 Mar 2002 07:45:51 -0800 (PST)
Subject: [Tutor] Uniques values in a list
In-Reply-To: <4.3.2.7.2.20020315190446.00c2c590@pop3.norton.antivirus>
Message-ID: <XFMail.20020316074551.shalehperry@attbi.com>

> 
> 
> => Do you know any other solution (eg. using functional programming or 
> similar woodoo)?
> 

the "standard" approach is to sort the list, then walk it.  You hold the first
index in your hand and look at the second.  If they match you dump the second
and move on to the third.  You continue until a non-match is found.  you then
hold the new item and look at the next one.

This is from the g++ 3.0 stl.

void list::unique
{
  iterator __first = begin();
  iterator __last = end();
  if (__first == __last) return;
  iterator __next = __first;
  while (++__next != __last) {
    if (*__first == *__next)
      erase(__next);
    else
      __first = __next;
    __next = __first;
  }
}

It does an in place cleaning.


From tim@johnsons-web.com  Sat Mar 16 18:08:42 2002
From: tim@johnsons-web.com (Tim Johnson)
Date: Sat, 16 Mar 2002 09:08:42 -0900
Subject: [Tutor] Need Simple Inheritance example
Message-ID: <20020316180842.GD6342@johnsons-web.com>

Hello All:
    Using python 2.1 on RH 7.2, Win98

    I'd like to build an FTP object that initializes with
    Host, login, and password as elements of a list, and
    then overloads the transfer methods with progress reporting.

    I've begun with the following code:
    class FtpNew(FTP):
        def __init__(self,_profile):
            self.login(profile[1],profile[2])

    and I would like to initialize the instance as

    params = ['www.host.com','login','password']
    ftp = FtpNew(params)

    I'm getting error messages about 'profile' being an undefined 
    global.
    Can anyone help me out here?
    Best regards
-- 
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com
      http://www.johnsons-web.com


From erikprice@mac.com  Sat Mar 16 18:12:39 2002
From: erikprice@mac.com (Erik Price)
Date: Sat, 16 Mar 2002 13:12:39 -0500
Subject: [Tutor] Parsing a file
In-Reply-To: <3C926921.4E5ECF3F@shaw.ca>
Message-ID: <6687E59C-3909-11D6-A658-00039351FE6A@mac.com>

On Friday, March 15, 2002, at 04:35  PM, Paul Sidorsky wrote:

> Lastly, the most common way to print multiple pieces of data is like
> this:
>
> print "%s %s" % (badword, line)
>
> If you stick some formatting stuff in there you can even get them to
> line up
> nicely:
>
> print "%-10s %-60s" % (badword, line)
>
> The % syntax is probably overkill for this, though, and since it's not
> all that easy to use unless you already know C (which is where it comes
> from) you can probably live without it for now.

I see this all the time -- in PHP it's printf() (to echo a formatted 
string) or sprintf() (to format a string and place it into a variable).

I have only used it once, though.  It seems that in a lot of tutorials, 
it is used frequently, and now I hear it confirmed by a Python-tutor 
sage that it is "the most common way to print multiple pieces of data".  
That interests me -- so, as a good rule of thumb, use "print 'x'" for 
printing single pieces of data but print '%s %s' (x, y) when printing 
multiple pieces?

Thank you for this style advice, of which I am always wondering.

Erik



From shalehperry@attbi.com  Sat Mar 16 18:10:44 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Sat, 16 Mar 2002 10:10:44 -0800 (PST)
Subject: [Tutor] Need Simple Inheritance example
In-Reply-To: <20020316180842.GD6342@johnsons-web.com>
Message-ID: <XFMail.20020316101044.shalehperry@attbi.com>

On 16-Mar-2002 Tim Johnson wrote:
> Hello All:
>     Using python 2.1 on RH 7.2, Win98
> 
>     I'd like to build an FTP object that initializes with
>     Host, login, and password as elements of a list, and
>     then overloads the transfer methods with progress reporting.
> 
>     I've begun with the following code:
>     class FtpNew(FTP):
>         def __init__(self,_profile):
>             self.login(profile[1],profile[2])
> 
>     and I would like to initialize the instance as
> 
>     params = ['www.host.com','login','password']
>     ftp = FtpNew(params)
> 
>     I'm getting error messages about 'profile' being an undefined 
>     global.
>     Can anyone help me out here?

Look in your python install, there are many inheritance examples there.  What
you are missing is that in python you must construct your parent, it is not
done for you.


From pythontutor@venix.com  Sat Mar 16 18:22:34 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Sat, 16 Mar 2002 13:22:34 -0500
Subject: [Tutor] Need Simple Inheritance example
References: <20020316180842.GD6342@johnsons-web.com>
Message-ID: <3C938D6A.3090504@venix.com>

My best guess is that you have a typo!

__init__ has a parameter _profile
BUT the call to login uses profile (witout the leading _)

Tim Johnson wrote:

> Hello All:
>     Using python 2.1 on RH 7.2, Win98
> 
>     I'd like to build an FTP object that initializes with
>     Host, login, and password as elements of a list, and
>     then overloads the transfer methods with progress reporting.
> 
>     I've begun with the following code:
>     class FtpNew(FTP):
>         def __init__(self,_profile):
>             self.login(profile[1],profile[2])
> 
>     and I would like to initialize the instance as
> 
>     params = ['www.host.com','login','password']
>     ftp = FtpNew(params)
> 
>     I'm getting error messages about 'profile' being an undefined 
>     global.
>     Can anyone help me out here?
>     Best regards
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582



From tim@johnsons-web.com  Sat Mar 16 19:30:29 2002
From: tim@johnsons-web.com (Tim Johnson)
Date: Sat, 16 Mar 2002 10:30:29 -0900
Subject: [Tutor] Need Simple Inheritance example
In-Reply-To: <3C938D6A.3090504@venix.com>
References: <20020316180842.GD6342@johnsons-web.com> <3C938D6A.3090504@venix.com>
Message-ID: <20020316193029.GF6342@johnsons-web.com>

* Lloyd Kvam <pythontutor@venix.com> [020316 09:45]:
> My best guess is that you have a typo!
 
  Yes, you are correct. Thank you!

> __init__ has a parameter _profile
> BUT the call to login uses profile (witout the leading _)
> 
> Tim Johnson wrote:
> 
> >Hello All:
> >    Using python 2.1 on RH 7.2, Win98
> >
> >    I'd like to build an FTP object that initializes with
> >    Host, login, and password as elements of a list, and
> >    then overloads the transfer methods with progress reporting.
> >
> >    I've begun with the following code:
> >    class FtpNew(FTP):
> >        def __init__(self,_profile):
> >            self.login(profile[1],profile[2])
> >
> >    and I would like to initialize the instance as
> >
> >    params = ['www.host.com','login','password']
> >    ftp = FtpNew(params)
> >
> >    I'm getting error messages about 'profile' being an undefined 
> >    global.
> >    Can anyone help me out here?
> >    Best regards
> >
> 
> 
> -- 
> Lloyd Kvam
> Venix Corp.
> 1 Court Street, Suite 378
> Lebanon, NH 03766-1358
> 
> voice: 
> 603-443-6155
> fax: 
> 801-459-9582

-- 
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com
      http://www.johnsons-web.com


From paulsid@shaw.ca  Sat Mar 16 20:19:38 2002
From: paulsid@shaw.ca (Paul Sidorsky)
Date: Sat, 16 Mar 2002 13:19:38 -0700
Subject: Printing style (was Re: [Tutor] Parsing a file)
References: <6687E59C-3909-11D6-A658-00039351FE6A@mac.com>
Message-ID: <3C93A8DA.18C2E4D@shaw.ca>

Erik Price wrote:

> > The % syntax is probably overkill for this, though, and since it's not
> > all that easy to use unless you already know C (which is where it comes
> > from) you can probably live without it for now.
> 
> I see this all the time -- in PHP it's printf() (to echo a formatted
> string) or sprintf() (to format a string and place it into a variable).

Yes, this looks like it comes directly from C, although I'm not familar
with PHP so I can't say for sure.

> I have only used it once, though.  It seems that in a lot of tutorials,
> it is used frequently, and now I hear it confirmed by a Python-tutor
> sage that it is "the most common way to print multiple pieces of data".
> That interests me -- so, as a good rule of thumb, use "print 'x'" for
> printing single pieces of data but print '%s %s' (x, y) when printing
> multiple pieces?

Loosely, I'd say that's a good guideline, but it's probably a bit too
general.  

Sometimes it's easier or nicer to use the comma or string addition.  In
the case that precipitated this thread I think the comma is the way to
go.  It's clear, clean, and quick to type.  The comma method doesn't
apply to string formation outside of print, though.

If you are concatenating strings and don't need any spacing or
punctuation then I think addition is a little nicer.  Compare these two
examples:

print prefix + word + suffix
print "%s%s%s" % (prefix, word, suffix)

I prefer the first one in this case for its clean look, even though the
second one isn't that bad and could also be considered more explicit.

However, with punctuation, the % way is a lot less awkward I think:

print "To: " + boss + ", " + employee + ", " + secretary
print "To: %s, %s, %s" % (boss, employee, secretary)

When in doubt I tend to use % because if nothing else it provides the
flexibility to make changes (e.g. add punctuation, formatting) with less
effort.  Also I come from a C background where the % codes and printf(),
sprintf(), fprintf(), etc. are more or less the only legitimate way to
do this kind of thing.

Of course for matters of style I always look first to PEP 8, the Python
Style Guide, at:

http://python.sourceforge.net/peps/pep-0008.html

String formatting is not specifically covered in the style guide, but
the guide's preamble says just about everything one ever needs to know
about style in any language:

> A Foolish Consistency is the Hobgoblin of Little Minds
> 
>     A style guide is about consistency. Consistency with this style
>     guide is important.  Consistency within a project is more
>     important. Consistency within one module or function is most
>     important.
> 
>     But most importantly: know when to be inconsistent -- sometimes
>     the style guide just doesn't apply. When in doubt, use your best
>     judgement. Look at other examples and decide what looks best. And
>     don't hesitate to ask!

Whenever doubts about style arise, reread the above.  Frame it and hang
it from your wall if you need to!  While it does take a long time to
develop good judgement about style, you're a lot less likely to go too
far off track if you keep this advice at the front of your mind.

Out of curiousity I conducted an incomplete, unscientific, and utterly
biased survey of Python 2.1's standard library and got the following
impressions:

- The comma is not uncommon, especially for things like error messages:
print "Error:", errormsg

- Addition is used but not very often.  It seems to be used mostly for
short constructions that have no more than 3 parts.

- % is actually not as common as I thought in printing, but it's used an
awful lot for construction of strings elsewhere.

- There are also some other methods used, like the backquote notation. 
I've never used this so I don't know where it's useful.

Probably the only thing that can be concluded from this (if anything can
be) is that programmers are free to choose so long as they are
reasonably consistent about it, which generally seemed to be the case.

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/



From wolf_binary@hotmail.com  Sat Mar 16 21:02:05 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Sat, 16 Mar 2002 15:02:05 -0600
Subject: [Tutor] functions and memory
Message-ID: <DAV56udlYLDFut1Pyks00014831@hotmail.com>

This is a multi-part message in MIME format.

------=_NextPart_000_0005_01C1CCFB.89783A60
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

When a function is done being used do the values for the variables in =
that function stay in memory?

Cameron Stoner

------=_NextPart_000_0005_01C1CCFB.89783A60
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.2713.1100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>When a function is done being used do =
the values=20
for the variables in that function stay in memory?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Cameron =
Stoner</FONT></DIV></BODY></HTML>

------=_NextPart_000_0005_01C1CCFB.89783A60--


From shalehperry@attbi.com  Sat Mar 16 21:31:03 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Sat, 16 Mar 2002 13:31:03 -0800 (PST)
Subject: [Tutor] functions and memory
In-Reply-To: <DAV56udlYLDFut1Pyks00014831@hotmail.com>
Message-ID: <XFMail.20020316133103.shalehperry@attbi.com>

On 16-Mar-2002 Cameron Stoner wrote:
> When a function is done being used do the values for the variables in that
> function stay in memory?
> 
> Cameron Stoner

Any object is marked for cleanup as soon as it leaves scope.  So when a
function ends all local variables are marked as unused and will be garbage
collected.


From Spam@nzpagans.8m.com  Sat Mar 16 14:41:33 2002
From: Spam@nzpagans.8m.com (Spam)
Date: Sun, 17 Mar 2002 02:41:33 +1200
Subject: [Tutor] Hello World.
References: <E16mAYh-0003Sn-00@mail.python.org> <001301c1ccdc$b1d5e120$0801a8c0@fugly> <3C93539E.1080200@venix.com>
Message-ID: <004301c1ccf8$ab4d4c50$0801a8c0@fugly>

Er, I know to type 'print'... But I was just intrigued, first by the website
(which may be old, or merely inaccurate), but more by the fact I couldn't
see why the Python Shell would be different.

Thanks for your reply.

Grail.

----- Original Message -----
From: "Lloyd Kvam" <pythontutor@venix.com>
To: "Grail" <python@nzpagans.8m.com>
Cc: <tutor@python.org>
Sent: Sunday, March 17, 2002 2:15 AM
Subject: Re: [Tutor] Hello World.


> In the Python Shell, results from expressions will be displayed if you
> do not assign the result to a variable.  In a program, results from
> an expression are simply discarded if the program does not save the
> result to a variable.
>
> A shell example:
>  >>> 2+2
> 4
>  >>> a = 2+2
>  >>>
>
> In a program, the first line
> 2+2
> will get python to calculate a result of 4.  HOWEVER, since the program
> gives no instructions as to what to do with that result, Python will
> simply discard it.  Effectively, the shell is a Python program the will
> print results before the result is discarded.
>
> Your program needs to say:
> print "Hello World"
>
> Grail wrote:
>
> > It says at http://www.geocities.com/SiliconValley/2072/python.htm
> > That all you need to type to display "Hello, World." is:
> > "Hello, World."
> > (no 'print' required)
> >
> > In the python shell, this worked!
> > Saved as a program, it didn't.
> >
> > So, why is there a difference between what you type in directly to the
> > Python Shell, and what you save as a program?
> >
> >
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
>
>
> --
> Lloyd Kvam
> Venix Corp.
> 1 Court Street, Suite 378
> Lebanon, NH 03766-1358
>
> voice:
> 603-443-6155
> fax:
> 801-459-9582
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>




From dyoo@hkn.eecs.berkeley.edu  Sat Mar 16 22:22:00 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat, 16 Mar 2002 14:22:00 -0800 (PST)
Subject: [Tutor] Hello World.
In-Reply-To: <004301c1ccf8$ab4d4c50$0801a8c0@fugly>
Message-ID: <Pine.LNX.4.21.0203161417270.14773-100000@hkn.eecs.berkeley.edu>

On Sun, 17 Mar 2002, Spam wrote:

> Er, I know to type 'print'... But I was just intrigued, first by the
> website (which may be old, or merely inaccurate), but more by the fact
> I couldn't see why the Python Shell would be different.

Python is designed to act slightly differently to make it more useful as
an interactive environment.  In interactive mode, values that would have
otherwise just fallen on the floor will get picked up and printed on
screen so we can see those values.  For example, in the interpreter:

###
>>> for x in range(10):
...     x
... 
###

actually prints numbers out, but that's just because Python expects that
we'd like to see those values.  In a preprepared program, though, Python
won't do this unless we explicitely say "print x".


Hope this helps!



From tim@johnsons-web.com  Sun Mar 17 01:08:32 2002
From: tim@johnsons-web.com (Tim Johnson)
Date: Sat, 16 Mar 2002 16:08:32 -0900
Subject: [Tutor] FTP File Size
Message-ID: <20020317010832.GH6342@johnsons-web.com>

Hello :
    Using python 2.1 on RH 7.2 and win98.
    I am finding that the ftp.size() command appears
    to be returning a size for a file at a remote ftp site
    consistanty larger than is actual.

    What I have seen of RFC959 makes no mention of SIZE command,
    and I see documentation in the standard distribution ftplib
    as follows:
    
        " Note that the RFC doesn't say anything about 'SIZE'"
        ==> line 454

    Can someone perhaps comment on this?
    Are others seeing the same results?
    Or am I doing something wrong.

    TIA
-- 
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com
      http://www.johnsons-web.com


From pythontutor@venix.com  Sun Mar 17 01:32:50 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Sat, 16 Mar 2002 20:32:50 -0500
Subject: [Tutor] Hello World.
References: <E16mAYh-0003Sn-00@mail.python.org> <001301c1ccdc$b1d5e120$0801a8c0@fugly> <3C93539E.1080200@venix.com> <004301c1ccf8$ab4d4c50$0801a8c0@fugly>
Message-ID: <3C93F242.1090303@venix.com>

I didn't mean to insult you.  Some of the queries come from people who are
fairly lost at first.

Spam wrote:

> Er, I know to type 'print'... But I was just intrigued, first by the website
> (which may be old, or merely inaccurate), but more by the fact I couldn't
> see why the Python Shell would be different.
> 
> Thanks for your reply.
> 
> Grail.
> 
> ----- Original Message -----
> From: "Lloyd Kvam" <pythontutor@venix.com>
> To: "Grail" <python@nzpagans.8m.com>
> Cc: <tutor@python.org>
> Sent: Sunday, March 17, 2002 2:15 AM
> Subject: Re: [Tutor] Hello World.
> 
> 
> 
>>In the Python Shell, results from expressions will be displayed if you
>>do not assign the result to a variable.  In a program, results from
>>an expression are simply discarded if the program does not save the
>>result to a variable.
>>
>>A shell example:
>> >>> 2+2
>>4
>> >>> a = 2+2
>> >>>
>>
>>In a program, the first line
>>2+2
>>will get python to calculate a result of 4.  HOWEVER, since the program
>>gives no instructions as to what to do with that result, Python will
>>simply discard it.  Effectively, the shell is a Python program the will
>>print results before the result is discarded.
>>
>>Your program needs to say:
>>print "Hello World"
>>
>>Grail wrote:
>>
>>
>>>It says at http://www.geocities.com/SiliconValley/2072/python.htm
>>>That all you need to type to display "Hello, World." is:
>>>"Hello, World."
>>>(no 'print' required)
>>>
>>>In the python shell, this worked!
>>>Saved as a program, it didn't.
>>>
>>>So, why is there a difference between what you type in directly to the
>>>Python Shell, and what you save as a program?
>>>
>>>
>>>
>>>_______________________________________________
>>>Tutor maillist  -  Tutor@python.org
>>>http://mail.python.org/mailman/listinfo/tutor
>>>
>>>
>>>
>>
>>--
>>Lloyd Kvam
>>Venix Corp.
>>1 Court Street, Suite 378
>>Lebanon, NH 03766-1358
>>
>>voice:
>>603-443-6155
>>fax:
>>801-459-9582
>>
>>
>>_______________________________________________
>>Tutor maillist  -  Tutor@python.org
>>http://mail.python.org/mailman/listinfo/tutor
>>
>>
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582



From sheila@thinkspot.net  Sun Mar 17 08:37:04 2002
From: sheila@thinkspot.net (Sheila King)
Date: Sun, 17 Mar 2002 00:37:04 -0800
Subject: [Tutor] Where to get Python patches?
Message-ID: <2DB28917763@kserver.org>

In this message:
http://groups.google.com/groups?as_umsgid=mailman.1014298776.15692.python-list%40python.org

Oleg Broytman writes that the following error message:

 File "/usr/local/lib/python2.2/email/Message.py", line 214, in get
    name = name.lower()
AttributeError: 'int' object has no attribute 'lower'


which was a bug in the email module, has been fixed and one should download
the "latest code from mimelib.sf.net".

However, I can't figure out where this latest code is or how to download
it. When I go to mimelib.sf.net, I get a somewhat broken page of the email
module docs. And I see no links to download files. When I go to the CVS for
Python at SourceForge.net, and look at the email module files, I'm not sure
which files, if any, I should download. There is something that is only 13
days old, there. But the rest of the stuff is at least 3 months old. So,
I'm not convinced this is the correct place to get the patch, either.

Could someone be VERY specific and tell me exactly where to go and how to
get this patch? I really need it for stuff I'm working on.

Thanks,

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/


From kalle@gnupung.net  Sun Mar 17 09:05:19 2002
From: kalle@gnupung.net (Kalle Svensson)
Date: Sun, 17 Mar 2002 10:05:19 +0100
Subject: [Tutor] Where to get Python patches?
In-Reply-To: <2DB28917763@kserver.org>
References: <2DB28917763@kserver.org>
Message-ID: <20020317090519.GA25396@sandra.lysator.liu.se>

[Sheila King]
[...]
> which was a bug in the email module, has been fixed and one should download
> the "latest code from mimelib.sf.net".
[...]
> Could someone be VERY specific and tell me exactly where to go and how to
> get this patch? I really need it for stuff I'm working on.

I would try the mimelib CVS, available from
http://sf.net/projects/mimelib.  It seems like there are files there
too that haven't been modified for some time, and the python CVS might
be just as good.

Peace,
  Kalle
-- 
Kalle Svensson (kalle@gnupung.net) - Laziness, impatience, hubris: Pick two!
English: http://www.gnupung.net/  Svenska: http://www.lysator.liu.se/~kalle/
Stuff: ["http://www.%s.org/" % x for x in "gnu debian python emacs".split()]


From Tron@submatrix.com  Sun Mar 17 12:38:52 2002
From: Tron@submatrix.com (Tron)
Date: Sun, 17 Mar 2002 04:38:52 -0800
Subject: [Tutor] Python forums
Message-ID: <001101c1cdb0$b1d21d40$6901a8c0@praxis>

This is a multi-part message in MIME format.

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

Does anyone know of Python forums that I could take a look at?  Not =
software to run a forum but to discuss and learn.

Thanks,
Tron

------=_NextPart_000_000E_01C1CD6D.A394ECA0
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.2713.1100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Does anyone know of Python forums that =
I could take=20
a look at?&nbsp; Not software to run a forum but to discuss and=20
learn.</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>Tron</FONT></DIV></BODY></HTML>

------=_NextPart_000_000E_01C1CD6D.A394ECA0--



From alex@gabuzomeu.net  Sun Mar 17 13:20:50 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Sun, 17 Mar 2002 14:20:50 +0100
Subject: [Tutor] Uniques values in a list
In-Reply-To: <XFMail.20020316074551.shalehperry@attbi.com>
References: <4.3.2.7.2.20020315190446.00c2c590@pop3.norton.antivirus>
Message-ID: <4.3.2.7.2.20020317140802.00b7e1f0@pop3.norton.antivirus>

Hi Sean,


At 07:45 16/03/2002 -0800, Sean 'Shaleh' Perry wrote:
[Filtering out unique values from a list:]
> > => Do you know any other solution (eg. using functional programming or
> > similar woodoo)?
>
>the "standard" approach is to sort the list, then walk it.  You hold the first
>index in your hand and look at the second.  If they match you dump the 
>second and move on to the third.  You continue until a non-match is 
>found.  you then hold the new item and look at the next one.

Thanks for this information. I guess this is the approach described in the 
Python FAQ. Here is an example (slighty modified):

def filterList(theList):
     if theList:
         theList.sort()
         last = theList[-1]
         for i in range(len(theList) - 2, -1, -1):
             if last == theList[i]:
                 del theList[i]
             else:
                 last = theList[i]
     return theList


if __name__ == "__main__":
     toto = [1, 2, 2, 3, 4, 5, 3, 2, 7]
     print filterList(toto)

 >>> [1, 2, 3, 4, 5, 7]

>This is from the g++ 3.0 stl.
>
>void list::unique
>{
>   iterator __first = begin();
>   iterator __last = end();
>   if (__first == __last) return;
>   iterator __next = __first;
>   while (++__next != __last) {
>     if (*__first == *__next)
>       erase(__next);
>     else
>       __first = __next;
>     __next = __first;
>   }
>}

One difference is that the Python example does a reverse loop, whereas your 
code snippet loops from first to last, if I understand it correctly.


Cheers.

Alexandre



From python@rcn.com  Sun Mar 17 13:28:10 2002
From: python@rcn.com (Raymond Hettinger)
Date: Sun, 17 Mar 2002 08:28:10 -0500
Subject: [Tutor] Uniques values in a list
References: <4.3.2.7.2.20020315190446.00c2c590@pop3.norton.antivirus>
Message-ID: <003801c1cdb7$95fbc920$83d8accf@othello>

----- Original Message -----
From: "Alexandre Ratti" <alex@gabuzomeu.net>
To: <tutor@python.org>
Sent: Saturday, March 16, 2002 9:32 AM
Subject: [Tutor] Uniques values in a list


> => Do you know any other solution (eg. using functional programming or
> similar woodoo)?

Here are the winning functions from a speed test of various implementations:

def uniq1(alist):                    # Fastest order preserving
    set = {}                            # memory: {key:key]*uniqcnt
    return [set.setdefault(e,e) for e in alist if e not in set]

def uniq4(alist):                       # Fastest non-order preserving
    set = {}
    map(set.__setitem__, alist, [])     # memory: [None]*n + {key:None}*u
    return set.keys()


Raymond Hettinger



From charlie@begeistert.org  Sun Mar 17 14:09:40 2002
From: charlie@begeistert.org (Charlie Clark)
Date: Sun, 17 Mar 2002 15:09:40 +0100
Subject: [Tutor] re: String formatting
In-Reply-To: <E16mWd5-0003yw-00@mail.python.org>
References: <E16mWd5-0003yw-00@mail.python.org>
Message-ID: <20020317151925.931.4@gormenghast.AUTODIAL>

On 2002-03-17 at 10:07:04 [+0100], tutor-request@python.org wrote:
> > print "%-10s %-60s" % (badword, line)
> >
> > The % syntax is probably overkill for this, though, and since it's not
> > all that easy to use unless you already know C (which is where it comes
> > from) you can probably live without it for now.

C-type formatting is really easy to trip over if you're not used to it; I'm not ;-). It doesn't feel like Python to me but it's obviously very useful to some people. It's quite useful for building SQL statements for example.

Concatenating objects either with "+" or using commas is really legible but often tiresome to type. I usually find I start with something like that and then move onto to something more efficient. One method which I didn't mentioned is using string.join() to do string formatting.
>>> data = ['mary', 'had', 'a', 'little', 'lamb']
>>> ",".join(data)
>>> 'mary', 'had', 'a', 'little', 'lamb'

Can be combined with great effect with other string methods and the ability to get a string representation from any Python data type is a godsend.

Charlie


From alex@gabuzomeu.net  Sun Mar 17 14:46:36 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Sun, 17 Mar 2002 15:46:36 +0100
Subject: [Tutor] Uniques values in a list
In-Reply-To: <003801c1cdb7$95fbc920$83d8accf@othello>
References: <4.3.2.7.2.20020315190446.00c2c590@pop3.norton.antivirus>
Message-ID: <4.3.2.7.2.20020317150641.00b711d0@pop3.norton.antivirus>

Hi Raymond,


At 08:28 17/03/2002 -0500, you wrote:
>From: "Raymond Hettinger" <python@rcn.com>
>Subject: Re: [Tutor] Uniques values in a list
>Date: Sun, 17 Mar 2002 08:28:10 -0500

[Filtering out unique values in a list]
> > => Do you know any other solution (eg. using functional programming or
> > similar woodoo)?
>
>Here are the winning functions from a speed test of various implementations:

Thanks for your input. I've added these solutions to my tests. They are the 
fastest solutions by far. The downside is that they both require Python 2.2.

>def uniq1(alist):                    # Fastest order preserving
>     set = {}                            # memory: {key:key]*uniqcnt
>     return [set.setdefault(e,e) for e in alist if e not in set]
>
>def uniq4(alist):                       # Fastest non-order preserving
>     set = {}
>     map(set.__setitem__, alist, [])     # memory: [None]*n + {key:None}*u
>     return set.keys()

Here are my results when running all 5 solutions:

Item count: 50000
Using a second list...
0.216866328858
Using a dictionary...
0.0358277278739
Using in place filtering...
0.210324158427
Filtering with list comprehension
0.000247238057568
Filtering with map
9.47047474682e-005

The last two solutions are order of magnitude faster than the others, 
that's impressive. 9.47e-005 is 0,0000947, right?


Cheers.

Alexandre



From python@rcn.com  Sun Mar 17 14:41:28 2002
From: python@rcn.com (Raymond Hettinger)
Date: Sun, 17 Mar 2002 09:41:28 -0500
Subject: [Tutor] Uniques values in a list
References: <4.3.2.7.2.20020315190446.00c2c590@pop3.norton.antivirus> <4.3.2.7.2.20020317150641.00b711d0@pop3.norton.antivirus>
Message-ID: <004c01c1cdc1$d332f980$83d8accf@othello>

----- Original Message -----
From: "Alexandre Ratti" <alex@gabuzomeu.net>
To: <tutor@python.org>
Cc: "Raymond Hettinger" <python@rcn.com>
Sent: Sunday, March 17, 2002 9:46 AM
Subject: Re: [Tutor] Uniques values in a list


> Thanks for your input. I've added these solutions to my tests. They are
the
> fastest solutions by far. The downside is that they both require Python
2.2.

The first only requires Python 2.0.  I think that is when list
comprehensions and setdefault went in.

>
> >def uniq1(alist):                    # Fastest order preserving
> >     set = {}                            # memory: {key:key}*uniqcnt
> >     return [set.setdefault(e,e) for e in alist if e not in set]
> >
> >def uniq4(alist):                       # Fastest non-order preserving
> >     set = {}
> >     map(set.__setitem__, alist, [])     # memory: [None]*n +
{key:None}*u
> >     return set.keys()
>
> Here are my results when running all 5 solutions:
>
> Item count: 50000
> Using a second list...
> 0.216866328858
> Using a dictionary...
> 0.0358277278739
> Using in place filtering...
> 0.210324158427
> Filtering with list comprehension
> 0.000247238057568
> Filtering with map
> 9.47047474682e-005
>
> The last two solutions are order of magnitude faster than the others,
> that's impressive. 9.47e-005 is 0,0000947, right?

Yes!

Raymond



From alex@gabuzomeu.net  Sun Mar 17 15:16:24 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Sun, 17 Mar 2002 16:16:24 +0100
Subject: [Tutor] Uniques values in a list
In-Reply-To: <004c01c1cdc1$d332f980$83d8accf@othello>
References: <4.3.2.7.2.20020315190446.00c2c590@pop3.norton.antivirus>
 <4.3.2.7.2.20020317150641.00b711d0@pop3.norton.antivirus>
Message-ID: <4.3.2.7.2.20020317160411.00b7b6c0@pop3.norton.antivirus>

Hi again,


At 09:41 17/03/2002 -0500, Raymond Hettinger wrote:

>Subject: Re: [Tutor] Uniques values in a list
>
> > Thanks for your input. I've added these solutions to my tests. They are the
> > fastest solutions by far. The downside is that they both require Python 
> 2.2.
>
>The first only requires Python 2.0.  I think that is when list
>comprehensions and setdefault went in.

No, "e not in set" seems unsupported in Python 2.1. I've modified your 1st 
solution to read :

     set = {}
     return [set.setdefault(e,e) for e in alist if not set.has_key(e)]

This runs in 2.1, though it is slightly slower:

Item count: 50000
Using a second list...
0.218316233399
Using a dictionary...
0.0351480327395
Using in place filtering...
0.208694901532
Using list comprehension (Python 2.1)
0.000308419000703
Using list comprehension (Python 2.2)
0.000226285679673
Filtering with map
9.47047474256e-005

> > The last two solutions are order of magnitude faster than the others,
> > that's impressive. 9.47e-005 is 0,0000947, right?
>Yes!

Now, I wonder whether we can backport your "map" solution to Python 2.0 and 
higher. :-)


Cheers.

Alex



From vdbroekw@wxs.nl  Sun Mar 17 15:13:35 2002
From: vdbroekw@wxs.nl (Walter van den Broek)
Date: Sun, 17 Mar 2002 16:13:35 +0100
Subject: [Tutor] lost
Message-ID: <3C94B29F.2D953513@wxs.nl>

I have a simple website, informative character, i want to redesign it in
xml using python as much as possible. From all the books i have i think
i can program automated formation of xml documents. I am a little
confused about the fastest way to transform xml to (X)HTML, i would like
to use css. Can anyone point me in the right direction.
I am using linux suse 7.3 prof and python 2.1
Thanks walter
lazy programmer


From erikprice@mac.com  Sun Mar 17 15:34:09 2002
From: erikprice@mac.com (Erik Price)
Date: Sun, 17 Mar 2002 10:34:09 -0500
Subject: [Tutor] lost
In-Reply-To: <3C94B29F.2D953513@wxs.nl>
Message-ID: <6CB7A1F2-39BC-11D6-A202-00039351FE6A@mac.com>

On Sunday, March 17, 2002, at 10:13  AM, Walter van den Broek wrote:

> I have a simple website, informative character, i want to redesign it in
> xml using python as much as possible. From all the books i have i think
> i can program automated formation of xml documents. I am a little
> confused about the fastest way to transform xml to (X)HTML, i would like
> to use css. Can anyone point me in the right direction.

The best way to take an XML document and transform it into an XHTML 
document is to use XSLT -- extensible style language transformations.

This is a superpowerful language, that lets you flexibly transform one 
XML document into another.  Simply put, you take an XML document and an 
XSLT style sheet and put them together with an XSLT parser like 
Sablotron or Saxon (the former is in C [I think] the latter is in Java, 
and I don't know of one in Python but there probably is one) and the 
resulting output document is the new XML document.  In your case you 
would want the resulting XML document to conform to the XHTML DTD.

This is also a fairly easy language to learn, similar to HTML and XML -- 
all it does is parse your XML document and look for certain 
elements/attributes/entities and follows the instructions that you 
specify in the XSLT document.  For more information, one of the best 
resources is http://www.w3.org/Style/XSL/ .  There are tutorials for 
using it listed on the right -- I learned about it with the PHP 
tutorial, and I don't see a Python one but google around and you may 
find something.

Let us know how it all works out!

Erik



From karthikg@aztec.soft.net  Sun Mar 17 15:47:39 2002
From: karthikg@aztec.soft.net (Karthik Gurumurthy)
Date: Sun, 17 Mar 2002 21:17:39 +0530
Subject: [Tutor] lost
In-Reply-To: <3C94B29F.2D953513@wxs.nl>
Message-ID: <NEBBJNMDEKBIBCMCNMBDIEDBDGAA.karthikg@aztec.soft.net>

>From all the books i have i think i can program automated formation of xml
documents.

Yes as already suggested, there is a very good opportunity for you to learn
XSLT.
Nice skill to have @ the moment :-).
PyXML0.7 has support for XSLT.
http://pyxml.sourceforge.net/
does'nt seem to be a part of standard python2.2 distribution. Am not
sure..c'd'nt find it in the module index.
So you can install pyxml and start using it.

I had problems finding the documentation..so did'nt really try it.
But i think now i shall give it another try.

..karthik




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


From alex@gabuzomeu.net  Sun Mar 17 16:56:21 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Sun, 17 Mar 2002 17:56:21 +0100
Subject: [Tutor] Uniques values in a list
In-Reply-To: <003801c1cdb7$95fbc920$83d8accf@othello>
References: <4.3.2.7.2.20020315190446.00c2c590@pop3.norton.antivirus>
Message-ID: <4.3.2.7.2.20020317174343.00b74ad0@pop3.norton.antivirus>

Hello,


At 08:28 17/03/2002 -0500, you wrote:
>From: "Raymond Hettinger" <python@rcn.com>
>Subject: Re: [Tutor] Uniques values in a list
>Date: Sun, 17 Mar 2002 08:28:10 -0500

[Filtering out unique values from a list.]

> > => Do you know any other solution (eg. using functional programming or
> > similar woodoo)?
>
>Here are the winning functions from a speed test of various implementations:

>def uniq4(alist):                       # Fastest non-order preserving
>     set = {}
>     map(set.__setitem__, alist, [])     # memory: [None]*n + {key:None}*u
>     return set.keys()

I modified this solution to run under Python 2.x:

def filterListWithMap21(aList):
     "Returns a list of unique list items."
     set = {}
     map(set.setdefault, aList, [])
     return set.keys()

I'm not sure what is the correct way to test these functions; I get 
inconsistent results.

- Here is my timer function:

import time

def actionTimer(action, *param):
     "Times an action."
     startTime = time.clock()
     action(*param)
     endTime = time.clock()
     return endTime - startTime

- Here is the function I use to create a list of values with duplicated 
entries:

import random

def createList(itemCount):
     "Returns a list filled with itemCount items."
     theList = []
     random.seed()
     for n in range(itemCount):
         theList.append(random.choice(range(50)))
     print "Item count: %i" % len(theList)
     return theList

- And here is the test function:

import sys

def runTest(itemCount = 50000):

     startList = createList(itemCount)

     sourceList = startList[:]
     assert sourceList == startList
     assert sourceList is not startList

     print "Using a second list..."
     print actionTimer(filterListWithList, sourceList)

     sourceList = startList[:]
     print "Using a dictionary..."
     print actionTimer(filterListWithDict, sourceList)

     sourceList = startList[:]
     print "Using in place filtering..."
     print actionTimer(filterListInPlace, sourceList)

     sourceList = startList[:]
     print "Using list comprehension (Python 2.1)..."
     print actionTimer(filterListWithComprehension21, sourceList)

     sourceList = startList[:]
     print "Using map (Python 2.1)..."
     print actionTimer(filterListWithMap21, sourceList)

     sourceList = startList[:]
     print "Using map and operator.setitem..."
     print actionTimer(filterListWithMapAndOperator, sourceList)

     # If version >= 2.2
     if eval(sys.version[:3]) >= 2.2:

         sourceList = startList[:]
         print "Using list comprehension (Python 2.2)..."
         print actionTimer(filterListWithComprehension22, sourceList)

         sourceList = startList[:]
         print "Using map (Python 2.2)..."
         print actionTimer(filterListWithMap22, sourceList)


Do they look reasonable?


Cheers.

Alexandre



From shalehperry@attbi.com  Sun Mar 17 19:14:55 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Sun, 17 Mar 2002 11:14:55 -0800 (PST)
Subject: [Tutor] Uniques values in a list
In-Reply-To: <4.3.2.7.2.20020317150641.00b711d0@pop3.norton.antivirus>
Message-ID: <XFMail.20020317111455.shalehperry@attbi.com>

> 
> Thanks for your input. I've added these solutions to my tests. They are the 
> fastest solutions by far. The downside is that they both require Python 2.2.
> 


replace the __setitem__ with setdefault.


From shalehperry@attbi.com  Sun Mar 17 19:16:57 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Sun, 17 Mar 2002 11:16:57 -0800 (PST)
Subject: [Tutor] Uniques values in a list
In-Reply-To: <4.3.2.7.2.20020317174343.00b74ad0@pop3.norton.antivirus>
Message-ID: <XFMail.20020317111657.shalehperry@attbi.com>

def benchmark(func, iters=100000):
    start = time.time()
    for i in range(iters):
        r = func(list1, list2)
    end = time.time()
    print "%d iterations of %s took: %.3f secs" % (iters, func, end - start)

was used on the python list Friday for similar testing.


From lumbricus@gmx.net  Sun Mar 17 19:18:27 2002
From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=)
Date: Sun, 17 Mar 2002 20:18:27 +0100 (MET)
Subject: [Tutor] FTP File Size
References: <20020317010832.GH6342@johnsons-web.com>
Message-ID: <22376.1016392707@www53.gmx.net>

> Hello :
>     Using python 2.1 on RH 7.2 and win98.
>     I am finding that the ftp.size() command appears
>     to be returning a size for a file at a remote ftp site
>     consistanty larger than is actual.

How much larger?
What kind of ftp server?
If its open source, how does it determine the size?
 
>     What I have seen of RFC959 makes no mention of SIZE command,
>     and I see documentation in the standard distribution ftplib
>     as follows:
>     
>         " Note that the RFC doesn't say anything about 'SIZE'"
>         ==> line 454

"http://www.python.org/doc/current/lib/ftp-objects.html":

| size(filename)
| Request the size of the file named filename on the server. 
| On success, the size of the file is returned as an integer, 
| otherwise None is  returned. Note that the "SIZE" command 
| is not standardized, but is supported by many common server
| implementations.

>     Can someone perhaps comment on this?
>     Are others seeing the same results?
>     Or am I doing something wrong.
> 
>     TIA

HTH, HAND and
Greetings, J"o!

-- 
$ make LOVE
Make: Don't know how to make LOVE.  Stop.
$ 


-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net



From python@rcn.com  Sun Mar 17 20:50:56 2002
From: python@rcn.com (Raymond Hettinger)
Date: Sun, 17 Mar 2002 15:50:56 -0500
Subject: [Tutor] Uniques values in a list
References: <XFMail.20020317111657.shalehperry@attbi.com>
Message-ID: <002001c1cdf5$71002100$a666accf@othello>

While we're building a test bench, I have a couple of
additions.  Do a full garbage collection just before the
timing starts -- this will reduce distortions due to gc.
Also, I would use xrange so that we don't eat-up
a meg of memory (100000 iters * (4 bytes per int + 4 bytes
per pointer to the int) ) before the function starts running.
At the end, print an excerpt of the results and its length.
That way you'll have some small assurance that the
function is really doing what it's supposed to.

Raymond


----- Original Message -----
From: "Sean 'Shaleh' Perry" <shalehperry@attbi.com>
To: "Alexandre Ratti" <alex@gabuzomeu.net>
Cc: <tutor@python.org>
Sent: Sunday, March 17, 2002 2:16 PM
Subject: Re: [Tutor] Uniques values in a list


>
import gc

> def benchmark(func, iters=100000):
       r = None
       gc.collect()
>     start = time.time()
>     for i in range(iters):
       # use xrange here instead of range
>         r = func(list1, list2)
>     end = time.time()
>     print "%d iterations of %s took: %.3f secs" % (iters, func, end -
start)
       print len(r), [:5]       # never hurts to get some validation that
the function works at all
>
> was used on the python list Friday for similar testing.
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



From glingl@aon.at  Sun Mar 17 21:24:33 2002
From: glingl@aon.at (Gregor Lingl)
Date: Sun, 17 Mar 2002 22:24:33 +0100
Subject: [Tutor] lost
References: <3C94B29F.2D953513@wxs.nl>
Message-ID: <005701c1cdfa$2245c380$1664a8c0@mega>

Maybe this new book (especially chaper 6)
could be helpful to you:

http://www.oreilly.com/catalog/pythonxml/toc.html

Gregor

----- Original Message ----- 
From: "Walter van den Broek" <vdbroekw@wxs.nl>
To: <tutor@python.org>
Sent: Sunday, March 17, 2002 4:13 PM
Subject: [Tutor] lost


> I have a simple website, informative character, i want to redesign it in
> xml using python as much as possible. From all the books i have i think
> i can program automated formation of xml documents. I am a little
> confused about the fastest way to transform xml to (X)HTML, i would like
> to use css. Can anyone point me in the right direction.
> I am using linux suse 7.3 prof and python 2.1
> Thanks walter
> lazy programmer
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 



From tim@johnsons-web.com  Sun Mar 17 22:24:17 2002
From: tim@johnsons-web.com (Tim Johnson)
Date: Sun, 17 Mar 2002 13:24:17 -0900
Subject: [Tutor] FTP File Size
In-Reply-To: <22376.1016392707@www53.gmx.net>
References: <20020317010832.GH6342@johnsons-web.com> <22376.1016392707@www53.gmx.net>
Message-ID: <20020317222417.GD10796@johnsons-web.com>

Hello:

* J=F6rg W=F6lke <lumbricus@gmx.net> [020317 10:39]:
> > Hello :
> >     Using python 2.1 on RH 7.2 and win98.
> >     I am finding that the ftp.size() command appears
> >     to be returning a size for a file at a remote ftp site
> >     consistanty larger than is actual.
>=20
> How much larger?

  Just a few percent larger.

> What kind of ftp server?

  Must ask domain hoster, but my guess is wu_ftpd, or FtpPro on
  RH linux. The clients I'm using (Midnight Commander and IglooFTP)
  are reporting correctly, I believe.

> If its open source, how does it determine the size?
 =20
   I'm using an object that inherits FTP from ftplib.=20
   =3D> using the "original" (not overloaded) 'size' method.
   I can send entire source if necessary.
> =20
> >     What I have seen of RFC959 makes no mention of SIZE command,
> >     and I see documentation in the standard distribution ftplib
> >     as follows:
> >    =20
> >         " Note that the RFC doesn't say anything about 'SIZE'"
> >         =3D=3D> line 454
>=20
> "http://www.python.org/doc/current/lib/ftp-objects.html":
>=20
> | size(filename)
> | Request the size of the file named filename on the server.=20
> | On success, the size of the file is returned as an integer,=20
> | otherwise None is  returned. Note that the "SIZE" command=20
> | is not standardized, but is supported by many common server
> | implementations.
>=20
> >     Can someone perhaps comment on this?
> >     Are others seeing the same results?
> >     Or am I doing something wrong.
> >=20
> >     TIA
>=20
> HTH, HAND and
> Greetings, J"o!
=20
  And thank you very much. :-)

> --=20
> $ make LOVE
> Make: Don't know how to make LOVE.  Stop.
> $=20
=20
  That's gcc for you...

>=20
> --=20
> GMX - Die Kommunikationsplattform im Internet.
> http://www.gmx.net
>=20
>=20
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--=20
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com
      http://www.johnsons-web.com


From erikprice@mac.com  Sun Mar 17 22:26:07 2002
From: erikprice@mac.com (Erik Price)
Date: Sun, 17 Mar 2002 17:26:07 -0500
Subject: [Tutor] lost
In-Reply-To: <005701c1cdfa$2245c380$1664a8c0@mega>
Message-ID: <F9BE655B-39F5-11D6-A202-00039351FE6A@mac.com>

On Sunday, March 17, 2002, at 04:24  PM, Gregor Lingl wrote:

> Maybe this new book (especially chaper 6)
> could be helpful to you:
>
> http://www.oreilly.com/catalog/pythonxml/toc.html
>
> Gregor

I'm kind of a dunce... I had forgotten that I have this book, 
backburnered and waiting for me to finish "Python Web Programming".  I 
can summarize some of the main points from Chapter 6 ("Transforming XML 
with XSLT"):

This chapter of the book starts with a short introduction to the theory 
behind XSLT, which you can get at W3C (linked to earlier in this 
thread).  It then goes on to show two different ways that you can take 
an XML document and transform it into HTML using an XSLT style sheet, 
the first way being with "simplified stylesheets" (which is a very 
limited but easy way to get your XML data into an [X]HTML document), and 
the second using "standalone stylesheets" (which are the traditional use 
of XSLT stylesheets, wherein you create XSL templates to handle the 
various XML elements that you may have used -- this is a more flexible 
way to go, especially if your data is not very homogenous).

The next few pages of the chapter are a more in-depth look at the 
functions available in XSLT, and how templates are best constructed.  
Following this are two detailed examples of using XSLT with Python: the 
first actually refers back to an example from an earlier chapter in the 
book (which focuses on SAX) and demonstrates how XSLT handles certain 
jobs much better than just using a straightup SAX program (specifically, 
transforming an XML document into a different XML document).  The second 
example discusses embedding 4XSLT (an open source XSLT parser 
implemented in Python with C extensions) into python CGI scripts for 
on-the-fly transformation upon HTTP request.

As far as XSLT processors go, the book explains that you can use any one 
you like, but recommends 4XSLT since it's open source and uses Python.  
If you need speed, I think Sablotron is supposed to be good, but might 
be tricky to connect.  Also, if you just want to experiment with XSLT 
right this minute, MSIE6 (5 on Macs) has a built-in XSLT processor.  As 
long as you construct the XSLT stylesheet correctly and link to the 
style sheet from the XML document, it should render correctly (I've 
tried it in IE and Mozilla 0.9.8).

Erik



From shalehperry@attbi.com  Sun Mar 17 23:12:05 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Sun, 17 Mar 2002 15:12:05 -0800 (PST)
Subject: [Tutor] Uniques values in a list
In-Reply-To: <002001c1cdf5$71002100$a666accf@othello>
Message-ID: <XFMail.20020317151205.shalehperry@attbi.com>

On 17-Mar-2002 Raymond Hettinger wrote:
> While we're building a test bench, I have a couple of
> additions.  Do a full garbage collection just before the
> timing starts -- this will reduce distortions due to gc.
> Also, I would use xrange so that we don't eat-up
> a meg of memory (100000 iters * (4 bytes per int + 4 bytes
> per pointer to the int) ) before the function starts running.
> At the end, print an excerpt of the results and its length.
> That way you'll have some small assurance that the
> function is really doing what it's supposed to.
> 

in tests I ran Friday, a loop using xrange ended up being slower.  This is
probably a case by case thing, but there does seem to be a trade off between
memory usage and speed (imagine that (-:)


From alan.gauld@bt.com  Sun Mar 17 23:47:47 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 17 Mar 2002 23:47:47 -0000
Subject: [Tutor] telling dir(_builtins_) from dir(__builtins__)
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C44B@mbtlipnt02.btlabs.bt.co.uk>

> How in the heck is a Newwbie to know  dir(_builtins_) 
> from dir(__builtins__)?!? both look like one hypen to me. 

> I have been working in Alan Gaulds book and ... don't 
> recall reading about this distinction. 

Assuming its the dead tree version you find it mentioned 
in the footnote on page 51 regarding the __init__() method.
It specifically says you need two underscores at each end.

Then again on page 79 discussing dir(__builtins__) the 
footnote remarks that "Many special names exist in Python, 
most of which are marked by this double underscore naming 
style"

So I did try... but I guess you could interpret a single 
underscore at each end as being a double underscore 
convention. If so sorry, I couldn't think of a clearer 
way to express it.

> exactly the kind of tedious dotting your I's and crossing 
> your T's that drove me nuts years ago when I tried to 
> learn basic but gave up. 

As I repeatedly remark in my book - computers are stupid. 
You have to be specific and precise. These  are the 
irritations of every programming language, sorry, but that's 
just how it is. Eventually siomebody might figure out how 
to make smarter interpreters, until then we're stuck with it.

Alan G


From alan.gauld@bt.com  Sun Mar 17 23:52:45 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 17 Mar 2002 23:52:45 -0000
Subject: [Tutor] curses module and screens on DOS
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C44C@mbtlipnt02.btlabs.bt.co.uk>

> I've read there is a module called curses to work with plain screens
> such as DOS or any other plain-text screen. However, I couldn't find
> it. 

It only comes standard with Unix.
There is a DOS version but with limited functionality and I
couldn't get it to work at all on one of my PCs.

Fred Lundh(?) has a generic console module that might do what 
you want and the msvcrt module also has a few DOS box routines.
Try a search on Google groups for python + console and 
you should unearth a URL.

Alan g


From python@nzpagans.8m.com  Mon Mar 18 01:34:14 2002
From: python@nzpagans.8m.com (Grail)
Date: Mon, 18 Mar 2002 13:34:14 +1200
Subject: [Tutor] Space
Message-ID: <001701c1ce1d$03704f70$0801a8c0@fugly>

This is a multi-part message in MIME format.

------=_NextPart_000_0014_01C1CE81.9847F440
Content-Type: text/plain;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

Another newbie question:
How can I *not* have a space between arguments(is that what they are =
called?)

E.g.
print oDay, suffix(oDay)

Displays as:
23 rd

I'd like to get rid of that space.


At http://starship.python.net/~da/jak/cookbook.html
It says
"In python, the print statement has very good default semantics --- most =
of the time, it does exactly what you want, putting a space between the =
arguments, and a newline at the end. If you want more control over the =
formatting, use the % operator [link to % operator]: rather than=20
    print k, ':', string.join(v)

you could use=20
print "%s: %s", (k, string.join(v))

to avoid the space before the colon."


I tried:
print "%s: %s", (oDay, suffix(oDay))

(just to see if it would work) But it displayed as:
%s: %s (12, 'th')


This is such a tiny little thing, sorry I couldn't find the answer =
myself!

------=_NextPart_000_0014_01C1CE81.9847F440
Content-Type: text/html;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252"><BASE=20
href=3D"file://C:\Program Files\Common Files\Microsoft =
Shared\Stationery\">
<STYLE>BODY {
	BACKGROUND-POSITION: left top; FONT-SIZE: 10pt; MARGIN-LEFT: 10px; =
COLOR: #000000; BACKGROUND-REPEAT: no-repeat; FONT-FAMILY: Arial
}
</STYLE>

<META content=3D"MSHTML 6.00.2713.1100" name=3DGENERATOR></HEAD>
<BODY vLink=3Dgreen link=3Dorange bgColor=3D#ffffff>
<DIV>Another newbie question:</DIV>
<DIV>How can I *not* have a space between arguments(is that what they =
are=20
called?)</DIV>
<DIV>&nbsp;</DIV>
<DIV>E.g.</DIV>
<DIV>print&nbsp;oDay, suffix(oDay)</DIV>
<DIV>&nbsp;</DIV>
<DIV>Displays as:</DIV>
<DIV>23 rd</DIV>
<DIV>&nbsp;</DIV>
<DIV>I'd like to get rid of that space.</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>At <A=20
href=3D"http://starship.python.net/~da/jak/cookbook.html">http://starship=
.python.net/~da/jak/cookbook.html</A></DIV>
<DIV>It says</DIV>
<DIV>"In python, the print statement has very good default semantics --- =
most of=20
the time, it does exactly what you want, putting a space between the =
arguments,=20
and a newline at the end. If you want more control over the formatting, =
use the=20
<CODE>%</CODE> operator [link to % operator]: rather than <XMP>    print =
k, ':', string.join(v)
</XMP>you could use <XMP>print "%s: %s", (k, string.join(v))
</XMP>to avoid the space before the colon."</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>I tried:</DIV>
<DIV>print "%s: %s", (oDay, suffix(oDay))</DIV>
<DIV>&nbsp;</DIV>
<DIV>(just to see if it would work) But it displayed as:</DIV>
<DIV>%s: %s (12, 'th')</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>This is&nbsp;such a tiny&nbsp;little thing, sorry I couldn't find =
the=20
answer myself!</DIV></BODY></HTML>

------=_NextPart_000_0014_01C1CE81.9847F440--




From scarblac@pino.selwerd.nl  Mon Mar 18 01:41:29 2002
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 18 Mar 2002 02:41:29 +0100
Subject: [Tutor] Space
In-Reply-To: <001701c1ce1d$03704f70$0801a8c0@fugly>; from python@nzpagans.8m.com on Mon, Mar 18, 2002 at 01:34:14PM +1200
References: <001701c1ce1d$03704f70$0801a8c0@fugly>
Message-ID: <20020318024129.A10493@pino.selwerd.nl>

On  0, Grail <python@nzpagans.8m.com> wrote:
> At http://starship.python.net/~da/jak/cookbook.html
> It says
> "In python, the print statement has very good default semantics --- most of the time, it does exactly what you want, putting a space between the arguments, and a newline at the end. If you want more control over the formatting, use the % operator [link to % operator]: rather than 
>     print k, ':', string.join(v)
> 
> you could use 
> print "%s: %s", (k, string.join(v))
> 
> to avoid the space before the colon."

This should read 

print "%s:%s" % (k, string.join(v))

Note the % (and the absence of the space in the string - otherwise there
will still be a space there...

-- 
Remco Gerlich


From python@nzpagans.8m.com  Mon Mar 18 01:55:19 2002
From: python@nzpagans.8m.com (Grail)
Date: Mon, 18 Mar 2002 13:55:19 +1200
Subject: [Tutor] Space
References: <001701c1ce1d$03704f70$0801a8c0@fugly> <20020317203444.35e1af94.rufmetal@rogers.com>
Message-ID: <002201c1ce1f$f789b630$0801a8c0@fugly>

Er, no?

Tried that (and just tried it again). I still get a space.
I'm using Python 2.1.2 by the way...


(I'm almost relieved that *didn't* work, and prove me a complete egiot - but
the day is young...)

----- Original Message -----
From: "Chris Keelan" <rufmetal@rogers.com>
To: "Grail" <python@nzpagans.8m.com>
Sent: Monday, March 18, 2002 1:34 PM
Subject: Re: [Tutor] Space


> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Dateline: Mon, 18 Mar 2002 13:34:14 +1200: laying low until the bleeding
> stops, "Grail" <python@nzpagans.8m.com> transmits:
>
> > Another newbie question:
> > How can I *not* have a space between arguments(is that what they are
> > called?)
> >
> > E.g.
> > print oDay, suffix(oDay)
> >
> > Displays as:
> > 23 rd
> >
> > I'd like to get rid of that space.
>
> print oDay,suffix(oDay)
>
> HTH
>
> ~ C
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.6 (GNU/Linux)
> Comment: Processed by Mailcrypt 3.5.6 and Gnu Privacy Guard
> <http://www.gnupg.org/>
>
> iD8DBQE8lUQls7Brp8Mn7wcRAsp1AJ9cdcPf2y5f73UmdqhadV2WWHnhsgCeNJeL
> OXFWCzlm4yLYsEpIylm3BN4=
> =BPUw
> -----END PGP SIGNATURE-----
>




From python@nzpagans.8m.com  Mon Mar 18 02:15:53 2002
From: python@nzpagans.8m.com (Grail)
Date: Mon, 18 Mar 2002 14:15:53 +1200
Subject: [Tutor] Space
References: <001701c1ce1d$03704f70$0801a8c0@fugly><20020317203444.35e1af94.rufmetal@rogers.com><002201c1ce1f$f789b630$0801a8c0@fugly> <20020317205807.2c2c81b5.rufmetal@rogers.com>
Message-ID: <003a01c1ce22$d5362570$0801a8c0@fugly>

Yep!
That works.

:)


----- Original Message -----
From: "Chris Keelan" <rufmetal@rogers.com>
To: "Grail" <python@nzpagans.8m.com>
Sent: Monday, March 18, 2002 1:58 PM
Subject: Re: [Tutor] Space


> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Dateline: Mon, 18 Mar 2002 13:55:19 +1200: laying low until the bleeding
> stops, "Grail" <python@nzpagans.8m.com> transmits:
>
> > Er, no?
> >
> > Tried that (and just tried it again). I still get a space.
> > I'm using Python 2.1.2 by the way...
> >
> >
> > (I'm almost relieved that *didn't* work, and prove me a complete egiot -
but
> > the day is young...)
> >
> Hmmm. Now I'm puzzled.
>
> Try Remco's suggestion of a format string, i.e.:
>
> someVar = "%s%s" % (oDay, suffix(oDay))
> print someVar
>
> That should do it.
>
> ~ C
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.6 (GNU/Linux)
> Comment: Processed by Mailcrypt 3.5.6 and Gnu Privacy Guard
> <http://www.gnupg.org/>
>
> iD8DBQE8lUmfs7Brp8Mn7wcRAmS3AJ9gNP44xGPU+RjlQqtEuU/9mpS4qgCcCbry
> BpbZ7ZJS+7cvNdpAfdzQeEA=
> =Avng
> -----END PGP SIGNATURE-----
>




From shalehperry@attbi.com  Mon Mar 18 02:34:17 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Sun, 17 Mar 2002 18:34:17 -0800 (PST)
Subject: [Tutor] Space
In-Reply-To: <001701c1ce1d$03704f70$0801a8c0@fugly>
Message-ID: <XFMail.20020317183417.shalehperry@attbi.com>

> 
> 
> At http://starship.python.net/~da/jak/cookbook.html
> It says
> "In python, the print statement has very good default semantics --- most of
> the time, it does exactly what you want, putting a space between the
> arguments, and a newline at the end. If you want more control over the
> formatting, use the % operator [link to % operator]: rather than 
>     print k, ':', string.join(v)
> 
> you could use 
> print "%s: %s", (k, string.join(v))
> 
> to avoid the space before the colon."
> 

as Remco points out, the cookbook here is wrong.  You did nothing wrong, you
just read a bum example (-:


From karshi.hasanov@utoronto.ca  Mon Mar 18 03:42:32 2002
From: karshi.hasanov@utoronto.ca (Karshi)
Date: Sun, 17 Mar 2002 22:42:32 -0500
Subject: [Tutor] array
Message-ID: <20020318034258Z234676-24735+5@bureau8.utcc.utoronto.ca>

Hi all,

 How do find the maximum number in an array: say A[i,j] ?
I've got the following error when I tried to use "max":
--------------------------------------------------------------------
>>> M=array([[1,2,3,],[3,4,56],[4,6,8]], Float32)
>>> M
array([[  1.,   2.,   3.],
       [  3.,   4.,  56.],
       [  4.,   6.,   8.]],'f')
>>> max(M)
array([ 4.,  6.,  8.],'f')
---------------------------------------------------------------------
which is not true.


From paulsid@shaw.ca  Mon Mar 18 03:58:19 2002
From: paulsid@shaw.ca (Paul Sidorsky)
Date: Sun, 17 Mar 2002 20:58:19 -0700
Subject: [Tutor] array
References: <20020318034258Z234676-24735+5@bureau8.utcc.utoronto.ca>
Message-ID: <3C9565DB.9C782163@shaw.ca>

Karshi wrote:

>  How do find the maximum number in an array: say A[i,j] ?
> I've got the following error when I tried to use "max":
> --------------------------------------------------------------------
> >>> M=array([[1,2,3,],[3,4,56],[4,6,8]], Float32)
> >>> M
> array([[  1.,   2.,   3.],
>        [  3.,   4.,  56.],
>        [  4.,   6.,   8.]],'f')
> >>> max(M)
> array([ 4.,  6.,  8.],'f')
> ---------------------------------------------------------------------
> which is not true.

Actually it is true.  Python does a memberwise comparison of sequence
types, and 4>3>1 so the last row is the biggest according to Python's
comparison logic.

Anyhow, try this:

>>> max([max(row) for row in M])
56.0

This pulls the maximum out of each row and then takes the maximum of
those maximums.  

I don't know if there's a faster solution using NumPy itself, but at
least this is something that seems to work.

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/


From ajs@ix.netcom.com  Sun Mar 17 14:38:14 2002
From: ajs@ix.netcom.com (Arthur Siegel)
Date: Sun, 17 Mar 2002 09:38:14 -0500
Subject: [Tutor] Operator overloading surprise
Message-ID: <000701c1cdc1$5fa95680$0334fea9@carol>

I posted the below on the python-list, and other than
a response seeming to share my surprise (and verifying that
the behavior can be duplicated), not much interest.  Thought
I'd try here.


Given:

class Complex(complex):
    def __mul__(self,other):
       other=Complex(other)
       t = complex.__mul__(self,other)
       return Complex(t.real,t.imag)
    __rmul__ = __mul__

    def __add__(self,other):
       other=Complex(other)
       return Complex(self.real.__add__
(other.real),self.imag.__add__(other.imag))
    __radd__ = __add__

Then:

print type(Complex(5,4) * 7)
>><class '__main__.Complex'>
print type(7 * Complex(5,4))
>><class '__main__.Complex'>
print type(Complex(5,4) + 7)
>><class '__main__.Complex'>

But:

print type(7 + Complex(5,4))
>><type 'complex'>

That the result at But is a surprise to me because I am missing:
      1)Something obvious about __radd__ or general classic syntax
      2)Something related to new style classes
      3)Other

Art






From red1355555@hotmail.com  Sun Mar 17 20:58:56 2002
From: red1355555@hotmail.com (red)
Date: Sun, 17 Mar 2002 12:58:56 -0800
Subject: [Tutor] python eney were
Message-ID: <OE13pugf4zkS71hxba0000194a6@hotmail.com>

This is a multi-part message in MIME format.

------=_NextPart_000_0005_01C1CDB3.7FAF00A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi i was wondering if there is eney way that i coud run a program that i =
made on python without installing python on that computer??

------=_NextPart_000_0005_01C1CDB3.7FAF00A0
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.2713.1100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi i was wondering if there is eney way =
that i coud=20
run a program that i made on python without installing python on that=20
computer??</FONT></DIV></BODY></HTML>

------=_NextPart_000_0005_01C1CDB3.7FAF00A0--


From dyoo@decrem.com  Mon Mar 18 05:21:39 2002
From: dyoo@decrem.com (dyoo@decrem.com)
Date: Sun, 17 Mar 2002 21:21:39 -0800 (PST)
Subject: [Tutor] telling dir(_builtins_) from dir(__builtins__)
 [spellchecking Python?]
Message-ID: <Pine.LNX.4.44.0203172008340.18232-100000@ns.decrem.com>

> As I repeatedly remark in my book - computers are stupid.  You have to
> be specific and precise. These are the irritations of every programming
> language, sorry, but that's just how it is.

It's actually something of a tradeoff between making the interpreter
efficient and making it more "nice" for people.  We could imagine a small
spelling-checker built into the Python interpreter that might check up on
a NameError and say something like:

"""Namerror: global name 'foo' is not defined.  Perhaps you mean 'Foo'?"""

IBM's 'jikes' Java compiler, for example, actually does this kind of
checking on the compilation step.  It might be good to expect this sort of
helpfulness from the interactive interpreter too, especially because time
isn't so much an issue here.



> Eventually somebody might figure out how to make smarter interpreters,
> until then we're stuck with it.

That sounds like a challenge.  *grin*

For fun, let's see how much work it might take to add such a spell
checking feature to Python's interactive interpreter.  How would we start?



Python has a function called 'difflib' which tells us how "closely"  
strings match up to each other --- it measures the relative difference
between strings.

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

We can cook up a very quick spellchecker by using 'difflib':

###
def spellcheck(misspelled, candidates):
    """Given a misspelled word, returns the best choices among a list
    of candidates.

    At the moment, this is just a call to difflib's
    get_close_matches() function, but we might want to use a more
    powerful spell checker when we have the chance."""
    return difflib.get_close_matches(misspelled, candidates)
###

Let's take a look:

###
>>> spellcheck('grob', ['glob', 'croak', 'foo'])
['glob']
>>> spellcheck('_builtins_', dir())
['__builtins__']
###

Ok, that step wasn't so bad.  *grin*



Every exception carries with it a 'stack frame' --- it's this "frame" that
contains all the names and values that a program uses to look up variable
values.

    http://www.python.org/doc/current/ref/execframes.html


These frames are accessible if we use the sys.exc_info() function.  For
example:

###
>>> def oops():
...     print _builtins_
... 
>>> try:
...     oops()
... except:
...     frame = sys.exc_info()[2].tb_frame
... 
>>> frame
<frame object at 0x819777c>
>>> dir(frame)
['__class__', '__delattr__', '__getattribute__', '__hash__', '__init__', 
'__new__', '__reduce__', '__repr__', '__setattr__', '__str__', 'f_back', 
'f_builtins', 'f_code', 'f_exc_traceback', 'f_exc_type', 'f_exc_value', 
'f_globals', 'f_lasti', 'f_lineno', 'f_locals', 'f_restricted', 'f_trace'] 
###

So once we see an NameError exception in action, we can pull out a frame,
and stare all all the possible names we can use... and that's where we can
pull out a candidate list of names to spell check against!



But how can we tie this into our programs, so that a NameError will
provoke our spellchecking system into action?  One possible solution is to
put our code within an exception-handling fence.  Here's a function that
will do just that:


###
def protect(function):
    def spell_check_wrapper(*args, **kwargs):
        try:
            return function(*args, **kwargs)
        except NameError:
            type, name_error, tb = sys.exc_info()
            misspelled = getNameFromNameError(name_error)
            choices = (tb.tb_frame.f_locals.keys()
                       + tb.tb_frame.f_globals.keys())
            corrections = map(repr, spellcheck(misspelled, choices))
            if corrections:
                msg = (str(name_error)
                       + ".  Perhaps you meant one of the following: "
                       + string.join(corrections, ','))
            else:
                msg = str(name_error)
            raise NameError, msg
    return spell_check_wrapper


def getNameFromNameError(name_error):
    """Extracts the 'name' from a NameError.  Dunno if this is a
    method of a NameError instance."""
    return str(name_error).split("'")[1]
###



The code is a bit ugly, but what it does is fairly simple: whenever a
NameError occurs, it tries to intercept and see if any variable names are
already defined that are similar in spelling.  If such a correction is
possible, it'll try to improve the error message.


Does this work?

###
>>> oops_protected = protect(oops)
>>> oops_protected()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/tmp/python-1037YCW", line 51, in spell_check_wrapper
NameError: global name '_builtins_' is not defined.  Perhaps you meant one 
of the following: '__builtins__'
###

*grin* Cool!


If someone is sufficiently interested, perhaps we can tie this into the
IDLE environment, since this seems like something that would be useful to
folks.


Hope this helps!



From dyoo@decrem.com  Mon Mar 18 05:33:34 2002
From: dyoo@decrem.com (Danny Yoo)
Date: Sun, 17 Mar 2002 21:33:34 -0800 (PST)
Subject: [Tutor] array
In-Reply-To: <3C9565DB.9C782163@shaw.ca>
Message-ID: <Pine.LNX.4.44.0203172127150.18232-100000@ns.decrem.com>

On Sun, 17 Mar 2002, Paul Sidorsky wrote:

> Karshi wrote:
> 
> >  How do find the maximum number in an array: say A[i,j] ?
> > I've got the following error when I tried to use "max":
> > --------------------------------------------------------------------
> > >>> M=array([[1,2,3,],[3,4,56],[4,6,8]], Float32)
> > >>> M
> > array([[  1.,   2.,   3.],
> >        [  3.,   4.,  56.],
> >        [  4.,   6.,   8.]],'f')
> > >>> max(M)
> > array([ 4.,  6.,  8.],'f')
> > ---------------------------------------------------------------------
> > which is not true.

Numeric's 'Ufuncs' work on entire columns at a time, so you may need to
apply the max() Ufunc twice to get the effect you want:


###
>>> from Numeric import *
>>> M = array([[1, 2, 3],
...            [4, 5, 6],
...            [7, 8, 9]])
>>> 
>>> M
array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]])
>>> max(M)
array([7, 8, 9])
>>> max(max(M))
9
###


You can read more details about Ufuncs here:

    http://www.pfdubois.com/numpy/html2/numpy-7.html#pgfId-36126

Good luck!



From acobb@oeb.harvard.edu  Mon Mar 18 04:35:28 2002
From: acobb@oeb.harvard.edu (Alex Cobb)
Date: Sun, 17 Mar 2002 23:35:28 -0500
Subject: [Tutor] array
In-Reply-To: <3C9565DB.9C782163@shaw.ca>
References: <20020318034258Z234676-24735+5@bureau8.utcc.utoronto.ca>
Message-ID: <5.1.0.14.0.20020317231913.024260b0@pop.fas.harvard.edu>

Hi there,

         I'm hardly a Numeric wiz but I've been using this:

 >>> import Numeric
 >>> M = Numeric.arange(0, 25)           ## creates a 1-D example array of 
values 0 to 24
 >>> M = Numeric.reshape(M, (5,5))               ## makes this into a 
square 2-D matrix
 >>> M
array([[ 0,  1,  2,  3,  4],
        [ 5,  6,  7,  8,  9],
        [10, 11, 12, 13, 14],
        [15, 16, 17, 18, 19],
        [20, 21, 22, 23, 24]])
 >>> max = Numeric.maximum.reduce(M.flat)
 >>> max
24

I don't know how this compares in terms of speed to the solution
below (" max([max(row) for row in M]) "), but it's a pretty
convenient if you're already using NumPy.

Hope this helps

Alex

At 08:58 PM 3/17/2002 -0700, Paul Sidorsky wrote:
>Karshi wrote:
>
> >  How do find the maximum number in an array: say A[i,j] ?
> > I've got the following error when I tried to use "max":
> > --------------------------------------------------------------------
> > >>> M=array([[1,2,3,],[3,4,56],[4,6,8]], Float32)
> > >>> M
> > array([[  1.,   2.,   3.],
> >        [  3.,   4.,  56.],
> >        [  4.,   6.,   8.]],'f')
> > >>> max(M)
> > array([ 4.,  6.,  8.],'f')
> > ---------------------------------------------------------------------
> > which is not true.
>
>Actually it is true.  Python does a memberwise comparison of sequence
>types, and 4>3>1 so the last row is the biggest according to Python's
>comparison logic.
>
>Anyhow, try this:
>
> >>> max([max(row) for row in M])
>56.0
>
>This pulls the maximum out of each row and then takes the maximum of
>those maximums.
>
>I don't know if there's a faster solution using NumPy itself, but at
>least this is something that seems to work.
>
>--
>======================================================================
>Paul Sidorsky                                          Calgary, Canada
>paulsid@shaw.ca                        http://members.shaw.ca/paulsid/
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor





From jonikas@ldr.lt  Mon Mar 18 06:01:53 2002
From: jonikas@ldr.lt (Jonikas Valdemaras)
Date: Mon, 18 Mar 2002 08:01:53 +0200
Subject: [Tutor] python eney were
References: <OE13pugf4zkS71hxba0000194a6@hotmail.com>
Message-ID: <022d01c1ce42$67702250$12f6c50a@LDR.local>

>> ----- Original Message -----
>> From: "red" <red1355555@hotmail.com>
>> To: <tutor@python.org>
>> Sent: Sunday, March 17, 2002 10:58 PM
>> Subject: [Tutor] python eney were
>>

>> Hi i was wondering if there is eney way that i coud run a program that i
made on python without installing python >> on that computer??


Hello,

If your OS is Windows, you could try this:

http://starship.python.net/crew/theller/py2exe/

Regards,
Valdas



From dyoo@decrem.com  Mon Mar 18 06:06:54 2002
From: dyoo@decrem.com (Danny Yoo)
Date: Sun, 17 Mar 2002 22:06:54 -0800 (PST)
Subject: [Tutor] python eney were
In-Reply-To: <OE13pugf4zkS71hxba0000194a6@hotmail.com>
Message-ID: <Pine.LNX.4.44.0203172205550.18773-100000@ns.decrem.com>

On Sun, 17 Mar 2002, red wrote:

> Hi i was wondering if there is eney way that i coud run a program that i
> made on python without installing python on that computer??

Yes, you can use the 'py2exe' utility to package up your program:

    http://py2exe.sourceforge.net/

A few of us here on Tutor have experience with py2exe, so if you have
questions, please feel free to ask on Tutor.


Good luck!



From dyoo@decrem.com  Mon Mar 18 10:53:58 2002
From: dyoo@decrem.com (Danny Yoo)
Date: Mon, 18 Mar 2002 02:53:58 -0800 (PST)
Subject: [Tutor] Operator overloading surprise
In-Reply-To: <000701c1cdc1$5fa95680$0334fea9@carol>
Message-ID: <Pine.LNX.4.44.0203180234300.19672-100000@ns.decrem.com>

On Sun, 17 Mar 2002, Arthur Siegel wrote:

> I posted the below on the python-list, and other than
> a response seeming to share my surprise (and verifying that
> the behavior can be duplicated), not much interest.  Thought
> I'd try here.
> 
> 
> Given:
> 
> class Complex(complex):
>     def __mul__(self,other):
>        other=Complex(other)
>        t = complex.__mul__(self,other)
>        return Complex(t.real,t.imag)
>     __rmul__ = __mul__
> 
>     def __add__(self,other):
>        other=Complex(other)
>        return Complex(self.real.__add__
> (other.real),self.imag.__add__(other.imag))
>     __radd__ = __add__
> 
> Then:
> 
> print type(Complex(5,4) * 7)
> >><class '__main__.Complex'>
> print type(7 * Complex(5,4))
> >><class '__main__.Complex'>
> print type(Complex(5,4) + 7)
> >><class '__main__.Complex'>
> 
> But:
> 
> print type(7 + Complex(5,4))
> >><type 'complex'>


Hmmmm...  This looks really subtle.  My guess at the moment is that
there's some type coersion going on that turns your Complex() class back
into the normal base 'complex' type.

I'm closely reading:

    http://www.python.org/doc/current/ref/numeric-types.html

at the moment... Hmmm...  I believe that what's happening is that Python
is coercing both into complex numbers, and then trying again, according to
rule 2a of the __coerce__() function.  What's probably happening is that
the built-in __coerce__() of the 'complex' type just blindly calls
'complex()' on both sides, treating them numerically as in rule 3c.

There's some ambiguous meanings with the new style classes that makes me
feel a little uncomfortable; someone may want to look at this later.

But to fix this problem, we can add one more method to tell Python to do
something special on coersion:

###
class Complex(complex):
    def __mul__(self,other):
        other = Complex(other)
        t = complex.__mul__(self,other)
        return Complex(t.real,t.imag)
    __rmul__ = __mul__
    
    def __coerce__(self, other):
        return (self, Complex(other))

    def __add__(self, other):
        return Complex(self.real.__add__(other.real),
                       self.imag.__add__(other.imag))

    __radd__ = __add__
###


And this fixes the problem you were running into:


###
>>> print type(7 + Complex(3, 4))
<class '__main__.Complex'>
>>> print 7+Complex(3, 4)
(10+4j)
###

That was subtle!  *grin*  Hope this helps!


(The server I use for my mail is down, so that's why I'm using an
emergency email account.  Apologies for those who can't access the IDLE
introduction on my web page!)



From dyoo@decrem.com  Mon Mar 18 12:26:45 2002
From: dyoo@decrem.com (Danny Yoo)
Date: Mon, 18 Mar 2002 04:26:45 -0800 (PST)
Subject: [Tutor] Operator overloading surprise  [Type coersion, part
 Deux!]
In-Reply-To: <Pine.LNX.4.44.0203180234300.19672-100000@ns.decrem.com>
Message-ID: <Pine.LNX.4.44.0203180314160.19672-100000@ns.decrem.com>

[Warning: I really go off hunting obscure stuff in this post.  Please skip
if you're beginning to learn Python; this is really not useful at all.  
*grin*]



On Mon, 18 Mar 2002, Danny Yoo wrote:

> But to fix this problem, we can add one more method to tell Python to do
> something special on coersion:
> 
> ###
> class Complex(complex):
>     def __mul__(self,other):
>         other = Complex(other)
>         t = complex.__mul__(self,other)
>         return Complex(t.real,t.imag)
>     __rmul__ = __mul__
>     
>     def __coerce__(self, other):
>         return (self, Complex(other))
> 
>     def __add__(self, other):
>         return Complex(self.real.__add__(other.real),
>                        self.imag.__add__(other.imag))
> 
>     __radd__ = __add__
> ###


This problem seemed so interesting that I can't sleep until I look at it
just a little more.  *grin*


There does appear to be a __coerce__ function defined for the standard
complex numbers.  Here's a small experiment I tried:

###
>>> complex(3,4).__coerce__(3)
((3+4j), (3+0j))
>>> c = complex(3, 4)
>>> c is complex(3, 4)
0
>>> c.__coerce__(4)[0] is c
1
###

If we look at this closely, we can deduce that the base __coerce__ method
of complex numbers might look like:

###
def __coerce__(self, other):
    return self, complex(other)
###


... but perhaps not!

###
>>> c1, c2 = complex(3, 4), Complex(3, 4)
>>> d1, d2 = c1.__coerce__(c2)
>>> c1 is d1
1
>>> c2 is d2
1
>>> complex(c2) is c2
0
###


That is, c2 looked sufficiently enough like a complex that the coersion
didn't do anything to it.  There is some wackiness involved here; I get
the distinct feeling that complex.__coerce__ is either more complicated or
more mysterious than I thought.  Let's look at the source code:

/*** in complexobject.c **/
	else if (PyComplex_Check(*pw)) {
		Py_INCREF(*pv);
		Py_INCREF(*pw);
		return 0;
	}
/*** end ***/

Ah.  If 'other' looks anything like a complex (if it's of either 'complex'
type or a subtype of 'complex', coersion won't touch it.  That was tricky!  
The documentation needs to be amended to explain this situation; it could
cause some confusion.



I've been staring at rule two:

"""
2.
    If y is a class instance:
2a.
    If y has a __coerce__() method: replace y and x with the 2-tuple 
returned by y.__coerce__(x); skip to step 3 if the coercion returns None.
2b.
    If neither x nor y is a class instance after coercion, go to step 3.
2b.
If y has a method __rop__(), return y.__rop__(x); otherwise, restore x and 
y to their value before step 2a.
"""


and I think it has a bug.  Besides the obvious cut-and-paste typo that
repeats '2b' twice in the list numbering, I believe there's a missing
step, which I'll call "2b'".

"""
2b.
    If neither x nor y is a class instance after coercion, go to step 3.

2b'.  If x has a method __op__(), return x.__op__(y).

2b''.
If y has a method __rop__(), return y.__rop__(x); otherwise, restore x and 
y to their value before step 2a.
"""


At least, that's how things appear to work from the interpreter.  Here are
three example classes I'm using to test these ideas:

###
class ComplexA(complex):
    def __coerce__(self, other):
        return (self, other)

    def __add__(self, other):
        return Complex(self.real.__add__(other.real),
                       self.imag.__add__(other.imag))
    __radd__ = __add__


class ComplexB(ComplexA):
    def __coerce__(self, other):
        return (self, complex(other))

class ComplexC(ComplexA):
    def __coerce__(self, other):
        return (self, ComplexC(other))
###


Let's see what happens:

###
>>> type(7 + ComplexA(3, 4))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: unsupported operand types for +: 'int' and 'ComplexA'
>>> type(7 + ComplexB(3, 4))
<type 'complex'>
>>> type(7 + ComplexC(3, 4))
<class '__main__.Complex'>
###

The situation with ComplexB appears to be what you've been running into.  
Yet, with the rules as they were written, things didn't make sense.  The 
development docs at:

   http://python.sourceforge.net/devel-docs/ref/numeric-types.html

also appear not to correct the problem.  However, if we introduce an
additional rule 2b' to that list of coersion rules, the predictions fit
more closely with reality.


In any case, this is definitely a bug in the documentation.  Arthur, bring
it up on comp.lang.python and Sourceforge again.  Someone should really
look at your example, since it does seem serious... if not a little
obscure.  *grin*

Thanks for bring this up; it was a fun problem.  Good luck to you!



From karthikg@aztec.soft.net  Mon Mar 18 11:32:31 2002
From: karthikg@aztec.soft.net (Karthik Gurumurthy)
Date: Mon, 18 Mar 2002 17:02:31 +0530
Subject: [Tutor] lost
In-Reply-To: <F9BE655B-39F5-11D6-A202-00039351FE6A@mac.com>
Message-ID: <NEBBJNMDEKBIBCMCNMBDKEEIDGAA.karthikg@aztec.soft.net>

> backburnered and waiting for me to finish "Python Web Programming".  I
> can summarize some of the main points from Chapter 6 ("Transforming XML
> with XSLT"):

unfortunately these books are not available in my country.
can you post the code snippet for transforming a simple xml using another
xsl stylesheet?
it w'd be of great use to me.

thanks,
karthik.




From alan.gauld@bt.com  Mon Mar 18 11:42:15 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 18 Mar 2002 11:42:15 -0000
Subject: [Tutor] Alan Gauld's new book
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C44E@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C1CE71.F3728700
Content-type: text/plain; charset="iso-8859-1"

>  I remember you saying something about you making a new book. 
 
Yes, but not about Python., Its a software engineering reference book 
- a catalog of design notations if you like.
 
>  How is it comming cause I have your Python one and want to try  
>  out this new one of yours?   
 
Its coming very slowly coz it needs lots of detailed research to make 
sure the details are correct. I'm aiming to have it out by this time next 
year - I'm a slow writer and also have a day job! :-)
 
>  Are you going to have it available online too so you can download it? 
 
Probably not, its much more complex (lots of diagrams etc) so much 
harder to maintain on a web site - and I'm lazy! I might put some of the 
more pertinent notations (ie those related to detailed design rather than 
requirement analysis etc)  linked from the Python tutor tho'
 
Thanks for the interest,
 
Alan G.

------_=_NextPart_001_01C1CE71.F3728700
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=120324511-18032002><FONT 
face="Courier New" color=#0000ff>&gt; &nbsp;</FONT></SPAN>I remember you saying 
something about you making a new book.<SPAN class=120324511-18032002><FONT 
face="Courier New" color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=120324511-18032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=120324511-18032002>Yes, but not 
about Python., Its a software engineering reference book 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=120324511-18032002>- a catalog of 
design notations if you like.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=120324511-18032002>&nbsp;</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=120324511-18032002><FONT 
face="Courier New" color=#0000ff>&gt; </FONT>&nbsp;</SPAN>How is it comming 
cause I have your Python one and want to try&nbsp;<SPAN 
class=120324511-18032002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=120324511-18032002><FONT 
face="Courier New" color=#0000ff>&gt; </FONT>&nbsp;</SPAN>out this new one of 
yours?&nbsp;&nbsp;<SPAN class=120324511-18032002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=120324511-18032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=120324511-18032002>Its coming 
very slowly coz it needs lots of detailed research to make 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=120324511-18032002>sure the 
details are correct. I'm aiming to have it out by this time next 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=120324511-18032002>year - I'm a 
slow writer and also </SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN 
class=120324511-18032002>have a day job! :-)</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=120324511-18032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=120324511-18032002>&gt; 
&nbsp;</SPAN>Are you going to have it available online too so you can download 
it?<SPAN class=120324511-18032002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><SPAN class=120324511-18032002><FONT face=Arial size=2>Probably not, its 
much more complex (lots of diagrams etc) so much </FONT></SPAN></DIV>
<DIV><SPAN class=120324511-18032002><FONT face=Arial size=2>harder to maintain 
on a web site - and I'm lazy! I might put some of the </FONT></SPAN></DIV>
<DIV><SPAN class=120324511-18032002><FONT face=Arial size=2>more pertinent 
notations (ie those related to&nbsp;detailed design rather than 
</FONT></SPAN></DIV>
<DIV><SPAN class=120324511-18032002><FONT face=Arial size=2>requirement analysis 
etc)&nbsp;&nbsp;linked from the Python tutor tho'</FONT></SPAN></DIV>
<DIV><SPAN class=120324511-18032002><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=120324511-18032002><FONT face="Courier New" color=#0000ff 
size=2>Thanks for the interest,</FONT></SPAN></DIV>
<DIV><SPAN class=120324511-18032002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=120324511-18032002><FONT face="Courier New" color=#0000ff 
size=2>Alan G.</FONT></SPAN></DIV></BODY></HTML>

------_=_NextPart_001_01C1CE71.F3728700--


From alan.gauld@bt.com  Mon Mar 18 11:59:18 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 18 Mar 2002 11:59:18 -0000
Subject: [Tutor] telling dir(_builtins_) from dir(__builtins__)
 [spell checking Python?]
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C44F@mbtlipnt02.btlabs.bt.co.uk>

> > Eventually somebody might figure out how to make smarter 
> > interpreters, until then we're stuck with it.
> 
> That sounds like a challenge.  *grin*

> ###
> >>> oops_protected = protect(oops)
> >>> oops_protected()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "/tmp/python-1037YCW", line 51, in spell_check_wrapper
> NameError: global name '_builtins_' is not defined.  Perhaps 
> you meant one 
> of the following: '__builtins__'
> ###

Danny, you slay me! Only you would take a throwaway comment 
and turn it into a spell checking interpreter!

:-)

Combined with the parameter hints already in IDLE I think this 
would indeed be a worthy improvement. In fact even for the 
command line interpreter in general with some tidy up and 
maybe a toggle facility... Is Guido listening? (I think he 
still looks after IDLE?)

Alan g


From erikprice@mac.com  Mon Mar 18 13:51:36 2002
From: erikprice@mac.com (Erik Price)
Date: Mon, 18 Mar 2002 08:51:36 -0500
Subject: [Tutor] lost
In-Reply-To: <NEBBJNMDEKBIBCMCNMBDKEEIDGAA.karthikg@aztec.soft.net>
Message-ID: <43A24778-3A77-11D6-9E31-00039351FE6A@mac.com>

On Monday, March 18, 2002, at 06:32  AM, Karthik Gurumurthy wrote:

>
>> backburnered and waiting for me to finish "Python Web Programming".  I
>> can summarize some of the main points from Chapter 6 ("Transforming XML
>> with XSLT"):
>
> unfortunately these books are not available in my country.
> can you post the code snippet for transforming a simple xml using 
> another
> xsl stylesheet?
> it w'd be of great use to me.

I will gladly post the code if you still want me to after reading this 
article:

http://www.WebmasterBase.com/article/595/25

The above deep link is actually not the BEGINNING of the tutorial, but 
if you click back to the beginning you'll see it focuses on an intro to 
XSLT theory and how you can use it with PHP.  So it's not really 
relevant for this audience.  But the point in the tutorial that I've 
linked to is where the XSLT-tutorial starts, and this isn't specific to 
any language (except XSLT), so it's good for Python users too.

I'm on my way to work but if people want me to post a bit more detail on 
how XSLT is used from Python, from "Python & XML" I will -- but really, 
the above tutorial does a fine job of explainining the basics of XSLT 
and the book simply goes a few steps further with some good examples 
(several pages in fact).  The difference is that the SitePoint tutorial 
focuses on using a browser's built-in XSLT processor and the Python book 
explains how to use an external [pre]processor called 4XSLT 
(http://fourthought.com/).

Good luck,

Erik



From karthikg@aztec.soft.net  Mon Mar 18 14:00:24 2002
From: karthikg@aztec.soft.net (Karthik Gurumurthy)
Date: Mon, 18 Mar 2002 19:30:24 +0530
Subject: [Tutor] lost
In-Reply-To: <43A24778-3A77-11D6-9E31-00039351FE6A@mac.com>
Message-ID: <NEBBJNMDEKBIBCMCNMBDIEEMDGAA.karthikg@aztec.soft.net>

> I will gladly post the code if you still want me to after reading this
article:

> http://www.WebmasterBase.com/article/595/25

> The above deep link is actually not the BEGINNING of the tutorial, but
> if you click back to the beginning you'll see it focuses on an intro to
> XSLT theory and how you can use it with PHP.  So it's not really
> relevant for this audience.  But the point in the tutorial that I've
> linked to is where the XSLT-tutorial starts, and this isn't specific to
> any language (except XSLT), so it's good for Python users too.

> I'm on my way to work but if people want me to post a bit more detail on
> how XSLT is used from Python, from "Python & XML" I will -- but really,
> the above tutorial does a fine job of explainining the basics of XSLT
> and the book simply goes a few steps further with some good examples
> (several pages in fact).  The difference is that the SitePoint tutorial
> focuses on using a browser's built-in XSLT processor and the Python book
> explains how to use an external [pre]processor called 4XSLT
> (http://fourthought.com/).

erik thanks for the link. Actually i have used xslt along with java in my
projects.
I was wondering how to use it with python libraries. But have not been able
to figure it out.
Am not sure what python-xml SIG thinks about JAXP from Sun which tries to
hide
different parser implementation so that the code becomes portable across
parsers.

So i looked for similar names in the PyXML src :-( to make some sense out of
it.
I know it might sound stupid but the documentation is'nt helpful.
There is no proper documentation for xslt stuff.
Hope they will provide one soon.

...karthik.









From alex@gabuzomeu.net  Mon Mar 18 14:16:19 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Mon, 18 Mar 2002 15:16:19 +0100
Subject: [Tutor] Uniques values in a list - testing functions
In-Reply-To: <002001c1cdf5$71002100$a666accf@othello>
References: <XFMail.20020317111657.shalehperry@attbi.com>
Message-ID: <4.3.2.7.2.20020318144433.00d93d10@pop3.norton.antivirus>

Hello,


At 15:50 17/03/2002 -0500, Raymond Hettinger wrote:
>While we're building a test bench, I have a couple of
>additions.  Do a full garbage collection just before the
>timing starts -- this will reduce distortions due to gc.
>Also, I would use xrange so that we don't eat-up
>a meg of memory (100000 iters * (4 bytes per int + 4 bytes
>per pointer to the int) ) before the function starts running.
>At the end, print an excerpt of the results and its length.
>That way you'll have some small assurance that the
>function is really doing what it's supposed to.

Yesterday I wrote a short test class. The results are copied below. In 
"Timer.testLists(n, m)", n is the data set size (number of items in the 
list passed to the functions) and m is the number of runs (number of times 
the functions are run).

The simple dictionary-based solution looks consistently faster, though the 
list comprehension version is close for large datasets.

If anyone is interested, the test code is here (you need both Timer and 
ListUtils modules):

         http://alexandre.ratti.free.fr/python/

If you find out that these tests are flawed, please let me know.


Cheers.

Alexandre


 >>> Timer.testLists(500, 1000)

Function name   Total runtime   Runtime per run
filterListWithDict      0.386876        0.000387
filterListWithMap22     0.421740        0.000422
filterListWithMap21     0.429549        0.000430
filterListWithComprehension22   0.547386        0.000547
filterListWithMapAndOperator    0.587310        0.000587
filterListWithComprehension21   0.963933        0.000964
filterListInPlace       2.015952        0.002016
filterListWithList      2.201321        0.002201

 >>> Timer.testLists(5000, 100)

filterListWithDict      0.358967        0.003590
filterListWithComprehension22   0.383897        0.003839
filterListWithMap22     0.392658        0.003927
filterListWithMap21     0.393884        0.003939
filterListWithMapAndOperator    0.529176        0.005292
filterListWithComprehension21   0.800180        0.008002
filterListInPlace       1.994437        0.019944
filterListWithList      2.189302        0.021893

 >>> Timer.testLists(50000, 30)

filterListWithDict      1.084748        0.036158
filterListWithComprehension22   1.141160        0.038039
filterListWithMap22     1.211721        0.040391
filterListWithMap21     1.212633        0.040421
filterListWithMapAndOperator    1.655985        0.055199
filterListWithComprehension21   2.386100        0.079537
filterListInPlace       6.323484        0.210783
filterListWithList      6.565961        0.218865

 >>> Timer.testLists(100000, 20)

filterListWithDict      1.430084        0.071504
filterListWithComprehension22   1.502246        0.075112
filterListWithMap21     1.637107        0.081855
filterListWithMap22     1.673499        0.083675
filterListWithMapAndOperator    2.202443        0.110122
filterListWithComprehension21   3.130225        0.156511
filterListInPlace       8.386927        0.419346
filterListWithList      8.685972        0.434299




From clogz@dreamsoft.com  Mon Mar 18 23:37:45 2002
From: clogz@dreamsoft.com (Sean Rhoades)
Date: Mon, 18 Mar 2002 15:37:45 -0800
Subject: [Tutor] beginners question
Message-ID: <016901c1ced5$e81bb390$b173d23f@seanxgvgsavpzh>

This is a multi-part message in MIME format.

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

I finished a little prog that asks ten multiplication questions then =
gives you your percanteage correct, my questoin is how can I have it =
start again by asking the user if they want to play again?

------=_NextPart_000_0166_01C1CE92.D9845500
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>I finished a little prog that asks ten=20
multiplication questions then gives you your percanteage correct, my =
questoin is=20
how can I have it start again by asking the user if they want&nbsp;to =
play=20
again?</FONT></DIV></BODY></HTML>

------=_NextPart_000_0166_01C1CE92.D9845500--



From sheila@thinkspot.net  Tue Mar 19 00:00:29 2002
From: sheila@thinkspot.net (Sheila King)
Date: Mon, 18 Mar 2002 16:00:29 -0800
Subject: [Tutor] beginners question
In-Reply-To: <016901c1ced5$e81bb390$b173d23f@seanxgvgsavpzh>
References: <016901c1ced5$e81bb390$b173d23f@seanxgvgsavpzh>
Message-ID: <227D627AF2@kserver.org>

On Mon, 18 Mar 2002 15:37:45 -0800, "Sean Rhoades" <clogz@dreamsoft.com>
wrote about [Tutor] beginners question:

> I finished a little prog that asks ten multiplication questions 
> then gives you your percanteage correct, my questoin is how can 
> I have it start again by asking the user if they want to play again?


How about something like this?

playagain = 'y'
while playagain == 'y':
    <your code here>
	playagain = raw_input("Would you like to play again? (y/n) \n")



--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/



From erikprice@mac.com  Tue Mar 19 03:20:47 2002
From: erikprice@mac.com (Erik Price)
Date: Mon, 18 Mar 2002 22:20:47 -0500
Subject: [Tutor] lost
In-Reply-To: <NEBBJNMDEKBIBCMCNMBDIEEMDGAA.karthikg@aztec.soft.net>
Message-ID: <4E2AFFF1-3AE8-11D6-9739-00039351FE6A@mac.com>

On Monday, March 18, 2002, at 09:00  AM, Karthik Gurumurthy wrote:

> I was wondering how to use it with python libraries. But have not been 
> able
> to figure it out.
> Am not sure what python-xml SIG thinks about JAXP from Sun which tries 
> to
> hide
> different parser implementation so that the code becomes portable across
> parsers.
>
> So i looked for similar names in the PyXML src :-( to make some sense 
> out of
> it.
> I know it might sound stupid but the documentation is'nt helpful.
> There is no proper documentation for xslt stuff.
> Hope they will provide one soon.

Karthik,

Here's what the book has to say:

Essentially, the book's example of embedding an XSLT processor into a 
Python program is a CGI script that takes two style sheets and an XML 
document, and runs the appropriate style sheet on the document depending 
on some user actions.  Since it sounds like you don't need me to post 
two XSLT sheets and an XML file to explain what's going on, I'll just 
post the Python CGI program (but if you want the other stuff let me 
know):

The book doesn't actually detail -how- to install 4XSLT but does say "as 
explained earlier", so maybe I missed it, or maybe the best thing is to 
go to their web site and follow their instructions (I haven't been there 
yet but it's http://www.4suite.org/).

<BookContents source="Python & XML" author="Christopher Jones & Fred 
Drake Jr" page="147-8">

#!/usr/local/bin/python
# xlst.cgi       # sic, probably a typo
import cgi
import os
import sys

from xml.xslt.Processor import Processor

# parse query string & instantiate xslt proc
query = cgi.FieldStorage()

xsltproc = Processor()

print "Content-type: text/html\r\n"

mode = query.getvalue("mode", "")
if not mode:
   print "<html><body>"
   print "<p>No mode given</p>"
   print "</html></body>"		# sic, again
   sys.exit()

if mode[0] == "show":
   # run XML through simple stylesheet
   xsltproc.appendStylesheetUri("story.xsl")
   html = xsltproc.runUri("story.xml")
   print html

elif mode[0] == "change":
   # change XML source file, rerun stylesheet and show
   newXML = '<?xml version="1.0"?>\n'
   newXML += "\t<story>\n\t<title>"
   newXML += quer.getvalue("title")[0] + "</title>\n"
   newXML += "\t<body>\n"
   newXML += query.getvalue("body")[0] + "\n\t</body>\n</story>\n"
   fd = open("story.xml", "w")
   fd.write(newXML)
   fd.close()

   # run updated XML through simple stylesheet
   xsltproc.appendStylesheetUri("story.xsl")
   html = xsltproc.runUri("story.xml")
   print html

elif mode[0] == "edit":
   # run XML through form-based stylesheet
   xsltproc.appendStylesheetUri("edstory.xsl")
   html = xsltproc.runUri("story.xml")
   print html

</BookContents>

This is kind of out of context since I didn't copy the XML or XSLT 
sheets -- they're very very simple, but if you want I can do those 
tomorrow, just let me know.


Erik



From moodykre8r@earthlink.net  Tue Mar 19 07:40:51 2002
From: moodykre8r@earthlink.net (binary_star)
Date: Mon, 18 Mar 2002 23:40:51 -0800
Subject: [Tutor] Total Newbie with IDLE issues...
Message-ID: <LPBBLEMICOGCGHANJMACKEJLDBAA.moodykre8r@earthlink.net>

Nobody expects the Spanish Inquisition!

Hello, World! I just recently began teaching myself Python. Python will
be---realistically speaking---my first programming language (at the age of
35). Although I have been exposed to programming via Visual Basic (yes, yes,
/I know/), and "looked at" Java and PERL, I have quickly come to believe
that Python offers the best path for me to learn programming on. It's OO,
it's structured without being unnecessarily rigid, and it's named after
Monty Python. Who could ask for more? Anyway....

I am learning Python on Mac OS X (10.1.3). I downloaded and installed Python
2.2 via Fink. Please don't think for one instant that I know squat about
*nix systems; I am a Windoze vict... er, veteran... um.... I'm surprised I
got Python up and running at all. I can run Python at the command line via
interpreter or script file (I use NANO) without a hitch. However---long
story short---I receive the following error when I try to run Idle:

-=----------------------------------------=-

Traceback (most recent call last):
   File "/sw/lib/python2.2/Tools/idle/idle.py", line 4, in ?
     PyShell.main()
   File "/sw/lib/python2.2/Tools/idle/PyShell.py", line 747, in main
     root = Tk(className="Idle")
   File "/sw/lib/python2.2/lib-tk/Tkinter.py", line 1487, in __init__
     self.tk = _tkinter.create(screenName, baseName, className)
TclError: no display name and no $DISPLAY environment variable

-=----------------------------------------=-

Also, the internal "Help" files/documentation appear to be AWOL.

I don't know if there's any way to just fix these issues (or at least the
first one!), short of waving a dead parrot over the computer. I would very
much appreciate any assistance.

Thank you!


Sincerely,
'.'M.'.


PS: The online tutorial I am happily using to teach myself Python is
_How_to_Think_like_a_Computer_Scientist_, which I found here:
http://www.ibiblio.org/obp/thinkCSpy/ .


  NOBODY expects the Spanish Inquisition! Our chief
  weapon is surprise .... surprise and fear .... fear
  and surprise .... Our two weapons are fear and
  surprise .... and ruthless efficiency .... Our
  three weapons are fear, surprise and ruthless
  efficiency .... and an almost fanatical devotion to
  the Pope .... Our four .... no .... Amongst our
  weapons .... Amongst our weaponry .... are such
  elements as fear, surprise .... I'll come in again.
  ( The Spanish Inquisition EXITS)



From erikprice@mac.com  Tue Mar 19 12:53:09 2002
From: erikprice@mac.com (Erik Price)
Date: Tue, 19 Mar 2002 07:53:09 -0500
Subject: [Tutor] Total Newbie with IDLE issues...
In-Reply-To: <LPBBLEMICOGCGHANJMACKEJLDBAA.moodykre8r@earthlink.net>
Message-ID: <43A64F6E-3B38-11D6-A0E4-00039351FE6A@mac.com>

On Tuesday, March 19, 2002, at 02:40  AM, binary_star wrote:

> I am learning Python on Mac OS X (10.1.3).

Salutons from a fellow OS X & Fink user!

> got Python up and running at all. I can run Python at the command line 
> via
> interpreter or script file (I use NANO) without a hitch. However---long
> story short---I receive the following error when I try to run Idle:
>
> -=----------------------------------------=-
>
> Traceback (most recent call last):
>    File "/sw/lib/python2.2/Tools/idle/idle.py", line 4, in ?
>      PyShell.main()
>    File "/sw/lib/python2.2/Tools/idle/PyShell.py", line 747, in main
>      root = Tk(className="Idle")
>    File "/sw/lib/python2.2/lib-tk/Tkinter.py", line 1487, in __init__
>      self.tk = _tkinter.create(screenName, baseName, className)
> TclError: no display name and no $DISPLAY environment variable

I haven't tried to run IDLE myself, mainly because from what I 
understand it requires that the Tk libraries be installed on your 
system.  According to an older Apple news article, Tk has been ported to 
OS X (check SourceForge.net to see how it's doing) but I haven't had 
time to try to install it and get it up and running.  I have seen a 
screenshot of IDLE running in OS X.  In fact, I think it was someone on 
this very list who passed me the link, so if you check this list's 
archives under IDLE or Tk, then you might be able to find more info.

When I get time, I plan to check it out, but for now I've been too busy 
with other things, and IDLE isn't as much of a priority for me.  If you 
want, I can try to dig up some more info but right now I'm just checking 
email before work and will have to do it later...

Good luck!


Erik



From israel@lith.com  Tue Mar 19 14:07:46 2002
From: israel@lith.com (Israel Evans)
Date: Tue, 19 Mar 2002 06:07:46 -0800
Subject: [Tutor] Gadfly... missing?
Message-ID: <AF020C5FC551DD43A4958A679EA16A15017B4020@abbott.lith.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_01C1CF4F.726A493E
Content-Type: text/plain

 
Hey, 
 
Does anybody know if anything terrible has happened to Gadfly?  I've been
trying to get the funky little Pythonic Database for two days now, but it
seems www.chordate.com <http://www.chordate.com/>  is down and out.  Is this
a temporary thing or will I have to mourn the demise of a snazzy product?
 
 
 
~Israel~
 

------_=_NextPart_001_01C1CF4F.726A493E
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:st1=3D"urn:schemas-microsoft-com:office:smarttags" =
xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">


<meta name=3DProgId content=3DWord.Document>
<meta name=3DGenerator content=3D"Microsoft Word 10">
<meta name=3DOriginator content=3D"Microsoft Word 10">
<link rel=3DFile-List href=3D"cid:filelist.xml@01C1CF0C.68B8C020">
<o:SmartTagType =
namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags"
 name=3D"country-region"/>
<o:SmartTagType =
namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags"
 name=3D"place"/>
<!--[if gte mso 9]><xml>
 <o:OfficeDocumentSettings>
  <o:DoNotRelyOnCSS/>
 </o:OfficeDocumentSettings>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:SpellingState>Clean</w:SpellingState>
  <w:GrammarState>Clean</w:GrammarState>
  <w:DocumentKind>DocumentEmail</w:DocumentKind>
  <w:EnvelopeVis/>
  <w:Compatibility>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
   <w:UseFELayout/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]--><!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:PMingLiU;
	panose-1:2 2 3 0 0 0 0 0 0 0;
	mso-font-alt:\65B0\7D30\660E\9AD4;
	mso-font-charset:136;
	mso-generic-font-family:roman;
	mso-font-pitch:variable;
	mso-font-signature:3 137232384 22 0 1048577 0;}
@font-face
	{font-family:"\@PMingLiU";
	panose-1:2 2 3 0 0 0 0 0 0 0;
	mso-font-charset:136;
	mso-generic-font-family:roman;
	mso-font-pitch:variable;
	mso-font-signature:3 137232384 22 0 1048577 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0in;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:PMingLiU;}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;
	text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;
	text-underline:single;}
p.MsoAutoSig, li.MsoAutoSig, div.MsoAutoSig
	{margin:0in;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";}
span.EmailStyle17
	{mso-style-type:personal-compose;
	mso-style-noshow:yes;
	mso-ansi-font-size:10.0pt;
	mso-bidi-font-size:10.0pt;
	font-family:Arial;
	mso-ascii-font-family:Arial;
	mso-hansi-font-family:Arial;
	mso-bidi-font-family:Arial;
	color:windowtext;}
span.SpellE
	{mso-style-name:"";
	mso-spl-e:yes;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;
	mso-header-margin:.5in;
	mso-footer-margin:.5in;
	mso-paper-source:0;}
div.Section1
	{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
 /* Style Definitions */=20
 table.MsoNormalTable
	{mso-style-name:"Table Normal";
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0in 5.4pt 0in 5.4pt;
	mso-para-margin:0in;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";}
</style>
<![endif]-->
</head>

<body lang=3DEN-US link=3Dblue vlink=3Dpurple =
style=3D'tab-interval:.5in'>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Hey, <o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Does anybody know if anything terrible has happened =
to
Gadfly?<span style=3D'mso-spacerun:yes'>&nbsp; </span>I've been trying =
to get
the funky little <span class=3DSpellE>Pythonic</span> Database for two =
days now,
but it seems <a href=3D"http://www.chordate.com/">www.chordate.com</a> =
is down
and out.<span style=3D'mso-spacerun:yes'>&nbsp; </span>Is this a =
temporary thing or
will I have to mourn the demise of a snazzy =
product?<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoAutoSig><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt;mso-no-proof:yes'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoAutoSig><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt;mso-no-proof:yes'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoAutoSig><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt;font-family:"Courier =
New";mso-no-proof:yes'>~</span></font><st1:country-region><st1:place><fo=
nt
  size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt;font-family:"Courier New";
  =
mso-no-proof:yes'>Israel</span></font></st1:place></st1:country-region><=
font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt;font-family:"Courier New";
mso-no-proof:yes'>~<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

</div>

</body>

</html>

------_=_NextPart_001_01C1CF4F.726A493E--


From dsh8290@rit.edu  Tue Mar 19 14:29:36 2002
From: dsh8290@rit.edu (dman)
Date: Tue, 19 Mar 2002 08:29:36 -0600
Subject: [Tutor] Gadfly... missing?
In-Reply-To: <AF020C5FC551DD43A4958A679EA16A15017B4020@abbott.lith.com>
References: <AF020C5FC551DD43A4958A679EA16A15017B4020@abbott.lith.com>
Message-ID: <20020319142936.GA23865@dman.ddts.net>

On Tue, Mar 19, 2002 at 06:07:46AM -0800, Israel Evans wrote:
|  
| Hey, 
|  
| Does anybody know if anything terrible has happened to Gadfly?  I've
| been trying to get the funky little Pythonic Database for two days
| now, but it seems www.chordate.com <http://www.chordate.com/>  is
| down and out.  Is this a temporary thing or will I have to mourn the
| demise of a snazzy product?

Likely you'll have to mourn its demise.  It doesn't appear to be
actively maintained any more, and the mailing list contains nothing
but spam.  The test suite works with 1.5.2 and 2.1 but issues
deprecation warnings.  The test suite fails with 2.2.

If you want a copy, you can grab it from
    http://http.us.debian.org/debian/pool/main/g/gadfly/gadfly_1.0-7.2_all.deb

A ".deb" is just an 'ar' archive that contains a file and a 2
tarballs.  The tarball contains all the files you're looking for.  If
you're stuck in windows, install cygwin.  To get the stuff you want
out of it :
    $ ar x gadfly_1.0-7.2_all.deb
    $ tar -zxvf data.tar.gz

HTH,
-D

PS. I'm sorry to see it go too.  It's the easiest way to begin working
    with SQL, and also the easiest way to get a db on windows (though
    I haven't actually tested to verify that it works on windows).

-- 

I tell you the truth, everyone who sins is a slave to sin.  Now a slave
has no permanent place in the family, but a son belongs to it forever.
So if the Son sets you free, you will be free indeed.
        John 8:34-36



From kalle@gnupung.net  Tue Mar 19 14:27:34 2002
From: kalle@gnupung.net (Kalle Svensson)
Date: Tue, 19 Mar 2002 15:27:34 +0100
Subject: [Tutor] Gadfly... missing?
In-Reply-To: <AF020C5FC551DD43A4958A679EA16A15017B4020@abbott.lith.com>
References: <AF020C5FC551DD43A4958A679EA16A15017B4020@abbott.lith.com>
Message-ID: <20020319142734.GB19824@sara.lysator.liu.se>

[Israel Evans]
> Does anybody know if anything terrible has happened to Gadfly?  I've
> been trying to get the funky little Pythonic Database for two days
> now, but it seems www.chordate.com <http://www.chordate.com/> is
> down and out.  Is this a temporary thing or will I have to mourn the
> demise of a snazzy product?

I don't know, but you can download the source code on any Debian
GNU/Linux mirror in the /debian/pool/main/g/gadfly/ subdirectory.

Peace,
  Kalle
-- 
Kalle Svensson (kalle@gnupung.net) - Laziness, impatience, hubris: Pick two!
English: http://www.gnupung.net/  Svenska: http://www.lysator.liu.se/~kalle/
Stuff: ["http://www.%s.org/" % x for x in "gnu debian python emacs".split()]


From israel@lith.com  Tue Mar 19 14:49:16 2002
From: israel@lith.com (Israel Evans)
Date: Tue, 19 Mar 2002 06:49:16 -0800
Subject: [Tutor] Gadfly... missing?
Message-ID: <AF020C5FC551DD43A4958A679EA16A15017B4021@abbott.lith.com>

Nuts!


I liked Gadfly.  It was small, simple (because it was a python thing), and
it was portable.  Now I have to figure out which of the "Big Boys" I should
fall back on.  Sometimes, it feels that the big databases are using a
backhoe when all I need is a spoon.

What do you think dman, fellow pythonistas?  Which of the "free" database
packages have you enjoyed working with?  Which python modules have you used
to connect to them?

I'm going to be working on both MacOSX and Debian with, perhaps a sprinkling
of windows if I can't avoid it, so I'd like something useable on either of
these platforms.  I'll be using the DB for webserving stuff, and your basic
educational experimentation type stuff.  Really I'll just be toying around
with python and databases and wxPython, Cocoa (when I get my hands on a
g4/g5?), and Aqua (because it's perty).

I see my choices could be between Zope, MySQL, PostgreSQL ( using cygwin ),
and possibly BerkelyDB.  What's your favorite?

Thanks,
In mourning'ly yours.



~Israel~


-----Original Message-----
From: dman [mailto:dsh8290@rit.edu] 
Sent: 19 March 2002 6:30 AM
To: 'tutor@python.org'
Subject: Re: [Tutor] Gadfly... missing?

On Tue, Mar 19, 2002 at 06:07:46AM -0800, Israel Evans wrote:
|  
| Hey, 
|  
| Does anybody know if anything terrible has happened to Gadfly?  I've
| been trying to get the funky little Pythonic Database for two days
| now, but it seems www.chordate.com <http://www.chordate.com/>  is
| down and out.  Is this a temporary thing or will I have to mourn the
| demise of a snazzy product?

Likely you'll have to mourn its demise.  It doesn't appear to be
actively maintained any more, and the mailing list contains nothing
but spam.  The test suite works with 1.5.2 and 2.1 but issues
deprecation warnings.  The test suite fails with 2.2.

If you want a copy, you can grab it from
 
http://http.us.debian.org/debian/pool/main/g/gadfly/gadfly_1.0-7.2_all.deb

A ".deb" is just an 'ar' archive that contains a file and a 2
tarballs.  The tarball contains all the files you're looking for.  If
you're stuck in windows, install cygwin.  To get the stuff you want
out of it :
    $ ar x gadfly_1.0-7.2_all.deb
    $ tar -zxvf data.tar.gz

HTH,
-D

PS. I'm sorry to see it go too.  It's the easiest way to begin working
    with SQL, and also the easiest way to get a db on windows (though
    I haven't actually tested to verify that it works on windows).

-- 

I tell you the truth, everyone who sins is a slave to sin.  Now a slave
has no permanent place in the family, but a son belongs to it forever.
So if the Son sets you free, you will be free indeed.
        John 8:34-36


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


From aschmidt@nv.cc.va.us  Tue Mar 19 15:08:42 2002
From: aschmidt@nv.cc.va.us (Schmidt, Allen J.)
Date: Tue, 19 Mar 2002 10:08:42 -0500
Subject: [Tutor] Gadfly... missing?
Message-ID: <47BCBF3251382B45893950D07804082475AEFD@novamail.nv.cc.va.us>

We use Zope with MySQL on Linux and on Windows2000. Works very well and have
had much success.

I am on Windows clients and use a free tool called MySQLfront to communicate
with MySQL. Fantastic tool! Makes working with the DB so much easier.

There is also a FULL install of Zope with a control panel for OSX. The guys
I work with love it.

Just my 2 cents.

Allen

-----Original Message-----
From: Israel Evans [mailto:israel@lith.com]
Sent: Tuesday, March 19, 2002 9:49 AM
To: 'tutor@python.org'
Subject: RE: [Tutor] Gadfly... missing?


Nuts!


I liked Gadfly.  It was small, simple (because it was a python thing), and
it was portable.  Now I have to figure out which of the "Big Boys" I should
fall back on.  Sometimes, it feels that the big databases are using a
backhoe when all I need is a spoon.

What do you think dman, fellow pythonistas?  Which of the "free" database
packages have you enjoyed working with?  Which python modules have you used
to connect to them?

I'm going to be working on both MacOSX and Debian with, perhaps a sprinkling
of windows if I can't avoid it, so I'd like something useable on either of
these platforms.  I'll be using the DB for webserving stuff, and your basic
educational experimentation type stuff.  Really I'll just be toying around
with python and databases and wxPython, Cocoa (when I get my hands on a
g4/g5?), and Aqua (because it's perty).

I see my choices could be between Zope, MySQL, PostgreSQL ( using cygwin ),
and possibly BerkelyDB.  What's your favorite?

Thanks,
In mourning'ly yours.



~Israel~


-----Original Message-----
From: dman [mailto:dsh8290@rit.edu] 
Sent: 19 March 2002 6:30 AM
To: 'tutor@python.org'
Subject: Re: [Tutor] Gadfly... missing?

On Tue, Mar 19, 2002 at 06:07:46AM -0800, Israel Evans wrote:
|  
| Hey, 
|  
| Does anybody know if anything terrible has happened to Gadfly?  I've
| been trying to get the funky little Pythonic Database for two days
| now, but it seems www.chordate.com <http://www.chordate.com/>  is
| down and out.  Is this a temporary thing or will I have to mourn the
| demise of a snazzy product?

Likely you'll have to mourn its demise.  It doesn't appear to be
actively maintained any more, and the mailing list contains nothing
but spam.  The test suite works with 1.5.2 and 2.1 but issues
deprecation warnings.  The test suite fails with 2.2.

If you want a copy, you can grab it from
 
http://http.us.debian.org/debian/pool/main/g/gadfly/gadfly_1.0-7.2_all.deb

A ".deb" is just an 'ar' archive that contains a file and a 2
tarballs.  The tarball contains all the files you're looking for.  If
you're stuck in windows, install cygwin.  To get the stuff you want
out of it :
    $ ar x gadfly_1.0-7.2_all.deb
    $ tar -zxvf data.tar.gz

HTH,
-D

PS. I'm sorry to see it go too.  It's the easiest way to begin working
    with SQL, and also the easiest way to get a db on windows (though
    I haven't actually tested to verify that it works on windows).

-- 

I tell you the truth, everyone who sins is a slave to sin.  Now a slave
has no permanent place in the family, but a son belongs to it forever.
So if the Son sets you free, you will be free indeed.
        John 8:34-36


_______________________________________________
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 virketis@fas.harvard.edu  Tue Mar 19 15:58:04 2002
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Tue, 19 Mar 2002 10:58:04 -0500
Subject: [Tutor] Gadfly... missing?
References: <AF020C5FC551DD43A4958A679EA16A15017B4021@abbott.lith.com>
Message-ID: <004401c1cf5e$db05f240$18adf78c@virketis2>

> What do you think dman, fellow pythonistas?  Which of the "free" database
> packages have you enjoyed working with?  Which python modules have you
used
> to connect to them?

I found MySQL straighforward to install/configure on WinXP and Libranet
(essentially Debian) Linux. I also checked out PostgreSQL on Linux, and my
general impression was that while it seemed somewhat more powerful
(transactions and some other niceties), it was also more complicated to
admin (installation was about the same in either case). As you said, when
simple (MySQL) is sufficient, it is preferable. Call me lazy ... :)

Cheers,

Pijus



From dsh8290@rit.edu  Tue Mar 19 16:54:29 2002
From: dsh8290@rit.edu (dman)
Date: Tue, 19 Mar 2002 10:54:29 -0600
Subject: [Tutor] Gadfly... missing?
In-Reply-To: <AF020C5FC551DD43A4958A679EA16A15017B4021@abbott.lith.com>
References: <AF020C5FC551DD43A4958A679EA16A15017B4021@abbott.lith.com>
Message-ID: <20020319165429.GA24713@dman.ddts.net>

On Tue, Mar 19, 2002 at 06:49:16AM -0800, Israel Evans wrote:
| Nuts!
| 
| I liked Gadfly.  It was small, simple (because it was a python thing), and
| it was portable.  Now I have to figure out which of the "Big Boys" I should
| fall back on.  Sometimes, it feels that the big databases are using a
| backhoe when all I need is a spoon.

Yeah.  You can still use it with the older pythons, though, and no one
can take the code away from you.

| What do you think dman, fellow pythonistas?

Anyone up to the task of maintaining gadfly? ;-)

| Which of the "free" database packages have you enjoyed working with?
| Which python modules have you used to connect to them?

At the moment I really haven't used any dbs.  I've toyed with gadfly a
little, and had to use cloudscape (not really free, java-based, and
I've been told it's a piece of junk) for a lab at school.
 
| I'm going to be working on both MacOSX and Debian with, perhaps a sprinkling
| of windows if I can't avoid it, so I'd like something useable on either of
| these platforms.  I'll be using the DB for webserving stuff, and your basic
| educational experimentation type stuff.  Really I'll just be toying around
| with python and databases and wxPython, Cocoa (when I get my hands on a
| g4/g5?), and Aqua (because it's perty).
| 
| I see my choices could be between Zope, MySQL, PostgreSQL ( using cygwin ),
| and possibly BerkelyDB.  What's your favorite?

Zope isn't a RDBMS.  It is a Web Application Server.  A component of
the Zope framework, ZODB (Zope Object Database) is an Object Database
that you can use standalone if you want.  Use it if you want to store
objects in your db.  Zope does include adapters for connecting to both
MySQL and PostgreSQL if you want to use those RDBMSes in your Web
Application.

If you want a relational db use PostgreSQL or MySQL.  I get the
impression that PostgreSQL scales better than MySQL.  I haven't
managed either one.  My new job makes use of MySQL (on linux) and MS
SQL Server and MS Access (both on windows).  I'll be learning soon
enough :-).  I've seen that cygwin packages PostgreSQL for you if you
need to serve off of a windows box.  I don't recommend that, though.
(nothing wrong with cygwin, but a solid foundation is essential, and
windows isn't)

For some comparisons of the two dbs try google :
   http://www.mysql.com/doc/M/y/MySQL-PostgreSQL_features.html

I also read a long article by someone at sourceforge detailing his
experiences with trying both MySQL and PostgreSQL in their
installation.

I don't know much about BerkelyDB other than 'rpm' uses it.  I don't
think it is a SQL db, though, and thus isn't in the same ballpark as
MySQL and PostgreSQL.


My recommendation is :
    If you want a RDBMS (SQL) :
        Stick with gadfly if you are trying to learn SQL and for
        proof-of-concept type projects.  In theory you can
        plug-and-play different dbs by simply changing the module that
        is used (see the DB-SIG for more details).

        If you need a production-level db then pick either PostgreSQL
        or MySQL.  You can try both too!  See which you like better.

    If you want an ODBMS :
        Go with ZODB.  Don't try to use the whole Zope package unless
        you are making a "Web Application".

    If you like BerkeleyDB, then learn about it so you know what it
    can and can't do. :-)

-D

-- 

"GUIs normally make it simple to accomplish simple actions and
impossible to accomplish complex actions."
    --Doug Gwyn  (22/Jun/91 in comp.unix.wizards)



From kalle@gnupung.net  Tue Mar 19 16:56:06 2002
From: kalle@gnupung.net (Kalle Svensson)
Date: Tue, 19 Mar 2002 17:56:06 +0100
Subject: [Tutor] Gadfly... missing?
In-Reply-To: <20020319165429.GA24713@dman.ddts.net>
References: <AF020C5FC551DD43A4958A679EA16A15017B4021@abbott.lith.com> <20020319165429.GA24713@dman.ddts.net>
Message-ID: <20020319165605.GA18885@sverker.lysator.liu.se>

[dman]
> Anyone up to the task of maintaining gadfly? ;-)

That's what I asked myself also.  I have started looking at moving
from regex to re, at least.  If anyone else is interested in helping
out, that'd be nice.  I've no real interest in maintaing it since I
don't use it myself, though.

Peace,
  Kalle
-- 
Kalle Svensson (kalle@gnupung.net) - Laziness, impatience, hubris: Pick two!
English: http://www.gnupung.net/  Svenska: http://www.lysator.liu.se/~kalle/
Stuff: ["http://www.%s.org/" % x for x in "gnu debian python emacs".split()]


From alan.gauld@bt.com  Tue Mar 19 17:00:13 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 19 Mar 2002 17:00:13 -0000
Subject: [Tutor] beginners question
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C459@mbtlipnt02.btlabs.bt.co.uk>

> How about something like this?
> 
> playagain = 'y'
> while playagain == 'y':
  while playagain in 'yY':  
	# to cover shift/caps lock...playagain[0] is better still!

>     <your code here>
> 	playagain = raw_input("Would you like to play again? (y/n) \n")

And personally I prefer my prompts to be on the same line as 
the input so I'd remove the \n at the end of the string...

Just feeling picky,

Alan G



From alan.gauld@bt.com  Tue Mar 19 17:08:57 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 19 Mar 2002 17:08:57 -0000
Subject: [Tutor] Total Newbie with IDLE issues...
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C45A@mbtlipnt02.btlabs.bt.co.uk>

> I am learning Python on Mac OS X (10.1.3). 

Cool, I'm currently on the verge of buying a laptop andf looking closely at
an Apple iBook. MacOS X is just sooooo sexy! :-)

> ...I receive the following error when I try to run Idle:

Ah, sbnag. The Unix version of Python needs an X server 
running to do IDLE. You either have to get XonX installed
(and running) or get the MacOS 9 version of Python and 
run it in Classic (Or have they got the Carbonised version 
up yet? - obvious self interest behind this question!)

> TclError: no display name and no $DISPLAY environment variable

Basically it says Tcl/Tk (from which IDLE is built) is 
looking for an X windows display to present its windows 
and can't find one. 

Try www.xonx.org.

and the Mac Python pages for more specifics.

Alan g


From garber@centralcatholic.org  Tue Mar 19 17:32:12 2002
From: garber@centralcatholic.org (Robert Garber)
Date: Tue, 19 Mar 2002 12:32:12 -0500
Subject: [Tutor] NEWBIE rolling dice script
Message-ID: <200203191232.AA3620405550@centralcatholic.org>

Hello all,

 Here is my problem I am working on. I am trying to write a small script that roll dice.  I have written it as a function so I can call it as I need it. When I test the function in the interpreter I get the message listed below. Is this telling my function is working?
Why doesn't it print out the formatted string.
After I get this script written I want to use it in an HTML document


import random
def rolldice():
    die1 = random.range(1,7)
    die2 = random.range(1,7)
    
    print "player rolled %d and %d" % (die1, die2,)
play = rolldice
>>> play
<function rolldice at 0180B53C>

ANY help in this area would be great thank you,
Robert



From shalehperry@attbi.com  Tue Mar 19 17:44:25 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue, 19 Mar 2002 09:44:25 -0800 (PST)
Subject: [Tutor] NEWBIE rolling dice script
In-Reply-To: <200203191232.AA3620405550@centralcatholic.org>
Message-ID: <XFMail.20020319094425.shalehperry@attbi.com>

On 19-Mar-2002 Robert Garber wrote:
> Hello all,
> 
>  Here is my problem I am working on. I am trying to write a small script that
> roll dice.  I have written it as a function so I can call it as I need it.
> When I test the function in the interpreter I get the message listed below.
> Is this telling my function is working?
> Why doesn't it print out the formatted string.
> After I get this script written I want to use it in an HTML document
> 
> 
> import random
> def rolldice():
>     die1 = random.range(1,7)
>     die2 = random.range(1,7)
>     
>     print "player rolled %d and %d" % (die1, die2,)
> play = rolldice
>>>> play
> <function rolldice at 0180B53C>
> 

you never call the function, you assign its name to 'play'.  You need to use ()
to call it:

rolldice() # that is all you need.



From scarblac@pino.selwerd.nl  Tue Mar 19 17:41:26 2002
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 19 Mar 2002 18:41:26 +0100
Subject: [Tutor] NEWBIE rolling dice script
In-Reply-To: <200203191232.AA3620405550@centralcatholic.org>; from garber@centralcatholic.org on Tue, Mar 19, 2002 at 12:32:12PM -0500
References: <200203191232.AA3620405550@centralcatholic.org>
Message-ID: <20020319184126.A20093@pino.selwerd.nl>

On  0, Robert Garber <garber@centralcatholic.org> wrote:
> Hello all,
> 
>  Here is my problem I am working on. I am trying to write a small script that roll dice.  I have written it as a function so I can call it as I need it. When I test the function in the interpreter I get the message listed below. Is this telling my function is working?
> Why doesn't it print out the formatted string.
> After I get this script written I want to use it in an HTML document
> 
> 
> import random
> def rolldice():
>     die1 = random.range(1,7)
>     die2 = random.range(1,7)
>     
>     print "player rolled %d and %d" % (die1, die2,)
> play = rolldice
> >>> play
> <function rolldice at 0180B53C>

When you do 'play = rolldice', that means that 'play' is now the same
function as rolldice is. It doesn't call the function.

Then when you do just 'play', it still doesn't call it, but shows that it's
a function (just like when you do 'x = 3' and then type 'x').

Instead, do

>>> rolldice()

To call the function. The () tell Python to actually run it.

-- 
Remco Gerlich


From tarabryan@yahoo.com  Tue Mar 19 09:00:37 2002
From: tarabryan@yahoo.com (Tara Bryan)
Date: Tue, 19 Mar 2002 14:00:37 +0500
Subject: [Tutor] NEWBIE rolling dice script
In-Reply-To: <200203191232.AA3620405550@centralcatholic.org>
References: <200203191232.AA3620405550@centralcatholic.org>
Message-ID: <0e3eb1552171332FE4@mail4.nc.rr.com>

This worked for me:

import random

def rolldice():
    die1 = random.choice(range(1,7))
    die2 = random.choice(range(1,7))
    print "player rolled %d and %d" % (die1, die2)
play = rolldice()
print play


From israel@lith.com  Tue Mar 19 18:00:20 2002
From: israel@lith.com (Israel Evans)
Date: Tue, 19 Mar 2002 10:00:20 -0800
Subject: [Tutor] NEWBIE rolling dice script
Message-ID: <AF020C5FC551DD43A4958A679EA16A15017B4026@abbott.lith.com>

You could also assign play to the name rolldice and then call play()...ie.


import random

>>>def rolldice():
       die1 = random.choice(range(1,7))
       die2 = random.choice(range(1,7))
       print "player rolled %d and %d" % (die1, die2)

>>>play = rolldice

>>>play()



~Israel~


-----Original Message-----
From: Tara Bryan [mailto:tarabryan@yahoo.com] 
Sent: 19 March 2002 1:01 AM
To: garber@centralcatholic.org; tutor@python.org
Subject: Re: [Tutor] NEWBIE rolling dice script


This worked for me:

import random

def rolldice():
    die1 = random.choice(range(1,7))
    die2 = random.choice(range(1,7))
    print "player rolled %d and %d" % (die1, die2)
play = rolldice()
print play

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


From moodykre8r@earthlink.net  Tue Mar 19 18:07:17 2002
From: moodykre8r@earthlink.net (binary_star)
Date: Tue, 19 Mar 2002 10:07:17 -0800
Subject: [Tutor] Total Newbie with IDLE issues...
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C45A@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <LPBBLEMICOGCGHANJMACGEJPDBAA.moodykre8r@earthlink.net>

Thank you Alan and Erik for your replies.

Gah! I had no idea it would be that simple a solution!

As it turns out, I /had/ already installed X on X (www.xonx.org) some while
back and, quite frankly, didn't even know what to do with it once I had
installed it. <g> Being a newbie, I am still learning how to use the OS X
command line effectively, and so have very little experience/understanding
where X-windows is concerned (it looks to me like a whole other animal).
Still, I had an idea it would be useful at /some/ point to have X-windows (I
am aware that it is required for some progs to work, actually, having read
enough to glean that much), but didn't think about it much. And now it turns
out that I made a good decision when I installed it.

Long story short: IDLE immediately came up once I invoked it from X-windows
(rootless mode).

As for OS X, I have to say that it has enabled me to accomplish in a few
days what I never could accomplish in Linux, while yet retaining all the
features I love and expect from a Mac. OS X is simply the most elegant,
beautiful, stable system I have ever laid fingers on. Don't get me wrong, I
think Linux is superb if you have enough experience of *nix systems (as does
a good friend of mine who uses SUSE), but for someone like me who simply
does not yet grok *nix, OS X makes for a much kinder "educational journey".
(Truthfully, I never got beyond trying to understand .rc files in Linux.)
Which is also the reason I am starting with Python and not Java or PERL. The
side benefit, of course (which will likely become a major benefit), is that
both OS X and Python are not just for beginners; they both have immense
power, and knowing how to work with them will ultimately open doors to
grokking other such systems/languages.

Thank you again for your assistance.


Sincerely,
'.'M.'.


> -----Original Message-----
> From: alan.gauld@bt.com [mailto:alan.gauld@bt.com]
> Sent: Tuesday, March 19, 2002 9:09 AM
> To: moodykre8r@earthlink.net; tutor@python.org
> Subject: RE: [Tutor] Total Newbie with IDLE issues...
>
>
> > I am learning Python on Mac OS X (10.1.3).
>
> Cool, I'm currently on the verge of buying a laptop andf looking
> closely at
> an Apple iBook. MacOS X is just sooooo sexy! :-)
>
> > ...I receive the following error when I try to run Idle:
>
> Ah, sbnag. The Unix version of Python needs an X server
> running to do IDLE. You either have to get XonX installed
> (and running) or get the MacOS 9 version of Python and
> run it in Classic (Or have they got the Carbonised version
> up yet? - obvious self interest behind this question!)
>
> > TclError: no display name and no $DISPLAY environment variable
>
> Basically it says Tcl/Tk (from which IDLE is built) is
> looking for an X windows display to present its windows
> and can't find one.
>
> Try www.xonx.org.
>
> and the Mac Python pages for more specifics.
>
> Alan g
>



From gayers7@cogeco.ca  Tue Mar 19 20:01:32 2002
From: gayers7@cogeco.ca (Gordon W. Ayers)
Date: Tue, 19 Mar 2002 14:01:32 -0600
Subject: [Tutor] OpenGl extensions
Message-ID: <3C97991C.F6AADA07@cogeco.ca>

 I have installed the package win32all.146.exe and tried to run the demo
in
pywin\demos\guidemo.py
 when I select Open Gl Demo I get this message:

PythonWin 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on
win32.
Portions Copyright 1994-2001 Mark Hammond (mhammond@skippinet.com.au) -
see 'Help/About PythonWin' for further copyright information.
>>> The OpenGL extensions do not appear to be installed.
This Pythonwin demo can not run
Demo of Open GL Demo failed - exceptions.SystemExit:1

 My question is where can I find these extensions so that I can install
them? Any help
will be geatly appreciated.

                                                Gord




From Doug.Shawhan@gecits.ge.com  Tue Mar 19 19:40:33 2002
From: Doug.Shawhan@gecits.ge.com (Doug.Shawhan@gecits.ge.com)
Date: Tue, 19 Mar 2002 14:40:33 -0500
Subject: [Tutor] Creating a list from a comma-seperated string.
Message-ID: <47B6167F8E69D31194BA0008C7918D4204E4BDCD@msxcvg02itscge.gecits.ge.com>

I know this is probably very simple.

I have strings of comma-seperated text that I want to split into lists.

split() of course, seperates every letter. How do I tell split() to do it's
business at the commas?

Thanks!


From Doug.Shawhan@gecits.ge.com  Tue Mar 19 19:46:16 2002
From: Doug.Shawhan@gecits.ge.com (Doug.Shawhan@gecits.ge.com)
Date: Tue, 19 Mar 2002 14:46:16 -0500
Subject: [Tutor] RE: Creating a list from a comma-seperated string.
Message-ID: <47B6167F8E69D31194BA0008C7918D4204E4BDCE@msxcvg02itscge.gecits.ge.com>



	[  I know this is probably very simple.

	[ I have strings of comma-seperated text that I want to split into
lists.

	[ split() of course, seperates every letter. How do I tell split()
to do it's business at the commas?

	[ Thanks!
	[Shawhan, Douglas (GEAE, GECC)]  

	...aaand the crowd says duh! :    .split(',')

	Of course, the answer popped into my head about 15 seconds after I
fired off the email. You can all go back to thinking about hard stuff now!
:-)


From deirdre@deirdre.net  Tue Mar 19 19:55:00 2002
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Tue, 19 Mar 2002 11:55:00 -0800 (PST)
Subject: [Tutor] Creating a list from a comma-seperated string.
In-Reply-To: <47B6167F8E69D31194BA0008C7918D4204E4BDCD@msxcvg02itscge.gecits.ge.com>
Message-ID: <Pine.LNX.4.31.0203191154260.22939-100000@emperor.deirdre.org>

On Tue, 19 Mar 2002 Doug.Shawhan@gecits.ge.com wrote:

> I know this is probably very simple.
>
> I have strings of comma-seperated text that I want to split into lists.
>
> split() of course, seperates every letter. How do I tell split() to do it's
> business at the commas?

split takes an optional second argument:

no_commas_please = string.split(string_with_commas, ',')

--
_Deirdre                                              http://deirdre.net
"I love deadlines. I like the whooshing sound they make as they fly by."
                                                         - Douglas Adams



From glingl@aon.at  Tue Mar 19 20:51:50 2002
From: glingl@aon.at (Gregor Lingl)
Date: Tue, 19 Mar 2002 21:51:50 +0100
Subject: [Tutor] OpenGl extensions
References: <3C97991C.F6AADA07@cogeco.ca>
Message-ID: <001901c1cf87$e4b86970$1664a8c0@mega>

----- Original Message ----- 
From: "Gordon W. Ayers" <gayers7@cogeco.ca>
To: <tutor@python.org>
Sent: Tuesday, March 19, 2002 9:01 PM
Subject: [Tutor] OpenGl extensions


> I have installed the package win32all.146.exe and tried to run the demo
> in
> pywin\demos\guidemo.py
>  when I select Open Gl Demo I get this message:
> 
> PythonWin 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on
> win32.
> Portions Copyright 1994-2001 Mark Hammond (mhammond@skippinet.com.au) -
> see 'Help/About PythonWin' for further copyright information.
> >>> The OpenGL extensions do not appear to be installed.
> This Pythonwin demo can not run
> Demo of Open GL Demo failed - exceptions.SystemExit:1
> 
>  My question is where can I find these extensions so that I can install
> them? Any help
> will be geatly appreciated.
> 
>                                                 Gord
> 
> 

You can find them at http://pyopengl.sourceforge.net/

But I am surprised to see you use PythonWin with Python2.2
How did you manage this?

The last time I heard from Pythonwin was, when ActiveState published
the alpha1-release for Python2.2. late in 2001
Then I heard some rumour about Mark Hammond having left ActiveState and
I fell into a deep sorrow about the future of PythonWin. 
So what's going on?

Any information would be greatly appreciated
especially one that lets me bring PythonWin for Python2.2 to work
Gregor




From glingl@aon.at  Tue Mar 19 21:50:23 2002
From: glingl@aon.at (Gregor Lingl)
Date: Tue, 19 Mar 2002 22:50:23 +0100
Subject: [Tutor] once again: IDLE amd mainloop()
References: <3C97991C.F6AADA07@cogeco.ca> <001901c1cf87$e4b86970$1664a8c0@mega>
Message-ID: <003301c1cf90$129bb880$1664a8c0@mega>

Some times ago I've heard, that Python posesses some means
of 'introspection'.

So I wonder if it would be possible for an application to detect
if it is launched from IDLE (in contrast to beeing launched from 
the commandline). Or aternatively if a Tkinter-mainloop is 
already running. If so, no additional call of mainloop is
necessary (nor advised).

This way one could (similar to the if __name__ == '__main__':
construction) write applications, that would run if started
from IDLE the same way as if they were run as a script.

Any suggestions?

Gregor



From shendric@arches.uga.edu  Tue Mar 19 21:48:57 2002
From: shendric@arches.uga.edu (shendric@arches.uga.edu)
Date: Tue, 19 Mar 2002 16:48:57 -0500
Subject: [Tutor] Underscores
Message-ID: <1016574537.smmsdV1.1.1@mail.arches.uga.edu>

Greetings all,

This is probably a really boring question, but I've been looking at some 
code and there are a number of cases where the method name is prefixed 
with and underscore (self._hull, etc.).  Now, I understand the use of 
the underscore in __init__, but does the underscore like that above 
serve a purpose?  In that particular code, I can't find a function that 
is defined as _hull.  Just to be clear, this code is used to configure a 
MegaWidget in Tkinter, and I know that hull is an option for a 
MegaWidget, but I've never seen _hull.

Sean




From Doug.Shawhan@gecits.ge.com  Tue Mar 19 21:52:16 2002
From: Doug.Shawhan@gecits.ge.com (Doug.Shawhan@gecits.ge.com)
Date: Tue, 19 Mar 2002 16:52:16 -0500
Subject: [Tutor] Searching for items in two lists.
Message-ID: <47B6167F8E69D31194BA0008C7918D4204E4BDD1@msxcvg02itscge.gecits.ge.com>

Hi there.

I have a simple sorting routine that is giving me some unexpected results.

I have a file full of 9 character strings. I have a second file that
contains strings with those same 9 character srings that I wish to extract
to a list, then save to a file.

When I try my basic idea in the interpreter it works like so:

>>> l='freep, creeep, jeep'
>>> foop=l.split(',')
>>> turf=['eee','aaa']
>>> dorf=[]
>>> for thing in turf:
	for each in foop:
		if re.findall(thing, each)==[]:
			print 'nope'
		else: dorf.append(each)

nope
nope
nope
nope
nope
>>> dorf
[' creeep']
>>> 

This is what I expected...

However, when I try it in a script:

------------------------script---------------
import re

#open list of stuff to look for

f1=open("\\tmp\\snarf.txt",'r')

#open 600k file to look in

f2=open("\\tmp\\new.csv",'r')

lookfor=f1.readlines()
lookin=f2.readlines()

answers=[]

for item in lookfor:
	for searched_string in lookin:
		if re.findall(item, searched_string) == []:
			print 'nope'
		else: answers.append(searched_string)

report=open("\\tmp\\report.csv",'w')
for all in answers:
	report.write(all)

report.close()

---------------/script--------------------------------

I must have a flaw in my logic somewhere, cause my output file is on the
order of 15 megs!

Halp! What am I overlooking?

Thanks!


From shalehperry@attbi.com  Tue Mar 19 22:02:35 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue, 19 Mar 2002 14:02:35 -0800 (PST)
Subject: [Tutor] Underscores
In-Reply-To: <1016574537.smmsdV1.1.1@mail.arches.uga.edu>
Message-ID: <XFMail.20020319140235.shalehperry@attbi.com>

On 19-Mar-2002 shendric@arches.uga.edu wrote:
> Greetings all,
> 
> This is probably a really boring question, but I've been looking at some 
> code and there are a number of cases where the method name is prefixed 
> with and underscore (self._hull, etc.).  Now, I understand the use of 
> the underscore in __init__, but does the underscore like that above 
> serve a purpose?  In that particular code, I can't find a function that 
> is defined as _hull.  Just to be clear, this code is used to configure a 
> MegaWidget in Tkinter, and I know that hull is an option for a 
> MegaWidget, but I've never seen _hull.
> 

a leading underscore says 'I am private, leave me alone'.  It is analogous to
placing the variable in the private section of a C++ or Java class definition,
although in python the privateness is a convention and only loosely enforced.


From charlie@begeistert.org  Tue Mar 19 22:33:05 2002
From: charlie@begeistert.org (Charlie Clark)
Date: Tue, 19 Mar 2002 23:33:05 +0100
Subject: [Tutor] Re: Gadfly
In-Reply-To: <E16nLFR-0007ZS-00@mail.python.org>
References: <E16nLFR-0007ZS-00@mail.python.org>
Message-ID: <20020319233428.1254.3@gormenghast.AUTODIAL>

On 2002-03-19 at 16:10:01 [+0100], tutor-request@python.org wrote:
> Likely you'll have to mourn its demise.  It doesn't appear to be actively 
> maintained any more, and the mailing list contains nothing but spam.  The 
> test suite works with 1.5.2 and 2.1 but issues deprecation warnings.  The 
> test suite fails with 2.2.

Gadfly is included with Zope in every release where it's great for testing databases on things like a notebook where they might not be connected.

Charlie


From lha2@columbia.edu  Tue Mar 19 22:38:22 2002
From: lha2@columbia.edu (Lloyd Hugh Allen)
Date: Tue, 19 Mar 2002 17:38:22 -0500
Subject: [Tutor] Creating a list from a comma-seperated string.
References: <Pine.LNX.4.31.0203191154260.22939-100000@emperor.deirdre.org>
Message-ID: <3C97BDDE.A714DDA@mail.verizon.net>

Deirdre Saoirse wrote:
> 
> On Tue, 19 Mar 2002 Doug.Shawhan@gecits.ge.com wrote:
> 
> > I know this is probably very simple.
> >
> > I have strings of comma-seperated text that I want to split into lists.
> >
> > split() of course, seperates every letter. How do I tell split() to do it's
> > business at the commas?
> 
> split takes an optional second argument:
> 
> no_commas_please = string.split(string_with_commas, ',')

Or, since There's More Than One Way To Do It (oops, wrong language)
(hey, wait, I don't even know that language), I personally find

string_with_commas.split(',')

more readable. Even if its inverse is

','.join(list_of_strings)


From charlie@begeistert.org  Tue Mar 19 22:39:47 2002
From: charlie@begeistert.org (Charlie Clark)
Date: Tue, 19 Mar 2002 23:39:47 +0100
Subject: [Tutor] Replacement for os.path.walk
In-Reply-To: <E16nLFR-0007ZS-00@mail.python.org>
References: <E16nLFR-0007ZS-00@mail.python.org>
Message-ID: <20020319234226.1451.4@gormenghast.AUTODIAL>

Hi all,

I remember someone posting a replacement for os.path.walk with less "magical" syntax but can't remember if it was here or the newsgroup. Does this ring a bell?

Charlie


From israel@lith.com  Tue Mar 19 22:50:10 2002
From: israel@lith.com (Israel Evans)
Date: Tue, 19 Mar 2002 14:50:10 -0800
Subject: [Tutor] Re: Gadfly
Message-ID: <AF020C5FC551DD43A4958A679EA16A15017B402A@abbott.lith.com>

Does that mean it's an updated version that works with python 2.2?



~Israel~


-----Original Message-----
From: Charlie Clark [mailto:charlie@begeistert.org] 
Sent: 19 March 2002 2:33 PM
To: tutor@python.org
Subject: [Tutor] Re: Gadfly

On 2002-03-19 at 16:10:01 [+0100], tutor-request@python.org wrote:
> Likely you'll have to mourn its demise.  It doesn't appear to be actively 
> maintained any more, and the mailing list contains nothing but spam.  The 
> test suite works with 1.5.2 and 2.1 but issues deprecation warnings.  The 
> test suite fails with 2.2.

Gadfly is included with Zope in every release where it's great for testing
databases on things like a notebook where they might not be connected.

Charlie

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


From dsh8290@rit.edu  Tue Mar 19 23:16:22 2002
From: dsh8290@rit.edu (dman)
Date: Tue, 19 Mar 2002 17:16:22 -0600
Subject: [Tutor] Re: Gadfly
In-Reply-To: <AF020C5FC551DD43A4958A679EA16A15017B402A@abbott.lith.com>
References: <AF020C5FC551DD43A4958A679EA16A15017B402A@abbott.lith.com>
Message-ID: <20020319231622.GD27367@dman.ddts.net>

On Tue, Mar 19, 2002 at 02:50:10PM -0800, Israel Evans wrote:
| From: Charlie Clark  , 19 March 2002 2:33 PM
| On 2002-03-19 at 16:10:01 [+0100], tutor-request@python.org wrote:
| | > Likely you'll have to mourn its demise.  It doesn't appear to be actively 
| | > maintained any more, and the mailing list contains nothing but spam.  The 
| | > test suite works with 1.5.2 and 2.1 but issues deprecation warnings.  The 
| | > test suite fails with 2.2.
| 
| | Gadfly is included with Zope in every release where it's great for testing
| | databases on things like a notebook where they might not be connected.
|
| Does that mean it's an updated version that works with python 2.2?

Unfortunately I think Zope is only for 2.1 right now.  The debian
packages are for 2.1, not 2.2, and the installation instructions that
I skimmed talk about 2.1 (and 1.5.2 for old versions).

Hopefully the zope people will update gadfly when they move to 2.2,
but who knows?

-D

-- 

Many are the plans in a man's heart,
but it is the Lord's purpose that prevails.
        Proverbs 19:21



From jeff@ccvcorp.com  Wed Mar 20 00:23:20 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Tue, 19 Mar 2002 16:23:20 -0800
Subject: [Tutor] PythonWin & Python 2.2
References: <E16nSC7-0003ux-00@mail.python.org>
Message-ID: <3C97D678.BB81E96@ccvcorp.com>


> "Gregor Lingl" <glingl@aon.at> wrote:
>
> But I am surprised to see you use PythonWin with Python2.2
> How did you manage this?
>
> The last time I heard from Pythonwin was, when ActiveState published
> the alpha1-release for Python2.2. late in 2001

That is still the latest version of ActivePython, though they're supposed to release a 2.2final "Real Soon Now(tm)".  However, Mark *has* released a new version of the win32all package for use with 2.2.  PythonLabs Python + win32all == almost the same thing as
ActivePython.  :)  (I'd expect that you can find the 2.2 version of win32all on www.python.org)

Jeff Shannon
Technician/Programmer
Credit International




From erikprice@mac.com  Wed Mar 20 00:41:59 2002
From: erikprice@mac.com (Erik Price)
Date: Tue, 19 Mar 2002 19:41:59 -0500
Subject: [Tutor] Gadfly... missing?
In-Reply-To: <20020319142936.GA23865@dman.ddts.net>
Message-ID: <49EB19AA-3B9B-11D6-B0D0-00039351FE6A@mac.com>

On Tuesday, March 19, 2002, at 09:29  AM, dman wrote:

> PS. I'm sorry to see it go too.  It's the easiest way to begin working
>     with SQL, and also the easiest way to get a db on windows (though
>     I haven't actually tested to verify that it works on windows).

This actually raises a quick question -- are there any small-scale open 
source relational databases?  I have been using MySQL for a while and I 
really like it, but I was wondering if there is something that can be 
easily embedded into a Python program.  Or is the preferred means of 
storing things like "preferences" to place them in a file?  I am 
interested in something that can run in Unix or Linux.

MySQL would be perfect except that it is really overkill to what I have 
in mind -- I'm thinking of something light and small that can store or 
retrieve data for a program that calls it, not a RDBMS server that can 
support numerous requests in a second etc.

But I don't know if this is even something that exists.


Erik



From jeff@ccvcorp.com  Wed Mar 20 00:45:35 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Tue, 19 Mar 2002 16:45:35 -0800
Subject: [Tutor] Searching for items in two lists.
References: <E16nSC7-0003ux-00@mail.python.org>
Message-ID: <3C97DBAF.3D3114FC@ccvcorp.com>

> Doug.Shawhan@gecits.ge.com wrote:
>
> When I try my basic idea in the interpreter it works like so:
> ......
> However, when I try it in a script:
> ........
> I must have a flaw in my logic somewhere, cause my output file is on the
> order of 15 megs!
>
> Halp! What am I overlooking?

I'm not sure just yet, but you might try this.  Use the same 'lookfor' file, but create a small (10-15 line) 'lookin' file -- make sure that some of the lines will match only one pattern, some will match more than one pattern, and some will match *no* patterns.  Run that
same script using the new, small lookin file, and then see what the results are.  By comparing what *that* spits out, versus what you'd expect, you may be able to narrow down the problem yourself.  If not, then maybe you can post both datafiles along with your script, here,
and we can take a better look.  :)

One possible reason that your output file is so big, is that currently, a line that matches multiple search strings gets output each time that a match is found.

By the way, for what you're doing, you probably don't need to use regular expressions.  (I'm guessing that the items in you 'lookfor' file are plain strings, not regexes?)  You can make this script much lighter-weight by replacing your inner loop with this:

for line in lookin:
    for item in lookfor:
        if line.find(item) < 0:
            print 'nope'
        else:
            answers.append(line)
            break

Note that, since you're searching each line of the lookin file, I've renamed the loop variable to reflect that.  I've also switched the order of the loops, because it makes more sense to see whether each line matches any of the search terms, rather than searching the whole
file for each of the search terms.  Most importantly, I've replaced the regex with a simple call to your string's find() method.  This returns the index of the start of the passed string, or -1 if the string isn't found.  So, if line.find() < 0, then the item was not found
in line.  I've also added a break statement.  This means that if any search item is found in that line, it will stop searching that line and move on to the next line.  (It breaks out of the 'for item in lookfor' loop, returning you to the 'for line in lookin' loop.)

If you have any other questions, or if any of this doesn't make sense (I don't think I'm explaining this at my best just now ;) ), don't hesitate to ask.  :)

Jeff Shannon
Technician/Programmer
Credit International






From erikprice@mac.com  Wed Mar 20 01:34:50 2002
From: erikprice@mac.com (Erik Price)
Date: Tue, 19 Mar 2002 20:34:50 -0500
Subject: [Tutor] definition of a library
Message-ID: <ABD92166-3BA2-11D6-B0D0-00039351FE6A@mac.com>

I've seen the word "library" used in the context of software code since 
before I can remember.  I've never really known what it is.  So I 
googled...

...according to webopedia.internet.com, a library has two definitions:

(1) A collection of files.

(2) In programming, a library is a collection of precompiled routines 
that a program can use. The routines, sometimes called modules, are 
stored in object format. Libraries are particularly useful for storing 
frequently used routines because you do not need to explicitly link them 
to every program that uses them. The linker automatically looks in 
libraries for routines that it does not find elsewhere. In MS-Windows 
environments, library files have a .DLL extension.

I'm referring to the second definition, when I ask my question -- are 
there libraries in Python?  Does the Python binary know where to search 
for this code, or do I need to import it as I do with modules?  Are 
libraries in Python generally in already-compiled form (as described in 
the second definition) or are they generally raw source code?

Thank you.


Erik



From israel@lith.com  Wed Mar 20 01:36:47 2002
From: israel@lith.com (Israel Evans)
Date: Tue, 19 Mar 2002 17:36:47 -0800
Subject: [Tutor] Gadfly... missing?
Message-ID: <AF020C5FC551DD43A4958A679EA16A15017B402D@abbott.lith.com>

http://starship.python.net/crew/shprentz/

has some interesting stuff on persistence.

There is of course always the shelve and pickle modules....



~Israel~


-----Original Message-----
From: Erik Price [mailto:erikprice@mac.com] 
Sent: 19 March 2002 4:42 PM
To: dman
Cc: 'tutor@python.org'
Subject: Re: [Tutor] Gadfly... missing?


On Tuesday, March 19, 2002, at 09:29  AM, dman wrote:

> PS. I'm sorry to see it go too.  It's the easiest way to begin working
>     with SQL, and also the easiest way to get a db on windows (though
>     I haven't actually tested to verify that it works on windows).

This actually raises a quick question -- are there any small-scale open 
source relational databases?  I have been using MySQL for a while and I 
really like it, but I was wondering if there is something that can be 
easily embedded into a Python program.  Or is the preferred means of 
storing things like "preferences" to place them in a file?  I am 
interested in something that can run in Unix or Linux.

MySQL would be perfect except that it is really overkill to what I have 
in mind -- I'm thinking of something light and small that can store or 
retrieve data for a program that calls it, not a RDBMS server that can 
support numerous requests in a second etc.

But I don't know if this is even something that exists.


Erik


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


From SWidney@ci.las-vegas.nv.us  Wed Mar 20 02:08:15 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Tue, 19 Mar 2002 18:08:15 -0800
Subject: [Tutor] NEWBIE rolling dice script
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F5A39@SOVEREIGN>

> import random
> def rolldice():
>     die1 = random.range(1,7)
>     die2 = random.range(1,7)
>     
>     print "player rolled %d and %d" % (die1, die2,)
> play = rolldice
> >>> play
> <function rolldice at 0180B53C>
> 
> ANY help in this area would be great thank you,
> Robert

A few changes...first the interactive prompt session:

>>> import random
>>> def rolldice():
...     die1 = random.randrange(1,7)
...     die2 = random.randrange(1,7)
...     print "player rolled %d and %d" % (die1,die2)
...     return (die1,die2)
... 
>>> play = rolldice()
player rolled 1 and 3
>>> play
(1, 3)
>>>

Now some notes:

1) The function name should be random.randrange()
2) "print"ing the results within the function is all well and good, but if
you want to store the values for later processing, you need to "return" them

HTH
Scott


From dsh8290@rit.edu  Wed Mar 20 04:46:29 2002
From: dsh8290@rit.edu (dman)
Date: Tue, 19 Mar 2002 22:46:29 -0600
Subject: [Tutor] definition of a library
In-Reply-To: <ABD92166-3BA2-11D6-B0D0-00039351FE6A@mac.com>
References: <ABD92166-3BA2-11D6-B0D0-00039351FE6A@mac.com>
Message-ID: <20020320044629.GA29681@dman.ddts.net>

On Tue, Mar 19, 2002 at 08:34:50PM -0500, Erik Price wrote:
| I've seen the word "library" used in the context of software code since 
| before I can remember.  I've never really known what it is.  So I 
| googled...
| 
| ...according to webopedia.internet.com, a library has two definitions:
| 
| (1) A collection of files.
| 
| (2) In programming, a library is a collection of precompiled routines 
| that a program can use. The routines, sometimes called modules, are 
| stored in object format. Libraries are particularly useful for storing 
| frequently used routines because you do not need to explicitly link them 
| to every program that uses them. The linker automatically looks in 
| libraries for routines that it does not find elsewhere. In MS-Windows 
| environments, library files have a .DLL extension.
| 
| I'm referring to the second definition, when I ask my question -- are 
| there libraries in Python? 

As it says, a library is
    a collection of routines that a program can use

| Does the Python binary know where to search for this code, or do I
| need to import it as I do with modules?  Are libraries in Python
| generally in already-compiled form (as described in the second
| definition) or are they generally raw source code?

In python, libraries can be written in Python, C, or C++ (and possibly
some other language, but I haven't seen them).  If they are python,
then they are usually distributed in source form since the interpreter
will automatically byte-compile them.  If they are C or C++ then they
must be compiled into a "shared libary" (.so on *nix, .dll on 'doze).
The interpreter knows how to load .py[co]? files itself, and locates
them via $PYTHONPATH and sys.path.  The C function dlopen() allows a
(C) program to link and load a .so at runtime.  Thus the interpreter
can load an extension module without being recompiled.

When dealing with python, people commonly use the terms "module" or
"package", but they basically mean the same thing as "library".

Since we have decided that a module or a package is a library, yes you
do need to import them :-).

HTH,
-D

-- 

I can do all things through Christ who strengthens me.
        Philippians 4:13



From apython101@yahoo.com  Wed Mar 20 07:29:13 2002
From: apython101@yahoo.com (john public)
Date: Tue, 19 Mar 2002 23:29:13 -0800 (PST)
Subject: [Tutor] telling dir(_builtins_) from dir(__builtins__)
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C44B@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20020320072913.80362.qmail@web21109.mail.yahoo.com>

--0-100769099-1016609353=:79666
Content-Type: text/plain; charset=us-ascii


 

Indeed it is. Opps! Sorry about that.

************************************************

Then again on page 79 discussing dir(__builtins__) the 
footnote remarks that "Many special names exist in Python, 
most of which are marked by this double underscore naming 
style"


John Q.Public



---------------------------------
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage
--0-100769099-1016609353=:79666
Content-Type: text/html; charset=us-ascii

<P>&nbsp;</P>
<P>Indeed it is. Opps! Sorry about that.</P>
<P>************************************************</P>
<P>Then again on page 79 discussing dir(__builtins__) the <BR>footnote remarks that "Many special names exist in Python, <BR>most of which are marked by this double underscore naming <BR>style"<BR></P>
<P>John Q.Public</P><p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href="$rd_url/tag/http://sports.yahoo.com/">Yahoo! Sports</a> - live college hoops coverage
--0-100769099-1016609353=:79666--


From erikprice@mac.com  Wed Mar 20 13:09:49 2002
From: erikprice@mac.com (Erik Price)
Date: Wed, 20 Mar 2002 08:09:49 -0500
Subject: [Tutor] definition of a library
In-Reply-To: <20020320044629.GA29681@dman.ddts.net>
Message-ID: <C2463130-3C03-11D6-B0D0-00039351FE6A@mac.com>

On Tuesday, March 19, 2002, at 11:46  PM, dman wrote:

> In python, libraries can be written in Python, C, or C++ (and possibly
> some other language, but I haven't seen them).  If they are python,
> then they are usually distributed in source form since the interpreter
> will automatically byte-compile them.  If they are C or C++ then they
> must be compiled into a "shared libary" (.so on *nix, .dll on 'doze).

Since I'm not quite ready to learn C or C++ (maybe tomorrow :), I can 
just assume that if a C or C++ library is intended to be embedded within 
Python programs, then it has already been compiled appropriately?  
There's something about this that reminds me of my recent Apache 
compile, since it can use DSO modules without needing a recompile, but I 
don't really understand all of the details....

> The interpreter knows how to load .py[co]? files itself, and locates
> them via $PYTHONPATH and sys.path.  The C function dlopen() allows a
> (C) program to link and load a .so at runtime.  Thus the interpreter
> can load an extension module without being recompiled.

Let me stop you for a minute for a clarification -- does this mean that 
any C programs need to be called with dlopen()?  I think I have seen a C 
module called "cpickle" that essentially operates as a faster "pickle".  
Has this been specially written so as not to require the dlopen() 
function, or is it because it's not a .so file?

Thanks dman for the useful knowledge!


Erik



From shendric@arches.uga.edu  Wed Mar 20 15:12:04 2002
From: shendric@arches.uga.edu (shendric@arches.uga.edu)
Date: Wed, 20 Mar 2002 10:12:04 -0500
Subject: [Tutor] using Tcl/Tk extensions
Message-ID: <1016637124.smmsdV1.1.1@mail.arches.uga.edu>

Hello,

Does anyone know how one would use a Tcl/Tk extension in a 
Python/Tkinter script?  I'm wanting to use a QuickTimeTcl extension to 
create a Quicktime video widget in an application, and I'm not sure how 
to go about it.

Also, does anyone know how to set the PYTHONPATH on a Windows 2000 
machine?  I'm wanting to use PMW, but I can't seem to convince a script 
that PMW exits in a directory nearby.

Sean




From Doug.Shawhan@gecits.ge.com  Wed Mar 20 15:41:25 2002
From: Doug.Shawhan@gecits.ge.com (Doug.Shawhan@gecits.ge.com)
Date: Wed, 20 Mar 2002 10:41:25 -0500
Subject: [Tutor] Searching for items in two lists.
Message-ID: <47B6167F8E69D31194BA0008C7918D4204E4BDD5@msxcvg02itscge.gecits.ge.com>

Quoth Alan:

>> >>> l='freep, creeep, jeep'
>> >>> foop=l.split(',')

>Here you split it into words.

Yes, I was just lazily splitting a string into a list, cause I wanted to
avoid typing quotes! :-)

>> #open 600k file to look in
>> f2=open("\\tmp\\new.csv",'r')
>> lookin=f2.readlines()

>But here you don't split even tho' it hints that its 
>a CSV file...

Yep, each line in the file represents an entry, so I don't need to split
them.

>> for item in lookfor:
>> 	for searched_string in lookin:

>So you are searching the full line of entries 
>not just the single items - is that what you want?

Yes indeed!

>> 		else: answers.append(searched_string)

>And appending the whole line not just an entry...

Right!

>> I must have a flaw in my logic somewhere, cause my output 
>> file is on the order of 15 megs!

>If you only appended single entries would it look more sane?

The format of the two files is like so:

lookfor:
123456
a12345
b12345
c12345

lookin:
"'Briggs', 'Joebob'", 'my house', '12345', 'Yadda yadda'
"'Briggs', 'Joejim'", 'Guy house', '12222', 'Fu-Bar'
"'Briggs', 'Joeweasel'", 'Thai house', 'b3214', 'Foo Bar'
"'Briggs', 'Joeblow'", 'thy house', 'c5588', 'Yadda yammar'

For each line in lookfor I want to search each line in lookin and return the
entire line to a list and thereby to a file. For some reason, I seem to be
finding more than my share of items.... several times! :-)

>Alan G


From lumbricus@gmx.net  Tue Mar 19 14:58:55 2002
From: lumbricus@gmx.net (=?ISO-8859-1?Q?J=F6rg_W=F6lke?=)
Date: Tue, 19 Mar 2002 15:58:55 +0100 (MET)
Subject: [Tutor] FTP File Size
References: <20020317222417.GD10796@johnsons-web.com>
Message-ID: <27961.1016549935@www26.gmx.net>

> Hello:

Hi!
 
> 
> > What kind of ftp server?
> 
>   Must ask domain hoster, but my guess is wu_ftpd, or FtpPro on
>   RH linux. The clients I'm using (Midnight Commander and IglooFTP)
>   are reporting correctly, I believe.
> 
> > If its open source, how does it determine the size?
>   
>    I'm using an object that inherits FTP from ftplib. 
>    => using the "original" (not overloaded) 'size' method.
>    I can send entire source if necessary.

No, the problem is, how the _server_ determines the
file size. Because ftplib.py just sends the size
command and prints the answer.

from my ftplib.py:

| def size(self, filename):
|                '''Retrieve the size of a file.'''
|                # Note that the RFC doesn't say anything about 'SIZE'
|                resp = self.sendcmd('SIZE ' + filename)
|                if resp[:3] == '213':
|                        return string.atoi(string.strip(resp[3:]))

$ perl -e 'print "X"x2023' > test.txt
$ telnet localhost 21
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 ******.uni-freiburg.de FTP server (Digital UNIX Version 5.60) ready.
user guest
331 Password required for guest.
pass ******
230 User guest logged in.
size test.txt
213 File size (test.txt): 2023 bytes
quit
221 Goodbye.
Connection closed by foreign host.
$ rm test.txt
$  

Here it seems to work correctly.
Don't know how "sparse files" are influencing
the servers answer to the 'SIZE' command.

HTH, HAND 
and Greetings J"o!

-- 
sigfault

GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net



From tanovak@hotmail.com  Wed Mar 20 17:25:08 2002
From: tanovak@hotmail.com (Tod Novak)
Date: Wed, 20 Mar 2002 09:25:08 -0800
Subject: [Tutor] Making executable
Message-ID: <OE15cJ1bhmPkYmGyyNK000104c1@hotmail.com>

This is a multi-part message in MIME format.

------=_NextPart_000_0005_01C1CFF1.2099C1A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,

I'm sure this is an easy question, so I came to the experts. I'd like to =
know how to make a program (or script) executable for people that do not =
have Python installed on their machine?

I'm a real newbie, so any help would be appreciated.

Thanx

------=_NextPart_000_0005_01C1CFF1.2099C1A0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I'm sure this is an easy question, so I =
came to the=20
experts. I'd like to know how to make a program (or script) executable =
for=20
people that do not have Python installed on their machine?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I'm a real newbie, so any help would be =

appreciated.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanx</FONT></DIV></BODY></HTML>

------=_NextPart_000_0005_01C1CFF1.2099C1A0--


From alex@gabuzomeu.net  Wed Mar 20 17:48:46 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Wed, 20 Mar 2002 18:48:46 +0100
Subject: [Tutor] definition of a library
In-Reply-To: <E16njSh-0005lm-00@mail.python.org>
Message-ID: <4.3.2.7.2.20020320183543.00e44210@pop3.norton.antivirus>

Hi Erik,


At 12:01 20/03/2002 -0500, you wrote:
>Date: Wed, 20 Mar 2002 08:09:49 -0500
>Subject: Re: [Tutor] definition of a library
>From: Erik Price <erikprice@mac.com>

>On Tuesday, March 19, 2002, at 11:46  PM, dman wrote:
>
> > In python, libraries can be written in Python, C, or C++ (and possibly
> > some other language, but I haven't seen them).  If they are python,
> > then they are usually distributed in source form since the interpreter
> > will automatically byte-compile them.  If they are C or C++ then they
> > must be compiled into a "shared libary" (.so on *nix, .dll on 'doze).
>
>Since I'm not quite ready to learn C or C++ (maybe tomorrow :), I can
>just assume that if a C or C++ library is intended to be embedded within
>Python programs, then it has already been compiled appropriately?

Yes, a library is basically any kind of module you can call from your 
program. It can be pure python or it can be written in C and precompiled. 
Precompiled C libraries are platform-dependant: you need to get the correct 
version for your operating system.

I think these compiled libraries usually have a .pyd extension. For 
instance, see this CSV module:

<QUOTE>

The CSV module provides a fast CSV parser which can split and join CSV 
records which have been produced by Microsoft products such as Access and 
Excel. http://www.object-craft.com.au/projects/csv/

</QUOTE>

The main point is that both kind of libraries can be called and used in the 
same way by the Python programmer. Example code for the CSV module:

import csv
p = csv.parser()
for i in xrange(100000):
     p.parse('1,2,3,4,5,6')

>There's something about this that reminds me of my recent Apache
>compile, since it can use DSO modules without needing a recompile, but I
>don't really understand all of the details....
>
> > The interpreter knows how to load .py[co]? files itself, and locates
> > them via $PYTHONPATH and sys.path.  The C function dlopen() allows a
> > (C) program to link and load a .so at runtime.  Thus the interpreter
> > can load an extension module without being recompiled.
>
>Let me stop you for a minute for a clarification -- does this mean that
>any C programs need to be called with dlopen()?  I think I have seen a C
>module called "cpickle" that essentially operates as a faster "pickle".
>Has this been specially written so as not to require the dlopen()
>function, or is it because it's not a .so file?

I think that C extension modules need to be developped in a special way if 
there are meant to be used from Python. Then you just import them into your 
Python program, just as any module.

>Thanks dman for the useful knowledge!


Cheers.

Alexandre




From arcege@speakeasy.net  Wed Mar 20 18:26:28 2002
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Wed, 20 Mar 2002 13:26:28 -0500
Subject: [Tutor] Replacement for os.path.walk
In-Reply-To: <20020319234226.1451.4@gormenghast.AUTODIAL>
References: <E16nLFR-0007ZS-00@mail.python.org> <20020319234226.1451.4@gormenghast.AUTODIAL>
Message-ID: <20020320182628.GG9563@speakeasy.net>

On Tue, Mar 19, 2002 at 11:39:47PM +0100, Charlie Clark wrote:
> Hi all,
> 
> I remember someone posting a replacement for os.path.walk with less "magical" syntax but can't remember if it was here or the newsgroup. Does this ring a bell?

Have you tried a search of the newsgroups?  You might be able to find
what you are talking about there. <URL:http://www.python.org/search.html>

About the only thing I myself can remember is Perl's very "magical" Find.
I don't see os.path.walk as that complex.  

How about something like:

def simple_walk(dir):
  flist = []
  for fname in os.listdir(dir):
    file = os.path.join(dir, fname)
    if os.path.isdir(file):
      flist.extend( simple_walk(file) )
    else:
      flist.append( file )
  return flist

This would just return a list of the 'files' in a directory tree.

  -Arcege



From dsh8290@rit.edu  Wed Mar 20 18:34:16 2002
From: dsh8290@rit.edu (dman)
Date: Wed, 20 Mar 2002 12:34:16 -0600
Subject: [Tutor] python and MS Access db's
In-Reply-To: <1311096262902.20020312095304@yahoo.com>
References: <1311096262902.20020312095304@yahoo.com>
Message-ID: <20020320183416.GA7075@dman.ddts.net>

On Tue, Mar 12, 2002 at 09:53:04AM -0800, pythonhack@yahoo.com wrote:
| I need to write a cgi for our company site that will receive input and
| add the supplied information to an Access database.  i've searched the
| web and haven't found much on how to do this.

I've got to do the same thing now at my new job.  What platform is
your CGI script going to be running on?  In my case the web stuff will
be on a linux system, and obviously MS Access is on Windows.  There
are some commercial (really expensive) ODBC drivers to allow a
C/C++/Python/whatever application on *nix connect to MS Access or SQL
Server databases.  OTOH, MS provides Windows-only ODBC drivers for
free.  I'm going to create my own server on the windows machine using
MS' ODBC driver to connect to the db, and then use either XML-RPC or
CORBA to connect to that server from the linux box.  I don't expect
this solution to be terribly difficult, but wrapping your head around
the various middleware products and the interactions between
components of a distributed system isn't beginner-level stuff.
 
HTH,
-D



From dsh8290@rit.edu  Wed Mar 20 18:37:22 2002
From: dsh8290@rit.edu (dman)
Date: Wed, 20 Mar 2002 12:37:22 -0600
Subject: [Tutor] Making executable
In-Reply-To: <OE15cJ1bhmPkYmGyyNK000104c1@hotmail.com>
References: <OE15cJ1bhmPkYmGyyNK000104c1@hotmail.com>
Message-ID: <20020320183722.GB7075@dman.ddts.net>

On Wed, Mar 20, 2002 at 09:25:08AM -0800, Tod Novak wrote:
| Hi,
| 
| I'm sure this is an easy question, so I came to the experts. I'd
| like to know how to make a program (or script) executable for people
| that do not have Python installed on their machine?
| 
| I'm a real newbie, so any help would be appreciated.

Best choice :
    tell them to install python

If you use a decent operating system you can simply package your
program and specify a dependency on python.  Then the system's
installer will take care of it for you and them.  (but MS Outlook
doesn't run on Debian so I don't think this is an option for you)

You can try Thomas Heller's "py2exe" or Gordon McMillan's "installer".
These are programs that take a python program and bundle it together
with python so that the end user doesn't have to know that python is
used at all.  Depending on your application, this might not be
trivial.

HTH,
-D

-- 

Who can say, "I have kept my heart pure;
I am clean and without sin"?
        Proverbs 20:9



From moodykre8r@earthlink.net  Wed Mar 20 18:37:26 2002
From: moodykre8r@earthlink.net (binary_star)
Date: Wed, 20 Mar 2002 10:37:26 -0800
Subject: [Tutor] OT: XonX/Linux. Was: Total Newbie with IDLE issues...
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C45D@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <LPBBLEMICOGCGHANJMACGEKIDBAA.moodykre8r@earthlink.net>

Comments with text:

> -----Original Message-----
> From: alan.gauld@bt.com [mailto:alan.gauld@bt.com]
> Sent: Wednesday, March 20, 2002 2:05 AM
> To: moodykre8r@earthlink.net; alan.gauld@bt.com; tutor@python.org;
> erikprice@mac.com
> Subject: RE: [Tutor] Total Newbie with IDLE issues...
>
> > Gah! I had no idea it would be that simple a solution!
>
> I'm glad it was since my reply was based entirely on
> reading web pages, having no hands on experience with
> MacOS X yet...

I am willing to bet that you will be very pleased with any hands on
experience you get. At the risk of waxing poetic, OS X is a dream strong
enough to pierce the veil of our waking reality. (Yeah, I know... Sorry.
<g>)

> > where X-windows is concerned (it looks to me like a whole
> > other animal).
>
> It is, its the native GUI for Unix so you need it to get the
> *nix GUI programs(like IDLE) to run on MacOS. (OpenOffice,
> GIMP, KDE, etc etc). The tricky bit is that MacOS X has
> its own proprietary GUI(Quartz) so the XonX guys have made
> X Windows run inside/alongside the MAC GUI (basically,
> for the curious, by using a zero sized root Window)

Rootless mode is amazingly well done, I must say. Were it not for the
X-windows look (which I am not complaining about, only noting), it would be
utterly transparent to the user.


> > As for OS X, I have to say that it has enabled me to
> > accomplish in a few days what I never could accomplish
> > in Linux,
>
> I've been playing with Linux since 1993 (Slackware 2
> and Kernel 0.9). I started on SunOS and moved to NT
> at work so Linux has great appeal, but I just couldn't
> get everything I wanted working on any one distro
> (I've tried RedHat, Mandrake, Suse, Slackware, Corel,
> Turbo and currently am using Redmond but none of them
> are all there). So don't feel too upset by that!

Point well taken. As it is, I am thinking of redoing my Aspen and installing
SuSE and Win2k fresh, kissing goodbye my dilapidated Red Hat and overstuffed
Win2k partitions.


> For a laptop I don't even have control over the hardware
> so I figured using a Linux laptop system was way too risky
> so MacOS promises me Unix in a stable environment out of the
> box with all the hardware working...

And sense 10.1.x, OS X works---for all intents and purposes, at least in my
case---virtually flawlessly. Admittedly, I occasionally have minor issues
with OS 9 on OS X, and have had a couple kernel panics when moving files in
the process of downloading from the Finder to the Desktop, but these
problems have been extremely few and far between.

Thank you for your responses.


Sincerely,
'.'M.'.



From alan.gauld@bt.com  Wed Mar 20 17:45:13 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 20 Mar 2002 17:45:13 -0000
Subject: [Tutor] Gadfly... missing?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C46F@mbtlipnt02.btlabs.bt.co.uk>

> This actually raises a quick question -- are there any 
> small-scale open source relational databases?  

There are several but I've no idea of the functionality on 
offer- try a google or sourceforge search. BUT...

> easily embedded into a Python program.  Or is the preferred means of 
> storing things like "preferences" to place them in a file?  I am 
> interested in something that can run in Unix or Linux.

...preferences etc are almost certainly better in a file (which 
is why unix programsd traditionally have a .foorc file) and in 
windows foo.ini. Windows even has a dedicated set of API calls 
for building and searching .ini files. Of course nowadays it 
should be the registry but personally I wouldn't trust 
anything to that!

> MySQL would be perfect except that it is really overkill to 
> what I have in mind -- I'm thinking of something light and 
> small that can store or retrieve data for a program 

Consider non relational databases then.
The DBM module should be adequate for your needs or as another 
approach (more Pythonic? )create a config object(class) with 
all the config variables in it and then pickle/unpickle 
that object.

Alan G.


From alan.gauld@bt.com  Wed Mar 20 17:59:14 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 20 Mar 2002 17:59:14 -0000
Subject: [Tutor] definition of a library
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C470@mbtlipnt02.btlabs.bt.co.uk>

> On Tuesday, March 19, 2002, at 11:46  PM, dman wrote:
> > In python, libraries can be written in Python, C, or C++ 
> (and possibly some other language, but I haven't seen them).  

FWIW
I usually distinguish between modules and libraries (despite 
the definition that was quited earlier!) Libraries can be an 
amalgam of several modules. A module is a unit of reusable code.
A library is a physical file that contains reusable or shared 
code, and that may include multiple modules. Its a subtle but 
sometimes important distinction (and one not recognised 
by UML for those who care :-).

> Since I'm not quite ready to learn C or C++ (maybe tomorrow :), I can 
> just assume that if a C or C++ library is intended to be 
> embedded within Python programs, then it has already been 
> compiled appropriately?  

Yes, usually. Occasionally you may get a library in source form 
in which case you need to comile it. In most cases you just use it.

> > them via $PYTHONPATH and sys.path.  The C function dlopen() allows a
> > (C) program to link and load a .so at runtime.  Thus the interpreter
> 
> Let me stop you for a minute for a clarification -- does this 
> mean that any C programs need to be called with dlopen()?  

Yes but its the python interpreter code that does it not yours.
When you import a module thats a C module the interpreter loads 
it via this function(I assume - I haven't looked!)

> Has this been specially written so as not to require the dlopen() 
> function, or is it because it's not a .so file?

It does exist in a .so somewhere I think but it *does* need 
dlopen() its just handled by Python when you import cpickle.

The good news is that regardless of whether a module is 
implemented in Python or in C you just import it and Python 
does the rest(provided you've installed it in the right 
place and told Python where to find it of course!)

HTH

Alan G.


From alan.gauld@bt.com  Wed Mar 20 10:05:00 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 20 Mar 2002 10:05:00 -0000
Subject: [Tutor] Total Newbie with IDLE issues...
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C45D@mbtlipnt02.btlabs.bt.co.uk>

> Thank you Alan and Erik for your replies.
> 
> Gah! I had no idea it would be that simple a solution!

I'm glad it was since my reply was based entirely on 
reading web pages, having no hands on experience with 
MacOS X yet...

> where X-windows is concerned (it looks to me like a whole 
> other animal).

It is, its the native GUI for Unix so you need it to get the
*nix GUI programs(like IDLE) to run on MacOS. (OpenOffice, 
GIMP, KDE, etc etc). The tricky bit is that MacOS X has 
its own proprietary GUI(Quartz) so the XonX guys have made 
X Windows run inside/alongside the MAC GUI (basically, 
for the curious, by using a zero sized root Window)

> As for OS X, I have to say that it has enabled me to 
> accomplish in a few days what I never could accomplish 
> in Linux, 

I've been playing with Linux since 1993 (Slackware 2 
and Kernel 0.9). I started on SunOS and moved to NT 
at work so Linux has great appeal, but I just couldn't 
get everything I wanted working on any one distro
(I've tried RedHat, Mandrake, Suse, Slackware, Corel, 
Turbo and currently am using Redmond but none of them 
are all there). So don't feel too upset by that!

For a laptop I don't even have control over the hardware 
so I figured using a Linux laptop system was way too risky 
so MacOS promises me Unix in a stable environment out of the 
box with all the hardware working...

Alan G.


From alan.gauld@bt.com  Wed Mar 20 10:42:33 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 20 Mar 2002 10:42:33 -0000
Subject: [Tutor] Searching for items in two lists.
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C460@mbtlipnt02.btlabs.bt.co.uk>

> >>> l='freep, creeep, jeep'
> >>> foop=l.split(',')

Here you split it into words.

> #open 600k file to look in
> f2=open("\\tmp\\new.csv",'r')
> lookin=f2.readlines()

But here you don't split even tho' it hints that its 
a CSV file...

> for item in lookfor:
> 	for searched_string in lookin:

So you are searching the full line of entries 
not just the single items - is that what you want?

> 		else: answers.append(searched_string)

And appending the whole line not just an entry...

> I must have a flaw in my logic somewhere, cause my output 
> file is on the order of 15 megs!

If you only appended single entries would it look more sane?

Alan G


From cpp@userline.ru  Wed Mar 20 19:31:53 2002
From: cpp@userline.ru (Alexey Rusakov)
Date: Wed, 20 Mar 2002 22:31:53 +0300
Subject: [Tutor] definition of a library
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C470@mbtlipnt02.btlabs.bt.co.uk>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C470@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20020320223153.76eaf5ba.cpp@userline.ru>

Hi!

> I usually distinguish between modules and libraries (despite 
> the definition that was quited earlier!) Libraries can be an 
> amalgam of several modules. A module is a unit of reusable code.
> A library is a physical file that contains reusable or shared 
> code, and that may include multiple modules. Its a subtle but 
> sometimes important distinction (and one not recognised 
> by UML for those who care :-).
What you call modules is named packages in UML. Libraries, respectively, are components in UML. Packages are used to represent a logical structure, components belong to a physical structure. The difference is not very subtle, IMHO :)

-- 
  Alexey Rusakov aka Ktirf
  RingRows
  mailto: cpp@userline.ru


From charlie@begeistert.org  Wed Mar 20 20:36:45 2002
From: charlie@begeistert.org (Charlie Clark)
Date: Wed, 20 Mar 2002 21:36:45 +0100
Subject: [Tutor] Re: What kind of database-like thing can be used for really small
 things?
In-Reply-To: <E16njSh-0005lm-00@mail.python.org>
References: <E16njSh-0005lm-00@mail.python.org>
Message-ID: <20020320214515.2965.8@gormenghast.AUTODIAL>

On 2002-03-20 at 18:01:19 [+0100], tutor-request@python.org wrote:
> 
> This actually raises a quick question -- are there any small-scale open 
> source relational databases?  I have been using MySQL for a while and I 
> really like it, but I was wondering if there is something that can be 
> easily embedded into a Python program.  Or is the preferred means of 
> storing things like "preferences" to place them in a file?  I am 
> interested in something that can run in Unix or Linux.
<off-topic>
Linux is a Un*x by the way or better put the various distributions of Linux (SuSE, Debian, RedHat) are Un*x built on the Linux kernel. I think the confusion is intended. Go *BSD (also Un*x) or even better go BeOS (definitely not Un*x) except for databases while select() doesn't (yet) work.

I've been working with MySQL for the last two days and it's a pig %-(. But tastes vary and luckily Python and Zope will soon be hiding me from most of it.
</off-topic>

> MySQL would be perfect except that it is really overkill to what I have 
> in mind -- I'm thinking of something light and small that can store or 
> retrieve data for a program that calls it, not a RDBMS server that can 
> support numerous requests in a second etc.
> 
> But I don't know if this is even something that exists.
Gadfly would be perfect for what you want but it also sounds as if you could use "shelve" or "pickle" or "anydbm" depending on whether you need record-locking. Use "shelve" and "pickle" if all you need to do is store the state/values of objects and you don't have to worry about concurrent access. "anydbm" will make use of any "dbm" on the machine and there should be at least one on your install.

Charlie


From wolf_binary@hotmail.com  Thu Mar 21 02:08:13 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Wed, 20 Mar 2002 20:08:13 -0600
Subject: [Tutor] OOP
Message-ID: <DAV17yXvEbjkyqU7a0x0000df74@hotmail.com>

This is a multi-part message in MIME format.

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

I wanted to know if my thinking is straight about OOP, cause I'm writing =
notes one how to do stuff in Python as I learn them. =20

Here it is:
- when making an instance(object) of a class it has all the =
behavior(functions or methods) of that class.
- objects take on all the characteristics of that class
- to use the characteristics you just name the behavior
- Example: Say you had a cat(class) named Max(instance); who likes to =
play.
    The class cat has Max as an object that can play.
- you have to initiate play from Max
- Max only plays when you tell it to

Feel free to add to this or set me straight because I want to be sure on =
this.

Thanks,
Cameron Stoner

------=_NextPart_000_0013_01C1D04A.F6EBF260
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.2713.1100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I wanted to know if my thinking is =
straight about=20
OOP, cause I'm writing notes one how to do stuff in Python as I learn=20
them.&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Here it is:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>- when making an instance(object) of a =
class it has=20
all the behavior(functions or methods) of that class.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>- objects take on all the =
characteristics of that=20
class</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>- to use the characteristics you just =
name the=20
behavior</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>- Example: Say you had a cat(class) =
named=20
Max(instance); who likes to play.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; The class cat has =
Max as an=20
object that can play.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>- you have to initiate play from =
Max</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>- Max only plays when you tell it =
to</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Feel free to add to this or set me =
straight because=20
I&nbsp;want to be sure on this.</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>Cameron =
Stoner</FONT></DIV></BODY></HTML>

------=_NextPart_000_0013_01C1D04A.F6EBF260--


From erikprice@mac.com  Thu Mar 21 02:41:12 2002
From: erikprice@mac.com (Erik Price)
Date: Wed, 20 Mar 2002 21:41:12 -0500
Subject: [Tutor] definition of a library
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C470@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <1B605E62-3C75-11D6-952A-00039351FE6A@mac.com>

On Wednesday, March 20, 2002, at 12:59  PM, alan.gauld@bt.com wrote:

> The good news is that regardless of whether a module is
> implemented in Python or in C you just import it and Python
> does the rest(provided you've installed it in the right
> place and told Python where to find it of course!)

Well, this has been an informative thread (and thanks to all), but this 
is really what I needed to hear!  I just wanted to make sure that I knew 
(1) which kinds of C libraries could be called from my python programs 
and (2) whether or not I had to do anything special.  The answer to 
those two questions, for newcomers to the thread, is that (1) certain 
kinds of C libraries (not just any library with C code) can be called 
from Python programs, and (2) you don't really have to do anything 
different from standard Python modules and libraries, just import them.


Thanks for the explanations, Python ninjas!

Erik



From erikprice@mac.com  Thu Mar 21 02:51:14 2002
From: erikprice@mac.com (Erik Price)
Date: Wed, 20 Mar 2002 21:51:14 -0500
Subject: [Tutor] python and MS Access db's
In-Reply-To: <20020320183416.GA7075@dman.ddts.net>
Message-ID: <8285EC24-3C76-11D6-952A-00039351FE6A@mac.com>

On Wednesday, March 20, 2002, at 01:34  PM, dman wrote:

> I'm going to create my own server on the windows machine using
> MS' ODBC driver to connect to the db, and then use either XML-RPC or
> CORBA to connect to that server from the linux box.

I just started learning about XML-RPC myself.  I'm interested in it, and 
if you don't mind my asking, why you are planning to use XML-RPC over 
SOAP.

I have a MySQL database (fortunately I don't have to deal with the 
headache of proprietary drivers!) which is normally used to provide the 
content for a PHP web application that I wrote.  I learned [what little 
I know] about XML a little too late to make it a pure XML-based PHP app, 
but that's okay because it really only needs to be HTML.  But I've also 
wanted to make a custom web client for my users, that simply runs 
through a user-designated directory and extracts information about the 
files inside of it (some may recognize this, I asked about graphics 
capabilities of Python and intend to use PIL to do this).

The custom web client was originally going to be designed to open up a 
socket connection and communicate directly "in Python" with the Python 
CGI script that would be sitting on the server with the MySQL 
connection.  This is a pretty quick way to do it, but I'm starting to 
think that if I make the CGI script capable of working in XML-RPC (or 
SOAP), and have the web client talk to it in that language, then it'll 
be a little less work someday if I ever need to write a client in Java, 
or if someone else wants to access the database from ASP (a lot of 
people I work with use ASP).  So I'm just starting to learn about 
XML-RPC and SOAP, and wanted to hear your thoughts about it.  This 
doesn't sound like such a difficult little program, does it?


Erik



From dsh8290@rit.edu  Thu Mar 21 03:41:50 2002
From: dsh8290@rit.edu (dman)
Date: Wed, 20 Mar 2002 21:41:50 -0600
Subject: [Tutor] python and MS Access db's
In-Reply-To: <8285EC24-3C76-11D6-952A-00039351FE6A@mac.com>
References: <20020320183416.GA7075@dman.ddts.net> <8285EC24-3C76-11D6-952A-00039351FE6A@mac.com>
Message-ID: <20020321034150.GA10880@dman.ddts.net>

On Wed, Mar 20, 2002 at 09:51:14PM -0500, Erik Price wrote:
| 
| On Wednesday, March 20, 2002, at 01:34  PM, dman wrote:
| 
| >I'm going to create my own server on the windows machine using
| >MS' ODBC driver to connect to the db, and then use either XML-RPC or
| >CORBA to connect to that server from the linux box.
| 
| I just started learning about XML-RPC myself.  I'm interested in it, and 
| if you don't mind my asking, why you are planning to use XML-RPC over 
| SOAP.

XML-RPC is rather lightweight.  I've heard that SOAP has
feature-creep.  I actually looked at both of them.  It appears that
XML-RPC only allows passing of primitive data between the processes.
I want to pass a object references (cursors, dates, times, and other
random stuff).  I think, but can't find any definitive documentation
indicating or refuting, that SOAP can pass object references around.
It looks a bit more involved and not as transparent as I'd like,
though.

At the moment it looks like I'll be going with CORBA.  I found
python-enabled win32 binaries for omniORB, and also saw comments to
the effect that ORBit works on windows.  I didn't find any binaries
for ORBit or orbit-python, and a MS compiler will be a must since I'll
need the python binary to access MS' ODBC or COM stuff.  (I can't use
gcc and the/a cygwin-enabled python)  To use CORBA I'll either need to
find a name server somewhere that both ORBs can use, or perhaps blend
in a little something else (I don't know, XML-RPC or just a plain
socket) to get the IOR for the initial object from.

Any comments, experiences, anecdotes, or pointers to documentation are
welcome :-).

| I have a MySQL database (fortunately I don't have to deal with the 
| headache of proprietary drivers!)

Yeah, nice.

| The custom web client was originally going to be designed to open up a 
| socket connection and communicate directly "in Python" with the Python 
| CGI script that would be sitting on the server with the MySQL 
| connection.

This sounds like an odd architecture to me.

Normally a CGI script is executed by a web server.  Input is given
either in the environment variable QUERY_STRING or on stdin.  The
output will be returned to the web browser, and thus ought to be some
sort of content the browser can handle sanely.

What I don't understand with the description you've given so far is
    What sort of data do you need to move through that socket?  
    What are the purposes of each process using that socket?

| This is a pretty quick way to do it, but I'm starting to 
| think that if I make the CGI script capable of working in XML-RPC
| (or SOAP), and have the web client talk to it in that language, then
| it'll be a little less work someday if I ever need to write a client
| in Java, 

Keep the java in your coffee mug.  Believe me, if you get into java
you'll _really_ love python afterwards!

| or if someone else wants to access the database from ASP (a lot of 
| people I work with use ASP).  So I'm just starting to learn about 
| XML-RPC and SOAP, and wanted to hear your thoughts about it.

Depends on what the client will be, who will use it, and what its
purpose is.  If you're just looking to get stuff out of a (open) SQL
db, then ODBC or JDBC will likely be your best middleware.  Otherwise
you'll need to rig something to bridge the gap (like I need to do).

| This doesn't sound like such a difficult little program, does it?

If all you're doing is creating an HTML view of a collection of images
on-disk, it could be done with just a not-too-complex CGI script
without any dbs or distributed objects.

I think expanding on what the requirements of the system are and
thinking about what roles each component will serve will help to clear
up some of the vagueness.

-D

-- 

No harm befalls the righteous,
but the wicked have their fill of trouble.
        Proverbs 12:21



From kalle@gnupung.net  Thu Mar 21 06:54:54 2002
From: kalle@gnupung.net (Kalle Svensson)
Date: Thu, 21 Mar 2002 07:54:54 +0100
Subject: [Tutor] python and MS Access db's
In-Reply-To: <8285EC24-3C76-11D6-952A-00039351FE6A@mac.com>
References: <20020320183416.GA7075@dman.ddts.net> <8285EC24-3C76-11D6-952A-00039351FE6A@mac.com>
Message-ID: <20020321065454.GA26438@sandra.lysator.liu.se>

[Erik Price]
> I just started learning about XML-RPC myself.  I'm interested in it, and 
> if you don't mind my asking, why you are planning to use XML-RPC over 
> SOAP.

Because XML-RPC fits my brain and SOAP doesn't.  This seems to be true
for other people too, as none of the XML-RPC implementations I've seen
suffer the compatibility problems reported from SOAP-land.

I suspect that XML-RPC might scale poorly to larger amounts of traffic
and more complex data structures, but it should work admirably for
most of my projects.  The larger projects using XML-RPC I know about
are O'Reilly's Meerkat and Blogger.  It would be interesting to hear
about their opinions on scalability, if they regret choosing XML-RPC.

Peace,
  Kalle
-- 
Kalle Svensson (kalle@gnupung.net) - Laziness, impatience, hubris: Pick two!
English: http://www.gnupung.net/  Svenska: http://www.lysator.liu.se/~kalle/
Stuff: ["http://www.%s.org/" % x for x in "gnu debian python emacs".split()]


From paulsid@shaw.ca  Thu Mar 21 07:01:34 2002
From: paulsid@shaw.ca (Paul Sidorsky)
Date: Thu, 21 Mar 2002 00:01:34 -0700
Subject: [Tutor] OOP
References: <DAV17yXvEbjkyqU7a0x0000df74@hotmail.com>
Message-ID: <3C99854E.4D7736BB@shaw.ca>

Cameron Stoner wrote:

You're more-or-less correct, just some minor points to clarify.  And
note that I'm not an OO person so if I've got something wrong then
somebody please correct me so I can learn too.

> - when making an instance(object) of a class it has all the
> behavior(functions or methods) of that class.

Yes, and also its own copy of all the properties (variables) of the
class.

> - objects take on all the characteristics of that class

True, and in Python they may also take additional characteristics or
properties strictly for that instance.  To use your example, if Max may
is a very special talking cat you can give him (and only him) a talk()
method and/or a voicetype property.  (In languages like C++ you can't
really do this without creating a derived TalkingCat class ahead of
time.)

>     The class cat has Max as an object that can play.

This is probably the only incorrect statement, at least technically. 
While it can be convenient to think of Max as "belonging to" the cat
class, in general the cat class has no way to know what objects you
create with it.  It's like a drawing template:  You take it off the
shelf, use it to draw a picture, and put the template back on the
shelf.  You can't look at the same template later to tell you stuff like
"I used this template to draw a triangle on a post-it note, a piece of
construction paper, and a cocktail napkin".  If you want to know this
you have to specifically make a record of it and for simplicity that
record is often external to both the class and all its objects.  (There
are ways to internalize such a record, though.)

> - you have to initiate play from Max

If and when you want Max to play, yes.  If you want other cats to play
you'd of course initiate it from them.  Also so-called "class variables"
and "class methods" can be initiated through their class without
necessarily having any instances. 

All in all though I'd say that was a pretty good summarization!

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/


From alan.gauld@bt.com  Thu Mar 21 10:40:44 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 21 Mar 2002 10:40:44 -0000
Subject: [Tutor] Making executable
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C473@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C1D0C4.DABC1050
Content-type: text/plain; charset="iso-8859-1"

>  I'm sure this is an easy question, so I came to the experts. I'd like to
know  
>  how to make a program (or script) executable for people that do not have

>  Python installed on their machine? 
 
To make the script executable is simply a matter of changing 
file permissions. To make it execute requires Python to be 
on the machine. 
 
Assuming you are on Windows (this only seems to be an issue for 
Windows users for some strange reason, despite the popularity 
of VB) there are a couple of tools that can package up your 
script witrh a cut down python interpreter installation so 
they look like an executable (.exe) file.
 
One is py2exe and the other is Gordon McMillan's installer.
Search for both on Google or at ActiveState and you should 
find them easily enough. 
 
The real question is why you need to do this? 
Why not just install Python with your script.
The py2exe route means they potentially wind up with multiple 
copies of Python installed whereas installing python per se 
means subsequent program uploads are tiny. Thats why VB 
requires a huge VBRUN.DLL file be installed but then all 
other VB programs are small(only a few kilobytes usually)
 
HTH
 
Alan G. 

------_=_NextPart_001_01C1D0C4.DABC1050
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=760214210-21032002><FONT 
face="Courier New" color=#0000ff>&gt; &nbsp;</FONT></SPAN>I'm sure this is an 
easy question, so I came to the experts. I'd like to know&nbsp;<SPAN 
class=760214210-21032002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=760214210-21032002><FONT 
face="Courier New" color=#0000ff>&gt; </FONT>&nbsp;</SPAN>how to make a program 
(or script) executable for people that do not have&nbsp;<SPAN 
class=760214210-21032002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=760214210-21032002><FONT 
face="Courier New" color=#0000ff>&gt; </FONT>&nbsp;</SPAN>Python installed on 
their machine?<SPAN class=760214210-21032002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=760214210-21032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=760214210-21032002><FONT 
face="Courier New" color=#0000ff>To make the script executable is simply a 
matter of changing </FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=760214210-21032002><FONT 
face="Courier New" color=#0000ff>file permissions. To make it execute requires 
Python to be </FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=760214210-21032002><FONT 
face="Courier New" color=#0000ff>on the 
machine.</FONT>&nbsp;</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002>Assuming you are on Windows (this only seems to be an 
issue for </SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002>Windows users for some strange reason, despite the 
popularity </SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002>of VB) there are a couple of tools that can package up 
your </SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002>script witrh a cut down python interpreter installation 
so </SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002>they look like an executable (.exe) 
file.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002>One is py2exe and the other is Gordon McMillan's 
installer.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002>Search for both on Google or at ActiveState and you 
should </SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002>find them easily enough. </SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002>The real question is why you need 
</SPAN></FONT></FONT><FONT face=Arial><FONT face="Courier New" color=#0000ff 
size=2><SPAN class=760214210-21032002>to do this? </SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002>Why not just install Python with your 
script.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002>The py2exe route means they potentially wind up with 
multiple </SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002>copies of Python installed whereas installing python 
per se </SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002>means subsequent program uploads are tiny. Thats why VB 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002>requires a huge VBRUN.DLL file be installed but then 
all </SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002>other VB programs are small(only a few kilobytes 
usually)</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002>HTH</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=760214210-21032002></SPAN></FONT></FONT><FONT face="Courier New"><FONT 
color=#0000ff><FONT size=2>A<SPAN class=760214210-21032002>lan 
G.&nbsp;</SPAN></FONT></FONT></FONT></DIV></BODY></HTML>

------_=_NextPart_001_01C1D0C4.DABC1050--


From alan.gauld@bt.com  Thu Mar 21 10:48:46 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 21 Mar 2002 10:48:46 -0000
Subject: [Tutor] python and MS Access db's
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C474@mbtlipnt02.btlabs.bt.co.uk>

> I've got to do the same thing now at my new job....
> are some commercial (really expensive) ODBC drivers 

Somewhat off topic, but are these really that expensive? 
How much is your time worth? If it took you a week to 
roll your own driver would it cost more or less to your 
company than buying a ready built one? Especially if you 
include the lost opportunity cost of getting the product 
to market one week quicker too!

Expensive drivers are relevant in pesonal use or academia 
but for companies who (presumably) develop software for 
sound commercial reasons buying "expensive" drivers 
is usually the cheapest option.

Just a thought,

Alan g.
[ who spends ~million dollars annually on expensive 
commercial software but saves 10s of millions on even
more expensive developer time ]


From alan.gauld@bt.com  Thu Mar 21 11:03:52 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 21 Mar 2002 11:03:52 -0000
Subject: [Tutor] definition of a library
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C475@mbtlipnt02.btlabs.bt.co.uk>

> > sometimes important distinction (and one not recognised 
> > by UML for those who care :-).
> What you call modules is named packages in UML. Libraries, 
> respectively, are components in UML. 

That's what I initially assumed but at a seminar with Grady 
Booch when I asked him he defined components as being 
*files* in C++ terms. In the old Booch notation there 
was a concept of subsystem and libraries could be 
represented there. 

Unfortunately UML has rationalised(sic!) the physical 
notation to the point where we have to make do with generic 
symbols like component which can represent several 
radically different physical entities. Thats what I meant 
by "not supporting" - there's nothing explicit, only 
overloading the component symbol.

> physical structure. The difference is not very subtle, IMHO :)

Personally I don't think so either but in discussions with
various CASE tool vendors plus Grady it would seem that the 
significance of the difference is not seen as high. (And 
incidentally I've even had CASE tool folks tell me that a 
package is a library which is definitely wrong!)

Alan g.


From fasal.waseem@cis.co.uk  Thu Mar 21 11:36:29 2002
From: fasal.waseem@cis.co.uk (fasal.waseem@cis.co.uk)
Date: Thu, 21 Mar 2002 11:36:29 +0000
Subject: [Tutor] Running A Command
Message-ID: <OFF9670444.5CEE466C-ON00256B83.003FA853@cis.co.uk>

Hi All

I am just new at this python thing, I have written a menu which is suppose
to call a simple line, so it can run it, what do I do. I am using unix
platform.

Faz
Distributed system support Analyst
CIS
Miller Street
Manchester
M60 0AL
0161 837 4487 (office)
www.cis.co.uk (our web page)

*************************************************************************

This e-mail may contain confidential information or be privileged. It is intended to be read and used only by the named recipient(s). If you are not the intended recipient(s) please notify us immediately so that we can make arrangements for its return: you should not disclose the contents of this e-mail to any other person, or take any copies. Unless stated otherwise by an authorised individual, nothing contained in this e-mail is intended to create binding legal obligations between us and opinions expressed are those of the individual author.

The CIS marketing group, which is regulated for Investment Business by the Financial Services Authority, includes:
Co-operative Insurance Society Limited Registered in England number 3615R - for life assurance and pensions
CIS Unit Managers Limited Registered in England and Wales number 2369965  - for unit trusts and PEPs
CIS Policyholder Services Limited Registered in England and Wales number 3390839 - for ISAs and investment products bearing the CIS name
Registered offices: Miller Street, Manchester M60 0AL   Telephone  0161-832-8686   Internet  http://www.cis.co.uk   E-mail cis@cis.co.uk

CIS Deposit and Instant Access Savings Accounts are held with The Co-operative Bank p.l.c., registered in England and Wales number 990937, P.O. Box 101, 1 Balloon Street, Manchester M60 4EP, and administered by CIS Policyholder Services Limited as agent of the Bank.

CIS is a member of the General Insurance Standards Council

CIS & the CIS logo (R) Co-operative Insurance Society Limited

********************************************************************************


From kalle@gnupung.net  Thu Mar 21 11:48:31 2002
From: kalle@gnupung.net (Kalle Svensson)
Date: Thu, 21 Mar 2002 12:48:31 +0100
Subject: [Tutor] Running A Command
In-Reply-To: <OFF9670444.5CEE466C-ON00256B83.003FA853@cis.co.uk>
References: <OFF9670444.5CEE466C-ON00256B83.003FA853@cis.co.uk>
Message-ID: <20020321114830.GE26438@sandra.lysator.liu.se>

[fasal.waseem@cis.co.uk]
> I am just new at this python thing, I have written a menu which is
> suppose to call a simple line, so it can run it, what do I do. I am
> using unix platform.

You might want to take a look at the os.popen* and os.system
functions.  http://python.org/doc/current/lib/module-os.html

Peace,
  Kalle
-- 
Kalle Svensson (kalle@gnupung.net) - Laziness, impatience, hubris: Pick two!
English: http://www.gnupung.net/  Svenska: http://www.lysator.liu.se/~kalle/
Stuff: ["http://www.%s.org/" % x for x in "gnu debian python emacs".split()]


From charlie@begeistert.org  Thu Mar 21 11:48:53 2002
From: charlie@begeistert.org (Charlie Clark)
Date: Thu, 21 Mar 2002 12:48:53 +0100
Subject: [Tutor] Re: Tutor digest, Vol 1 #1502 - 10 msgs
In-Reply-To: <E16o0tP-0006Im-00@mail.python.org>
References: <E16o0tP-0006Im-00@mail.python.org>
Message-ID: <20020321125907.8143.4@gormenghast.AUTODIAL>

On 2002-03-21 at 12:38:03 [+0100], tutor-request@python.org wrote:
> Hi All
> 
> I am just new at this python thing, I have written a menu which is 
> suppose to call a simple line, so it can run it, what do I do. I am using=
 
> unix platform.

Hello Faz and greetings to my hometown,

your description is a bit short...

The most basic way of doing executing shell-commands is the following:

import sys

my_cmd =3D rawinput("Command?")
os.system(mycmd)

What do you mean by a menu?
1 =3D dir
2 =3D cd
3 =3D more
etc?

could be implemented like this:
menu =3D {'1':'dir', '2':'cd', '3':'more'}

def choice(menu=3Dmenu):
=09my_cmd =3D rawinput("Command?")
=09=09if my_cmd in menu.keys():
=09=09=09os.system(menu[my_cmd])
=09=09else:
=09=09=09print "Command not available"
=09=09=09choice(menu)

choice(menu)

But maybe you're after something entirely different.

Charlie


From erikprice@mac.com  Thu Mar 21 12:23:18 2002
From: erikprice@mac.com (Erik Price)
Date: Thu, 21 Mar 2002 07:23:18 -0500
Subject: [Tutor] python and MS Access db's
In-Reply-To: <20020321065454.GA26438@sandra.lysator.liu.se>
Message-ID: <6D3B4F4E-3CC6-11D6-AB64-00039351FE6A@mac.com>

On Thursday, March 21, 2002, at 01:54  AM, Kalle Svensson wrote:

> Because XML-RPC fits my brain and SOAP doesn't.  This seems to be true
> for other people too, as none of the XML-RPC implementations I've seen
> suffer the compatibility problems reported from SOAP-land.

I also find this an attractive reason -- that I can actually work with 
XML-RPC pretty quickly, and that SOAP would take a bit longer to grasp.  
Ironically, the book that I thought would be the ideal resource for this 
kind of thing, "Python & XML", doesn't discuss XML-RPC but for a short 
ending paragraph in the SOAP chapter.  This led me to believe that I 
should probably focus on learning more about SOAP.

Erik



From erikprice@mac.com  Thu Mar 21 12:23:23 2002
From: erikprice@mac.com (Erik Price)
Date: Thu, 21 Mar 2002 07:23:23 -0500
Subject: [Tutor] python and MS Access db's
In-Reply-To: <20020321034150.GA10880@dman.ddts.net>
Message-ID: <6FDBD51E-3CC6-11D6-AB64-00039351FE6A@mac.com>

On Wednesday, March 20, 2002, at 10:41  PM, dman wrote:

> | The custom web client was originally going to be designed to open up a
> | socket connection and communicate directly "in Python" with the Python
> | CGI script that would be sitting on the server with the MySQL
> | connection.
>
> This sounds like an odd architecture to me.
>
> Normally a CGI script is executed by a web server.  Input is given
> either in the environment variable QUERY_STRING or on stdin.  The
> output will be returned to the web browser, and thus ought to be some
> sort of content the browser can handle sanely.
>
> What I don't understand with the description you've given so far is
>     What sort of data do you need to move through that socket?
>     What are the purposes of each process using that socket?

Maybe I'm confused -- I was thinking to simply open the socket for 
communication, and pass name/value pairs as POST requests to the CGI 
script.  When I say "in Python" I simply meant "not using XMLRPC or SOAP 
or whatever".  This CGI script would not be intended to be accessed by a 
browser, rather a simple Python script on the user's computer -- 
displaying of the graphics files aren't a requirement, just passing some 
information from the client machine to the server.  Perhaps opening a 
socket is completely unnecessary?  I can just have the web client fire 
off HTTP requests instead?  Now that I think about it, I realize that 
this "in my head" scheme might not be what I think it is.


Erik



From alan.gauld@bt.com  Thu Mar 21 12:40:47 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 21 Mar 2002 12:40:47 -0000
Subject: [Tutor] OOP
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C477@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C1D0D5.A0517930
Content-type: text/plain; charset="iso-8859-1"

>  I wanted to know if my thinking is straight about OOP, cause I'm writing
notes  
>  one how to do stuff in Python as I learn them.   
 
Good idea, I often do that when starting a new project. 

- to use the characteristics you just name the behavior 

There is an important semantic difference at work here. It depends a bit on 
whether you want to understand OOP in general or just how Python does OOP.
 
In Python you are essentially correct. In general you use characteristics
(or more commenly termed: attributes) by *sending a message* to an instance.
In Python you send a message by specifying the name but in other OO 
environments (eg Lisp/Flavors, Actor etc) the message sending mechanism 
is decoupled from the method invocation mechanism. Thus sending the 
message "print" may activate a method called "output" say...
 
So in general you send messages to instances. Instances respond by
activating 
methods and returning the results in a message response.
 
It may seem like splitting hairs but in some languages the distinction is
very 
important and from a conceptual modelling basis its important to have the 
distinction clear in your head.
 
 >  - Max only plays when you tell it to 
 
 Again some OO environments allow for self energising 
objects which will activate methods (apparently) 
spontaneuosly. This is important in simuilsation type 
environments where a degree of randomness is required. 
Of course in practice there has to be some kind of 
trigger but again conceptually and in general objects 
can self activate.
 
HTH rather than just obfuscating things,
 
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_01C1D0D5.A0517930
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=890104012-21032002><FONT 
face="Courier New" color=#0000ff>&gt; &nbsp;</FONT></SPAN>I wanted to know if my 
thinking is straight about OOP, cause I'm writing notes&nbsp;<SPAN 
class=890104012-21032002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=890104012-21032002><FONT 
face="Courier New" color=#0000ff>&gt; </FONT>&nbsp;</SPAN>one how to do stuff in 
Python as I learn them.&nbsp;&nbsp;<SPAN class=890104012-21032002><FONT 
face="Courier New" color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=890104012-21032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=890104012-21032002><FONT 
face="Courier New" color=#0000ff>Good idea, I often do that when starting a new 
project.</FONT>&nbsp;</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><FONT size=2>- to use the characteristics you just name 
  the behavior<SPAN class=890104012-21032002><FONT face="Courier New" 
  color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV></BLOCKQUOTE>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN class=890104012-21032002>There 
is an important semantic difference at work here. It depends a bit on 
</SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN 
class=890104012-21032002>whether you want to understand OOP in general or just 
how Python does OOP.</SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN 
class=890104012-21032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN class=890104012-21032002>In 
Python you are essentially correct. In general you use 
characteristics</SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN class=890104012-21032002>(or 
more commenly termed: attributes) by *sending a message* to an 
instance.</SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN class=890104012-21032002>In 
Python you send a message by specifying the name but in other OO 
</SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN 
class=890104012-21032002>environments (eg Lisp/Flavors, Actor etc) the message 
sending mechanism </SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN class=890104012-21032002>is 
decoupled from the method invocation mechanism. Thus sending the 
</SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN 
class=890104012-21032002>message "print" may activate a method called "output" 
say...</SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN 
class=890104012-21032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN class=890104012-21032002>So in 
general you send messages to instances. Instances respond by activating 
</SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN 
class=890104012-21032002>methods and returning the results in a message 
response.</SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN 
class=890104012-21032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN class=890104012-21032002>It may 
seem like splitting hairs but in some languages the distinction is very 
</SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN 
class=890104012-21032002>important and from a conceptual modelling basis its 
important to have the </SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN 
class=890104012-21032002>distinction clear in your 
head.</SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN 
class=890104012-21032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN class=890104012-21032002><FONT 
face="Courier New" color=#0000ff>&nbsp;&gt; &nbsp;</FONT></SPAN>- Max only plays 
when you tell it to<SPAN class=890104012-21032002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN 
class=890104012-21032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN 
class=890104012-21032002>&nbsp;<FONT face="Courier New" color=#0000ff>Again some 
OO environments allow for self energising </FONT></SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN class=890104012-21032002><FONT 
face="Courier New" color=#0000ff>objects which will activate methods 
(apparently) </FONT></SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN class=890104012-21032002><FONT 
face="Courier New" color=#0000ff>spontaneuosly. This is important in 
simuilsation type </FONT></SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN class=890104012-21032002><FONT 
face="Courier New" color=#0000ff>environments where a degree of randomness is 
required. </FONT></SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN class=890104012-21032002><FONT 
face="Courier New" color=#0000ff>Of course in practice there has to be some kind 
of </FONT></SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN class=890104012-21032002><FONT 
face="Courier New" color=#0000ff>trigger but again conceptually and in general 
objects </FONT></SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT size=2><SPAN class=890104012-21032002><FONT 
face="Courier New" color=#0000ff>can self 
activate.</FONT></SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face=Arial><FONT face="Courier New" color=#0000ff 
size=2><SPAN class=890104012-21032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV dir=ltr><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=890104012-21032002>HTH rather than just obfuscating 
things,</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=890104012-21032002></SPAN></FONT>&nbsp;</DIV>
<DIV dir=ltr><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=890104012-21032002>
<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>
<DIV dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px"><FONT 
face="Courier New" color=#0000ff size=2><SPAN 
class=890104012-21032002></SPAN></FONT>&nbsp;</DIV></BODY></HTML>

------_=_NextPart_001_01C1D0D5.A0517930--


From dsh8290@rit.edu  Thu Mar 21 13:03:54 2002
From: dsh8290@rit.edu (dman)
Date: Thu, 21 Mar 2002 07:03:54 -0600
Subject: [Tutor] python and MS Access db's
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C474@mbtlipnt02.btlabs.bt.co.uk>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C474@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20020321130354.GA13135@dman.ddts.net>

On Thu, Mar 21, 2002 at 10:48:46AM +0000, alan.gauld@bt.com wrote:
| > I've got to do the same thing now at my new job....  are some
| > commercial (really expensive) ODBC drivers 
| 
| Somewhat off topic, but are these really that expensive? 

Around 2 grand (US).

| How much is your time worth? 

$10.50/hr :-).

| If it took you a week to roll your own driver would it cost more or
| less to your company than buying a ready built one?

Less.

| Especially if you include the lost opportunity cost of getting the
| product to market one week quicker too!

Ok, now I'll explain :

The company is a non-profit organization that provides training and
administrative support to missionaries.  You can learn about them at
www.iteams.org if you want.  My position is a co-op/intern in the
"Information Systems" department.  (there's 3 of us in this
department) This product is for internal use, not for sale.

The systems are a mix of Linux (RedHat) on servers, a couple NT/2k
servers, and a lot of Windows on workstations (and I think 1 Mac).
(Then add in the 2 Debian boxen I brought with me :-))  They used to
have everything in a MUMPS database, but are migrating off that now.
Most of the financial stuff is in a SQL Server database using a
commercial product.  Some info is in MS Access and some is in MySQL,
and they're looking at PostgreSQL too.  They want to integrate the
data more by providing easy-to-use web interfaces.  The existing web
stuff is HTML and PHP driven by Apache on the RedHat box.  It can get
to the MySQL and MSSQL dbs already, but can't get at the Access dbs.
All we need is to get at the Access db from the web server.  

I found that win32 python with the win32all extension can load an
Access db and perform queries right away (using odbc).  All that's
left is plugging in a middleware for controlling those objects
remotely.

Given the background, I think you'll agree that building my own
adapter is the best option.  I'll need to create IDL files and
probably a couple hundred LOC, and I want a ZOPE DA too.  My boss had
looked at zope, but without formal software education and time to
spend he didn't really get far with it.  I took a look at it, and I
"get it".  (BTW, it is _much_ easier to work with than J2EE!)  It is
likely that much of the new web stuff will be a mix of Zope, Python,
PHP, and Perl.

| Expensive drivers are relevant in pesonal use or academia but for
| companies who (presumably) develop software for sound commercial
| reasons buying "expensive" drivers is usually the cheapest option.

Yeah, if it was to be part of a commercial product, then buying an
existing piece would have many more benefits and the tradeoffs would
be different.

-D


PS.
    For those who are interested and not so familiar with english
    slang, "2 grand" is $2,000.

    "They" is primarily just my boss.  He's had extensive hands-on
    experience but no formal education with computers.  He is mostly a
    one-man show managing all the computer stuff here.  He, and the
    rest of the staff, are glad to have another geek around to help
    with the workload.

-- 

(E)ventually (M)allocs (A)ll (C)omputer (S)torage



From dsh8290@rit.edu  Thu Mar 21 13:10:49 2002
From: dsh8290@rit.edu (dman)
Date: Thu, 21 Mar 2002 07:10:49 -0600
Subject: [Tutor] gadfly comming back to life
Message-ID: <20020321131049.GB13135@dman.ddts.net>

I found this yesterday.  It looks like, in time, gadfly may come back
to life.

http://aspn.activestate.com/ASPN/Mail/Message/db-sig/1059726

-D
-- 

the nice thing about windoze is - it does not just crash,
it displays a dialog box and lets you press 'ok' first.



From alan.gauld@bt.com  Thu Mar 21 13:26:32 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 21 Mar 2002 13:26:32 -0000
Subject: [Tutor] python and MS Access db's
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C47A@mbtlipnt02.btlabs.bt.co.uk>

> On Wednesday, March 20, 2002, at 01:34  PM, dman wrote:
> > MS' ODBC driver to connect to the db, and then use either XML-RPC or
> > CORBA to connect to that server from the linux box.
> 
> if you don't mind my asking, why you are planning to 
> use XML-RPC over SOAP.

I should imagine because its a lot simpler to use - especially 
from Python. I haven't seen a really easy to use SOAP solution 
for Python but the XML-RPC stuff(now standard from v2.2?) is 
simplicity itself.

Speaking for dman so I might be completely wrong! :-)

Alan g
[ Who hates XML as a transport since its horribly 
  inefficient of bandwidth...but recognises that 
  he's(as usual) in a minority of one! ;-]


From alan.gauld@bt.com  Thu Mar 21 13:49:57 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 21 Mar 2002 13:49:57 -0000
Subject: [Tutor] Running A Command
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C47C@mbtlipnt02.btlabs.bt.co.uk>

> I am just new at this python thing, 

As a matter of interest are you new to programming too? 
Or have you programmed in other languages? The answer 
makes a big difference to how we best frame responses 
to your questions.

> I have written a menu which is suppose
> to call a simple line, so it can run it, 

There are several ways of doing this, each getting 
more sophisticated. Since I don't know your level yet 
I'll start with the simplest one:

########################
import sys
while 1:   # 1 => TRUE
    menu = """
	Here is a menu of commands. 
	Enter the number of the required item.

	1. Display "FOO"
	2. Display "BAR"
	3. Ask my name
	4. Quit

    """
    resp = raw_input(menu)
    if resp == '1': print "FOO"
    elif resp == '2': print "BAR"
    elif resp == '3': name = raw_input("What's your name? ")
    elif resp == '4': 
	if name: print "Goodbye", name
      sys.exit()
####################

Does that make sense and help? If not we need to start at 
the very beginning. If its too simple then we can moive 
up a level or two...

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


From urnerk@qwest.net  Thu Mar 21 16:20:14 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 21 Mar 2002 08:20:14 -0800
Subject: [Tutor] OOP
In-Reply-To: <DAV17yXvEbjkyqU7a0x0000df74@hotmail.com>
Message-ID: <4.2.0.58.20020321081155.00cd77c0@pop3.norton.antivirus>

I think this is pretty clear.  I'll interleave random
two cents just to colorize a bit, add some perspective.

At 08:08 PM 3/20/2002 -0600, Cameron Stoner wrote:
>I wanted to know if my thinking is straight about OOP, cause I'm writing 
>notes one how to
>do stuff in Python as I learn them.
>
>Here it is:
>- when making an instance(object) of a class it has all the 
>behavior(functions or methods) of that class.

Class = blueprint, template (generic cat -- none exist for real).
Instance = special case creation based on blueprint (e.g. Max).
In Python, to be an instance is to have a self.  Classes are
self-less.

>- objects take on all the characteristics of that class

But this isn't what we mean by inheritance.  Classes may
be subclasses of other classes, meaning the Cat blueprint
may inherit from the Mammal blueprint, which in turn
inherits from, say, Animal.  You might put functionality
at these various levels, "fleshing out the details"
(hyuk) as you specialize towards the species.


>- to use the characteristics you just name the behavior

Well, sort of.  You invoke a method.  An object is
characteristically a mixture of properties (attributes)
and methods (functions, behaviors).  In Python, you
can "name" a method by giving its name without
ending parentheses, in which case you get back an
indication of where this method lives in memory --
without actually invoking it.

>- Example: Say you had a cat(class) named Max(instance); who likes to play.
>     The class cat has Max as an object that can play.

That's OK.  More idiomatic is to say Max is an
instance of Cat.  Also, my Pythonic is to have
classes be uppercase (Cat) whereas instances
might not be (I sometimes prefix my object pointers
with a lowercase o, as in oCat for "object of class
Cat").

>- you have to initiate play from Max

Now we should be subtle and mention class methods.
Python is developing these, meaning we're no longer
going to need a "self" in order to trigger behavior.
Some methods may be invoked right on the class --
like having a blueprint with some circuitry active.

>- Max only plays when you tell it to

Or when some other part of your program tells it
to.  You could have a blueprint that runs off a
timer, creating random behaviors at intervals --
just adding nuance to what I think is basically an
on-target summary.

>
>Feel free to add to this or set me straight because I want to be sure on this.
>
>Thanks,
>Cameron Stoner



From alan.gauld@bt.com  Thu Mar 21 17:17:16 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 21 Mar 2002 17:17:16 -0000
Subject: [Tutor] python and MS Access db's
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C482@mbtlipnt02.btlabs.bt.co.uk>

> Maybe I'm confused -- I was thinking to simply open the socket for 
> communication, and pass name/value pairs as POST requests to the CGI 
> script.  

Yes that's OK, its classic web client programming. There used 
to be an O'Reilly book on it but I think its out of print now :-(

The only real questions are:

1) Is it an existing CGI script? 
2) Will it ever be used from the web? 

If the answer to either question is yes then 
carry on exactly as you suggested.

If the answer to both is no then consider a dedicated 
client/server solution using raw sockets - it will perform 
much better. The web is many wonderful things but a good 
client/server platform is not one of them....

Alan G.


From garber@centralcatholic.org  Thu Mar 21 20:27:11 2002
From: garber@centralcatholic.org (Robert Garber)
Date: Thu, 21 Mar 2002 15:27:11 -0500
Subject: [Tutor] NEWBIE is it possible to use HTML and Python together?
Message-ID: <200203211527.AA397542012@centralcatholic.org>

Hello all,

 With help from many people i was able to fix my last problem ( rolling dice). I was even able to add a while loop to keep rolling. NOW comes the part I am in the dark about. My friend has written  dome HTML stull that he uses to play a baseball simulation game. The dice scrit is for him. We both want to know if it possible to use the dice script with in th HTML. the HTMl is sett up as a baseball diamond with checkboxes to keep track of base runners. he has a fram set up that he would like to use for the roll of the dice ( hit a roll button and have the script roll the dice, then display the roll). I have no idea about HTML. I am just now learning Python. Is there a way to "merge" the two so they can work as one? ANy help would be greatly appreciated.

Thanks,
Robert



From dyoo@hkn.eecs.berkeley.edu  Fri Mar 22 02:13:45 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 21 Mar 2002 18:13:45 -0800 (PST)
Subject: [Tutor] NEWBIE is it possible to use HTML and Python together?
In-Reply-To: <200203211527.AA397542012@centralcatholic.org>
Message-ID: <Pine.LNX.4.44.0203211800480.27394-100000@hkn.eecs.berkeley.edu>

On Thu, 21 Mar 2002, Robert Garber wrote:

> With help from many people i was able to fix my last problem ( rolling
> dice). I was even able to add a while loop to keep rolling. NOW comes
> the part I am in the dark about. My friend has written dome HTML stull
> that he uses to play a baseball simulation game. The dice scrit is for
> him. We both want to know if it possible to use the dice script with in
> th HTML.

Hi Robert,

Yes, this is very possible.  This is where "CGI", or "Common Gateway
Interface" comes in: if your web page lives on a hosting server that
supports CGI, then you should be able to mix HTML around with Python.

In many cases, your Python programs just need to bend their output to have
HTML formatting codes, like this:

###
def helloWorld():
    print "<html><body>"
    print "Hello world!"
    print "</body></html>"

if __name__ == '__main__':
    print "Content-type: text/html\n"
    helloWorld()
###

is a simple way of getting a Python program to build an HTML page.  When
the server executes a Python program with CGI, whatever is printed out
actually goes back to the browser window.  CGI also defines how to grab
variable values from the browser, and there's a 'cgi' module in Python
that'll be helpful when you learn more about it.



> the HTMl is sett up as a baseball diamond with checkboxes to keep track
> of base runners. he has a fram set up that he would like to use for the
> roll of the dice ( hit a roll button and have the script roll the dice,
> then display the roll).

Very cool.  Yes, this is very doable, and sounds like a fun project.



> I have no idea about HTML. I am just now learning Python. Is there a way
> to "merge" the two so they can work as one?

There's some good tutorials on doing this here:

    http://www.devshed.com/Server_Side/Python/CGI/page1.html

and you're always welcome to ask questions here; we'd be glad to show some
examples of doing this.


HTML is actually not too hard; you can pick up the basics in an afternoon.
I've found that Phil Greenspun's tutorial on HTML is very useful:

    http://www.arsdigita.com/books/panda/html

and he gives his (very) personal justification of why someone would want
to mix HTML with some sort of programming language.


Please feel free to ask more questions; we'd like to hear about your
progress.  Good luck!



From urnerk@qwest.net  Fri Mar 22 02:33:27 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 21 Mar 2002 18:33:27 -0800
Subject: [Tutor] NEWBIE is it possible to use HTML and Python
 together?
In-Reply-To: <Pine.LNX.4.44.0203211800480.27394-100000@hkn.eecs.berkeley
 .edu>
References: <200203211527.AA397542012@centralcatholic.org>
Message-ID: <4.2.0.58.20020321183227.019ea100@pop3.norton.antivirus>

At 06:13 PM 3/21/2002 -0800, Danny Yoo wrote:

>Please feel free to ask more questions; we'd like to hear about your
>progress.  Good luck!

Would it be accurate to suggest that any CGI-Python solution
to the dice rolling program would involve reloading the page,
and/or serving a new one?  To change the content of a web
page *in place* (without reloading) would require some other
solution, no? (e.g. JavaScript).

Kirby



From dsh8290@rit.edu  Fri Mar 22 03:10:16 2002
From: dsh8290@rit.edu (dman)
Date: Thu, 21 Mar 2002 21:10:16 -0600
Subject: [Tutor] NEWBIE is it possible to use HTML and Python together?
In-Reply-To: <4.2.0.58.20020321183227.019ea100@pop3.norton.antivirus>
References: <200203211527.AA397542012@centralcatholic.org> <4.2.0.58.20020321183227.019ea100@pop3.norton.antivirus>
Message-ID: <20020322031016.GA6480@dman.ddts.net>

On Thu, Mar 21, 2002 at 06:33:27PM -0800, Kirby Urner wrote:
| At 06:13 PM 3/21/2002 -0800, Danny Yoo wrote:
| 
| >Please feel free to ask more questions; we'd like to hear about your
| >progress.  Good luck!
| 
| Would it be accurate to suggest that any CGI-Python solution
| to the dice rolling program would involve reloading the page,
| and/or serving a new one?  To change the content of a web
| page *in place* (without reloading) would require some other
| solution, no? (e.g. JavaScript).

The choices are :
    o   server-side generation
    o   client-side generation

If the data is generated on the server (using python, cgi, zope, perl,
php, whatever-you-like) then the browser must reload the page every
time.

If the data is generated client-side, then the page doesn't have to be
reloaded.  Unfortunately, the only widespread client-side technologies
are Javascript and Java (applets).  I think this is mainly because it
is hard to change client-side technologies -- every single user has to
upgrade their system.  With server-side, only the server changes while
the client uses the same old HTML it has been using for years.

HTH,
-D

-- 

A man of many companions may come to ruin,
but there is a friend that sticks closer than a brother.
        Proverbs 18:24



From erikprice@mac.com  Fri Mar 22 03:36:51 2002
From: erikprice@mac.com (Erik Price)
Date: Thu, 21 Mar 2002 22:36:51 -0500
Subject: [Tutor] python and MS Access db's
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C482@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <0C383677-3D46-11D6-90DA-00039351FE6A@mac.com>

On Thursday, March 21, 2002, at 12:17  PM, alan.gauld@bt.com wrote:

> Yes that's OK, its classic web client programming. There used
> to be an O'Reilly book on it but I think its out of print now :-(

I was reading that at a library in a town far from me -- it was very 
interesting.  A lot of it focused on HTTP itself.  That's what prompted 
me to pick up "Python Web Programming".  It seems like a similar book 
but for Python and much more recent, printed this year.  I haven't 
gotten to the good stuff yet; I'm still reading the second chapter 
(which is a summary of Python -- I don't really have to read it but I 
should).

> The only real questions are:
>
> 1) Is it an existing CGI script?

No, it doesn't exist yet.  I am planning to write it though.

> 2) Will it ever be used from the web?

Yes, the idea is to use the web since that is the only thing I am 
familiar with from programming with PHP.

> If the answer to either question is yes then
> carry on exactly as you suggested.

Okay, but...

> If the answer to both is no then consider a dedicated
> client/server solution using raw sockets - it will perform
> much better. The web is many wonderful things but a good
> client/server platform is not one of them....

... it sounds like there are alternatives.  "raw socket"?  I haven't 
heard of those.  The only sockets I am familiar with are network 
sockets -- the sort that work like this

= socket listens at port 80 or whichever
= request comes along
= socket daemon spawns a new socket for the request and redirects the 
request to the new socket
= client and server do their business on new socket, while socket daemon 
continues to listen at port 80 for more requests

is this different from what you are talking about?  Since the only 
programming experience I have is with PHP, I sometimes have a hard time 
envisioning how programs that are not stateless or are not web scripts 
are supposed to work.  In the back of my mind, I'm always thinking about 
GET, POST, and cookies.

Erik



From erikprice@mac.com  Fri Mar 22 03:56:01 2002
From: erikprice@mac.com (Erik Price)
Date: Thu, 21 Mar 2002 22:56:01 -0500
Subject: [Tutor] NEWBIE is it possible to use HTML and Python together?
In-Reply-To: <20020322031016.GA6480@dman.ddts.net>
Message-ID: <B9D3D618-3D48-11D6-90DA-00039351FE6A@mac.com>

On Thursday, March 21, 2002, at 10:10  PM, dman wrote:

> If the data is generated client-side, then the page doesn't have to be
> reloaded.  Unfortunately, the only widespread client-side technologies
> are Javascript and Java (applets).  I think this is mainly because it
> is hard to change client-side technologies -- every single user has to
> upgrade their system.  With server-side, only the server changes while
> the client uses the same old HTML it has been using for years.

<side-note status="unasked for">
And since it may or may not be enabled by or available to the client, 
JavaScript is often avoided as much as possible by the majority of PHP 
developers that I've been in contact with (via the PHP mailing list).  
This is not to say that JavaScript is not a good language -- it is a 
very powerful language -- but simply that given the choice between 
executing some code server side or client side (with JS), it is more 
reliable to do so at the server.
</side-note>




Erik



From stan@coolquiz.com  Fri Mar 22 05:43:20 2002
From: stan@coolquiz.com (STAN)
Date: Thu, 21 Mar 2002 21:43:20 -0800 (PST)
Subject: [Tutor] Threading in Python
Message-ID: <20020322054320.6CA9236F9@sitemail.everyone.net>

Hi,


How is it possible to run a seperate process in the background using Python ?


For Eg:

I have a main process that is console based, that gives the user a few options and acts according to their choice.

But I want a process to be running in the background, which sleeps for x secs and keeps checking for some data [ Contacts a C++ extension].

I tried thread.start_new_thread(...) and also the Thread class but was unsuccessful :

This is what I tried ( a very simple and abstract simulation of what I intend to do)::

*****************************************************
from threading import *
from random import Random


def printResult():
	r = Random(68)
	while 1:
		time.sleep(0.5)   # Is there a wait method I can use here for more efficiency ?
		x = r.random()
		if (x > 0.75):
			print "The Event has occured"

# End of printResult()


def startit():
	t = Thread(target = printResult(),args=())
	t.start()
	while 1:
		ch = raw_input("Continue ?")
		if (ch not in ('y',)):
			break

# End of startit()

>>> startit()

*************************************************************************************

I wanted printResult to be running in the background ..... But it is the only one that is running !!!

Could anybody suggest me as to how I can use threads effectively in Python to acheive my task.

Thanks and Regards
  S

_____________________________________________________________
Cool Quiz - Websites That Keep You Guessing! http://www.coolquiz.com

_____________________________________________________________
Run a small business? Then you need professional email like you@yourbiz.com from Everyone.net  http://www.everyone.net?tag


From tutor@python.org  Fri Mar 22 07:19:05 2002
From: tutor@python.org (Tim Peters)
Date: Fri, 22 Mar 2002 02:19:05 -0500
Subject: [Tutor] Threading in Python
In-Reply-To: <20020322054320.6CA9236F9@sitemail.everyone.net>
Message-ID: <LNBBLJKPBEHFEDALKOLCGELAOGAA.tim.one@comcast.net>

[STAN]
> How is it possible to run a seperate process in the background
> using Python ?

Sounds like you actually want a thread (!= process), and actually don't mean
much of anything by "background" <wink>.

> I have a main process that is console based, that gives the user
> a few options and acts according to their choice.
>
> But I want a process to be running in the background, which
> sleeps for x secs and keeps checking for some data [ Contacts a
> C++ extension].
>
> I tried thread.start_new_thread(...) and also the Thread class
> but was unsuccessful :

The good news is that this is easy to fix.

> This is what I tried ( a very simple and abstract simulation of
> what I intend to do)::
>
> *****************************************************
> from threading import *
> from random import Random

You're missing an "import time" here.

> def printResult():
> 	r = Random(68)
> 	while 1:
> 		time.sleep(0.5)   # Is there a wait method I can
>                             # use here for more efficiency ?

What do you want it to wait *for*?  Not enough information.  Sleeping is
very efficient, btw, if the best answer you've got is "wait for half a
second".

> 		x = r.random()
> 		if (x > 0.75):

The parentheses aren't needed here, and are rarely seen in Python.

> 			print "The Event has occured"
>
> # End of printResult()
>
>
> def startit():
> 	t = Thread(target = printResult(),args=())
                                     ^^

The parentheses there are the cause of your problem:  you're *calling*
printResult here, and since printResult() never returns, neither does the
call to Thread (your main thread never gets beyond this line).  Delete the
parentheses and you'll be much happier.

> 	t.start()
> 	while 1:
> 		ch = raw_input("Continue ?")
> 		if (ch not in ('y',)):
> 			break
>
> # End of startit()
>
> >>> startit()
> ...
> I wanted printResult to be running in the background ..... But it
> is the only one that is running !!!

That's explained above -- your main thread is waiting for the printResult()
call to return; you never actually got so far as to create a second thread.
But you're close:  remove the parens and you'll have two threads.



From karthikg@aztec.soft.net  Fri Mar 22 07:40:32 2002
From: karthikg@aztec.soft.net (Karthik Gurumurthy)
Date: Fri, 22 Mar 2002 13:10:32 +0530
Subject: [Tutor] Threading in Python
In-Reply-To: <LNBBLJKPBEHFEDALKOLCGELAOGAA.tim.one@comcast.net>
Message-ID: <NEBBJNMDEKBIBCMCNMBDOELNDGAA.karthikg@aztec.soft.net>

what is the basic difference in threading model of say java and python?
i ask this because i find all the method names in the library to be very
similar.

thanks,
karthik.


From dyoo@hkn.eecs.berkeley.edu  Fri Mar 22 07:47:04 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Thu, 21 Mar 2002 23:47:04 -0800 (PST)
Subject: [Tutor] NEWBIE is it possible to use HTML and Python  together?
In-Reply-To: <4.2.0.58.20020321183227.019ea100@pop3.norton.antivirus>
Message-ID: <Pine.LNX.4.44.0203212251040.866-100000@hkn.eecs.berkeley.edu>


On Thu, 21 Mar 2002, Kirby Urner wrote:

> >Please feel free to ask more questions; we'd like to hear about your
> >progress.  Good luck!
>
> Would it be accurate to suggest that any CGI-Python solution to the dice
> rolling program would involve reloading the page, and/or serving a new
> one?  To change the content of a web page *in place* (without reloading)
> would require some other solution, no? (e.g. JavaScript).


Yes, I was thinking of using form submission.  If we want to make the game
play in-place, it'll would probably involve some client-side Javascript.
But client-side stuff can be tricky and frustrating, especially because
it's traditionally so platform specific.  (I've heard some good things
about Flash though.)


For simple stuff, I think that Python with CGI on the server side can be
effective.  As an example, I cooked up a small cgi program that plays Rock
Paper Scissors, and I've placed the source code on ChalkBoard:

    http://www.decrem.com:8080/ChalkBoard/1016787291

(I'm still running into some wackiness with HTML quoting though... doh!
I have to look into this when I have time...hmm... maybe I should get
ChalkBoard to run CGI scripts.)


Hope this helps!



From idiot1@netzero.net  Fri Mar 22 07:11:09 2002
From: idiot1@netzero.net (kirk Bailey)
Date: Fri, 22 Mar 2002 02:11:09 -0500
Subject: [Tutor] 1.2.1 online
Message-ID: <3C9AD90D.45D23104@netzero.net>

TL1.2.0 had a documentation bug, the docs referred to 'tinylist.conf',
but the programs referr to 'tinylist.cf'! The doc doing so is
corrected. The updated archives are now on the site.

1.2.0+ reads it's domain name from a config file, and knows how to
locate itself, so you do not have to edit and place in it the path to
the cgi-bin. YOU STILL HAVE TO TELL THEM THE PATH TO PYTHON up in line
1.

-- 
 
end
	    Respectfully,
			 Kirk D Bailey


+---------------------"Thou Art Free." -Eris----------------------+
| http://www.howlermonkey.net mailto:highprimate@howlermonkey.net |
| http://www.tinylist.org  +--------+  mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking---------------------+
                           +--------+

NOTE: By sending SPAM to this address you agree to pay me a service
fee of $100 for the service of receiving,  storing,  examining, and
deleting your piece of SPAM. I am a postmaster, and take a dim view
of such.


From idiot1@netzero.net  Fri Mar 22 07:19:22 2002
From: idiot1@netzero.net (kirk Bailey)
Date: Fri, 22 Mar 2002 02:19:22 -0500
Subject: [Tutor] tinylist.1.2.0 bug report
Message-ID: <3C9ADAFA.6F3CD5A1@netzero.net>

TL1.2.0 had a documentation bug, the docs referred to 'tinylist.conf',
but the programs referr to 'tinylist.cf'! The doc doing so is
corrected. The updated archives are now on the site.

1.2.0+ reads it's domain name from a config file, and knows how to
locate itself, so you do not have to edit and place in it the path to
the cgi-bin. YOU STILL HAVE TO TELL THEM THE PATH TO PYTHON up in line
1.
-- 
 
end
	    Respectfully,
			 Kirk D Bailey


+---------------------"Thou Art Free." -Eris----------------------+
| http://www.howlermonkey.net mailto:highprimate@howlermonkey.net |
| http://www.tinylist.org  +--------+  mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking---------------------+
                           +--------+

NOTE: By sending SPAM to this address you agree to pay me a service
fee of $100 for the service of receiving,  storing,  examining, and
deleting your piece of SPAM. I am a postmaster, and take a dim view
of such.


From apython101@yahoo.com  Fri Mar 22 10:46:41 2002
From: apython101@yahoo.com (john public)
Date: Fri, 22 Mar 2002 02:46:41 -0800 (PST)
Subject: [Tutor] cookies
Message-ID: <20020322104641.5485.qmail@web21108.mail.yahoo.com>

--0-1139435547-1016794001=:2804
Content-Type: text/plain; charset=us-ascii


Does anyone know if someone has written a program in Python that allows manipulation of cookies for internet privacy? I have always been concerned about internet privacy if some one has written such a program maybe I can do something about my privacy concerns and learn something about Python code at the same time. I am running windows 98. Will switching to Linux make cookie and internet cache management easier?

 Thanx

John Q. Public



---------------------------------
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
--0-1139435547-1016794001=:2804
Content-Type: text/html; charset=us-ascii

<P>Does anyone know if someone has written a program in Python that allows manipulation of cookies for internet privacy? I have always been concerned about internet privacy if some one has written such a program maybe I can do something about my privacy concerns and learn something about Python code at the same time. I am running windows 98. Will switching to Linux make cookie and internet cache management easier?</P>
<P>&nbsp;Thanx</P>
<P>John Q. Public</P><p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href="$rd_url/tag/http://movies.yahoo.com/">Yahoo! Movies</a> - coverage of the 74th Academy Awards®
--0-1139435547-1016794001=:2804--


From erikprice@mac.com  Fri Mar 22 12:37:47 2002
From: erikprice@mac.com (Erik Price)
Date: Fri, 22 Mar 2002 07:37:47 -0500
Subject: [Tutor] cookies
In-Reply-To: <20020322104641.5485.qmail@web21108.mail.yahoo.com>
Message-ID: <9D853736-3D91-11D6-B772-00039351FE6A@mac.com>

On Friday, March 22, 2002, at 05:46  AM, john public wrote:

> Does anyone know if someone has written a program in Python that allows 
> manipulation of cookies for internet privacy? I have always been 
> concerned about internet privacy if some one has written such a program 
> maybe I can do something about my privacy concerns and learn something 
> about Python code at the same time. I am running windows 98. Will 
> switching to Linux make cookie and internet cache management easier?

What is it about privacy that you want addressed?  As far as privacy 
goes, cookies are actually pretty non-invasive -- there's a whole slew 
of rules about how they can and can't be used (which is more than can be 
said for a majority of the spyware being installed on people's boxes 
from P2P freeware).  In fact, cookies were designed all along to be 
helpful to the user, rather than to track their browsing habits.  But 
privacy issues are always important.  I think a Python script to manage 
cookies would be pretty neat.

You will have an inherently more private system if you switch from 
Windows to Linux, although this is a more accurate statement for people 
running Windows e[X]tra [P]roprietary.  Linux distributions generally 
don't try to contact the company that markets them with information 
about your system at random (though who knows?), and you have access to 
every tiny piece of your system, even the source code if you should want 
it.  I don't know how Win systems allow you to manage your cookies (I 
imagine it's through browser preferences and perhaps the filesystem), so 
I couldn't say whether or not it is easier in Linux.  But once you 
understand the structure of a Linux system, there's really nowhere you 
can't go.


Erik



From garber@centralcatholic.org  Fri Mar 22 12:40:09 2002
From: garber@centralcatholic.org (Robert Garber)
Date: Fri, 22 Mar 2002 07:40:09 -0500
Subject: [Tutor] NEWBIE is it possible to use HTML and Python  together?
Message-ID: <200203220740.AA1363869738@centralcatholic.org>

I there any way to set the python up to run on a client side. I don think it's planned to run on the web, it's just his own little game. is there away to use something like py2exe to solve this?

Thank you for your time in helping me solve this.
Robert
--------- Original Message ----------------------------------
From: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
Date: Thu, 21 Mar 2002 23:47:04 -0800 (PST)

>
>
>On Thu, 21 Mar 2002, Kirby Urner wrote:
>
>> >Please feel free to ask more questions; we'd like to hear about your
>> >progress.  Good luck!
>>
>> Would it be accurate to suggest that any CGI-Python solution to the dice
>> rolling program would involve reloading the page, and/or serving a new
>> one?  To change the content of a web page *in place* (without reloading)
>> would require some other solution, no? (e.g. JavaScript).
>
>
>Yes, I was thinking of using form submission.  If we want to make the game
>play in-place, it'll would probably involve some client-side Javascript.
>But client-side stuff can be tricky and frustrating, especially because
>it's traditionally so platform specific.  (I've heard some good things
>about Flash though.)
>
>
>For simple stuff, I think that Python with CGI on the server side can be
>effective.  As an example, I cooked up a small cgi program that plays Rock
>Paper Scissors, and I've placed the source code on ChalkBoard:
>
>    http://www.decrem.com:8080/ChalkBoard/1016787291
>
>(I'm still running into some wackiness with HTML quoting though... doh!
>I have to look into this when I have time...hmm... maybe I should get
>ChalkBoard to run CGI scripts.)
>
>
>Hope this helps!
>
>


From aduran@us.ibm.com  Fri Mar 22 13:58:23 2002
From: aduran@us.ibm.com (Aldo Duran)
Date: Fri, 22 Mar 2002 07:58:23 -0600
Subject: [Tutor] Use of a global variable in many scripts
Message-ID: <OF975C575C.49D45E9E-ON85256B84.004C374E@raleigh.ibm.com>

This is a multipart message in MIME format.
--=_alternative 004CC28D86256B84_=
Content-Type: text/plain; charset="us-ascii"

Hello everyone

I am new to python and I have some questions, here is my first.

I have a set of scripts, and I would like to use a variable being set in
the main program and use in all the others scripts. I have a file1.py
which defines global variabel var1 and then I import file2.py, I tryed
to use the variable from file2.py, but I get the exception

Traceback (most recent call last):
  File "/tivoli/homes/4/aduran/bin/py/file1.py", line 7, in ?
    file2.useVar1()
  File "/tivoli/homes/4/aduran/bin/py/file2.py", line 6, in useVar1
    print var1
NameError: global name 'var1' is not defined

How can I use the same global variables in all my scripts?

I know that using global variables is not a very good practice but
sometimes it is easy, convenient, quick and simple.

Thanks
aldo

file1.py
-------------------------------------------------
#!/usr/bin/env python2.2

global var1
var1 = 1
import file2

file2.useVar1()

file2.py
-------------------------------------------------
#!/usr/bin/env python2.2

global var1

def useVar1():
    print "var1 value == " ,var1

file3.py
-------------------------------------------------
#!/usr/bin/env python2.2

global var1

def useVar1():
    print "another file using the same variable == " ,var1

--=_alternative 004CC28D86256B84_=
Content-Type: text/html; charset="us-ascii"


<br><font size=2 face="sans-serif">Hello everyone</font>
<br>
<br><font size=2 face="sans-serif">I am new to python and I have some questions, here is my first.</font>
<br>
<br><font size=2 face="sans-serif">I have a set of scripts, and I would like to use a variable being set in</font>
<br><font size=2 face="sans-serif">the main program and use in all the others scripts. I have a file1.py</font>
<br><font size=2 face="sans-serif">which defines global variabel var1 and then I import file2.py, I tryed</font>
<br><font size=2 face="sans-serif">to use the variable from file2.py, but I get the exception</font>
<br>
<br><font size=2 face="sans-serif">Traceback (most recent call last):</font>
<br><font size=2 face="sans-serif">&nbsp; File &quot;/tivoli/homes/4/aduran/bin/py/file1.py&quot;, line 7, in ?</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; file2.useVar1()</font>
<br><font size=2 face="sans-serif">&nbsp; File &quot;/tivoli/homes/4/aduran/bin/py/file2.py&quot;, line 6, in useVar1</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; print var1</font>
<br><font size=2 face="sans-serif">NameError: global name 'var1' is not defined</font>
<br>
<br><font size=2 face="sans-serif">How can I use the same global variables in all my scripts?</font>
<br>
<br><font size=2 face="sans-serif">I know that using global variables is not a very good practice but</font>
<br><font size=2 face="sans-serif">sometimes it is easy, convenient, quick and simple.</font>
<br>
<br><font size=2 face="sans-serif">Thanks</font>
<br><font size=2 face="sans-serif">aldo</font>
<br>
<br><font size=2 face="sans-serif">file1.py</font>
<br><font size=2 face="sans-serif">-------------------------------------------------</font>
<br><font size=2 face="sans-serif">#!/usr/bin/env python2.2</font>
<br>
<br><font size=2 face="sans-serif">global var1</font>
<br><font size=2 face="sans-serif">var1 = 1</font>
<br><font size=2 face="sans-serif">import file2</font>
<br>
<br><font size=2 face="sans-serif">file2.useVar1()</font>
<br>
<br><font size=2 face="sans-serif">file2.py</font>
<br><font size=2 face="sans-serif">-------------------------------------------------</font>
<br><font size=2 face="sans-serif">#!/usr/bin/env python2.2</font>
<br>
<br><font size=2 face="sans-serif">global var1</font>
<br>
<br><font size=2 face="sans-serif">def useVar1():</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; print &quot;var1 value == &quot; ,var1</font>
<br>
<br><font size=2 face="sans-serif">file3.py</font>
<br><font size=2 face="sans-serif">-------------------------------------------------</font>
<br><font size=2 face="sans-serif">#!/usr/bin/env python2.2</font>
<br>
<br><font size=2 face="sans-serif">global var1</font>
<br>
<br><font size=2 face="sans-serif">def useVar1():</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; print &quot;another file using the same variable == &quot; ,var1</font>
<br>
--=_alternative 004CC28D86256B84_=--


From pythontutor@venix.com  Fri Mar 22 16:48:31 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Fri, 22 Mar 2002 11:48:31 -0500
Subject: [Tutor] Use of a global variable in many scripts
References: <OF975C575C.49D45E9E-ON85256B84.004C374E@raleigh.ibm.com>
Message-ID: <3C9B605F.2010304@venix.com>

It is probably simplest to turn things around.  Create a file
	globvar.py (or whatever name makes sense to you)

file1.py should contain:
import globalvar
globalvar.var1 = 'test'
print globalvar.var1

file2.py and others contain:
import globalvar
print globalvar.var1

Aldo Duran wrote:

> 
> Hello everyone
> 
> I am new to python and I have some questions, here is my first.
> 
> I have a set of scripts, and I would like to use a variable being set in
> the main program and use in all the others scripts. I have a file1.py
> which defines global variabel var1 and then I import file2.py, I tryed
> to use the variable from file2.py, but I get the exception
> 
> Traceback (most recent call last):
>   File "/tivoli/homes/4/aduran/bin/py/file1.py", line 7, in ?
>     file2.useVar1()
>   File "/tivoli/homes/4/aduran/bin/py/file2.py", line 6, in useVar1
>     print var1
> NameError: global name 'var1' is not defined
> 
> How can I use the same global variables in all my scripts?
> 
> I know that using global variables is not a very good practice but
> sometimes it is easy, convenient, quick and simple.
> 
> Thanks
> aldo
> 
> file1.py
> -------------------------------------------------
> #!/usr/bin/env python2.2
> 
> global var1
> var1 = 1
> import file2
> 
> file2.useVar1()
> 
> file2.py
> -------------------------------------------------
> #!/usr/bin/env python2.2
> 
> global var1
> 
> def useVar1():
>     print "var1 value == " ,var1
> 
> file3.py
> -------------------------------------------------
> #!/usr/bin/env python2.2
> 
> global var1
> 
> def useVar1():
>     print "another file using the same variable == " ,var1


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582



From urnerk@qwest.net  Fri Mar 22 17:22:34 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Fri, 22 Mar 2002 09:22:34 -0800
Subject: [Tutor] NEWBIE is it possible to use HTML and Python
 together?
In-Reply-To: <200203220740.AA1363869738@centralcatholic.org>
Message-ID: <4.2.0.58.20020322084118.00ad9520@pop3.norton.antivirus>

At 07:40 AM 3/22/2002 -0500, you wrote:
>I there any way to set the python up to run on a client side.
>I don think it's planned to run on the web, it's just his own
>little game. is there away to use something like py2exe to
>solve this?
>
>Thank you for your time in helping me solve this.
>Robert

Is there a web server in this picture at all -- even just
a local one on the same machine as the client?  It's
perfectly possible for a standalone machine not permanently
connected to the internet with static, public IP to run a
web server "facing inward" (i.e. to be a "host" and to
"run a web server" are not the same thing).

Perhaps your friend is using HTML to sort of mock up an
interface, i.e. is using the browser as a front end for
an app?  This is trendy, as various flavors of XML for
GUI-design are popping up and programmers will be taking
this approach quite a bit.

However, without a server in the picture, web pages need
something running client side to be dynamic.  Either that,
or use Python to take the place of the missing server,
i.e. you could write a tiny server in Python and point
the browser to it.  This is easier than it sounds.
However, you should make sure this code never handles
HTTP requests originating outside your box.

For example, put some html file (say thefile.html) in
your Python root directory and enter the following two
lines of code in IDLE.  Then point your browser to
http://127.0.0.1/thefile.html and it should come up in
your browser:

 >>> import SocketServer.CGIHTTPServer
 >>> SocketServer.ThreadingTCPServer(('127.0.0.1',80),\
       CGIHTTPServer.CGIHTTPRequestHandler).serve_forever()

You may need to kill your Python process from outside
when you're done with this demo.

A good resource here is 'The Python 2.1 Bible' Chapter 15,
from where I copied the above.  From here, you can go on
to write CGI handlers that handle requests.

Kirby



From israel@lith.com  Fri Mar 22 17:36:49 2002
From: israel@lith.com (Israel Evans)
Date: Fri, 22 Mar 2002 09:36:49 -0800
Subject: [Tutor] Mysqldb.py:::Cursor has no 'query' attribute?
Message-ID: <AF020C5FC551DD43A4958A679EA16A15017B403C@abbott.lith.com>

I've just started working with MySQL, and the Mysqldb module for python and,
as usual, I've run into some problems...


after I type the following code in the the Python shell...

>>> import CompatMysqldb
>>> conn = CompatMysqldb.mysqldb('test@localhost israel
SuperSecretPassword1')
>>> cursor = CompatMysqldb.Cursor(conn)
>>> cursor.execute('select version(), current_date')

... I get the error:

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in ?
    cursor.execute('select version(), current_date')
  File "C:\proj\Python22\Lib\site-packages\CompatMysqldb.py", line 243, in
execute
    self.__conn.query(op)
  File "C:\proj\Python22\Lib\site-packages\CompatMysqldb.py", line 123, in
__getattr__
    return getattr(self.__curs, key)
AttributeError: Cursor instance has no attribute 'query'

Anybody know why and what I can do about it?



line 243 calls this:
self.__conn.query(op) 

which looks and the self.__conn of the cursor which looks at the conn passed
into it at creation time which is supposed to reflect the (self.__curs, key)
of the instance of the Connection class I created with the conn = blah
blah... command which happens to be self.__curs = Cursor(self.__conn).

I feel like it's running in circles!  
Confused'ly yours

~Israel~



From apython101@yahoo.com  Fri Mar 22 17:57:01 2002
From: apython101@yahoo.com (john public)
Date: Fri, 22 Mar 2002 09:57:01 -0800 (PST)
Subject: [Tutor] cookies
In-Reply-To: <9D853736-3D91-11D6-B772-00039351FE6A@mac.com>
Message-ID: <20020322175701.53866.qmail@web21110.mail.yahoo.com>

--0-548574130-1016819821=:50523
Content-Type: text/plain; charset=us-ascii


 -What is it about privacy that you want addressed? As far as privacy 
goes, cookies are actually pretty non-invasive -- 

 I was under the impression that cookies told a web page administrator which web page you last visited and if you had been to their web page before and which parts of their web page you visited ect. I know that the Yahoo web site remebers which news stories I have read ect. I would just as soon be nameless, just out of principal. I have read about cookies in an online computer dictionary but it really did not talk about how they could be used to watch what you do online. I am under the impression that if I visit a web page if it has the appropriate software it can get my e-mail address. I see people on rent a coder asking for this kind of software to be written. I really did not have anything specific in mind. I know I need to understand cookies and spyware in general and wanted to see some cookie code in Python if it existed. You awnsered my most important question. That switching to Linux will improve my control over everything. I am getting a new computer soon and will install Linux on it. Does Linux come with a browser?

 Thanx

John Q. Public

 

there's a whole slew 
of rules about how they can and can't be used (which is more than can be 
said for a majority of the spyware being installed on people's boxes 
from P2P freeware). In fact, cookies were designed all along to be 
helpful to the user, rather than to track their browsing habits. But 
privacy issues are always important. I think a Python script to manage 
cookies would be pretty neat.

You will have an inherently more private system if you switch from 
Windows to Linux, although this is a more accurate statement for people 
running Windows e[X]tra [P]roprietary. Linux distributions generally 
don't try to contact the company that markets them with information 
about your system at random (though who knows?), and you have access to 
every tiny piece of your system, even the source code if you should want 
it. I don't know how Win systems allow you to manage your cookies (I 
imagine it's through browser preferences and perhaps the filesystem), so 
I couldn't say whether or not it is easier in Linux. But once you 
understand the structure of a Linux system, there's really nowhere you 
can't go.


Erik




---------------------------------
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
--0-548574130-1016819821=:50523
Content-Type: text/html; charset=us-ascii

<P>&nbsp;-What is it about privacy that you want addressed? As far as privacy <BR>goes, cookies are actually pretty non-invasive -- </P>
<P>&nbsp;I was under the impression that cookies told a web page administrator which web page you last visited and if you had been to their web page before and which parts of their web page you visited ect. I know that the Yahoo web site remebers which news stories I have read ect. I would just as soon be nameless, just out of principal. I have read about cookies in an online computer dictionary but it really did not talk about how they could be used to watch what you do online. I am under the impression that if I visit a web page if it has the appropriate software it can get my e-mail address. I see people on rent a coder asking for this kind of software to be written. I really did not have anything specific in mind. I know I need to understand cookies and spyware in general and wanted to see some cookie code in Python if it existed. You awnsered my most important question. That switching to Linux will improve my control over everything. I am getting a new computer soon and will install Linux on it. Does Linux come with a browser?</P>
<P>&nbsp;Thanx</P>
<P>John Q. Public</P>
<P>&nbsp;</P>
<P>there's a whole slew <BR>of rules about how they can and can't be used (which is more than can be <BR>said for a majority of the spyware being installed on people's boxes <BR>from P2P freeware). In fact, cookies were designed all along to be <BR>helpful to the user, rather than to track their browsing habits. But <BR>privacy issues are always important. I think a Python script to manage <BR>cookies would be pretty neat.<BR><BR>You will have an inherently more private system if you switch from <BR>Windows to Linux, although this is a more accurate statement for people <BR>running Windows e[X]tra [P]roprietary. Linux distributions generally <BR>don't try to contact the company that markets them with information <BR>about your system at random (though who knows?), and you have access to <BR>every tiny piece of your system, even the source code if you should want <BR>it. I don't know how Win systems allow you to manage your cookies (I <BR>imagine it's through browser preferences and perhaps the filesystem), so <BR>I couldn't say whether or not it is easier in Linux. But once you <BR>understand the structure of a Linux system, there's really nowhere you <BR>can't go.<BR><BR><BR>Erik<BR></P><p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href="$rd_url/tag/http://movies.yahoo.com/">Yahoo! Movies</a> - coverage of the 74th Academy Awards®
--0-548574130-1016819821=:50523--


From jeff@ccvcorp.com  Fri Mar 22 18:08:13 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Fri, 22 Mar 2002 10:08:13 -0800
Subject: [Tutor] NEWBIE is it possible to use HTML and Python  together?
References: <E16oSPp-0006eA-00@mail.python.org>
Message-ID: <3C9B730D.6C94B708@ccvcorp.com>

> "Robert Garber" <garber@centralcatholic.org> wrote:
>
> I there any way to set the python up to run on a client side. I don think it's planned to run on the web, it's just his own little game. is there away to use something like py2exe to solve this?

Yes, you can do this.  Every machine that is to run this game must have Python and the win32all extensions installed.  Your best bet will be to install ActiveState's distribution, which comes
complete with all the extensions you'll need, out of the box.  You'll also need to be running Internet Exploder -- AFAIK, no other browser currently uses the Windows ActiveScripting engine, which is
what's required to use Python as a client-side script.  With these prerequisites in place, then it's a simple matter to write your scripts like this:

<script language="python">
def MyFunction():
    pass

def OtherFunction():
    # do stuff
    window.MyFunction()  # call other script function
    # do more stuff

</script>

You can pretty much use any valid Python in your scripts, but in order to be very effective, you'll have to have them manipulate the IE document model.  This is a pretty complicated topic, and you
might want to get a book about that.  I've used "Programming Internet Explorer 5" (Microsoft Press), and found it to be okay, and of course there's quite a bit of information available on
Microsoft's website.  A word of warning, though -- almost the code examples that you will see for doing client-side scripting will be in Javascript or VBScript, and you will have to translate.
That's usually not too hard -- watch out for parens vs brackets (VBS uses () in many places where Python uses [] ), and remember that Python will require explicitly specifying a lot more than VBS
does (what VBS refers to as, say, document.forms(0), Python will need to refer to as window.document.forms[0] ).

And of course, if there's anything that you're having problems with, you're welcome to ask about it here.  :)

Jeff Shannon
Technician/Programmer
Credit International




From virketis@fas.harvard.edu  Fri Mar 22 18:41:42 2002
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Fri, 22 Mar 2002 13:41:42 -0500
Subject: [Tutor] Mysqldb.py:::Cursor has no 'query' attribute?
References: <AF020C5FC551DD43A4958A679EA16A15017B403C@abbott.lith.com>
Message-ID: <004f01c1d1d1$361ee910$18adf78c@virketis2>

Israel,

> >>> import CompatMysqldb

What module is this? I usually use MySQLdb
(http://sourceforge.net/projects/mysql-python/), which is called with an
"import MySQLdb." Can you point me to the place where you got it, so I can
try and replicate the behaviour? Also, what version of Python and MySQL are
you using?

Cheers,

Pijus



From israel@lith.com  Fri Mar 22 18:54:39 2002
From: israel@lith.com (Israel Evans)
Date: Fri, 22 Mar 2002 10:54:39 -0800
Subject: [Tutor] Mysqldb.py:::Cursor has no 'query' attribute?
Message-ID: <AF020C5FC551DD43A4958A679EA16A15017B4041@abbott.lith.com>

I'm using python 2.2 and MySQL 3.23.49-nt and the MySQL python module I'm
using is from http://www.python.org/topics/database/modules.html .
I selected the MySQL link on that page which took me to a page which sent me
off to sourceforge to get the latest stuff whereat I downloaded 
MySQL-python-0.9.1.win32-py2.2.exe.  The module is then only callable by
using the funky CompatMysqldb.py file.

In the source file I see this paragraph hints at a number of frustrations
that led to this naming scheme.  :)

"""
This is the original Mysqldb.py module which came with MySQLmodule-1.4,
only it has been adapted to use _mysql instead MySQL. It is intended
for backwards compatibility purposes only. But as a bonus, transactions
will work if your database server and table types support them. It is
called CompatMysqldb instead of Mysqldb so as not to interfere with an
existing Mysqldb, or MySQLdb on case-insensitive brain-dead operating
systems.

Under no circumstances should you bug James Henstridge about this!!!
"""


So am I using an old Mysql module?  Is there a new more standard one I
should be using?  Since I've just started working with all of this, I'm
extremely flexible on the tools I use.  Any suggestions?

~Israel~


-----Original Message-----
From: Pijus Virketis [mailto:virketis@fas.harvard.edu] 
Sent: 22 March 2002 10:42 AM
To: Israel Evans
Cc: tutor@python.org
Subject: Re: [Tutor] Mysqldb.py:::Cursor has no 'query' attribute?

Israel,

> >>> import CompatMysqldb

What module is this? I usually use MySQLdb
(http://sourceforge.net/projects/mysql-python/), which is called with an
"import MySQLdb." Can you point me to the place where you got it, so I can
try and replicate the behaviour? Also, what version of Python and MySQL are
you using?

Cheers,

Pijus


From dyoo@hkn.eecs.berkeley.edu  Fri Mar 22 19:17:33 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 22 Mar 2002 11:17:33 -0800 (PST)
Subject: [Tutor] Mysqldb.py:::Cursor has no 'query' attribute?
In-Reply-To: <AF020C5FC551DD43A4958A679EA16A15017B403C@abbott.lith.com>
Message-ID: <Pine.LNX.4.44.0203220954030.16662-100000@hkn.eecs.berkeley.edu>


On Fri, 22 Mar 2002, Israel Evans wrote:

> I've just started working with MySQL, and the Mysqldb module for python and,
> as usual, I've run into some problems...

Do you mean the "Mysqldb" module, or the "MySQLdb" module?  *grin*  I've
used Andy Dustman's MySQLdb module with good success:

    http://sourceforge.net/projects/mysql-python



> after I type the following code in the the Python shell...
>
> >>> import CompatMysqldb
> >>> conn = CompatMysqldb.mysqldb('test@localhost israel
> SuperSecretPassword1')
> >>> cursor = CompatMysqldb.Cursor(conn)
> >>> cursor.execute('select version(), current_date')
>
> ... I get the error:
>
> Traceback (most recent call last):
>   File "<pyshell#4>", line 1, in ?
>     cursor.execute('select version(), current_date')
>   File "C:\proj\Python22\Lib\site-packages\CompatMysqldb.py", line 243, in
> execute
>     self.__conn.query(op)
>   File "C:\proj\Python22\Lib\site-packages\CompatMysqldb.py", line 123, in
> __getattr__
>     return getattr(self.__curs, key)
> AttributeError: Cursor instance has no attribute 'query'
>
> Anybody know why and what I can do about it?


I'm not too familiar with CompatMysqldb.py.  The equivalent code, using
MySQLdb, would look like:

###
import MySQLdb
conn = MySQLdb.connect(db='test@localhost',
                       user='israel',
                       passwd='SuperSecretPassword1')
cursor = conn.cursor()
cursor.execute('select version(), current_date')
###


Hope this helps!



From israel@lith.com  Fri Mar 22 19:52:13 2002
From: israel@lith.com (Israel Evans)
Date: Fri, 22 Mar 2002 11:52:13 -0800
Subject: [Tutor] Mysqldb.py:::Cursor has no 'query' attribute?
Message-ID: <AF020C5FC551DD43A4958A679EA16A15017B4042@abbott.lith.com>

I think I've figured out the problem with the help of our good friends here
on the list.

I was using the CompatMysqldb module because that's the only real .py file
that looked right.  I've since found out that after I install the MySQLdb
module I can just import MySQLdb and use the documentation on the Python
Database API Specification 2.0 found on the python.org site to figure out
how to use it.

Now I just have to figure out why localhost is not a recognized host when I
try to create a connection.

Thanks people.

~Israel~


-----Original Message-----
From: Danny Yoo [mailto:dyoo@hkn.eecs.berkeley.edu] 
Sent: 22 March 2002 11:18 AM
To: Israel Evans
Cc: 'tutor@python.org'
Subject: Re: [Tutor] Mysqldb.py:::Cursor has no 'query' attribute?



On Fri, 22 Mar 2002, Israel Evans wrote:

> I've just started working with MySQL, and the Mysqldb module for python
and,
> as usual, I've run into some problems...

Do you mean the "Mysqldb" module, or the "MySQLdb" module?  *grin*  I've
used Andy Dustman's MySQLdb module with good success:

    http://sourceforge.net/projects/mysql-python



> after I type the following code in the the Python shell...
>
> >>> import CompatMysqldb
> >>> conn = CompatMysqldb.mysqldb('test@localhost israel
> SuperSecretPassword1')
> >>> cursor = CompatMysqldb.Cursor(conn)
> >>> cursor.execute('select version(), current_date')
>
> ... I get the error:
>
> Traceback (most recent call last):
>   File "<pyshell#4>", line 1, in ?
>     cursor.execute('select version(), current_date')
>   File "C:\proj\Python22\Lib\site-packages\CompatMysqldb.py", line 243, in
> execute
>     self.__conn.query(op)
>   File "C:\proj\Python22\Lib\site-packages\CompatMysqldb.py", line 123, in
> __getattr__
>     return getattr(self.__curs, key)
> AttributeError: Cursor instance has no attribute 'query'
>
> Anybody know why and what I can do about it?


I'm not too familiar with CompatMysqldb.py.  The equivalent code, using
MySQLdb, would look like:

###
import MySQLdb
conn = MySQLdb.connect(db='test@localhost',
                       user='israel',
                       passwd='SuperSecretPassword1')
cursor = conn.cursor()
cursor.execute('select version(), current_date')
###


Hope this helps!


From israel@lith.com  Fri Mar 22 21:00:02 2002
From: israel@lith.com (Israel Evans)
Date: Fri, 22 Mar 2002 13:00:02 -0800
Subject: [Tutor] Database queries returning indexes rather than strings...
Message-ID: <AF020C5FC551DD43A4958A679EA16A15017B4045@abbott.lith.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_01C1D1E4.8919B3EC
Content-Type: text/plain

 
I'm using the MySQLdb module recently mentioned here and I'm running into
issues of trying to interpret the results of my queries.  It's seems after
having made a connection and a cursor when I try to execute a query I get
the answer to that query back as binary character or at least a Long integer
or something.  It comes back to me a a number followed by an L.  My
questions are these:  how do I get information rather than location or
amount out of a query?  How do I specify what form of answer I should be
getting from a query?  Is there documentation anywhere?
 
I've tried some of the documentation in sourceforge, but I'm probably at
such a basic level that I'm just missing something.  
 
Thanks for any info...
 
 
 
~Israel~
 

------_=_NextPart_001_01C1D1E4.8919B3EC
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:st1=3D"urn:schemas-microsoft-com:office:smarttags" =
xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">


<meta name=3DProgId content=3DWord.Document>
<meta name=3DGenerator content=3D"Microsoft Word 10">
<meta name=3DOriginator content=3D"Microsoft Word 10">
<link rel=3DFile-List href=3D"cid:filelist.xml@01C1D1A1.7AF6D0A0">
<o:SmartTagType =
namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags"
 name=3D"country-region"/>
<o:SmartTagType =
namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags"
 name=3D"place"/>
<!--[if gte mso 9]><xml>
 <o:OfficeDocumentSettings>
  <o:DoNotRelyOnCSS/>
 </o:OfficeDocumentSettings>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:GrammarState>Clean</w:GrammarState>
  <w:DocumentKind>DocumentEmail</w:DocumentKind>
  <w:EnvelopeVis/>
  <w:Compatibility>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
   <w:UseFELayout/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]--><!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:PMingLiU;
	panose-1:2 2 3 0 0 0 0 0 0 0;
	mso-font-alt:\65B0\7D30\660E\9AD4;
	mso-font-charset:136;
	mso-generic-font-family:roman;
	mso-font-pitch:variable;
	mso-font-signature:3 137232384 22 0 1048577 0;}
@font-face
	{font-family:"\@PMingLiU";
	panose-1:2 2 3 0 0 0 0 0 0 0;
	mso-font-charset:136;
	mso-generic-font-family:roman;
	mso-font-pitch:variable;
	mso-font-signature:3 137232384 22 0 1048577 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0in;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:PMingLiU;}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;
	text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;
	text-underline:single;}
p.MsoAutoSig, li.MsoAutoSig, div.MsoAutoSig
	{margin:0in;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";}
span.EmailStyle17
	{mso-style-type:personal-compose;
	mso-style-noshow:yes;
	mso-ansi-font-size:10.0pt;
	mso-bidi-font-size:10.0pt;
	font-family:Arial;
	mso-ascii-font-family:Arial;
	mso-hansi-font-family:Arial;
	mso-bidi-font-family:Arial;
	color:windowtext;}
span.GramE
	{mso-style-name:"";
	mso-gram-e:yes;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;
	mso-header-margin:.5in;
	mso-footer-margin:.5in;
	mso-paper-source:0;}
div.Section1
	{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
 /* Style Definitions */=20
 table.MsoNormalTable
	{mso-style-name:"Table Normal";
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0in 5.4pt 0in 5.4pt;
	mso-para-margin:0in;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";}
</style>
<![endif]-->
</head>

<body lang=3DEN-US link=3Dblue vlink=3Dpurple =
style=3D'tab-interval:.5in'>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>I'm using the MySQLdb module recently mentioned here
and I'm running into issues of trying to interpret the results of my
queries. <span style=3D'mso-spacerun:yes'>&nbsp;</span>It's seems after
having made a connection and a cursor when I try to execute a query I =
get the
answer to that query back as binary character or at least a Long =
integer or
something. <span style=3D'mso-spacerun:yes'>&nbsp;</span>It comes back =
to me <span
class=3DGramE>a</span> a number followed by an L.<span
style=3D'mso-spacerun:yes'>&nbsp; </span>My questions are these:<span
style=3D'mso-spacerun:yes'>&nbsp; </span>how do I get information =
rather than
location or amount out of a query?<span =
style=3D'mso-spacerun:yes'>&nbsp;
</span>How do I specify what form of answer I should be getting from a =
query? <span
style=3D'mso-spacerun:yes'>&nbsp;</span>Is there documentation =
anywhere?<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>I've tried some of the documentation in sourceforge,
but I'm probably at such a basic level that I'm just missing
something.<span style=3D'mso-spacerun:yes'>&nbsp; =
</span><o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Thanks for any info...<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoAutoSig><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt;mso-no-proof:yes'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoAutoSig><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt;mso-no-proof:yes'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoAutoSig><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt;font-family:"Courier =
New";mso-no-proof:yes'>~</span></font><st1:country-region><st1:place><fo=
nt
  size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt;font-family:"Courier New";
  =
mso-no-proof:yes'>Israel</span></font></st1:place></st1:country-region><=
font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt;font-family:"Courier New";
mso-no-proof:yes'>~<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

</div>

</body>

</html>

------_=_NextPart_001_01C1D1E4.8919B3EC--


From slyskawa@yahoo.com  Fri Mar 22 21:03:51 2002
From: slyskawa@yahoo.com (Steve)
Date: Fri, 22 Mar 2002 16:03:51 -0500
Subject: [Tutor] View pop3 commands/responses script
In-Reply-To: <E16fNz2-0001Hk-00@mail.python.org>
Message-ID: <E16oWDm-0004Ni-00@mail.python.org>

I am a beta tester for an email program.  I have a program which 
emulates a server that I use to manually test it.  I want to create 
a python script that will allow me to see what the mail program is 
sending to the pop3 server and to see the responses back from the 
server to the mail program.

I started the script and it is able to accept a call from the mail 
program.  I used server.py by Joe Strout as an example.  I am 
having problems connecting to the remote pop3 server.  I have no 
problem doing this using the poplib, but I never tried it using the 
socket library.  I suspect my problem is that I cannot use the bind 
command for a remote server.  Here is my script:

from socket import *
import string,time
local=socket(AF_INET,SOCK_STREAM)
local.bind(('127.0.0.1',110))
local.setblocking(0)
local.listen(1)
addr=0
while not addr:
   try:
      conn,addr=local.accept()
   except:
       pass
print 'ip,port ',conn,addr
conn.setblocking(0)
remote=socket(AF_INET,SOCK_STREAM)
remote.bind(('192.108.102.201',110))
remote.setblocking(0)
remote.listen(1)

count = 0
while count < 10:
    time.sleep(1)
    count=count+1
    try:
        data = conn.recv(1024)
        print data
    except:
        pass

local.close()

Here is my error:
ip,port  <socket._socketobject instance at 007F7714> 
('127.0.0.1',4719)
Traceback (most recent call last):
  File "D:\apps\Python\sjl\EmailServer.py", line 16, in ?
    remote.bind(('192.108.102.201',110))
  File "<string>", line 1, in bind
socket.error: (10049, "Can't assign requested address")


When I get this working, I want data to flow back and forth to the 
server and I want to either log stuff to a file or print on the 
console.  Any help would be appreciated.
-- 
Steve



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com



From garber@centralcatholic.org  Fri Mar 22 21:39:15 2002
From: garber@centralcatholic.org (Robert Garber)
Date: Fri, 22 Mar 2002 16:39:15 -0500
Subject: [Tutor] NEWBIE is it possible to use HTML and Python together?
Message-ID: <200203221639.AA171115128@centralcatholic.org>

I willbe adding that book to my collection also. that will bring me up to 5 now.

there is no web server involved with this little thing.  it will be strictly in his own machine.
am i correct in assuming the following steps:
1. set up a server on his machine with a python script?
2. then set up the HTML to look at the server
3. have the server execute the rolling dice script
4. have server report the results back to the HTML

next problem. Python is not instaled on his lap top. I there a way to do this with out putting the complete python 2.1 in his machine?

thanks for your help, this is starting to sound like a bigger project then I first thought. I thought it would be simple...he writes the HTML, I write the dice script, embed the python script ( like Java?) in to the HTML frame...and play.

thanks again for your help. I am leaving school right now. On my way home, I am buying a new book. Glad I saw this one at Media Play a week ago, know right where to go. this will bring my python collection to 5 ( the new Deitel & Deitel book, A. Gauld book, Python in 24 hours (YUCK), O'Riley/Mark Lutz book Learning python)ANymore that you would recomend, I should consider?

Thanks
Robert

---------- Original Message ----------------------------------
From: Kirby Urner <urnerk@qwest.net>
Date: Fri, 22 Mar 2002 09:22:34 -0800

>At 07:40 AM 3/22/2002 -0500, you wrote:
>>I there any way to set the python up to run on a client side.
>>I don think it's planned to run on the web, it's just his own
>>little game. is there away to use something like py2exe to
>>solve this?
>>
>>Thank you for your time in helping me solve this.
>>Robert
>
>Is there a web server in this picture at all -- even just
>a local one on the same machine as the client?  It's
>perfectly possible for a standalone machine not permanently
>connected to the internet with static, public IP to run a
>web server "facing inward" (i.e. to be a "host" and to
>"run a web server" are not the same thing).
>
>Perhaps your friend is using HTML to sort of mock up an
>interface, i.e. is using the browser as a front end for
>an app?  This is trendy, as various flavors of XML for
>GUI-design are popping up and programmers will be taking
>this approach quite a bit.
>
>However, without a server in the picture, web pages need
>something running client side to be dynamic.  Either that,
>or use Python to take the place of the missing server,
>i.e. you could write a tiny server in Python and point
>the browser to it.  This is easier than it sounds.
>However, you should make sure this code never handles
>HTTP requests originating outside your box.
>
>For example, put some html file (say thefile.html) in
>your Python root directory and enter the following two
>lines of code in IDLE.  Then point your browser to
>http://127.0.0.1/thefile.html and it should come up in
>your browser:
>
> >>> import SocketServer.CGIHTTPServer
> >>> SocketServer.ThreadingTCPServer(('127.0.0.1',80),\
>       CGIHTTPServer.CGIHTTPRequestHandler).serve_forever()
>
>You may need to kill your Python process from outside
>when you're done with this demo.
>
>A good resource here is 'The Python 2.1 Bible' Chapter 15,
>from where I copied the above.  From here, you can go on
>to write CGI handlers that handle requests.
>
>Kirby
>
>


From dyoo@hkn.eecs.berkeley.edu  Fri Mar 22 21:58:44 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 22 Mar 2002 13:58:44 -0800 (PST)
Subject: [Tutor] Database queries returning indexes rather than strings...
In-Reply-To: <AF020C5FC551DD43A4958A679EA16A15017B4045@abbott.lith.com>
Message-ID: <Pine.LNX.4.44.0203221351270.23874-100000@hkn.eecs.berkeley.edu>


On Fri, 22 Mar 2002, Israel Evans wrote:

>  I'm using the MySQLdb module recently mentioned here and I'm running
> into issues of trying to interpret the results of my queries.  It's
> seems after having made a connection and a cursor when I try to execute
> a query I get the answer to that query back as binary character or at
> least a Long integer or something.  It comes back to me a a number
> followed by an L.

Yes, this is telling us the number of rows that were either affected or
found by the execute().  To actually traverse through the results, we can
use the fetchone() or fetchall() method.  Here's a quicky interactive
session with MySQLdb:

###
>>> import MySQLdb
>>> conn = MySQLdb.connect(db='test')
>>> cursor = conn.cursor()
>>> cursor.execute("create table foobar (name varchar(20))")
0L
>>> cursor.execute("insert into foobar values ('evans')")
1L
>>> cursor.execute("insert into foobar values ('danny')")
1L
>>> cursor.execute("select * from foobar")
2L
>>> cursor.fetchone()
('evans',)
>>> cursor.fetchone()
('danny',)
>>> cursor.fetchone()
>>> cursor.execute("select * from foobar")
2L
>>> cursor.fetchall()
(('evans',), ('danny',))
##

That's basically it.  *grin* No, there's a little more to it, and you can
take a look at the Python/DB API 2.0 docs:

    http://www.python.org/topics/database/DatabaseAPI-2.0.html

for the details.  You might also want to look at amk's explanation of the
API itself:

    http://www.amk.ca/python/writing/DB-API.html



MySQLdb should also come with its own set of documentation and examples in
the source code; check the "docs" directory in the source directory, and
you should see it.


Please feel free to ask more questions.  Database stuff can be really
exciting when it starts working.  *grin* Good luck!



From hall@nhn.ou.edu  Fri Mar 22 21:54:12 2002
From: hall@nhn.ou.edu (Ike Hall)
Date: Fri, 22 Mar 2002 15:54:12 -0600
Subject: [Tutor] Making a large scale GUI interface run more efficently in TKinter/PMW
Message-ID: <200203222138.g2MLcT515850@phyast.nhn.ou.edu>

Hello all,
I have been on this list for some time now (although this is a new 
registration address because of email address problems...thanks for your 
assistance Danny!), and have gotten some rather useful tips and tricks that 
have helped my python programming through the months.  Thank you all for your 
help (either by answering my questions direclty, or by answering someone 
elses).  Anyway, I have a new question that has been keeping me awake at 
nights squirming in the darkness.

First, it should be noted that I am not really a programmer...I am a 
physicist (grad student really) who only really wants to write enough 
programs as to make my life computationally easier.

anyway, back to the real question....

I am writing a rather large scale GUI Monitoring client for a rather large 
experiment.  this client will take in quite a lot of information which is all 
designed to tell us if the an apparatus is working as it should or not, and 
if it is not, the information being brought in will tell us where the 
problems are.  So the idea is to display the information graphically, because 
much of what we receive are histograms, Circular buffers (displayed like pie 
charts), and many many other things too...so anyway, there are thousands of 
these objects, and they get received OK and seperated into their respective 
"Geographic" reigons, then passed on to the display where they are displayed 
based upon their "geographic origin"....(I know this is long winded, but I 
want to be as detailed as possible without sending the entire 7 files that 
contain this program)  so now these things are displayed in various levels of 
notebooks in a PMW frame (for those unfamiliar with PMW, its just like the 
tabs on some GUI applications)  so that we can find where problems are.

Now the problem:

We receive this information every 5 seconds.  Currently, with the program 
drawing everything that gets sent, and in the right place, just the drawing 
of stuff takes well over this 5 second interval.  Is there any way to speed 
this up....like maybe perhaps getting the total pictures drawn in memory 'on 
the fly'?? or maybe even only drawing to the page that is being viewed?? I 
dont know if either of these options are possible,much less how to implent 
them, so if any of you happen to know of possible solutions, I would be 
THRILLED to hear them.

Thank you all
Isaac (Ike) Hall
University of Oklahoma


From apython101@yahoo.com  Sat Mar 23 00:40:13 2002
From: apython101@yahoo.com (john public)
Date: Fri, 22 Mar 2002 16:40:13 -0800 (PST)
Subject: [Tutor] NEWBIE is it possible to use HTML and Python together?
In-Reply-To: <200203221639.AA171115128@centralcatholic.org>
Message-ID: <20020323004013.89014.qmail@web21109.mail.yahoo.com>

--0-72270782-1016844013=:87925
Content-Type: text/plain; charset=us-ascii


On my way home, I am buying a new book. Glad I saw this one at Media Play a week ago, know right where to go. this will bring my python collection to 5 ( the new Deitel & Deitel book, A. Gauld book, Python in 24 hours (YUCK), O'Riley/Mark Lutz book Learning python)ANymore that you would recomend, I should consider?
========================================================================================

http://www.ibiblio.org/obp/thinkCSpy/ How to think like a computer scientist  at the link to the left, Alan Gaulds book and Learning Python have been the three that have been working best for me.

 I like Richard Baldwins style  http://www.phrantic.com/scoop/tocpyth.htm the set is incomplete and I could'nt get some of the links to work right. He said that would be fixed soon. So maybe they are working now
Thanks
Robert

---------- Original Message ----------------------------------
From: Kirby Urner 
Date: Fri, 22 Mar 2002 09:22:34 -0800

>At 07:40 AM 3/22/2002 -0500, you wrote:
>>I there any way to set the python up to run on a client side.
>>I don think it's planned to run on the web, it's just his own
>>little game. is there away to use something like py2exe to
>>solve this?
>>
>>Thank you for your time in helping me solve this.
>>Robert
>
>Is there a web server in this picture at all -- even just
>a local one on the same machine as the client? It's
>perfectly possible for a standalone machine not permanently
>connected to the internet with static, public IP to run a
>web server "facing inward" (i.e. to be a "host" and to
>"run a web server" are not the same thing).
>
>Perhaps your friend is using HTML to sort of mock up an
>interface, i.e. is using the browser as a front end for
>an app? This is trendy, as various flavors of XML for
>GUI-design are popping up and programmers will be taking
>this approach quite a bit.
>
>However, without a server in the picture, web pages need
>something running client side to be dynamic. Either that,
>or use Python to take the place of the missing server,
>i.e. you could write a tiny server in Python and point
>the browser to it. This is easier than it sounds.
>However, you should make sure this code never handles
>HTTP requests originating outside your box.
>
>For example, put some html file (say thefile.html) in
>your Python root directory and enter the following two
>lines of code in IDLE. Then point your browser to
>http://127.0.0.1/thefile.html and it should come up in
>your browser:
>
> >>> import SocketServer.CGIHTTPServer
> >>> SocketServer.ThreadingTCPServer(('127.0.0.1',80),\
> CGIHTTPServer.CGIHTTPRequestHandler).serve_forever()
>
>You may need to kill your Python process from outside
>when you're done with this demo.
>
>A good resource here is 'The Python 2.1 Bible' Chapter 15,
>from where I copied the above. From here, you can go on
>to write CGI handlers that handle requests.
>
>Kirby
>
>

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



---------------------------------
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
--0-72270782-1016844013=:87925
Content-Type: text/html; charset=us-ascii

<BLOCKQUOTE style="BORDER-LEFT: #1010ff 2px solid; MARGIN-LEFT: 5px; PADDING-LEFT: 5px">
<P>On my way home, I am buying a new book. Glad I saw this one at Media Play a week ago, know right where to go. this will bring my python collection to 5 ( the new Deitel &amp; Deitel book, A. Gauld book, Python in 24 hours (YUCK), O'Riley/Mark Lutz book Learning python)ANymore that you would recomend, I should consider?<BR>========================================================================================</P>
<P><A href="http://www.ibiblio.org/obp/thinkCSpy/">http://www.ibiblio.org/obp/thinkCSpy/</A>&nbsp;How to think like a computer scientist&nbsp; at the link to the left, Alan Gaulds book and Learning Python have been the three that have been working best for me.</P>
<P>&nbsp;I like Richard Baldwins style  <A href="http://www.phrantic.com/scoop/tocpyth.htm">http://www.phrantic.com/scoop/tocpyth.htm</A>&nbsp;the set is incomplete and I could'nt get some of the links to work right. He said that would be fixed soon. So maybe they are working now<BR>Thanks<BR>Robert<BR><BR>---------- Original Message ----------------------------------<BR>From: Kirby Urner <URNERK@QWEST.NET><BR>Date: Fri, 22 Mar 2002 09:22:34 -0800<BR><BR>&gt;At 07:40 AM 3/22/2002 -0500, you wrote:<BR>&gt;&gt;I there any way to set the python up to run on a client side.<BR>&gt;&gt;I don think it's planned to run on the web, it's just his own<BR>&gt;&gt;little game. is there away to use something like py2exe to<BR>&gt;&gt;solve this?<BR>&gt;&gt;<BR>&gt;&gt;Thank you for your time in helping me solve this.<BR>&gt;&gt;Robert<BR>&gt;<BR>&gt;Is there a web server in this picture at all -- even just<BR>&gt;a local one on the same machine as the client? It's<BR>&gt;perfectly possible for a standalone machine not permanently<BR>&gt;connected to the internet with static, public IP to run a<BR>&gt;web server "facing inward" (i.e. to be a "host" and to<BR>&gt;"run a web server" are not the same thing).<BR>&gt;<BR>&gt;Perhaps your friend is using HTML to sort of mock up an<BR>&gt;interface, i.e. is using the browser as a front end for<BR>&gt;an app? This is trendy, as various flavors of XML for<BR>&gt;GUI-design are popping up and programmers will be taking<BR>&gt;this approach quite a bit.<BR>&gt;<BR>&gt;However, without a server in the picture, web pages need<BR>&gt;something running client side to be dynamic. Either that,<BR>&gt;or use Python to take the place of the missing server,<BR>&gt;i.e. you could write a tiny server in Python and point<BR>&gt;the browser to it. This is easier than it sounds.<BR>&gt;However, you should make sure this code never handles<BR>&gt;HTTP requests originating outside your box.<BR>&gt;<BR>&gt;For example, put some html file (say thefile.html) in<BR>&gt;your Python root directory and enter the following two<BR>&gt;lines of code in IDLE. Then point your browser to<BR>&gt;http://127.0.0.1/thefile.html and it should come up in<BR>&gt;your browser:<BR>&gt;<BR>&gt; &gt;&gt;&gt; import SocketServer.CGIHTTPServer<BR>&gt; &gt;&gt;&gt; SocketServer.ThreadingTCPServer(('127.0.0.1',80),\<BR>&gt; CGIHTTPServer.CGIHTTPRequestHandler).serve_forever()<BR>&gt;<BR>&gt;You may need to kill your Python process from outside<BR>&gt;when you're done with this demo.<BR>&gt;<BR>&gt;A good resource here is 'The Python 2.1 Bible' Chapter 15,<BR>&gt;from where I copied the above. From here, you can go on<BR>&gt;to write CGI handlers that handle requests.<BR>&gt;<BR>&gt;Kirby<BR>&gt;<BR>&gt;<BR><BR>_______________________________________________<BR>Tutor maillist - Tutor@python.org<BR>http://mail.python.org/mailman/listinfo/tutor</P></BLOCKQUOTE><p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href="$rd_url/tag/http://movies.yahoo.com/">Yahoo! Movies</a> - coverage of the 74th Academy Awards®
--0-72270782-1016844013=:87925--


From urnerk@qwest.net  Sat Mar 23 00:52:19 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Fri, 22 Mar 2002 16:52:19 -0800
Subject: [Tutor] NEWBIE is it possible to use HTML and Python
 together?
In-Reply-To: <200203221639.AA171115128@centralcatholic.org>
Message-ID: <4.2.0.58.20020322165107.01a26400@pop3.norton.antivirus>

>
>thanks for your help, this is starting to sound like a bigger project then 
>I first thought. I thought it would be simple...he writes the HTML, I 
>write the dice script, embed the python script ( like Java?) in to the 
>HTML frame...and play.

Jeff suggested a way to write client-side Python embedded in
the HTML, using win32all and/or ActiveState's distro.  I haven't
tested this way of doing things, but it sounds a lot closer to
what you want than using Python as a server.

Kirby



From wolf_binary@hotmail.com  Sat Mar 23 01:44:28 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Fri, 22 Mar 2002 19:44:28 -0600
Subject: [Tutor] a little debate I hear
Message-ID: <DAV7046Gjxoo5RgFzp2000078ba@hotmail.com>

This is a multi-part message in MIME format.

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

This is sort of a Python related subject in that it has to do with =
computing.

The dabate I here constantly is that mainframes and minicomputers are =
being replaced with servers.  Then I here it the other way saying that  =
servers can't beat the processing power of a mainframe or minicomputer.

My question is as a general poll to everyone in the IT fields; what is =
being used and what is your take on this subject? Is Python able to be =
used on say an AS 400 or some other type of major computing device?

Cameron Stoner

------=_NextPart_000_0007_01C1D1D9.FA7D2B20
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.2713.1100" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>This is sort of a Python related =
subject in that it=20
has to do with computing.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>The dabate I here constantly is that =
mainframes and=20
minicomputers are being replaced with servers.&nbsp; Then I here it the =
other=20
way saying that&nbsp; servers can't beat the processing power of a =
mainframe or=20
minicomputer.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>My question is as a general poll to =
everyone in the=20
IT fields; what is being used and what is your take on this subject? Is =
Python=20
able to be used on say an AS 400 or some other type of major computing=20
device?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Cameron =
Stoner</FONT></DIV></BODY></HTML>

------=_NextPart_000_0007_01C1D1D9.FA7D2B20--


From slyskawa@yahoo.com  Sat Mar 23 02:32:12 2002
From: slyskawa@yahoo.com (Steve)
Date: Fri, 22 Mar 2002 21:32:12 -0500
Subject: [Tutor] View pop3 commands/responses script - part II
Message-ID: <E16obLq-0007Mp-00@mail.python.org>

Okay, I figured out my problem, I was using bind instead of
connect.  Now I need a way to detect if the connection went away.
I could use some pointers on blocking versus non-blocking IO and
how I could use it to my advantage in my program.  Here is what I
have.

Thanks,
Steve
___________________________________________


from socket import *
import string,time
local=socket(AF_INET,SOCK_STREAM)
local.bind(('127.0.0.1',110))
local.setblocking(0)
local.listen(1)
addr=0
while not addr:
 try:
   conn,addr=local.accept()
 except:
   pass
print 'ip,port ',conn,addr
conn.setblocking(0)
remote=socket(AF_INET,SOCK_STREAM)
remote.connect(('popmail.com',110))
remote.setblocking(0)

count = 0
while 1:

  try:
    rdata=remote.recv(2048)
    print '<==  Data Received'
    print rdata
    conn.send(rdata)
  except:
    try:
     sdata=conn.recv(2048)
     print '==> Data sent'
     print sdata
     remote.send(sdata)
    except:
     time.sleep(1)
     pass


local.close()
remote.close()







_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com



From dyoo@hkn.eecs.berkeley.edu  Sat Mar 23 03:25:26 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 22 Mar 2002 19:25:26 -0800 (PST)
Subject: [Tutor] NameError spell checking, part three
Message-ID: <Pine.LNX.4.44.0203221912030.32582-100000@hkn.eecs.berkeley.edu>

Hi everyone,

I've cleaned up the presentation of the NameError spell checker a little
more, and now it should be much easier to use.  I've plageriz... er...
modelled its design from the 'cgitb' module.


Behold, the DebugSpelling module:

###
>>> import DebugSpelling
>>> DebugSpelling.enable()
>>> _builtins_
  File "<stdin>", line 1, in ?
NameError: name '_builtins_' is not defined.
Perhaps you meant one of the following: '__builtins__'
###


I've placed the code on ChalkBoard at the moment:

    http://www.decrem.com:8080/ChalkBoard/1016858358/index_html

Who wants to polish it up to add support for AttributeErrors?  *grin*
Perhaps, with some work, the Tutor mailing list can submit DebugSpelling
as a standard Python module.


This was a fun miniproject.  I hope this helps!



From dsh8290@rit.edu  Sat Mar 23 06:11:36 2002
From: dsh8290@rit.edu (dman)
Date: Sat, 23 Mar 2002 00:11:36 -0600
Subject: [Tutor] python and MS Access db's
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C47A@mbtlipnt02.btlabs.bt.co.uk>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C47A@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20020323061136.GB13386@dman.ddts.net>

On Thu, Mar 21, 2002 at 01:26:32PM +0000, alan.gauld@bt.com wrote:
| > On Wednesday, March 20, 2002, at 01:34  PM, dman wrote:
| > > MS' ODBC driver to connect to the db, and then use either XML-RPC or
| > > CORBA to connect to that server from the linux box.
| > 
| > if you don't mind my asking, why you are planning to 
| > use XML-RPC over SOAP.
| 
| I should imagine because its a lot simpler to use - especially 
| from Python.

That's why I was considering XML-RPC at all.  Unfortunately it seems
that it is too simple for the task I have.

| I haven't seen a really easy to use SOAP solution for Python 

The few examples I came across so far look less location and access
transparent than I want.

| but the XML-RPC stuff(now standard from v2.2?) is simplicity itself.
| 
| Speaking for dman so I might be completely wrong! :-)
| 
| Alan g
| [ Who hates XML as a transport since its horribly 
|   inefficient of bandwidth...but recognises that 
|   he's(as usual) in a minority of one! ;-]

I don't really care what the transport is as long as it works.  To me
XML is mostly just a new (or not so new) buzzword, though it does have
some merits for *some* tasks.

-D

-- 

The teaching of the wise is a fountain of life,
turning a man from the snares of death.
        Proverbs 13:14



From budgester@budgester.com  Sat Mar 23 09:48:06 2002
From: budgester@budgester.com (Martin Stevens)
Date: Sat, 23 Mar 2002 09:48:06 +0000
Subject: [Tutor] a little debate I hear
In-Reply-To: <DAV7046Gjxoo5RgFzp2000078ba@hotmail.com>
References: <DAV7046Gjxoo5RgFzp2000078ba@hotmail.com>
Message-ID: <20020323094806.GA10742@akira.budgenet>

On Fri, Mar 22, 2002 at 07:44:28PM -0600, Cameron Stoner wrote:
> This is sort of a Python related subject in that it has to do with computing.
> 
> The dabate I here constantly is that mainframes and minicomputers are being replaced with servers.  Then I here it the other way saying that  servers can't beat the processing power of a mainframe or minicomputer.
> 
> My question is as a general poll to everyone in the IT fields; what is being used and what is your take on this subject? Is Python able to be used on say an AS 400 or some other type of major computing device?


Well, if you can run linux on the IBM big iron, which you can, and you can run python on Linux, i think you have an answer. :-)


From dyoo@hkn.eecs.berkeley.edu  Sat Mar 23 10:15:39 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sat, 23 Mar 2002 02:15:39 -0800 (PST)
Subject: [Tutor] Use of a global variable in many scripts
In-Reply-To: <OF975C575C.49D45E9E-ON85256B84.004C374E@raleigh.ibm.com>
Message-ID: <Pine.LNX.4.44.0203230157530.6606-100000@hkn.eecs.berkeley.edu>


On Fri, 22 Mar 2002, Aldo Duran wrote:

> Hello everyone
>
> I am new to python and I have some questions, here is my first.
>
> I have a set of scripts, and I would like to use a variable being set in
> the main program and use in all the others scripts. I have a file1.py
> which defines global variabel var1 and then I import file2.py, I tryed
> to use the variable from file2.py, but I get the exception
>
> Traceback (most recent call last):
>   File "/tivoli/homes/4/aduran/bin/py/file1.py", line 7, in ?
>     file2.useVar1()
>   File "/tivoli/homes/4/aduran/bin/py/file2.py", line 6, in useVar1
>     print var1
> NameError: global name 'var1' is not defined
>
> How can I use the same global variables in all my scripts?

Hi Aldo,

If we imported by doing something like:

###
import file1
###

that does give us access to the 'var1' variable, but we still need to name
the package that we're reading from:

###
print file1.var1
###



If we'd like to copy over a variable from the other module, we can do
something like

###
var1 = file1.var1
###


And to save some effort, there's a specialized way of pulling variables
'from' modules:

###
from file1 import var1
###




> I know that using global variables is not a very good practice but
> sometimes it is easy, convenient, quick and simple.

Agreed... but we still recommend not doing it.  *grin* At least, not in a
widespread way.  It may be possible to do what you're trying to do in a
more direct fashion, without using global variables to communicate between
functions or modules.



> file1.py
> -------------------------------------------------
> #!/usr/bin/env python2.2
>
> global var1
> var1 = 1
> import file2
>
> file2.useVar1()
>
> file2.py
> -------------------------------------------------
> #!/usr/bin/env python2.2
>
> global var1
>
> def useVar1():
>     print "var1 value == " ,var1


To get the variable 'var1' so that file2 can access it, you can do
something like this at the beginning of file2:

###
from file1 import var1
###


But in this particulal case, it might be better to have file2 show that
it's actually grabbing the value from file1:

###
import file1
def usevar1():
    print "var1 value ==", file1.var1
###

just so that someone who is reading the code understands where var1 is
coming from.



You're still learning and experimenting, so we shouldn't pound the "global
variables are evil!" mantra too much... at least, not yet.  *grin*


Good luck to you!



From pythontutor@venix.com  Sat Mar 23 13:35:26 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Sat, 23 Mar 2002 08:35:26 -0500
Subject: [Tutor] a little debate I hear
References: <DAV7046Gjxoo5RgFzp2000078ba@hotmail.com>
Message-ID: <3C9C849E.50406@venix.com>

Unfortunately, many of the terms used here have acquired spin from
marketing departments.  They are not defined well enough to really
debate them.

With the collapse of Prime, DEC, Data General, Wang (and others?) ten
years ago, I am not sure there is still much point in trying to
distinguish minicomputers as a class of computers.


Cameron Stoner wrote:

> This is sort of a Python related subject in that it has to do with 
> computing.
> 
>  
> 
> The dabate I here constantly is that mainframes and minicomputers are 
> being replaced with servers.  Then I here it the other way saying that  
> servers can't beat the processing power of a mainframe or minicomputer.
> 
>  
> 
> My question is as a general poll to everyone in the IT fields; what is 
> being used and what is your take on this subject? Is Python able to be 
> used on say an AS 400 or some other type of major computing device?
> 
>  
> 
> Cameron Stoner
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582



From mikalzet@libero.it  Sat Mar 23 13:47:52 2002
From: mikalzet@libero.it (mikalzet@libero.it)
Date: Sat, 23 Mar 2002 14:47:52 +0100 (CET)
Subject: [Tutor] learning Tkinter
Message-ID: <Pine.LNX.4.33L2.0203231416010.2308-100000@localhost.localdomain>

So, every couple of weeks or so I find an odd hour for python and I keep
on imagining how my python-shift program could be.

Lately I've been trying to face tkinter, but I'm finding it far harder
than anything else, probably not because it is complicated in itself but
because I'm not finding the type of documentation I'd like.
In fact, seems like tkinter is almost a different language.
On line references pore for pages and pages over dozens of options for
each possible widget ... which is something I would like to face after
having understood how these tie in with the rest of a program.
Being a complete beginner I would like a tutorial to explain WHY things
have to be written in a certain way.
In fact the only useful type of thing I've found so far is Alan Gauld's
chapters on event driven programming and GUI programming with tkinter.
Even he is still too obscure for REAL beginners with GENUINE brick heads
like me; for instance he has this code:

class KeysApp(Frame):
# all right, I create a new class which inherits from class Frame
	def __init__(self):
# why not just def __init__(): or def __init__(other): ?
	self.txtBox=Text(self)
# I create an instance of Text widget which I call txtBox
# 'self' again appears twice - I could memorize this and accept it
# as an article of faith but I would really prefer to understand what
# it means
	self.txtBox.bind("<space>", self.doQuitEvent)
# bind is a method which takes two parameters ? I suppose documentation on
# bind will explain this somewhere - but if the example explained it would
# be easier
	etc. etc.

Anybody know of any resource like 'explaining tkinter to elementary school
children' ?

-- 
Michele Alzetta



From erikprice@mac.com  Sat Mar 23 17:16:15 2002
From: erikprice@mac.com (Erik Price)
Date: Sat, 23 Mar 2002 12:16:15 -0500
Subject: now OT:  Re: [Tutor] cookies
In-Reply-To: <20020322175701.53866.qmail@web21110.mail.yahoo.com>
Message-ID: <AEB850D2-3E81-11D6-A840-00039351FE6A@mac.com>

This thread has practically nothing to do with Python.



On Friday, March 22, 2002, at 12:57  PM, john public wrote:

> =A0I was under the impression that cookies told a web page =
administrator=20
> which web page you last visited and if you had been to their web page=20=

> before and which parts of their web page you visited ect.

Well, technically this is true.  But let me explain a bit.  First of=20
all, when you request a new web page, you send along with this request a=20=

number of "invisible" headers that help the receiving web server=20
understand a bit more about how to help you.  Some of the things that=20
get sent are the user agent you are using (your web browser type and=20
version), the IP address from which you are making the request, and the=20=

web page which "referred" you to this page (in other words, the web page=20=

that you most recently visited).  Some of these headers are standard=20
part of the HTTP protocol, and are required, others are sent at the=20
discretion of the user agent.  Normally you don't see these headers, but=20=

using scripting languages like JavaScript, PHP, and probably Python, you=20=

could probably test to see them yourself if you have a web server at=20
your disposal.  So right off the bat, you're not really as "secure" as=20=

you think you are, with or without cookies.

A cookie is simply a chunk of information stored on your computer.  The=20=

"rules" of how cookies behave work in such fashion that a cookie can=20
only give this information to the site that placed the cookie.  So if=20
you received or accepted a cookie from yahoo.com, the next time you=20
access a page at yahoo.com, the name and value of the variable stored in=20=

the cookie is sent along with your request.  This information doesn't go=20=

out to aol.com or lycos.com when you request pages from these sites, but=20=

if you have cookies from aol.com or lycos.com, then they do.  The only=20=

information that gets sent in a cookie is the information that was set=20=

there by the web site which placed the cookie.  In other words, if you=20=

go to my site and accept a cookie, and I have placed the name/value pair=20=

"user_id=3D88787" into that cookie, then the next time you visit my =
site,=20
you will also send the name/value pair "user_id=3D88787".  Nothing more. =
=20
So the only information I see is the information that I put there,=20
unless you have deliberately changed the contents of the cookie files on=20=

your system (and you have to know what you're doing to do that).

The privacy concerns about cookies are really that one company (ahem,=20
DoubleClick?) will track so many hundreds of thousands of cookies=20
amongst users.  DoubleClick can't track your yahoo.com cookies or your=20=

aol.com cookies, but they can track the doubleclick.com cookies.  And if=20=

DoubleClick is a business partner of Yahoo!, then a Yahoo! site can be=20=

programmed to set doubleclick.com cookies.  If all the sites on the=20
internet were setting doubleclick.com cookies, then yes, obviously=20
DoubleClick can keep track of where you are going when and how, simply=20=

by giving you a unique number and watching for this unique number to pop=20=

up wherever you request web pages.

In reality, it's not as bad as that.  It's very difficult for=20
DoubleClick and other browser-watching companies to know who you are. =20=

These companies really track trends more than individual users, though=20=

this is still a privacy concern (sort of like unknowingly filling out=20
marketing surveys).  But it's not like they're really watching John Q=20
Public whenever he turns on his computer.

What I do is set my browser to ask me if I want to accept each cookie=20
that comes my way.  There are so many cookies that get sent, so=20
fortunately MS IE 5.1 for Mac lets you say "all cookies from this site"=20=

or "no cookies from that site" -- so if yahoo.com sends me 3 cookies I=20=

don't have to be bothered 3 times.  But if a Yahoo site tries to give me=20=

3 yahoo cookies and a DoubleClick cookie, a separate box will come up to=20=

ask me if I want to accept the cookie.  As a rule of thumb, I accept=20
cookies from most sites that I intend to frequent, and sites that I=20
don't expect to return to I reject.  And I always reject a cookie that=20=

is sent to me from a domain that does not match the one from which I am=20=

requesting the document.  In other words, if I am at www.devshed.com,=20
and devshed.com tries to give me a cookie, I accept it, but when=20
mediaplex.com tries to send me a cookie at the same time, I reject it. =20=

It's probably just a marketing cookie, not a "helpful" one for=20
remembering my preferences and interests at DevShed.

Hope this clears up any concerns you may have about the power of =
cookies.

> I know that the Yahoo web site remebers which news stories I have read=20=

> ect. I would just as soon be nameless, just out of principal.

Me too, unless I have preferences stored with that site.  For instance,=20=

at SlashDot it's easier for me to accept the cookie so I don't have to=20=

reconfigure the setup each time I go there or log in each time I want to=20=

post.  But for msnbc.com I never accept cookies, because I hardly go=20
there or am just there to read an article.

> I have read about cookies in an online computer dictionary but it=20
> really did not talk about how they could be used to watch what you do=20=

> online.

That's the problem -- there's a lot of hype.

> I am under the impression that if I visit a web page if it has the=20
> appropriate software it can get my e-mail address.

If you have given this site your email address in the past, and you=20
accept an identification string in a cookie, then when you go back to=20
the site, they will know who you are and be able to match the=20
identification string to your email address.  But cookies can't actually=20=

get your email address from your mail client and send it to the site=20
(though I wouldn't put it past MS Outlook, MS IE, and MS Windows working=20=

in conjunction to provide a "convenience" like this on your behalf,=20
without clearly documenting it or providing an "opt-in"*).

* Why the anti-MS bent?  Here's an instance of invasion of privacy: =20
http://www.glassdog.com/smarttags/

> I see people on rent a coder asking for this kind of software to be=20
> written. I really did not have anything specific in mind. I know I =
need=20
> to understand cookies and spyware in general and wanted to see some=20
> cookie code in Python if it existed.

Most of the time your browser (even MS IE) lets you manipulate the=20
cookies directly -- you can delete them, accept them, reject them,=20
whichever.  Actually, I have heard that MS IE 6 is incredibly strict in=20=

what it allows and does not allow, but I have no experience with it=20
myself.  (Is it true that you can't request plaintext *.css documents in=20=

MS IE 6 on Windows?  I had heard this....)

> You awnsered my most important question. That switching to Linux will=20=

> improve my control over everything. I am getting a new computer soon=20=

> and will install Linux on it. Doe! s Linux come with a browser?

Linux comes with so much software, you will probably never actually buy=20=

any software for it.  Ever.

Admittedly, it doesn't have MS Word or Excel, or most of the games that=20=

a PC has available to it, but it has its own word processing and=20
spreadsheet programs which are 90% as good in most cases, or better in=20=

others.  There are some games available for it.  It comes with its own=20=

browsers, in fact thousands of programs are available for free on Linux,=20=

and none of them are pirated... they're just free, like Python. =20
(Actually, Python comes with almost every Linux distribution I've ever=20=

heard of.)  There's a price to pay in that you have to learn more about=20=

how your computer works, because there isn't a lot of software that=20
"does it for you".  For instance, you will find it helpful to learn how=20=

software is compiled from source code -- it's as easy as three simple=20
commands in most cases (like Python).  But in the end you'll be so much=20=

richer for having this knowledge, and it's not hard to come by -- there=20=

are hundreds of thousands of Linux users on the web, with thousands of=20=

web pages devoted to the subject of open source software like Linux. =20
Learning isn't going to be hard, just be willing.

Erik

PS: feel free to contact me offlist if you have further questions in=20
this direction.



From alan.gauld@bt.com  Sat Mar 23 22:14:44 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sat, 23 Mar 2002 22:14:44 -0000
Subject: [Tutor] python and MS Access db's
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C48C@mbtlipnt02.btlabs.bt.co.uk>

> > If the answer to both is no then consider a dedicated
> > client/server solution using raw sockets - it will perform
> ... it sounds like there are alternatives.  "raw socket"?  I haven't 
> heard of those.  The only sockets I am familiar with are network 
> sockets -- the sort that work like this
> 
> = socket listens at port 80 or whichever
> = request comes along
> = socket daemon spawns a new socket for the request and redirects the 
> request to the new socket
> = client and server do their business on new socket, 

Yes thats what i meant by a raw socket type approach. In opther words 
not using a pre canned protocol like http/CGI

You can use any port(non standard) for the listener. And the messages 
can be any string you define thus for a bespoke application you can 
define your own protocol using specific requests with specific 
parameters etc. This is usually much more efficient that trying to use 
http/GET or POST type requiests, especially since you can hold the 
connection open for as long as you need so don't need to keep 
posting the context.

> envisioning how programs that are not stateless 

THis is one of the biggest gains. Sending state with each request
(or reassembling it from cache) is a real performance hit. If you 
just think of it as a dialogue between two objects conducted 
using strings its pretty easy. Typically you use a fixed length 
first field to identify the message then the server application
uses an event loop type approach:

msg = rec_str[:3]  # assume 3 char msg ID
if msg == "CHK":  # check balance
    return checkBalance(msg[3:])  # knows how to unpack the params
elif msg == "ADD":  # add to balance
    return addSum(msg[3:])
elif msg == "SUB":
	...etc...
else: return "ERR:unknown message"

Some people would have you believe that passing message parameters 
is an enormously difficult task and call it marshalling coz it 
sounds good. But for simmple apps it doesn't need to be more 
complicated than an agreed set of string formatting conventions.

Of course you can use the struct module and send binary values 
but IMHO thats too complicated anda sign you've reached the stage 
where you need CORBA or something else more industrial strength...

Alan g.


From cheshire_cat_sf@yahoo.com  Sun Mar 24 00:08:28 2002
From: cheshire_cat_sf@yahoo.com (Britt Green)
Date: Sat, 23 Mar 2002 16:08:28 -0800 (PST)
Subject: [Tutor] Saving a dictionary to a text file
In-Reply-To: <E16ootx-00011B-00@mail.python.org>
Message-ID: <20020324000828.99747.qmail@web14102.mail.yahoo.com>

I'm wondering how one goes about saving a dictionary as part of a text
file. This is how I've been trying to do it, and the error message that
I'm getting:

>>> mydict = {'foo' : 1, 'bar' : 2}
>>> f = open ('mydict.txt', 'w')
>>> f.write(mydict)
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in ?
    f.write(mydict)
TypeError: argument 1 must be string or read-only character buffer, not
dict
>>> 

Any help is greatly appreciated!

Britt

=====
"The ocean, she is strange and wondrous, filled with animals that disturb even a Frenchman."

__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
http://movies.yahoo.com/


From sheila@thinkspot.net  Sun Mar 24 00:30:47 2002
From: sheila@thinkspot.net (Sheila King)
Date: Sat, 23 Mar 2002 16:30:47 -0800
Subject: [Tutor] Saving a dictionary to a text file
In-Reply-To: <20020324000828.99747.qmail@web14102.mail.yahoo.com>
References: <E16ootx-00011B-00@mail.python.org> <20020324000828.99747.qmail@web14102.mail.yahoo.com>
Message-ID: <84CFA5227D@kserver.org>

On Sat, 23 Mar 2002 16:08:28 -0800 (PST), Britt Green
<cheshire_cat_sf@yahoo.com>  wrote about [Tutor] Saving a dictionary to a
text file:

> I'm wondering how one goes about saving a dictionary as part of a text
> file. This is how I've been trying to do it, and the error message that
> I'm getting:
> 
> >>> mydict = {'foo' : 1, 'bar' : 2}
> >>> f = open ('mydict.txt', 'w')
> >>> f.write(mydict)
> Traceback (most recent call last):
>   File "<pyshell#2>", line 1, in ?
>     f.write(mydict)
> TypeError: argument 1 must be string or read-only character buffer, not
> dict
> >>> 


Hopefully, these examples will help:

Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> mydict = {'foo' : 1, 'bar' : 2}
>>> f = open ('mydict.txt', 'w')
>>> f.write(str(mydict))
>>> f.close()
>>> g = open('mydict.txt', 'r')
>>> g.read()
"{'foo': 1, 'bar': 2}"
>>> g.close()
>>> h = open('mydict.txt', 'r')
>>> newdict = eval(h.read())
>>> newdict
{'foo': 1, 'bar': 2}
>>> 

If you still have questions, ask again.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/




From glingl@aon.at  Sun Mar 24 06:38:22 2002
From: glingl@aon.at (Gregor Lingl)
Date: Sun, 24 Mar 2002 07:38:22 +0100
Subject: [Tutor] learning Tkinter
References: <Pine.LNX.4.33L2.0203231416010.2308-100000@localhost.localdomain>
Message-ID: <002301c1d2fe$7effbd20$1664a8c0@mega>

----- Original Message -----
From: <mikalzet@libero.it>
To: <tutor@python.org>
Sent: Saturday, March 23, 2002 2:47 PM
Subject: [Tutor] learning Tkinter


>
> So, every couple of weeks or so I find an odd hour for python and I keep
> on imagining how my python-shift program could be.
>
> Lately I've been trying to face tkinter, but I'm finding it far harder
> than anything else, probably not because it is complicated in itself but
> because I'm not finding the type of documentation I'd like.

It's also my opinion, that this is seriously missing

> In fact, seems like tkinter is almost a different language.

Yes, it is (under the hood)

> On line references pore for pages and pages over dozens of options for
> each possible widget ... which is something I would like to face after
> having understood how these tie in with the rest of a program.
> Being a complete beginner I would like a tutorial to explain WHY things
> have to be written in a certain way.
> In fact the only useful type of thing I've found so far is Alan Gauld's
> chapters on event driven programming and GUI programming with tkinter.
> Even he is still too obscure for REAL beginners with GENUINE brick heads
> like me; for instance he has this code:
>
> class KeysApp(Frame):
> # all right, I create a new class which inherits from class Frame
> def __init__(self):
> # why not just def __init__(): or def __init__(other): ?
> self.txtBox=Text(self)
> # I create an instance of Text widget which I call txtBox
> # 'self' again appears twice - I could memorize this and accept it
> # as an article of faith but I would really prefer to understand what
> # it means

Nevertheless your self - problem is an issue of of object-oriented
programming and how it is done in Python (and not an issue of Tkinter
proper). To learn about this you could (and should) consult Alan Gauld's
Chapter on OOP:
http://www.freenetpages.co.uk/hp/alan.gauld/tutclass.html

> self.txtBox.bind("<space>", self.doQuitEvent)
> # bind is a method which takes two parameters ? I suppose documentation on
> # bind will explain this somewhere - but if the example explained it would
> # be easier
> etc. etc.
>

Resources on how to use Tkinter you can find at
http://www.python.org/topics/tkinter/doc.html and
specifically at
http://www.pythonware.com/library/tkinter/introduction/index.htm
although this might not be at the introductory level you
are looking for.

The chapter on binding events is here:

http://www.pythonware.com/library/tkinter/introduction/events-and-bindings.h
tm

You can download this in pdf-format at http://www.pythonware.com/library/

Hope this helps

Gregor

> Anybody know of any resource like 'explaining tkinter to elementary school
> children' ?
>
> --
> Michele Alzetta
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



From sheila@thinkspot.net  Sun Mar 24 06:41:56 2002
From: sheila@thinkspot.net (Sheila King)
Date: Sat, 23 Mar 2002 22:41:56 -0800
Subject: [Tutor] learning Tkinter
In-Reply-To: <Pine.LNX.4.33L2.0203231416010.2308-100000@localhost.localdomain>
References: <Pine.LNX.4.33L2.0203231416010.2308-100000@localhost.localdomain>
Message-ID: <1D8945E2367@kserver.org>

On Sat, 23 Mar 2002 14:47:52 +0100 (CET), <mikalzet@libero.it>  wrote about
[Tutor] learning Tkinter:

> Lately I've been trying to face tkinter, but I'm finding it far harder
> than anything else, probably not because it is complicated in itself but
> because I'm not finding the type of documentation I'd like.
> In fact, seems like tkinter is almost a different language.
> On line references pore for pages and pages over dozens of options for
> each possible widget ... which is something I would like to face after
> having understood how these tie in with the rest of a program.
> Being a complete beginner I would like a tutorial to explain WHY things
> have to be written in a certain way.
> In fact the only useful type of thing I've found so far is Alan Gauld's
> chapters on event driven programming and GUI programming with tkinter.

The most useful thing I found on using Tkinter, believe it or not, was
Programming Python, 2nd Ed. by Mark Lutz. It has several chapters in the
middle of the tome that delve extensively into Tkinter. It is not a
reference, by any means. Not short, sweet and to the point. But goes into
great detail, explains every line and nuance.

I highly recommend the book, especially if you want to learn Tkinter. It
also has a lot of other good stuff, too. It's not a book for Python
beginners, really, but the Tkinter stuff is the best I found. If you're
ready to learn Tkinter, then you're ready for at least the Tkinter chapters
of Programming Python.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/



From TwIsTeRmEtAl4@aol.com  Sun Mar 24 16:41:37 2002
From: TwIsTeRmEtAl4@aol.com (TwIsTeRmEtAl4@aol.com)
Date: Sun, 24 Mar 2002 11:41:37 EST
Subject: [Tutor] Re: Welcome to the "Tutor" mailing list
Message-ID: <197.4400bb7.29cf5bc1@aol.com>

--part1_197.4400bb7.29cf5bc1_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

how can you learn to hack into other coumputers

--part1_197.4400bb7.29cf5bc1_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

<HTML><FONT FACE=arial,helvetica><FONT  SIZE=2 FAMILY="SCRIPT" FACE="Comic Sans MS" LANG="0">how can you learn to hack into other coumputers</FONT></HTML>

--part1_197.4400bb7.29cf5bc1_boundary--


From TwIsTeRmEtAl4@aol.com  Sun Mar 24 16:42:38 2002
From: TwIsTeRmEtAl4@aol.com (TwIsTeRmEtAl4@aol.com)
Date: Sun, 24 Mar 2002 11:42:38 EST
Subject: [Tutor] Re: Welcome to the "Tutor" mailing list
Message-ID: <98.2341f1ad.29cf5bfe@aol.com>

--part1_98.2341f1ad.29cf5bfe_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

twistermetal4@aol.com


--part1_98.2341f1ad.29cf5bfe_boundary
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

<HTML><FONT FACE=arial,helvetica><FONT  COLOR="#ff0080" SIZE=2 FAMILY="SCRIPT" FACE="Comic Sans MS" LANG="0">twistermetal4@aol.com
<BR></FONT></HTML>

--part1_98.2341f1ad.29cf5bfe_boundary--


From charlie@begeistert.org  Sun Mar 24 17:16:45 2002
From: charlie@begeistert.org (Charlie Clark)
Date: Sun, 24 Mar 2002 18:16:45 +0100
Subject: [Tutor] Re: Saving a dictionary to a text file
In-Reply-To: <E16pBMn-0006VM-00@mail.python.org>
References: <E16pBMn-0006VM-00@mail.python.org>
Message-ID: <20020324182339.1411.3@gormenghast.AUTODIAL>

On 2002-03-24 at 18:01:13 [+0100], tutor-request@python.org wrote:
> Hopefully, these examples will help:
> 
> Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 
> Type "copyright", "credits" or "license" for more information. IDLE 0.8 
> -- press F1 for help
> >>> mydict = {'foo' : 1, 'bar' : 2}
> >>> f = open ('mydict.txt', 'w')
> >>> f.write(str(mydict))
> >>> f.close()
> >>> g = open('mydict.txt', 'r')
> >>> g.read()
> "{'foo': 1, 'bar': 2}"
> >>> g.close()
> >>> h = open('mydict.txt', 'r')
> >>> newdict = eval(h.read())
> >>> newdict
> {'foo': 1, 'bar': 2}
> >>> 

> If you still have questions, ask again

using eval could cause problems as the text could have been manipulated so that instead of 
{'foo': 1, 'bar': 2}
you have
'do something very nasty to python' 
like
'os.system("rm *")'
Please don't try this!!! I'm not sure if it would work but it should show the possible dangers.

the pickle module (import pickle)
allows you to pickle anything in a file just like you would pickle onions or eggs or beetroots. You can then unpickle it and be sure to get back what you put in and they taste just as fresh too.

But those smart Pythoneers have come up with something even better for those wanting to store dictionaries - the shelve module (import shelve). When you use shelve you have, to most intents and purposes, a dictionary which is stored directly in a file.

Charlie


From kojo@hal-pc.org  Sun Mar 24 18:00:46 2002
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Sun, 24 Mar 2002 12:00:46 -0600
Subject: [Tutor] Re: Welcome to the "Tutor" mailing list
In-Reply-To: <197.4400bb7.29cf5bc1@aol.com>
Message-ID: <5.1.0.14.0.20020324120004.01fde6f0@Pop3.norton.antivirus>

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

Read this:
<http://www.tuxedo.org/~esr/faqs/hacker-howto.html>

It will give you the information you need.

At 11:41 AM 3/24/2002 -0500, TwIsTeRmEtAl4@aol.com wrote:
>how can you learn to hack into other coumputers

****************************
Kojo Idrissa

kojo@hal-pc.org
http://www.hal-pc.org/~kojo/
****************************
--=====================_857653==_.ALT
Content-Type: text/html; charset="us-ascii"

<html>
Read this:<br>
&lt;<a href="http://www.tuxedo.org/~esr/faqs/hacker-howto.html" eudora="autourl">http://www.tuxedo.org/~esr/faqs/hacker-howto.html</a>&gt;<br><br>
It will give you the information you need.<br><br>
At 11:41 AM 3/24/2002 -0500, TwIsTeRmEtAl4@aol.com wrote:<br>
<blockquote type=cite class=cite cite><font face="Comic Sans MS" size=2>how
can you learn to hack into other coumputers</font><font face="arial">
</blockquote>
<x-sigsep><p></x-sigsep>
**************************** <br>
Kojo Idrissa <br>
&nbsp; <br>
kojo@hal-pc.org<br>
<a href="http://www.hal-pc.org/~kojo/" eudora="autourl">http://www.hal-pc.org/~kojo/<br>
</a>****************************</font></html>

--=====================_857653==_.ALT--



From nicole.seitz@urz.uni-hd.de  Sun Mar 24 20:39:18 2002
From: nicole.seitz@urz.uni-hd.de (Nicole Seitz)
Date: Sun, 24 Mar 2002 21:39:18 +0100
Subject: [Tutor] Extracting words..
Message-ID: <02032421391800.00703@utopia>

Hi there!

I'm trying to write a little script that extracts word creations like 
"StarOffice","CompuServe","PalmPilot",etc. from an text file.

import re; import string

reg = re.compile(r"\b[A-Z][a-z]+[A-Z][a-z]+\b")

file = open("heise_klein.txt")

txt = file.read()
result = reg.findall(txt)


-->returns a list containing such words, e.g.

['JavaScript', 'MacWeek', 'MacWeek', 'CompuServe', 'CompuServe', 
'CompuServe', 'CompuServe', 'CompuServe', 'SysOps', 'SysOps', 'CompuServe', 
'CompuServe', 'CompuServe', 'InterBus', 'NeuroVisionen', 'NeuroVisionen', 
'InterBus']

My first question:

What do I have to do that each word appears only once in the list,i.e. is 
found only once??

Second question:

I might want to have an output like that:

line 3: StarOffice
line34: CompuServe
line 42: PalmPilot

Would I then have to use match() or search() or whatever instead of findall- 
scan the file line per line (file.readline() )??

Thanx in advance!

Nicole


From dsh8290@rit.edu  Sun Mar 24 20:42:47 2002
From: dsh8290@rit.edu (dman)
Date: Sun, 24 Mar 2002 14:42:47 -0600
Subject: [Tutor] Threading in Python
In-Reply-To: <NEBBJNMDEKBIBCMCNMBDOELNDGAA.karthikg@aztec.soft.net>
References: <LNBBLJKPBEHFEDALKOLCGELAOGAA.tim.one@comcast.net> <NEBBJNMDEKBIBCMCNMBDOELNDGAA.karthikg@aztec.soft.net>
Message-ID: <20020324204247.GA10420@dman.ddts.net>

On Fri, Mar 22, 2002 at 01:10:32PM +0530, Karthik Gurumurthy wrote:
| what is the basic difference in threading model of say java and python?
| i ask this because i find all the method names in the library to be very
| similar.

synchronized ( <name> ) 
{
    <code block>
}


The key differences are :
    o   Python doesn't have a 'synchronized' keyword
    o   each object in python does not have an implicit "lock" object
            associated with it

Thus the locking is all done "manually" via a method call.  The above
Java looks like this in python :

<name> = threading.Lock()
<name>.acquire()
<code block>
<name>.release()


Of course, "<name>" is a placeholder for an identifier and
"<code block>" is a placeholder for a block (or snippet) of code.

-D

-- 

A)bort, R)etry, B)ang it with a large hammer



From dyoo@hkn.eecs.berkeley.edu  Sun Mar 24 20:52:19 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 24 Mar 2002 12:52:19 -0800 (PST)
Subject: [Tutor] learning Tkinter
In-Reply-To: <Pine.LNX.4.33L2.0203231416010.2308-100000@localhost.localdomain>
Message-ID: <Pine.LNX.4.44.0203231116200.12089-100000@hkn.eecs.berkeley.edu>


On Sat, 23 Mar 2002 mikalzet@libero.it wrote:

> Being a complete beginner I would like a tutorial to explain WHY things
> have to be written in a certain way.

When we write Tkinter programs, we often use object oriented programming
concepts; if you haven't played around with classes too much yet, Tkinter
will look somewhat foreign.


> class KeysApp(Frame):
> # all right, I create a new class which inherits from class Frame
> 	def __init__(self):
> # why not just def __init__(): or def __init__(other): ?


'def __init__(other)' will work; it's just an arbitrary convention that we
name the instance 'self'.  Yes, we can use 'other', although it will be a
quite shocking to people.  Sorta like saying "thee" instead of "me".
*grin*


However, 'def __init__()' without giving an argument wouldn't be so
useful: the point of an __init__ function is to initialize an instance ---
we want to define what things our Frame will know about, and to do that,
we probably need to touch it at some point.


> 	self.txtBox=Text(self)
> # I create an instance of Text widget which I call txtBox
> # 'self' again appears twice - I could memorize this and accept it
> # as an article of faith but I would really prefer to understand what
> # it means

Let's break it down into two statements; that'll make it a little easier
to see what's happening:

###
txtBox = Text(self)
###

What this is saying is "create a Text widget, and make sure that it's
connected to myself".  Whenever we attach widgets, we usually have to tell
that widget where it's should connect itself to.  Since we're a Frame, we
want to tell the new Text box that _we_ are that container.

At this point, this Textbox now knows about us... but we want to make sure
that we, the Frame, remember about the Textbox as well.  We want things to
be a two-way street, but unless we do something, we'll drop the local
variable.  That leads us to the next statement:

###
self.txtBox = txtBox
###

which says "create an attribute called txtBox".  Any "attributes" will be
almost like global variables: they'll continue to live even after we exit
out of this '__init__()' function.  One of the reasons for having an
__init__ is to help to construct and initialize our new frame.



> 	self.txtBox.bind("<space>", self.doQuitEvent)
> # bind is a method which takes two parameters ? I suppose documentation on
> # bind will explain this somewhere - but if the example explained it would
> # be easier

Actually, this is somewhat advanced Tkinter programming.  You often don't
need to use bind() at the beginning.  What this is doing is "binding" the
space key to a function called self.doQuitEvent --- that is, when the
space key is pressed, ou doQuitEvent() function will fire off.



> Anybody know of any resource like 'explaining tkinter to elementary school
> children' ?

It's possible to do Tkinter stuff without mixing it too much with OOP
concepts --- I think the main difficulty is that you're chewing too much.
*grin*  How about something like:

###
import Tkinter
root_window = Tkinter.Tk()
label = Tkinter.Label(root_window, text="Hello world")
label.pack()
###

>From what I've seen, the "Introduction to Tkinter" takes a non-OOP
approach to showing Tkinter stuff, and you might find it easier to read:

    http://www.pythonware.com/library/tkinter/introduction/


To understand the example that you were working on before, you'll want dig
a little deeper on the concept of "Object Oriented Programming".  Here's
one place you can look at:

    http://www.freenetpages.co.uk/hp/alan.gauld/tutclass.htm

Good luck!



From dsh8290@rit.edu  Sun Mar 24 20:58:14 2002
From: dsh8290@rit.edu (dman)
Date: Sun, 24 Mar 2002 14:58:14 -0600
Subject: [Tutor] View pop3 commands/responses script - part II
In-Reply-To: <E16obLq-0007Mp-00@mail.python.org>
References: <E16obLq-0007Mp-00@mail.python.org>
Message-ID: <20020324205814.GB10420@dman.ddts.net>

On Fri, Mar 22, 2002 at 09:32:12PM -0500, Steve wrote:
| Okay, I figured out my problem, I was using bind instead of
| connect.  Now I need a way to detect if the connection went away.
| I could use some pointers on blocking versus non-blocking IO and
| how I could use it to my advantage in my program.  Here is what I
| have.

|     rdata=remote.recv(2048)

One potential technique is to use select() to asynchronously wait for
an event to happen on a file descriptor.  When select() returns it
will tell you whether or not you can read from the file or if an
exceptional condition occurred.

I just did some quick-n-dirty testing and found this to work if you use
blocking I/O :

data = remote.recv( 1 )
if not data :
    print "all done!"

If you don't really want to completely block then definitely use
select().  

Actually, I just tried it in non-blocking mode, if there's no data you
get an exception.  If the other side closes the socket you get an
empty string.

HTH,
-D

-- 

The light of the righteous shines brightly,
but the lamp of the wicked is snuffed out.
        Proverbs 13:9



From dsh8290@rit.edu  Sun Mar 24 21:04:43 2002
From: dsh8290@rit.edu (dman)
Date: Sun, 24 Mar 2002 15:04:43 -0600
Subject: [Tutor] Extracting words..
In-Reply-To: <02032421391800.00703@utopia>
References: <02032421391800.00703@utopia>
Message-ID: <20020324210443.GC10420@dman.ddts.net>

On Sun, Mar 24, 2002 at 09:39:18PM +0100, Nicole Seitz wrote:

I'll answer the first part since that is easy :-).

| -->returns a list containing such words, e.g.
| 
| ['JavaScript', 'MacWeek', 'MacWeek', 'CompuServe', 'CompuServe', 
| 'CompuServe', 'CompuServe', 'CompuServe', 'SysOps', 'SysOps', 'CompuServe', 
| 'CompuServe', 'CompuServe', 'InterBus', 'NeuroVisionen', 'NeuroVisionen', 
| 'InterBus']
| 
| My first question:
| 
| What do I have to do that each word appears only once in the list,i.e. is 
| found only once??

Strings are a hashable object, and a dict can have each key occur only
once.  In addition, key lookups are fast.  This will filter out
duplicates :

l = ['JavaScript', 'MacWeek', 'MacWeek', 'CompuServe', 'CompuServe' ]
d = {}
for item in l :
    d[item] = None
l = d.keys()
print l

The value associated with the key is irrelevant in this usage.  You
could also do it with lists, but the execution time grows
exponentially with the data size :

l = ['JavaScript', 'MacWeek', 'MacWeek', 'CompuServe', 'CompuServe' ]
m = []
for item in l :
    if item not in m :
        m.append( item )
l = m
print l

The two problems with this approach are :
    o   a linear search to see if the item is a duplicate
    o   lists are implented as a C array, when you run out of space, a
        new chunk of memory must be allocated and all the old data copied
        over.  You don't need to worry about this in your code (the
        interpreter takes care of it) but it does affect the
        performance of certain algorithms.


To briefly touch on your second question, I recommend modifying your
method to build a dict and return it instead of a list.  You can store
whatever data you like (line numbers, etc) as the value in the dict.
This will reduce the overall overhead since you won't be first
building a list with duplicates, then building a dict to eliminate
them, then converting it back to a list.

HTH,
-D

-- 

The truly righteous man attains life,
but he who pursues evil goes to his death.
        Proverbs 11:19



From dyoo@hkn.eecs.berkeley.edu  Sun Mar 24 21:04:21 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 24 Mar 2002 13:04:21 -0800 (PST)
Subject: [Tutor] Re: Welcome to the "Tutor" mailing list
In-Reply-To: <197.4400bb7.29cf5bc1@aol.com>
Message-ID: <Pine.LNX.4.44.0203241254140.27560-100000@hkn.eecs.berkeley.edu>


On Sun, 24 Mar 2002 TwIsTeRmEtAl4@aol.com wrote:

> how can you learn to hack into other coumputers

Hello,


TwIsTeRmEtAl4, we can't help on this one.  Here, we mean "hack" in the
constructive sense.  All of use here want to help each other learn
programming.  Compared to the joy of writing Tkinter programs and games,
cracking and destroying other computers is just not interesting to us.


You're probably tired of seeing this, but just in case:

    http://www.tuxedo.org/~esr/faqs/hacker-howto.html

is what we're thinking of when we say "hacker".  Again, sorry, but
cracking is something we don't have any competence in, and you're better
off checking a newsgroup like alt.2600.


Best of wishes to you.



From dyoo@hkn.eecs.berkeley.edu  Sun Mar 24 21:25:08 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 24 Mar 2002 13:25:08 -0800 (PST)
Subject: [Tutor] Re: Saving a dictionary to a text file  [xml_pickle]
In-Reply-To: <20020324182339.1411.3@gormenghast.AUTODIAL>
Message-ID: <Pine.LNX.4.44.0203241304360.27560-100000@hkn.eecs.berkeley.edu>

> the pickle module (import pickle)
> allows you to pickle anything in a file just like you would pickle
> onions or eggs or beetroots. You can then unpickle it and be sure to get
> back what you put in and they taste just as fresh too.

I just noticed that David Mertz has written an 'xml_pickle' module that
does the same thing as the pickle module, except that what comes out is
almost readable.  *grin* Take a look:

    http://www-106.ibm.com/developerworks/library/xml-matters1/index.html
    http://www-106.ibm.com/developerworks/library/xml-matters2/index.html
    http://www-106.ibm.com/developerworks/xml/library/x-matters11.html


So we can  do something like this:


###
>>> import gnosis.xml.pickle as xml_pickle
>>> mydict = {'topic': 'saving dictionaries as text',
...           'technique': 'use xml_pickle',
...           'url':  'http://www-106.ibm.com/developerworks/'
                    + 'library/xml-matters1/index.html'}
>>> c = Container()
>>> c.dict = mydict
>>> xml_string = xml_pickle.XML_Pickler(c).dumps()
>>> print xml_string
<?xml version="1.0"?>
<!DOCTYPE PyObject SYSTEM "PyObjects.dtd">
<PyObject module="__main__" class="Container" id="135638484">
<attr name="dict" type="dict" id="136067228" >
  <entry>
    <key type="string" value="topic" />
    <val type="string" value="saving dictionaries as text" />
  </entry>
  <entry>
    <key type="string" value="url" />
    <val type="string"
value="http://www-106.ibm.com/developerworks/library/xml-matters1/index.html"
/>
  </entry>
  <entry>
    <key type="string" value="technique" />
    <val type="string" value="use xml_pickle" />
  </entry>
</attr>
</PyObject>
###


This xml_pickle apparently only likes to see class instances; in my
experiments, it complained when it saw a raw dictionary.  But we can
write something to automate this packing:


###
>>> class Container:
...     def __init__(self, dict): self.dict = dict
...
>>> def dict_to_xml(dict):
...     return xml_pickle.XML_Pickler(Container(dict)).dumps()
...
>>> dict_to_xml({1:'one', 2:'two'})
'<?xml version="1.0"?>\n<!DOCTYPE PyObject SYSTEM
"PyObjects.dtd">\n<PyObject module="__main__" class="Container"
id="136067692">\n<attr name="dict" type="dict" id="135569884" >\n
<entry>\n    <key type="numeric" value="1" />\n    <val type="string"
value="one" />\n  </entry>\n  <entry>\n    <key type="numeric" value="2"
/>\n    <val type="string" value="two" />\n
</entry>\n</attr>\n</PyObject>\n'

>>> def xml_to_dict(xml):
...     return xml_pickle.XML_Pickler().loads(xml).dict
>>> xml_to_dict(dict_to_xml({1: 'one'}))
{1: 'one'}
###


Hope this helps!



From dyoo@hkn.eecs.berkeley.edu  Sun Mar 24 21:48:23 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Sun, 24 Mar 2002 13:48:23 -0800 (PST)
Subject: [Tutor] Extracting words..    [sort | uniq]
In-Reply-To: <20020324210443.GC10420@dman.ddts.net>
Message-ID: <Pine.LNX.4.44.0203241327110.27560-100000@hkn.eecs.berkeley.edu>

> | My first question:
> |
> | What do I have to do that each word appears only once in the list,i.e. is
> | found only once??
>
> Strings are a hashable object, and a dict can have each key occur only
> once.  In addition, key lookups are fast.  This will filter out
> duplicates :
>
> l = ['JavaScript', 'MacWeek', 'MacWeek', 'CompuServe', 'CompuServe' ]
> d = {}
> for item in l :
>     d[item] = None
> l = d.keys()
> print l
>
> The value associated with the key is irrelevant in this usage.  You
> could also do it with lists, but the execution time grows
> exponentially with the data size :
>
> l = ['JavaScript', 'MacWeek', 'MacWeek', 'CompuServe', 'CompuServe' ]
> m = []
> for item in l :
>     if item not in m :
>         m.append( item )
> l = m
> print l


To offer a counterpoint: the list structure doesn't stop us from finding
unique elements effectively.  We can also do this uniqueness filter by
first sorting the words.  What ths does is bring all the duplicates right
next to each other.  Once we have this sorted list, just taking its unique
members is just a matter of picking them out:

###
def uniq(mylist):
    """Returns a unique list of elements in mylist.

    Warning: this function also has a side effect of sorting mylist."""
    mylist.sort()
    if not mylist: return mylist
    results = [mylist[0]]
    for i in range(1, len(mylist)):
        if mylist[i-1] != mylist[i]:
            results.append(mylist[i])
    return results
###


Here's a test drive:

###
>>> words = """hello this is a test of the emergency
... broadcast system this is only a test""".split()
>>> uniq(words)
['a', 'broadcast', 'emergency', 'hello', 'is',
 'of', 'only', 'system', 'test', 'the', 'this']
###


People who run Unix will recognize this as the "sort | uniq" approach.


For people who are interested: here's a similar problem: "Given a text
file and an integer K, you are to print the K most common words in the
file (and the number of their occurences) in decreasing frequency."

It's a fun problem to work on, and useful when one is writing an essay and
wants to avoid overusing words.  *grin*


Hope this helps!



From dsh8290@rit.edu  Sun Mar 24 22:01:38 2002
From: dsh8290@rit.edu (dman)
Date: Sun, 24 Mar 2002 16:01:38 -0600
Subject: [Tutor] Extracting words..    [sort | uniq]
In-Reply-To: <Pine.LNX.4.44.0203241327110.27560-100000@hkn.eecs.berkeley.edu>
References: <20020324210443.GC10420@dman.ddts.net> <Pine.LNX.4.44.0203241327110.27560-100000@hkn.eecs.berkeley.edu>
Message-ID: <20020324220138.GA11090@dman.ddts.net>

On Sun, Mar 24, 2002 at 01:48:23PM -0800, Danny Yoo wrote:
| > | My first question:
| > |
| > | What do I have to do that each word appears only once in the list,i.e. is
| > | found only once??

| > l = ['JavaScript', 'MacWeek', 'MacWeek', 'CompuServe', 'CompuServe' ]
| > m = []
| > for item in l :
| >     if item not in m :
| >         m.append( item )
| > l = m
| > print l
| 
| To offer a counterpoint: the list structure doesn't stop us from finding
| unique elements effectively.  We can also do this uniqueness filter by
| first sorting the words.  What ths does is bring all the duplicates right
| next to each other.  Once we have this sorted list, just taking its unique
| members is just a matter of picking them out:

Good point!  I wasn't thinking of this.

| People who run Unix will recognize this as the "sort | uniq" approach.

For a while (when I read the subject) I thought you were going to
suggest piping the words out to 'uniq' :-).

| For people who are interested: here's a similar problem: "Given a text
| file and an integer K, you are to print the K most common words in the
| file (and the number of their occurences) in decreasing frequency."

<cheater's hint>
Search the tutor archives.  With only a couple minor modifications the
answer is already there.
</cheater's hint>
 
| It's a fun problem to work on, and useful when one is writing an essay and
| wants to avoid overusing words.  *grin*

Oh, you want to count words in an essay ... that means filtering out
the LaTeX markup too :-).

mostly just babbling at the moment,
-D

-- 

I tell you the truth, everyone who sins is a slave to sin.  Now a slave
has no permanent place in the family, but a son belongs to it forever.
So if the Son sets you free, you will be free indeed.
        John 8:34-36



From pythontutor@venix.com  Sun Mar 24 22:14:59 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Sun, 24 Mar 2002 17:14:59 -0500
Subject: [Tutor] Saving a dictionary to a text file
References: <E16ootx-00011B-00@mail.python.org> <20020324000828.99747.qmail@web14102.mail.yahoo.com> <84CFA5227D@kserver.org>
Message-ID: <3C9E4FE3.4010305@venix.com>

	from pprint import pprint
	fielddict_file = open("fielddict.txt","w")
	pprint(fielddict, fielddict_file)
	fielddict_file.close()

pprint (at least for the data I've pushed through it) produces an output
that is readable and also suitable to paste into a python program as source
code.  I've been using it to print dictionaries of database information.

Sheila King wrote:

> On Sat, 23 Mar 2002 16:08:28 -0800 (PST), Britt Green
> <cheshire_cat_sf@yahoo.com>  wrote about [Tutor] Saving a dictionary to a
> text file:
> 
> 
>>I'm wondering how one goes about saving a dictionary as part of a text
>>file. This is how I've been trying to do it, and the error message that
>>I'm getting:
>>
>>
>>>>>mydict = {'foo' : 1, 'bar' : 2}
>>>>>f = open ('mydict.txt', 'w')
>>>>>f.write(mydict)
>>>>>
>>Traceback (most recent call last):
>>  File "<pyshell#2>", line 1, in ?
>>    f.write(mydict)
>>TypeError: argument 1 must be string or read-only character buffer, not
>>dict
>>
> 
> 
> Hopefully, these examples will help:
> 
> Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
> Type "copyright", "credits" or "license" for more information.
> IDLE 0.8 -- press F1 for help
> 
>>>>mydict = {'foo' : 1, 'bar' : 2}
>>>>f = open ('mydict.txt', 'w')
>>>>f.write(str(mydict))
>>>>f.close()
>>>>g = open('mydict.txt', 'r')
>>>>g.read()
>>>>
> "{'foo': 1, 'bar': 2}"
> 
>>>>g.close()
>>>>h = open('mydict.txt', 'r')
>>>>newdict = eval(h.read())
>>>>newdict
>>>>
> {'foo': 1, 'bar': 2}
> 
> 
> If you still have questions, ask again.
> 
> --
> Sheila King
> http://www.thinkspot.net/sheila/
> http://www.k12groups.org/
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582



From alan.gauld@bt.com  Sun Mar 24 23:41:26 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 24 Mar 2002 23:41:26 -0000
Subject: [Tutor] learning Tkinter
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C48E@mbtlipnt02.btlabs.bt.co.uk>

> > In fact, seems like tkinter is almost a different language.

GUI programming is essentially a special interest topic in its own right.
It requires as a pre requisite a pretty good understanding of other 
programming styles like OOP and Event driven programming before you 
even start. Environments like Visual Basic and Delphi in windows make 
it as easy as it can be but even then there is a lot to learn once 
you get beyond the basics(sic!). Its one of those things that is 
just plain hard to learn for total newbies. Its unfortunate because 
nowadays everyone wants GUI front ends and they are hard to build.

> > In fact the only useful type of thing I've found so far is 
> Alan Gauld's chapters on event driven programming and GUI programming 
> with tkinter.


Thanks for that, I made it as easy as I could but I'm well aware 
that it demands a lot of background even so...

> > def __init__(self):
> > # why not just def __init__(): or def __init__(other): ?

As Gregor says, this is an OOP issue not Tkinter. You need to 
look at that first to understand what self is and how its used.

> Chapter on OOP:
> http://www.freenetpages.co.uk/hp/alan.gauld/tutclass.html

> > self.txtBox.bind("<space>", self.doQuitEvent)

This is explained a wee bit more in the GUI page but I must admit 
that the bind() rules are one of the hardest bits tyo learn in 
any GUI system not just Tkinter and not just in Python either. 
They trip up even experienced users.

> Anybody know of any resource like 'explaining tkinter to elementary school
> children' ?

Unfortunately the current state of GUI programming makes this nigh 
impossible. You might like to look at PythonCard(??) on sourceforge 
which is a project trying to make Tkinter GUI programming easier.
I owe them some feedback but am short on cycles ust now, but it 
might be an easier approach for beginners - me I didn't find it that
big an advantage...

BTW If you do have specific questions/issues with my pages please 
do send offlist feedback by email - that's how the tutor gets better, 
by user feedback.

Alan g.


From alan.gauld@bt.com  Sun Mar 24 23:55:38 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 24 Mar 2002 23:55:38 -0000
Subject: [Tutor] Extracting words..
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C48F@mbtlipnt02.btlabs.bt.co.uk>

> could also do it with lists, but the execution time grows
> exponentially with the data size :

True, but at least its shorter to code using map:

> Lst = ['JavaScript', 'MacWeek', 'MacWeek', 'CompuServe', 'CompuServe' ]

  Lst = map(lambda item: item not in Lst, Lst)

Or if you must you could use list comprehension... ;-)

But isn't there a uniq() method on lists nowadays? 
Or have I been hallucinating again?

Alan G


From urnerk@qwest.net  Mon Mar 25 00:58:59 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Sun, 24 Mar 2002 16:58:59 -0800
Subject: [Tutor] Extracting words..
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C48F@mbtlipnt02.btlabs
 .bt.co.uk>
Message-ID: <4.2.0.58.20020324165834.01a02180@pop3.norton.antivirus>

>
>But isn't there a uniq() method on lists nowadays?
>Or have I been hallucinating again?

Hallucinating again. :-D

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



From jboyko@sympatico.ca  Mon Mar 25 01:55:01 2002
From: jboyko@sympatico.ca (jb)
Date: 24 Mar 2002 20:55:01 -0500
Subject: [Tutor] file name change script
Message-ID: <1017021302.2213.26.camel@localhost.localdomain>

Hi, I'm a old fart struggling to learn to program with python and to use
linux at the same time. I'd be pulling out my hair if only I had some.
=-)   

What I'm trying to figure out, is how to write a python script which
would do the following in the bash shell ...

change all the existing file names in a directory to new file names
which are made up of sequencial numbers,

eg.  <oldfilename_x.txt> to <001.txt>
     <oldfilename_y.txt> to <002.txt>
     <oldfilename_z.txt> to <003.txt>
     ...

Any suggestions would be greatly appreciated


-- 
===============================================================================

            "  not everything that can be counted counts,
           and not everything that counts can be counted  "
	                ----- Einstein -----

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



From paulsid@shaw.ca  Mon Mar 25 02:05:01 2002
From: paulsid@shaw.ca (Paul Sidorsky)
Date: Sun, 24 Mar 2002 19:05:01 -0700
Subject: [Tutor] file name change script
References: <1017021302.2213.26.camel@localhost.localdomain>
Message-ID: <3C9E85CC.C665A8B8@shaw.ca>

jb wrote:

> Hi, I'm a old fart struggling to learn to program with python and to use
> linux at the same time. I'd be pulling out my hair if only I had some.
> =-)
> 
> What I'm trying to figure out, is how to write a python script which
> would do the following in the bash shell ...
> 
> change all the existing file names in a directory to new file names
> which are made up of sequencial numbers,
> 
> eg.  <oldfilename_x.txt> to <001.txt>
>      <oldfilename_y.txt> to <002.txt>
>      <oldfilename_z.txt> to <003.txt>
>      ...
> 
> Any suggestions would be greatly appreciated

Sure, this is really easy to do.  (Especially since I had a similar
script lying around from a web site restructuring.)  This code will
operate on the present working directory:

import os

count = 1
for fn in os.listdir("."):
    if fn[-4:] == ".txt":
        os.rename(fn, "%03i.txt" % count)
        count = count + 1

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/


From erikprice@mac.com  Mon Mar 25 02:25:45 2002
From: erikprice@mac.com (Erik Price)
Date: Sun, 24 Mar 2002 21:25:45 -0500
Subject: [Tutor] Re: Welcome to the "Tutor" mailing list
In-Reply-To: <197.4400bb7.29cf5bc1@aol.com>
Message-ID: <9CF3B8D0-3F97-11D6-ACA6-00039351FE6A@mac.com>

On Sunday, March 24, 2002, at 11:41  AM, TwIsTeRmEtAl4@aol.com wrote:

> how can you learn to hack into other coumputers
>

::yawn::



From erikprice@mac.com  Mon Mar 25 02:29:02 2002
From: erikprice@mac.com (Erik Price)
Date: Sun, 24 Mar 2002 21:29:02 -0500
Subject: [Tutor] Re: Saving a dictionary to a text file  [xml_pickle]
In-Reply-To: <Pine.LNX.4.44.0203241304360.27560-100000@hkn.eecs.berkeley.edu>
Message-ID: <11E94090-3F98-11D6-ACA6-00039351FE6A@mac.com>

On Sunday, March 24, 2002, at 04:25  PM, Danny Yoo wrote:

> I just noticed that David Mertz has written an 'xml_pickle' module that
> does the same thing as the pickle module, except that what comes out is
> almost readable.  *grin* Take a look:

Neat.





From sheila@thinkspot.net  Mon Mar 25 01:59:52 2002
From: sheila@thinkspot.net (Sheila King)
Date: Sun, 24 Mar 2002 17:59:52 -0800
Subject: [Tutor] file name change script
In-Reply-To: <1017021302.2213.26.camel@localhost.localdomain>
References: <1017021302.2213.26.camel@localhost.localdomain>
Message-ID: <7920AD7AF2@kserver.org>

On 24 Mar 2002 20:55:01 -0500, jb <jboyko@sympatico.ca>  wrote about
[Tutor] file name change script:

> What I'm trying to figure out, is how to write a python script which
> would do the following in the bash shell ...
> 
> change all the existing file names in a directory to new file names
> which are made up of sequencial numbers,
> 
> eg.  <oldfilename_x.txt> to <001.txt>
>      <oldfilename_y.txt> to <002.txt>
>      <oldfilename_z.txt> to <003.txt>
>      ...
> 
> Any suggestions would be greatly appreciated

You can make a script that will do this on any platform that Python runs
on, making it portable. (Maybe you don't care about that right now, but it
is a plus of the Python language...)

Perhaps you want to check out the os module, which has many commands for
working with files, filenames and directory names and paths:
http://www.python.org/doc/current/lib/module-os.html

HTH,

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/



From python@rcn.com  Mon Mar 25 07:58:25 2002
From: python@rcn.com (Raymond Hettinger)
Date: Mon, 25 Mar 2002 02:58:25 -0500
Subject: [Tutor] Re: Welcome to the "Tutor" mailing list
References: <197.4400bb7.29cf5bc1@aol.com>
Message-ID: <004801c1d3d2$d8b7c680$f6d8accf@othello>

This is a multi-part message in MIME format.

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

A little more information would be helpful in order to give you
a worked out example.  Please post your userid and password
and then someone can give you an object lesson in hacking.

always-happy-to-help-ly yours,  Raymond
  ----- Original Message -----=20
  From: TwIsTeRmEtAl4@aol.com=20
  To: tutor@python.org=20
  Sent: Sunday, March 24, 2002 11:41 AM
  Subject: [Tutor] Re: Welcome to the "Tutor" mailing list


  how can you learn to hack into other coumputers=20

------=_NextPart_000_0045_01C1D3A8.EEDCD1A0
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.4207.2601" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>A&nbsp;little more information would be =

helpful&nbsp;in order to give you</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>a worked out example.&nbsp; Please post =
your userid=20
and password</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>and then someone can give you an object =
lesson in=20
hacking.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>always-happy-to-help-ly yours,&nbsp; =
</FONT><FONT=20
face=3DArial size=3D2>Raymond</FONT></DIV>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3DTwIsTeRmEtAl4@aol.com=20
  href=3D"mailto:TwIsTeRmEtAl4@aol.com">TwIsTeRmEtAl4@aol.com</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A title=3Dtutor@python.org =

  href=3D"mailto:tutor@python.org">tutor@python.org</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Sunday, March 24, 2002 =
11:41=20
  AM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Tutor] Re: Welcome to =
the=20
  "Tutor" mailing list</DIV>
  <DIV><BR></DIV><FONT face=3Darial,helvetica><FONT lang=3D0 =
face=3D"Comic Sans MS"=20
  size=3D2 FAMILY=3D"SCRIPT">how can you learn to hack into other =
coumputers</FONT>=20
  </FONT></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0045_01C1D3A8.EEDCD1A0--



From nicole.seitz@urz.uni-hd.de  Mon Mar 25 10:20:57 2002
From: nicole.seitz@urz.uni-hd.de (Nicole Seitz)
Date: Mon, 25 Mar 2002 11:20:57 +0100
Subject: [Tutor] Extracting words(quest 2)
In-Reply-To: <20020324210443.GC10420@dman.ddts.net>
References: <02032421391800.00703@utopia> <20020324210443.GC10420@dman.ddts.net>
Message-ID: <02032511205700.00703@utopia>

Hi!

Many thanks( to all of you) for answering my first question!I'm trying out 
your solutions...
Maybe someone has suggestions concerning question 2 ?
Here it is again:



I'm trying to write a little script that extracts word creations like 
"StarOffice","CompuServe","PalmPilot",etc. from an text file.

import re; import string

reg = re.compile(r"\b[A-Z][a-z]+[A-Z][a-z]+\b")

file = open("heise_klein.txt")

txt = file.read()
result = reg.findall(txt)


-->returns a list containing such words



Second question:

I might want to have an output like that:

line 3: StarOffice
line34: CompuServe
line 42: PalmPilot

This means I need some additional information, namely in which line the words 
were found. Using the function findall() from the re module, this is not 
possible, is it??

I had some kind of solution starting like that:
wordsAndLines = [ ]
lineCount = 0
while 1:
     line = file.readline()
     if not line: break
     result  = re.match(reg,line)
     if result:
          wordsAndLines.append((result, lineCount))
          lineCount = lineCount + 1
     

Unfortunately, this didn't work at all.

Would be very thankful for suggestions!!

Nicole
     



From nicole.seitz@urz.uni-hd.de  Mon Mar 25 10:26:29 2002
From: nicole.seitz@urz.uni-hd.de (Nicole Seitz)
Date: Mon, 25 Mar 2002 11:26:29 +0100
Subject: [Tutor] Extracting words.. [sort | uniq]
In-Reply-To: <Pine.LNX.4.44.0203241327110.27560-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.44.0203241327110.27560-100000@hkn.eecs.berkeley.edu>
Message-ID: <02032511262901.00703@utopia>

Am Sonntag, 24. M=E4rz 2002 22:48 schrieb Danny Yoo:

> For people who are interested: here's a similar problem: "Given a text
> file and an integer K, you are to print the K most common words in the
> file (and the number of their occurences) in decreasing frequency."
>
> It's a fun problem to work on, and useful when one is writing an essay =
and
> wants to avoid overusing words.  *grin*

Sounds interesting, but complicated as well. I guess I give it a try anyw=
ay.

Nicole



From seedseven@home.nl  Mon Mar 25 13:49:49 2002
From: seedseven@home.nl (ingo)
Date: Mon, 25 Mar 2002 14:49:49 +0100
Subject: [Tutor] code colorizer
Message-ID: <200203251449490046.006C418F@mail>

povsdl2html.py is a little code colorizer I made. Before adding all
kinds of, probably useless, features, I'd like to have some critique on
the code.
What aspects of it can be improved, where could/should an other
approach be taken? That kind of comment.
Also what would be a way to use classes with this thing?

Three files are located at:

http://members.home.nl/seedseven/povsdl2html.py  (it looks rather big
but half of it is dictionaries to hold keywords)

http://members.home.nl/seedseven/construct.pov   (a POV-Ray scene file
to convert)

http://members.home.nl/seedseven/construct.html  (the result of a
conversion)

TIA,

Ingo



From max_ig@yahoo.com  Mon Mar 25 14:10:10 2002
From: max_ig@yahoo.com (Maximiliano Ichazo)
Date: Mon, 25 Mar 2002 06:10:10 -0800 (PST)
Subject: [Tutor] bar code
Message-ID: <20020325141010.95909.qmail@web11301.mail.yahoo.com>

Does anybody has experience or know about any module to work with bar
codes (like those in a supermarket) in Python?

I'll appreciate your help,

Max



__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
http://movies.yahoo.com/


From urnerk@qwest.net  Mon Mar 25 15:02:05 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Mon, 25 Mar 2002 07:02:05 -0800
Subject: [Tutor] code colorizer
In-Reply-To: <200203251449490046.006C418F@mail>
Message-ID: <4.2.0.58.20020325065749.0159d6a0@pop3.norton.antivirus>

At 02:49 PM 3/25/2002 +0100, you wrote:
>povsdl2html.py is a little code colorizer I made. Before adding all
>kinds of, probably useless, features, I'd like to have some critique on
>the code.

Looks like it'd be useful.

I'd like it to optionally run from within the Python
shell, e.g.

  >>> import povsdl2html
  >>> povs12html.convert('myfile.pov')

something like that.  The current code doesn't make
this easy.

Kirby



From dsh8290@rit.edu  Mon Mar 25 15:11:56 2002
From: dsh8290@rit.edu (dman)
Date: Mon, 25 Mar 2002 09:11:56 -0600
Subject: [Tutor] bar code
In-Reply-To: <20020325141010.95909.qmail@web11301.mail.yahoo.com>
References: <20020325141010.95909.qmail@web11301.mail.yahoo.com>
Message-ID: <20020325151156.GB14261@dman.ddts.net>

On Mon, Mar 25, 2002 at 06:10:10AM -0800, Maximiliano Ichazo wrote:
| Does anybody has experience or know about any module to work with
| bar codes (like those in a supermarket) in Python?

The systems I've seen have a (physical) scanner that handles the
optical part of interpreting a bar code and converts the bars into
characters.  The characters are then input into the computer via a
keyboard or serial port.  When the software gets the data it can't
tell the difference between a bar code scanned automatically or a
human operator pressing keys on a keyboard or another program feeding
it data through a pipe.

Can you give any detail on how you intend to work with the bar codes?
I ask because most likely you don't have to do anything different at
the python level than you would for manual input via keyboard.

HTH,
-D

-- 

All a man's ways seem innocent to him,
but motives are weighed by the Lord.
        Proverbs 16:2



From seedseven@home.nl  Mon Mar 25 15:15:52 2002
From: seedseven@home.nl (ingo)
Date: Mon, 25 Mar 2002 16:15:52 +0100
Subject: [Tutor] code colorizer
In-Reply-To: <4.2.0.58.20020325065749.0159d6a0@pop3.norton.antivirus>
References: <4.2.0.58.20020325065749.0159d6a0@pop3.norton.antivirus>
Message-ID: <200203251615520296.00BB0A81@mail>

>Looks like it'd be useful.

Thanks,

Sorry, you may have to get it again, there was a bug in it with the
multiline comments (this will learn me to never make a change a minute
before upload).

>I'd like it to optionally run from within the Python
>shell, e.g.
>
>  >>> import povsdl2html
>  >>> povs12html.convert('myfile.pov')
>

Mmmm, I'll give it a try.

Ingo



From seedseven@home.nl  Mon Mar 25 16:06:45 2002
From: seedseven@home.nl (ingo)
Date: Mon, 25 Mar 2002 17:06:45 +0100
Subject: [Tutor] code colorizer
In-Reply-To: <4.2.0.58.20020325065749.0159d6a0@pop3.norton.antivirus>
References: <4.2.0.58.20020325065749.0159d6a0@pop3.norton.antivirus>
Message-ID: <200203251706450031.00E99F40@mail>

On 2002/03/25 at 07:02 Kirby Urner wrote:

>  >>> import povsdl2html
>  >>> povs12html.convert('myfile.pov')
>
>something like that.  The current code doesn't make
>this easy.

Done,
code is at the same place.

Ingo



From bembry@bembry.org  Mon Mar 25 14:06:48 2002
From: bembry@bembry.org (Bryce Embry)
Date: Mon, 25 Mar 2002 08:06:48 -0600
Subject: [Tutor] learning Tkinter
In-Reply-To: <Pine.LNX.4.33L2.0203231416010.2308-100000@localhost.locald
 omain>
Message-ID: <5.1.0.14.0.20020325074609.00ad4a18@www.bembry.org>

I've been struggling with a similar issue.  I'm not a trained programmer 
and have been learning how to program while teaching a course on the 
subject to high school students.  We are just finishing a section on OOP 
and getting ready to cover GUI with Tkinter after spring break.  So, I've 
been learning how to use Tkinter and thought I'd share some of the helpful 
things I've found.  (It's not Tkinter for elementary children, but it is 
Tkinter for high school kids.  Maybe that's close enough.)

Since I don't have a background in OOP, I found the following Tkinter 
tutorial very helpful:
http://cmbipc58.cmbi.kun.nl/pythoncourse/index.php?job=chapter&ch=15
It is pretty short, but gave me the conceptual groundwork I needed to begin 
understanding what Tkinter does.   It doesn't assume that you know anything 
about classes and OOP, so it helped me a lot.

Eventually, though, it helps to understand OOP.  So, to learn more about 
OOP, I'd suggest the Python OOP articles at DevShed.  I found them to be 
pretty straightforward and helpful:
http://www.devshed.com/Server_Side/Python/OOPWithPython

Also, I have the notes for my classes posted online at 
http://www.bembry.org/tech/python/index.shtml  .  I only have the first set 
of lessons on Tkinter finished, but you might find it or some of the other 
notes useful.  I'm approaching Tkinter in three or four lessons.  Like you 
mentioned, I got really overwhelmed with all the various widgets available, 
so I'm introducing my students to three basic widgets to start with, then 
explaining what a grid manager does and how to use it (lesson 2), and 
finally going in to how to make the GUI work (using binds and stuff I 
haven't figured out yet).  Once we get these concepts down, I'll add more 
widgets and PMW stuff.  I'm not sure how useful my notes will be, but 
hopefully they will make some sense.

And finally, I really like John Grayson's "Python and Tkinter Programming" 
book.  Once I understood what I was doing, this book provided all the 
documentation on what options were available with what features and so 
forth.   If you aren't sure what you are doing, though, the book is a 
little overwhelming.

Hope this helps,

Bryce Embry
Geek-of-All-Trades / Master-of-None


At 07:47 AM 3/23/2002, you wrote:

>So, every couple of weeks or so I find an odd hour for python and I keep
>on imagining how my python-shift program could be.
>
>Lately I've been trying to face tkinter, but I'm finding it far harder
>than anything else, probably not because it is complicated in itself but
>because I'm not finding the type of documentation I'd like.
>In fact, seems like tkinter is almost a different language.
>On line references pore for pages and pages over dozens of options for
>each possible widget ... which is something I would like to face after
>having understood how these tie in with the rest of a program.
>Being a complete beginner I would like a tutorial to explain WHY things
>have to be written in a certain way.
>In fact the only useful type of thing I've found so far is Alan Gauld's
>chapters on event driven programming and GUI programming with tkinter.
>Even he is still too obscure for REAL beginners with GENUINE brick heads
>like me; for instance he has this code:
>
>class KeysApp(Frame):
># all right, I create a new class which inherits from class Frame
>         def __init__(self):
># why not just def __init__(): or def __init__(other): ?
>         self.txtBox=Text(self)
># I create an instance of Text widget which I call txtBox
># 'self' again appears twice - I could memorize this and accept it
># as an article of faith but I would really prefer to understand what
># it means
>         self.txtBox.bind("<space>", self.doQuitEvent)
># bind is a method which takes two parameters ? I suppose documentation on
># bind will explain this somewhere - but if the example explained it would
># be easier
>         etc. etc.
>
>Anybody know of any resource like 'explaining tkinter to elementary school
>children' ?
>
>--
>Michele Alzetta
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

--------------------------------------------------------------------------------------------
"Lord, you establish peace for us.
All that we have accomplished
you have done for us" -- Isaiah 26:12



From garber@centralcatholic.org  Mon Mar 25 17:38:00 2002
From: garber@centralcatholic.org (Robert Garber)
Date: Mon, 25 Mar 2002 12:38:00 -0500
Subject: [Tutor] py2exe HOW TO MAKE IT WORK?
Message-ID: <200203251238.AA369754786@centralcatholic.org>

Hello all,

Stuck on py2exe.  I seem to be having a problem getting this to work. I have followed thte steps that are on the web page, but with no luck. 

 I am wondering if I have things in the right directory (WIN98). ANy ideas out there? 

The dos's say: 
run python setup.py py2exe

Which run are they ta;lking about I have tried run from winpython, MSDOS, at the >>> in the interprter, with no luck..

                    thanks, 
                    Robert 


From urnerk@qwest.net  Mon Mar 25 17:42:37 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Mon, 25 Mar 2002 09:42:37 -0800
Subject: [Tutor] code colorizer
In-Reply-To: <200203251706450031.00E99F40@mail>
References: <4.2.0.58.20020325065749.0159d6a0@pop3.norton.antivirus>
 <4.2.0.58.20020325065749.0159d6a0@pop3.norton.antivirus>
Message-ID: <4.2.0.58.20020325093708.019f2700@pop3.norton.antivirus>

At 05:06 PM 3/25/2002 +0100, ingo wrote:
>On 2002/03/25 at 07:02 Kirby Urner wrote:
>
> >  >>> import povsdl2html
> >  >>> povs12html.convert('myfile.pov')
> >
> >something like that.  The current code doesn't make
> >this easy.
>
>Done,
>code is at the same place.
>
>Ingo

Excellent!

Seems to me that:

   return reduce(lambda x,y:x+y,s)

in ad_tag() is a bottleneck, which is better replaced with:

   return ''.join(s)

I've been testing .convert('group366.pov') in shell mode
and need to make the above substitution to have it work.

If you want to test the same file (nothing special to look
at, just long ~120K of mostly cylinders), I've put it at:

http://www.inetarena.com/~pdx4d/ocn/python/group366.pov

Kirby



From curtis.larsen@covance.com  Mon Mar 25 18:20:12 2002
From: curtis.larsen@covance.com (Curtis Larsen)
Date: Mon, 25 Mar 2002 12:20:12 -0600
Subject: [Tutor] Comma Chameleon?
Message-ID: <sc9f1606.056@madis2.truax.covance.com>

<grin>
I'm  probably missing it, but isn't there some sort of formatting
option for use with the 'print' command that will automagically insert
commas into a number?  If not, what's the best Pythonic method to do
this?  (Note: I don't need currency or a +/-: I just want 123456789 to
look like 123,456,789.)

Thanks!
Curtis



-----------------------------------------------------
Confidentiality Notice: This e-mail transmission 
may contain confidential or legally privileged 
information that is intended only for the individual 
or entity named in the e-mail address. If you are not 
the intended recipient, you are hereby notified that 
any disclosure, copying, distribution, or reliance 
upon the contents of this e-mail is strictly prohibited. 

If you have received this e-mail transmission in error, 
please reply to the sender, so that we can arrange 
for proper delivery, and then please delete the message 
from your inbox. Thank you.



From alex@gabuzomeu.net  Mon Mar 25 18:35:11 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Mon, 25 Mar 2002 19:35:11 +0100
Subject: [Tutor] Extracting words(quest 2)
In-Reply-To: <E16pX3o-000849-00@mail.python.org>
Message-ID: <4.3.2.7.2.20020325192321.00b9a810@pop3.norton.antivirus>

Hi Nicole,


At 11:11 25/03/2002 -0500, you wrote:
>From: Nicole Seitz <nicole.seitz@urz.uni-hd.de>
>Subject: Re: [Tutor] Extracting words(quest 2)
>Date: Mon, 25 Mar 2002 11:20:57 +0100

>I'm trying to write a little script that extracts word creations like
>"StarOffice","CompuServe","PalmPilot",etc. from an text file.

>I might want to have an output like that:
>
>line 3: StarOffice
>line34: CompuServe
>line 42: PalmPilot
>
>This means I need some additional information, namely in which line the 
>words  were found. Using the function findall() from the re module, this 
>is not possible, is it??
>
>I had some kind of solution starting like that:

OK, here is an example based on your code to get you started:

import re, pprint

def indexWord(filename):
     wordDict = {}
     lineCount = 0
     file = open(filename)
     expr = re.compile("\w+", re.LOCALE)
     while 1:
         line = file.readline()
         if not line:
             break
         lineCount = lineCount + 1
         resultList  = expr.findall(line)
         if resultList:
             for word in resultList:
                 if wordDict.has_key(word):
                     # line numbers are stored in a list for every word
                     wordDict[word].append(lineCount)
                 else:
                     wordDict[word] = [lineCount]
     file.close()
     return wordDict


if __name__ == "__main__":
     filename = r"c:\foo\bar\baz.txt"
     wordDict = indexWord(filename)
     # prettyprint the results
     pprint.pprint(wordDict)

Example output:
...
  'extraordinarily': [381],
  'extremely': [246],
  'facilities': [159, 190, 360],
  'fail': [294],
  'fairly': [331],
  'family': [177, 339],
...

Notes:
- You need to use your own regular expression here; the one I used matches 
any group of alphanumeric characters.
- If a word occurs twice in the same line, it will be listed twice. To 
avoid this behaviour, you need to filter resultList (left as an exercice :-).

>Would be very thankful for suggestions!!


HTH.

Alex




From alex@gabuzomeu.net  Mon Mar 25 18:55:36 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Mon, 25 Mar 2002 19:55:36 +0100
Subject: [Tutor] Extracting words..
In-Reply-To: <E16pX3o-000849-00@mail.python.org>
Message-ID: <4.3.2.7.2.20020325194217.00d091d0@pop3.norton.antivirus>

Hi Alan,


At 11:11 25/03/2002 -0500, you wrote:
>From: alan.gauld@bt.com
>Subject: RE: [Tutor] Extracting words..
>Date: Sun, 24 Mar 2002 23:55:38 -0000

>True, but at least its shorter to code using map:
>
> > Lst = ['JavaScript', 'MacWeek', 'MacWeek', 'CompuServe', 'CompuServe' ]
>
>   Lst = map(lambda item: item not in Lst, Lst)

Does this snippet work on your computer? I get "[0, 0, 0, 0, 0]".


Cheers.

Alexandre



From chez@reyndersgray.com  Mon Mar 25 19:16:42 2002
From: chez@reyndersgray.com (Chez)
Date: Mon, 25 Mar 2002 14:16:42 -0500
Subject: [Tutor] Using python to copy file1 into file2
In-Reply-To: <4.3.2.7.2.20020325192321.00b9a810@pop3.norton.antivirus>
Message-ID: <PNEJJIHDPEGJKOIEPBGLEEENCBAA.chez@reyndersgray.com>

I have to files

file1

a  100
b  200
c  300
d  400


and I wnat to create file2 with   "-"  sign

file2

a  -100
b  -200
c  -300
d  -400

how can I do it with python?

Chez


-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
Alexandre Ratti
Sent: Mon, March 25, 2002 1:35 PM
To: tutor@python.org
Cc: Nicole Seitz
Subject: Re: [Tutor] Extracting words(quest 2)


Hi Nicole,


At 11:11 25/03/2002 -0500, you wrote:
>From: Nicole Seitz <nicole.seitz@urz.uni-hd.de>
>Subject: Re: [Tutor] Extracting words(quest 2)
>Date: Mon, 25 Mar 2002 11:20:57 +0100

>I'm trying to write a little script that extracts word creations like
>"StarOffice","CompuServe","PalmPilot",etc. from an text file.

>I might want to have an output like that:
>
>line 3: StarOffice
>line34: CompuServe
>line 42: PalmPilot
>
>This means I need some additional information, namely in which line the
>words  were found. Using the function findall() from the re module, this
>is not possible, is it??
>
>I had some kind of solution starting like that:

OK, here is an example based on your code to get you started:

import re, pprint

def indexWord(filename):
     wordDict = {}
     lineCount = 0
     file = open(filename)
     expr = re.compile("\w+", re.LOCALE)
     while 1:
         line = file.readline()
         if not line:
             break
         lineCount = lineCount + 1
         resultList  = expr.findall(line)
         if resultList:
             for word in resultList:
                 if wordDict.has_key(word):
                     # line numbers are stored in a list for every word
                     wordDict[word].append(lineCount)
                 else:
                     wordDict[word] = [lineCount]
     file.close()
     return wordDict


if __name__ == "__main__":
     filename = r"c:\foo\bar\baz.txt"
     wordDict = indexWord(filename)
     # prettyprint the results
     pprint.pprint(wordDict)

Example output:
...
  'extraordinarily': [381],
  'extremely': [246],
  'facilities': [159, 190, 360],
  'fail': [294],
  'fairly': [331],
  'family': [177, 339],
...

Notes:
- You need to use your own regular expression here; the one I used matches
any group of alphanumeric characters.
- If a word occurs twice in the same line, it will be listed twice. To
avoid this behaviour, you need to filter resultList (left as an exercice
:-).

>Would be very thankful for suggestions!!


HTH.

Alex



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



From chez@reyndersgray.com  Mon Mar 25 19:34:54 2002
From: chez@reyndersgray.com (Chez)
Date: Mon, 25 Mar 2002 14:34:54 -0500
Subject: [Tutor] Updating numbers in file..
Message-ID: <PNEJJIHDPEGJKOIEPBGLEEEOCBAA.chez@reyndersgray.com>

I have to files

file1

a  100
b  200
c  300
d  400


and I wnat to create file2 with   "-"  sign

file2

a  -100
b  -200
c  -300
d  -400

how can I do it with python?

Chez


From dsh8290@rit.edu  Mon Mar 25 20:32:04 2002
From: dsh8290@rit.edu (dman)
Date: Mon, 25 Mar 2002 14:32:04 -0600
Subject: [Tutor] Extracting words..
In-Reply-To: <4.3.2.7.2.20020325194217.00d091d0@pop3.norton.antivirus>
References: <E16pX3o-000849-00@mail.python.org> <4.3.2.7.2.20020325194217.00d091d0@pop3.norton.antivirus>
Message-ID: <20020325203204.GA19588@dman.ddts.net>

On Mon, Mar 25, 2002 at 07:55:36PM +0100, Alexandre Ratti wrote:
| Hi Alan,
| 
| At 11:11 25/03/2002 -0500, you wrote:
| >From: alan.gauld@bt.com
| >Subject: RE: [Tutor] Extracting words..
| >Date: Sun, 24 Mar 2002 23:55:38 -0000
| 
| >True, but at least its shorter to code using map:
| >
| >> Lst = ['JavaScript', 'MacWeek', 'MacWeek', 'CompuServe', 'CompuServe' ]
| >
| >  Lst = map(lambda item: item not in Lst, Lst)
| 
| Does this snippet work on your computer? I get "[0, 0, 0, 0, 0]".

hehe, nice catch.

How about :
    Lst = filter(lambda item: item not in Lst, Lst)
?

Hmm, that won't work either -- everything in Lst is in Lst so the
filter will return an empty list.

I guess using map or filter or a list comprehension is harder for this
job than we thought.

-D

-- 

In my Father's house are many rooms; if it were not so, I would have
told you.  I am going there to prepare a place for you.  And if I go and
prepare a place for you, I will come and take you to be with me that you
also may be where I am.
        John 14:2-3 



From dsh8290@rit.edu  Mon Mar 25 20:34:14 2002
From: dsh8290@rit.edu (dman)
Date: Mon, 25 Mar 2002 14:34:14 -0600
Subject: [Tutor] Updating numbers in file..
In-Reply-To: <PNEJJIHDPEGJKOIEPBGLEEEOCBAA.chez@reyndersgray.com>
References: <PNEJJIHDPEGJKOIEPBGLEEEOCBAA.chez@reyndersgray.com>
Message-ID: <20020325203414.GB19588@dman.ddts.net>

Thanks for posting as a new message instead of a reply to an unrelated
thread :-).

On Mon, Mar 25, 2002 at 02:34:54PM -0500, Chez wrote:
| 
| I have two files
| 
| file1
| 
| a  100
| b  200
| c  300
| d  400
| 
| 
| and I wnat to create file2 with   "-"  sign
| 
| file2
| 
| a  -100
| b  -200
| c  -300
| d  -400
| 
| how can I do it with python?

f1 = open( "file1" , "r" )
f2 = open( "file2" , "w" )
for line in f1.xreadlines() :
    letter , num = line.split( ' ' )
    f2.write( "%s -%s" % (letter , num) )
f2.close()
f1.close()

(this is untested, btw)
If you want this explained just ask (on-list please).

-D

-- 

A perverse man stirs up dissension,
and a gossip separates close friends.
        Proverbs 16:28



From seedseven@home.nl  Mon Mar 25 20:40:17 2002
From: seedseven@home.nl (ingo)
Date: Mon, 25 Mar 2002 21:40:17 +0100
Subject: [Tutor] code colorizer
In-Reply-To: <4.2.0.58.20020325093708.019f2700@pop3.norton.antivirus>
References: <4.2.0.58.20020325065749.0159d6a0@pop3.norton.antivirus>
 <4.2.0.58.20020325065749.0159d6a0@pop3.norton.antivirus>
 <4.2.0.58.20020325093708.019f2700@pop3.norton.antivirus>
Message-ID: <200203252140170109.01E40CEE@mail>

On 2002/03/25 at 09:42 Kirby Urner wrote:

>   return reduce(lambda x,y:x+y,s)
>in ad_tag() is a bottleneck, which is better replaced with:
>
>   return ''.join(s)

Changed it. Makes quite a difference.

>If you want to test the same file (nothing special to look
>at, just long ~120K of mostly cylinders), I've put it at:

Just tried a 60 MB mesh, not fun :( 
I stopped it after 15 min and the use of ~1GB memory.

Ingo



From charlie@begeistert.org  Mon Mar 25 21:43:17 2002
From: charlie@begeistert.org (Charlie Clark)
Date: Mon, 25 Mar 2002 22:43:17 +0100
Subject: [Tutor] Re: Storing dictionaries
In-Reply-To: <E16pGHT-0006oG-00@mail.python.org>
References: <E16pGHT-0006oG-00@mail.python.org>
Message-ID: <20020325224530.5505.14@gormenghast.AUTODIAL>

On 2002-03-24 at 23:16:03 [+0100], tutor-request@python.org wrote:
> 
>    from pprint import pprint
>    fielddict_file = open("fielddict.txt","w")
>    pprint(fielddict, fielddict_file)
>    fielddict_file.close()
> 
> pprint (at least for the data I've pushed through it) produces an output 
> that is readable and also suitable to paste into a python program as 
> source code.  I've been using it to print dictionaries of database 
> information

wow, what an amazing language and what a great list.
Python provides a generic, easy to use serialisation method (Pickle) and some top-notch and still easy to use alternatives for specialised use and this list makes this information available to all in an easy to understand and informal way. I've learned so much since I joined it!!!

A big thanx to all!

Charlie


From printers@sendme.cz  Mon Mar 25 22:16:28 2002
From: printers@sendme.cz (A)
Date: Mon, 25 Mar 2002 23:16:28 +0100
Subject: [Tutor] How to get a key from  dictionary?
Message-ID: <3C9FAFCC.20062.91741D@localhost>

Hi,
Is there a possibility to get, from a dictionary, a key according to a 
value ?
For example
I have a dictionary

dict={'aa':1,'bb':2}

and 
dict['aa']
is 1

But how can I for value 1 find out  key? (That is here  'aa')

Thank you for help
Ladislav




From in_ur_face64@hotmail.com  Mon Mar 25 18:36:02 2002
From: in_ur_face64@hotmail.com (Charlie Lemley)
Date: Mon, 25 Mar 2002 12:36:02 -0600
Subject: [Tutor] hacking
Message-ID: <F21Qez1enAqpfkNsjUH0001d595@hotmail.com>

hey i would like to learn how to hack could u teach
me the basics and then i would like to become a professinal

<br><br><br><html><DIV>
<DIV><FONT face="Arial Black, Geneva, Arial, Sans-serif" size=7>&nbsp;<IMG 
height=12 src="http://graphics.hotmail.com/emdgust.gif" width=12><FONT 
size=6><FONT color=#000099>Silent Bob</FONT><IMG height=12 
src="http://graphics.hotmail.com/emdgust.gif" width=12>®</FONT></FONT></DIV>
<DIV><FONT color=#ff0000 size=1>or Chuck<FONT 
color=#000000>®,</FONT>Chucky<FONT color=#000000>®,</FONT>Charles<FONT 
color=#000000>®,</FONT>Ed<FONT color=#000000>®,</FONT>Eddy<FONT 
color=#000000>®,</FONT>Edward<FONT color=#000000>®,</FONT>Edwardo<FONT 
color=#000000>®</FONT></FONT></DIV></DIV></html>


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



From pythonhack@yahoo.com  Mon Mar 25 22:40:29 2002
From: pythonhack@yahoo.com (pythonhack@yahoo.com)
Date: Mon, 25 Mar 2002 14:40:29 -0800
Subject: [Tutor] hacking
In-Reply-To: <F21Qez1enAqpfkNsjUH0001d595@hotmail.com>
References: <F21Qez1enAqpfkNsjUH0001d595@hotmail.com>
Message-ID: <1681057718448.20020325144029@yahoo.com>

I think your chances of getting help depend on your definition of
"hacking"...

brett

CL> hey i would like to learn how to hack could u teach
CL> me the basics and then i would like to become a professinal

CL> <br><br><br><html><DIV>
CL> <DIV><FONT face="Arial Black, Geneva, Arial, Sans-serif" size=7>&nbsp;<IMG 
CL> height=12 src="http://graphics.hotmail.com/emdgust.gif" width=12><FONT 
size=6>><FONT color=#000099>Silent Bob</FONT><IMG height=12 
CL> src="http://graphics.hotmail.com/emdgust.gif" width=12>®</FONT></FONT></DIV>
CL> <DIV><FONT color=#ff0000 size=1>or Chuck<FONT 
color=#000000>>®,</FONT>Chucky<FONT color=#000000>®,</FONT>Charles<FONT 
color=#000000>>®,</FONT>Ed<FONT color=#000000>®,</FONT>Eddy<FONT 
color=#000000>>®,</FONT>Edward<FONT color=#000000>®,</FONT>Edwardo<FONT 
color=#000000>>®</FONT></FONT></DIV></DIV></html>


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


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


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com



From dyoo@hkn.eecs.berkeley.edu  Mon Mar 25 22:50:19 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 25 Mar 2002 14:50:19 -0800 (PST)
Subject: [Tutor] Comma Chameleon?
In-Reply-To: <sc9f1606.056@madis2.truax.covance.com>
Message-ID: <Pine.LNX.4.44.0203251444130.12815-100000@hkn.eecs.berkeley.edu>


On Mon, 25 Mar 2002, Curtis Larsen wrote:

> <grin>
> I'm  probably missing it, but isn't there some sort of formatting
> option for use with the 'print' command that will automagically insert
> commas into a number?  If not, what's the best Pythonic method to do
> this?  (Note: I don't need currency or a +/-: I just want 123456789 to
> look like 123,456,789.)

Actually, it doesn't appear to be built in.  I know I've seen this
somewhere in the Zope source code, so perhaps we can just yank it out of
Zope... ah, there it is!

In Zope, variables can be displayed with a "thousands_commas" attribute,
and the source code that does this is in DocumentTemplate/DT_Var.py.  It
might be educational to see what "production" code looks like.

Here's the relevant fragment that adds commas in:

###
def thousands_commas(v, name='(Unknown name)', md={},
                     thou=re.compile(
                         r"([0-9])([0-9][0-9][0-9]([,.]|$))").search):
    v=str(v)
    vl=v.split('.')
    if not vl: return v
    v=vl[0]
    del vl[0]
    if vl: s='.'+'.'.join(vl)
    else: s=''
    mo=thou(v)
    while mo is not None:
        l = mo.start(0)
        v=v[:l+1]+','+v[l+1:]
        mo=thou(v)
    return v+s
###

This isn't as bad as it might look.  You can ignore or remove the 'name'
and 'md' parameters --- I think they're specific to Zope --- but
everything else appears to try to do the "right" thing, no matter how ugly
the input is.  *grin* It even tries to treat floating point numbers
properly.

The approach they take is to use a regular expression to grab chunks of
thousands from a number, and add some decorative commas, until there's no
more commas to plug in.

Here's an example of it in action:

###
>>> thousands_commas(1234567890)
'1,234,567,890'
>>> thousands_commas(123456.7890)
'123,456.789'
###


Hope this helps!



From kojo@hal-pc.org  Mon Mar 25 23:01:06 2002
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Mon, 25 Mar 2002 17:01:06 -0600
Subject: [Tutor] hacking
In-Reply-To: <F21Qez1enAqpfkNsjUH0001d595@hotmail.com>
Message-ID: <5.1.0.14.0.20020325170030.00b19b10@Pop3.norton.antivirus>

Here's the best place to start learning:

<http://www.tuxedo.org/~esr/faqs/hacker-howto.html>


At 12:36 PM 3/25/2002 -0600, Charlie Lemley wrote:

>hey i would like to learn how to hack could u teach
>me the basics and then i would like to become a professinal

****************************
Kojo Idrissa

kojo@hal-pc.org
http://www.hal-pc.org/~kojo/
****************************



From dman@dman.ddts.net  Mon Mar 25 22:59:01 2002
From: dman@dman.ddts.net (dman)
Date: Mon, 25 Mar 2002 16:59:01 -0600
Subject: [Tutor] How to get a key from  dictionary?
In-Reply-To: <3C9FAFCC.20062.91741D@localhost>
References: <3C9FAFCC.20062.91741D@localhost>
Message-ID: <20020325225901.GB20910@dman.ddts.net>

On Mon, Mar 25, 2002 at 11:16:28PM +0100, A wrote:
| Hi,
| Is there a possibility to get, from a dictionary, a key according to a 
| value ?
| For example
| I have a dictionary
| 
| dict={'aa':1,'bb':2}
| 
| and 
| dict['aa']
| is 1
| 
| But how can I for value 1 find out  key? (That is here  'aa')

That is not how dictionaries are intended to be used.  It is possible,
with a little work and a few CPU cycles, to work backwards like that.
If you give more details regarding why you want to do this then
perhaps we can suggest a more efficient solution.  In the meantime,

a_dict = { 'aa' : 1 , 'bb' : 2 }
items = a_dict.items()
VALUE = 1 # the value you want to find
t = filter( lambda x : x[1] == VALUE , items )[0]
key = t[0]
print key


What this does it get the list of (key,value) tuples from the
dictionary, then iterate over it finding all the pairs that have the
value you want to find.  It then takes the first of those (bear in mind
dicts can have duplicate values but not duplicate keys) and prints the
key for that pair.  This algorithm requires linear time.  As the
dictionary grows larger the time for this code to execute grows at the
same rate.

Also note that using 'dict' as a variable name is not recommended
since it is a built-in name in python >= 2.2.

HTH,
-D

-- 

Micros~1 :  
 For when quality, reliability 
  and security just aren't
   that important!



From dman@dman.ddts.net  Mon Mar 25 23:05:25 2002
From: dman@dman.ddts.net (dman)
Date: Mon, 25 Mar 2002 17:05:25 -0600
Subject: [Tutor] hacking
In-Reply-To: <F21Qez1enAqpfkNsjUH0001d595@hotmail.com>
References: <F21Qez1enAqpfkNsjUH0001d595@hotmail.com>
Message-ID: <20020325230525.GC20910@dman.ddts.net>

On Mon, Mar 25, 2002 at 12:36:02PM -0600, Charlie Lemley wrote:
 
| hey i would like to learn how to hack could u teach
| me the basics and then i would like to become a professinal

Start with
    http://www.tuxedo.org/~esr/faqs/hacker-howto.html
and move into
    http://www.freenetpages.co.uk/hp/alan.gauld/

I hadn't seen this before but after a quick skim it looks decent
    http://www.hetland.org/python/instant-hacking.php


| <br><br><br><html><DIV>
| <DIV><FONT face="Arial Black, Geneva, Arial, Sans-serif" size=7>&nbsp;<IMG 
| height=12 src="http://graphics.hotmail.com/emdgust.gif" width=12><FONT 
| size=6><FONT color=#000099>Silent Bob</FONT><IMG height=12 
| src="http://graphics.hotmail.com/emdgust.gif" width=12>?</FONT></FONT></DIV>
| <DIV><FONT color=#ff0000 size=1>or Chuck<FONT 
| color=#000000>?,</FONT>Chucky<FONT color=#000000>?,</FONT>Charles<FONT 
| color=#000000>?,</FONT>Ed<FONT color=#000000>?,</FONT>Eddy<FONT 
| color=#000000>?,</FONT>Edward<FONT color=#000000>?,</FONT>Edwardo<FONT 
| color=#000000>?</FONT></FONT></DIV></DIV></html>

If you can help it (I noticed you used hotmail, so you might not be
able to) try to avoid the HTML in email.

HTH,
-D

-- 

Many are the plans in a man's heart,
but it is the Lord's purpose that prevails.
        Proverbs 19:21



From pythontutor@venix.com  Mon Mar 25 23:39:31 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Mon, 25 Mar 2002 18:39:31 -0500
Subject: [Tutor] How to get a key from  dictionary?
References: <3C9FAFCC.20062.91741D@localhost> <20020325225901.GB20910@dman.ddts.net>
Message-ID: <3C9FB533.4030404@venix.com>

Depending upon the values you are dealing with, and how often you need to
do the reverse lookup, you could build a reverse dictionary.  Borrowing from
dman's example:
b_dict = {}
for item in a_dict.items()
	[b_dict[item[1]] = item[0]
 >>> b_dict
{2: 'bb', 1: 'aa'}

dman wrote:

> On Mon, Mar 25, 2002 at 11:16:28PM +0100, A wrote:
> | Hi,
> | Is there a possibility to get, from a dictionary, a key according to a 
> | value ?
> | For example
> | I have a dictionary
> | 
> | dict={'aa':1,'bb':2}
> | 
> | and 
> | dict['aa']
> | is 1
> | 
> | But how can I for value 1 find out  key? (That is here  'aa')
> 
> That is not how dictionaries are intended to be used.  It is possible,
> with a little work and a few CPU cycles, to work backwards like that.
> If you give more details regarding why you want to do this then
> perhaps we can suggest a more efficient solution.  In the meantime,
> 
> a_dict = { 'aa' : 1 , 'bb' : 2 }
> items = a_dict.items()
> VALUE = 1 # the value you want to find
> t = filter( lambda x : x[1] == VALUE , items )[0]
> key = t[0]
> print key
> 
> 
> What this does it get the list of (key,value) tuples from the
> dictionary, then iterate over it finding all the pairs that have the
> value you want to find.  It then takes the first of those (bear in mind
> dicts can have duplicate values but not duplicate keys) and prints the
> key for that pair.  This algorithm requires linear time.  As the
> dictionary grows larger the time for this code to execute grows at the
> same rate.
> 
> Also note that using 'dict' as a variable name is not recommended
> since it is a built-in name in python >= 2.2.
> 
> HTH,
> -D
> 
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582



From hall@phyast.nhn.ou.edu  Mon Mar 25 23:23:14 2002
From: hall@phyast.nhn.ou.edu (Isaac Hall)
Date: Mon, 25 Mar 2002 17:23:14 -0600
Subject: [Tutor] How to get a key from dictionary?
In-Reply-To: <3C9FAFCC.20062.91741D@localhost>
References: <3C9FAFCC.20062.91741D@localhost>
Message-ID: <02032517402800.20761@ouhep1>

I had a similar question not long ago.  My case was a little different (maybe)
in that I was gauranteed a one to one mapping between key and value.  I found
that provided the dictionary was not too long, the easiest solution was to
create 2 entries for every one which you have.  for instance, in the example
below you would have:

dict = {'aa':1, 'bb':2, 1:'aa', 2:'bb'}
then 
dict[1]
will give the desired 'aa'

however, this obviously does not work if there is not a one to one mapping (ie
if a value has more than one key).  If that is the case, then the best way I
have thought of so far is to place a list as the value for each new key.

for instance:
if your original dictionary is:
dict = {'aa':1, 'bb':2, 'cc':1}
then we want to make our new dictionary be:
dict = {'aa':1, 'bb':2, 'cc':1, 1:['aa','cc'], 2:['bb']}

if the dictionary is too large to do this by hand, we can automate it

def addtodict(dict):                          # Import a normal dictionary
    for key in dict.has_key():             # loop over all keys
        if dict[dict[key]]:                      #see if we already have an
                                                    #entry for each value   
            dict[dict[key]].append(key)    #if so, append to it
        else:
            dict[dict[key]] = [key]             #if not create it 

I haven't tested this, but something of this nature should work.  this will
take a little bit of time out of the program (depending on how large the
dictionary is) but for modestly sized dictionaries, should not be a problem
also note, that we can make all values in the dictionary to be lists and make
this much more complicated, but hopefully this will be enough to get you
started.

Ike 

On Mon, 25 Mar 2002, A wrote:
> Hi,
> Is there a possibility to get, from a dictionary, a key according to a 
> value ?
> For example
> I have a dictionary
> 
> dict={'aa':1,'bb':2}
> 
> and 
> dict['aa']
> is 1
> 
> But how can I for value 1 find out  key? (That is here  'aa')
> 
> Thank you for help
> Ladislav
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


From mikalzet@libero.it  Mon Mar 25 23:44:16 2002
From: mikalzet@libero.it (mikalzet@libero.it)
Date: Tue, 26 Mar 2002 00:44:16 +0100 (CET)
Subject: [Tutor] learning Tkinter
In-Reply-To: <5.1.0.14.0.20020325074609.00ad4a18@www.bembry.org>
Message-ID: <Pine.LNX.4.33L2.0203260039190.2612-100000@localhost.localdomain>

Thanks to ALL who answered for the suggestions and advice. The type of
team spirit this list shows is I think one of the biggest assets of python.
Thanks again !

-- 
Michele Alzetta



From r.nyborg@telia.com  Mon Mar 25 23:36:41 2002
From: r.nyborg@telia.com (Robert Nyborg)
Date: Tue, 26 Mar 2002 00:36:41 +0100
Subject: [Tutor] Comma Chameleon?
References: <sc9f1606.056@madis2.truax.covance.com>
Message-ID: <00b301c1d455$eba2d3b0$040fa8c0@COMPAQ>

I'm sure other people on the list have elegant examples for this, =20
but this is what I've used for a similar problem:

###

import locale
locale.setlocale(locale.LC_ALL, 'US')
print locale.format('%s','123456789',1)

###

/RobertN

----- Original Message -----=20
From: "Curtis Larsen" <curtis.larsen@covance.com>
To: <tutor@python.org>
Sent: Monday, March 25, 2002 7:20 PM
Subject: [Tutor] Comma Chameleon?


> <grin>
> I'm  probably missing it, but isn't there some sort of formatting
> option for use with the 'print' command that will automagically insert
> commas into a number?  If not, what's the best Pythonic method to do
> this?  (Note: I don't need currency or a +/-: I just want 123456789 to
> look like 123,456,789.)
>=20
> Thanks!
> Curtis
>=20
>=20
>=20
> -----------------------------------------------------
> Confidentiality Notice: This e-mail transmission=20
> may contain confidential or legally privileged=20
> information that is intended only for the individual=20
> or entity named in the e-mail address. If you are not=20
> the intended recipient, you are hereby notified that=20
> any disclosure, copying, distribution, or reliance=20
> upon the contents of this e-mail is strictly prohibited.=20
>=20
> If you have received this e-mail transmission in error,=20
> please reply to the sender, so that we can arrange=20
> for proper delivery, and then please delete the message=20
> from your inbox. Thank you.
>=20
>=20
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor



From garber@centralcatholic.org  Tue Mar 26 01:09:40 2002
From: garber@centralcatholic.org (Robert Garber)
Date: Mon, 25 Mar 2002 20:09:40 -0500
Subject: [Tutor] Python & windows XP professional
Message-ID: <200203252009.AA1661141316@centralcatholic.org>

I just built a new Athlon XP 1900+ system running windows XP professional. I want to install python (eiterh active state 2.1 or python 2.2 and the win32 extesions), any words of wisdom or warning before I do this? An ounce of prevention is worth a pound of cure.

Thanks 
Robert



From urnerk@qwest.net  Tue Mar 26 01:26:29 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Mon, 25 Mar 2002 17:26:29 -0800
Subject: [Tutor] How to get a key from dictionary?
In-Reply-To: <02032517402800.20761@ouhep1>
References: <3C9FAFCC.20062.91741D@localhost>
 <3C9FAFCC.20062.91741D@localhost>
Message-ID: <4.2.0.58.20020325170126.00d09ac0@pop3.norton.antivirus>

At 05:23 PM 3/25/2002 -0600, Isaac Hall wrote:
>If that is the case, then the best way I have thought of
>so far is to place a list as the value for each new key.

Yes, I had to do something like this recently.  I wanted
a dictionary of spheres keyed by floating point distance
from the origin, but with several values possible at the
same distance (same key).  So I decided to just accumulate
all those sharing a key in a list.  Sometimes this is a
good solution.

>def addtodict(dict):           # Import a normal dictionary

Not really importing -- just passing a dictionary as a
parameter.

>     for key in dict.has_key(): # loop over all keys
>         if dict[dict[key]]:     #see if we already have an
>                                 #entry for each value
>             dict[dict[key]].append(key) #if so, append to it
>         else:
>             dict[dict[key]] = [key] #if not create it
>
>I haven't tested this, but something of this nature should work.

Very untested :-D.  dict.has_key returns 1 or 0 (true or
false) so isn't something to iterate over with for.

An easy way to accumulate:

  >>> def addtodict(thedict, thekey, thevalue):
         thedict[thekey] = thedict.get(thekey,[]) + [thevalue]


  >>> thedict = {}
  >>> addtodict(thedict,'aa',1)
  >>> addtodict(thedict,'bb',3)
  >>> addtodict(thedict,'aa',2)
  >>> addtodict(thedict,'cc',4)
  >>> addtodict(thedict,'bb','r')
  >>> thedict
  {'aa': [1, 2], 'cc': [4], 'bb': [3, 'r']}

What this does is use thedict.get(thekey,[]) + [thevalue]
to return return the existing value appended to the new
value, or, if there's no existing value, to initialize
with [thevalue] (because if there's no existing value,
thedict.get(thekey,[]) returns [] and [] + [thevalue]
is just [thevalue].

The above is sort of non-functional programming in that
it uses a function to change a dictionary object passed
as a parameter, but returns nothing.  You can return
thedict if you prefer syntax like:

   >>> thedict = add2dict(thedict, 'rr', 78)

You can also define the function with thedict assumed
global.  Or have a function factory to bind a specific
dictionary (extending a thread I was working on earlier):

  >>> def addto(thedict):
          def main(thekey,thevalue):
             thedict[thekey] = thedict.get(thekey,[]) + [thevalue]
          return main

  >>> it = {}             # some dictionary
  >>> add2it = addto(it)  # a function for this dict in particular
  >>> add2it
  <function main at 0x01256F20>
  >>> add2it('aa',1)       # no need to mention which dictionary
  >>> add2it('aa',2)
  >>> add2it('bb',3)
  >>> it
  {'aa': [1, 2], 'bb': [3]}

Kirby



From TBelich@skcc.org  Tue Mar 26 01:23:33 2002
From: TBelich@skcc.org (Tom Belich)
Date: Mon, 25 Mar 2002 17:23:33 -0800
Subject: [Tutor] Parsing modules
Message-ID: <EC29AFD5E8A1D311A86C0008C79F87C5ABD362@sidney.skcc.org>

I need to parse a tab delimited flat file into a number of files that I can
load into a mysql database.  I've tried Parse::RecDescent in Perl.  Is there
a Python module that does this and are there examples I could modify to
learn it?

TIA
Tom Belich


From dyoo@hkn.eecs.berkeley.edu  Tue Mar 26 02:05:54 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 25 Mar 2002 18:05:54 -0800 (PST)
Subject: [Tutor] Parsing modules
In-Reply-To: <EC29AFD5E8A1D311A86C0008C79F87C5ABD362@sidney.skcc.org>
Message-ID: <Pine.LNX.4.44.0203251803470.16024-100000@hkn.eecs.berkeley.edu>


On Mon, 25 Mar 2002, Tom Belich wrote:

> I need to parse a tab delimited flat file into a number of files that I
> can load into a mysql database.  I've tried Parse::RecDescent in Perl.
> Is there a Python module that does this and are there examples I could
> modify to learn it?

Hi Tom,

Yes, I think you can use SimpleParse:

    http://www-106.ibm.com/developerworks/linux/library/l-simple.html

There are other parse modules available, but I think SimpleParse is close
in spirit to Perl's Parse::RecDescent.


Good luck to you!



From dyoo@hkn.eecs.berkeley.edu  Tue Mar 26 02:11:24 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Mon, 25 Mar 2002 18:11:24 -0800 (PST)
Subject: [Tutor] Comma Chameleon?
In-Reply-To: <00b301c1d455$eba2d3b0$040fa8c0@COMPAQ>
Message-ID: <Pine.LNX.4.44.0203251807030.16024-100000@hkn.eecs.berkeley.edu>

[Danny]
>> Actually, it doesn't appear to be built in.


[Robert]
> I'm sure other people on the list have elegant examples for this,
> but this is what I've used for a similar problem:
>
> ###
>
> import locale
> locale.setlocale(locale.LC_ALL, 'US')
> print locale.format('%s','123456789',1)
>
> ###


Wow, it is built in after all.  I stand corrected.  *grin*



I've had to use the "en_US" locale to get this to work:

###
>>> import locale
>>> locale.format('%s', '12345678', 1)
'12345678'
>>> locale.setlocale(locale.LC_ALL, 'US')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/opt/Python-2.1.1/lib/python2.1/locale.py", line 374, in setlocale
    return _setlocale(category, locale)
locale.Error: locale setting not supported
>>> locale.setlocale(locale.LC_ALL, 'en_US')
'en_US'
>>> locale.format('%s', '12345678', 1)
'12,345,678'
###




From arcege@speakeasy.net  Tue Mar 26 02:28:16 2002
From: arcege@speakeasy.net (Michael P. Reilly)
Date: Mon, 25 Mar 2002 21:28:16 -0500
Subject: [Tutor] How to get a key from  dictionary?
In-Reply-To: <3C9FB533.4030404@venix.com>
References: <3C9FAFCC.20062.91741D@localhost> <20020325225901.GB20910@dman.ddts.net> <3C9FB533.4030404@venix.com>
Message-ID: <20020326022816.GF885@speakeasy.net>

On Mon, Mar 25, 2002 at 06:39:31PM -0500, Lloyd Kvam wrote:
> Depending upon the values you are dealing with, and how often you need to
> do the reverse lookup, you could build a reverse dictionary.  Borrowing from
> dman's example:
> b_dict = {}
> for item in a_dict.items()
> 	[b_dict[item[1]] = item[0]
> >>> b_dict
> {2: 'bb', 1: 'aa'}

Be careful,  dman took a short-cut.  One that your's doesn't handle
at all.

Given an n-1 dictionary, the reverse would be 1-n, but your loop doesn't
collect the `n'.

>>> a_dict = {'a': 100, 'b': 2, 'c': 100, 'd': 200}
>>> b_dict = {}
>>> for key, value in a_dict.items():
...   b_dict[value] = b_dict.get(value, []) + [ key ]
...
>>> print b_dict
{100: ['c', 'a'], 2: ['b'], 200: ['d']}

This lets you capture that the values are unique.  Also, you would
have to worry if the value are unhashable.

>>> c_dict = {}
>>> for key, value in b_dict.items():
...   c_dict[value] = c_dict.get(value, []) + [ key ]
...
Traceback (innermost last):
  File "<stdin>", line 2, in ?
TypeError: unhashable type
>>>

Using tuples would be the solution here; they are hashable.

Not everything is as easy as it seems.

  -Arcege



From wolf_binary@hotmail.com  Tue Mar 26 03:54:41 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Mon, 25 Mar 2002 21:54:41 -0600
Subject: [Tutor] FYI
Message-ID: <DAV68Vjp3b6uIU1Gj0300020558@hotmail.com>

This is a multi-part message in MIME format.

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

Hi all,

For anyone who wants a good site for learning computer terms here is a =
good online dictionary search engine www.webopedia.com.

Also does anyone use the commandline version of python that much?  It =
has some really neat help stuff built into that that is also accessable =
from the interpreter GUI. =20

***** This is an FYI mostly for people new to the programming.

Cameron Stoner

------=_NextPart_000_0087_01C1D447.AADC10C0
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.2713.1100" 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>For anyone who wants a good site for =
learning=20
computer terms here is a good online dictionary search engine <A=20
href=3D"http://www.webopedia.com">www.webopedia.com</A>.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Also does anyone use the commandline =
version of=20
python that much?&nbsp; It has some really neat help stuff built into =
that that=20
is also accessable from the interpreter GUI.&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>***** This is an FYI mostly for people =
new to the=20
programming.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Cameron =
Stoner</FONT></DIV></BODY></HTML>

------=_NextPart_000_0087_01C1D447.AADC10C0--


From hall@nhn.ou.edu  Tue Mar 26 05:25:10 2002
From: hall@nhn.ou.edu (Ike Hall)
Date: Mon, 25 Mar 2002 23:25:10 -0600
Subject: [Tutor] How to get a key from dictionary?
In-Reply-To: <4.2.0.58.20020325170126.00d09ac0@pop3.norton.antivirus>
References: <3C9FAFCC.20062.91741D@localhost> <4.2.0.58.20020325170126.00d09ac0@pop3.norton.antivirus>
Message-ID: <200203260508.g2Q58t510318@phyast.nhn.ou.edu>

Oh I just realized....in the function I gave earlier, I meant to use 
dict.keys() instead of dict.has_key().....Ive got physics on the brain today 
instead of python....tomorrow Ill be better  :)

Ike

On Monday 25 March 2002 07:26 pm, you wrote:
> At 05:23 PM 3/25/2002 -0600, Isaac Hall wrote:
> >If that is the case, then the best way I have thought of
> >so far is to place a list as the value for each new key.
>
> Yes, I had to do something like this recently.  I wanted
> a dictionary of spheres keyed by floating point distance
> from the origin, but with several values possible at the
> same distance (same key).  So I decided to just accumulate
> all those sharing a key in a list.  Sometimes this is a
> good solution.
>
> >def addtodict(dict):           # Import a normal dictionary
>
> Not really importing -- just passing a dictionary as a
> parameter.
>
> >     for key in dict.has_key(): # loop over all keys
> >         if dict[dict[key]]:     #see if we already have an
> >                                 #entry for each value
> >             dict[dict[key]].append(key) #if so, append to it
> >         else:
> >             dict[dict[key]] = [key] #if not create it
> >
> >I haven't tested this, but something of this nature should work.
>
> Very untested :-D.  dict.has_key returns 1 or 0 (true or
> false) so isn't something to iterate over with for.
>
> An easy way to accumulate:
>   >>> def addtodict(thedict, thekey, thevalue):
>
>          thedict[thekey] = thedict.get(thekey,[]) + [thevalue]
>
>   >>> thedict = {}
>   >>> addtodict(thedict,'aa',1)
>   >>> addtodict(thedict,'bb',3)
>   >>> addtodict(thedict,'aa',2)
>   >>> addtodict(thedict,'cc',4)
>   >>> addtodict(thedict,'bb','r')
>   >>> thedict
>
>   {'aa': [1, 2], 'cc': [4], 'bb': [3, 'r']}
>
> What this does is use thedict.get(thekey,[]) + [thevalue]
> to return return the existing value appended to the new
> value, or, if there's no existing value, to initialize
> with [thevalue] (because if there's no existing value,
> thedict.get(thekey,[]) returns [] and [] + [thevalue]
> is just [thevalue].
>
> The above is sort of non-functional programming in that
> it uses a function to change a dictionary object passed
> as a parameter, but returns nothing.  You can return
>
> thedict if you prefer syntax like:
>    >>> thedict = add2dict(thedict, 'rr', 78)
>
> You can also define the function with thedict assumed
> global.  Or have a function factory to bind a specific
>
> dictionary (extending a thread I was working on earlier):
>   >>> def addto(thedict):
>
>           def main(thekey,thevalue):
>              thedict[thekey] = thedict.get(thekey,[]) + [thevalue]
>           return main
>
>   >>> it = {}             # some dictionary
>   >>> add2it = addto(it)  # a function for this dict in particular
>   >>> add2it
>
>   <function main at 0x01256F20>
>
>   >>> add2it('aa',1)       # no need to mention which dictionary
>   >>> add2it('aa',2)
>   >>> add2it('bb',3)
>   >>> it
>
>   {'aa': [1, 2], 'bb': [3]}
>
> Kirby


From hall@nhn.ou.edu  Tue Mar 26 05:45:59 2002
From: hall@nhn.ou.edu (Ike Hall)
Date: Mon, 25 Mar 2002 23:45:59 -0600
Subject: [Tutor] Python & windows XP professional
In-Reply-To: <200203252009.AA1661141316@centralcatholic.org>
References: <200203252009.AA1661141316@centralcatholic.org>
Message-ID: <200203260529.g2Q5Th527602@phyast.nhn.ou.edu>

due to a personal bias against microsoft (hey, at least Im telling you Im 
biased), my highest recommendation would be to get a better OS, however, I 
realize you probably think Im a linux kook too (I am  :)  ), so with that out 
of the way I would say to you that you are the first person I know of to use 
python on XP. (This is because the XP'rs I know dont want to program, and the 
programmers I know dont want XP), so although I can't be of any real help 
now,(hopefully others here may be), you are in the unique situation of what 
in my mind is treading new ground.  My Suggestion to you would be to 
periodically keep this list informed of how well it works, the problems you 
encounter, and their solutions.  And to keep reading from this list as you 
will no doubt gain much experience that will help other who will want to be 
like you :) 
so although this message surely wont be of any real help, I do sincerely want 
to wish you good luck.


Ike

PS.
on a side note I did a google search under python, windows, XP
and a curious article struck my eye about a privacy leak in python for 
windows (couldnt tell if this also applies to XP or not, but still may be 
helpful).  This may fall under the ounce of prevention you speak of.  the URL 
is http://www.securiteam.com/windowsntfocus/5BP0N0U61G.html

On Monday 25 March 2002 07:09 pm, you wrote:
> I just built a new Athlon XP 1900+ system running windows XP professional.
> I want to install python (eiterh active state 2.1 or python 2.2 and the
> win32 extesions), any words of wisdom or warning before I do this? An ounce
> of prevention is worth a pound of cure.
>
> Thanks
> Robert
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


From virketis@fas.harvard.edu  Tue Mar 26 05:48:08 2002
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Tue, 26 Mar 2002 00:48:08 -0500
Subject: [Tutor] Python & windows XP professional
References: <200203252009.AA1661141316@centralcatholic.org> <200203260529.g2Q5Th527602@phyast.nhn.ou.edu>
Message-ID: <004b01c1d489$ceaff290$18adf78c@virketis2>

Ike,

> of the way I would say to you that you are the first person I know of to
use
> python on XP. (This is because the XP'rs I know dont want to program, and
the
> programmers I know dont want XP), so although I can't be of any real help

I had replied to Robert's original querry about XP and Python in private,
since this did not strike me as a topic of wide general interest. But now I
would like to mention that I have indeed run Python 1.5.2, 2.1 and 2.2 on
XP, along with MySQL and Apache for development, and everything is working
just fine out of the box. While I agree in principle with your scepticism
about Micro$oft, in fairness one has to grant that XP is orders of magnitude
more stable than any of the previous consumer Windows incarnations. Of
course, stability is not everything, and I cannot, for instance, figure out
how to get rid of the accursed MS Messenger, plus a bunch of other things,
but that's most certainly a subject for another day and a different list. :)

Cheers,

Pijus



From shalehperry@attbi.com  Tue Mar 26 06:01:59 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Mon, 25 Mar 2002 22:01:59 -0800 (PST)
Subject: [Tutor] Comma Chameleon?
In-Reply-To: <Pine.LNX.4.44.0203251807030.16024-100000@hkn.eecs.berkeley.edu>
Message-ID: <XFMail.20020325220159.shalehperry@attbi.com>

> 
> I've had to use the "en_US" locale to get this to work:
> 

yeah, simple typo on his part.


From imcmeans@shaw.ca  Tue Mar 26 07:53:34 2002
From: imcmeans@shaw.ca (Ian!)
Date: Mon, 25 Mar 2002 23:53:34 -0800
Subject: [Tutor] IDLE question
References: <E16pjXy-0008BZ-00@mail.python.org>
Message-ID: <003601c1d49b$549b5550$da494e18@cr536745a>

I have edited my IDLE color preferences, but I haven't found a way to change
the color of the text on tooltip popups. Is there a way to do this? I
haven't been able to find any documentation for IDLE's config.txt files, and
none of the settings in the file change the tooltip color.



From imcmeans@shaw.ca  Tue Mar 26 07:34:42 2002
From: imcmeans@shaw.ca (Ian!)
Date: Mon, 25 Mar 2002 23:34:42 -0800
Subject: [Tutor] lists
Message-ID: <002201c1d498$b1b744e0$da494e18@cr536745a>

Hello! I'd just like to say that I've been happily using python on XP for a
few months now. (to answer Rob's question). I haven't run into any glitches.

Okay, here's a question. How should I access the elements of a list in a for
loop? Right now, when I try to do it, I get a list that contains all of the
letters of each element in the list. Here's what I mean:

>>> somewords = ['goo', 'foo', 'loo', 'moo', 'too']
>>> fillme = []
>>> for word in somewords:
         fillme += word
>>> fillme
['g', 'o', 'o', 'f', 'o', 'o', 'l', 'o', 'o', 'm', 'o', 'o', 't', 'o', 'o']

How can I make the for loop work with whole strings at a time, instead of
characters?



From python@rcn.com  Tue Mar 26 12:17:07 2002
From: python@rcn.com (Raymond Hettinger)
Date: Tue, 26 Mar 2002 07:17:07 -0500
Subject: [Tutor] lists
References: <002201c1d498$b1b744e0$da494e18@cr536745a>
Message-ID: <000e01c1d4c0$26bb4120$6466accf@othello>

Hello Ian,

The plus operator for lists concatenates two sequences.
'Word' is interpreted as a sequence of letters in your example.
Putting brackets around it, makes the word itself a sequence of one.
Alternatively, the usual style for building a list is to use the append
method.

Replace 'fillme += word'
with 'fillme += [word]'
or with 'fillme.append(word)'


Raymond Hettinger


----- Original Message -----
From: "Ian!" <imcmeans@shaw.ca>
To: <Tutor@python.org>
Sent: Tuesday, March 26, 2002 2:34 AM
Subject: Re: [Tutor] lists


> Hello! I'd just like to say that I've been happily using python on XP for
a
> few months now. (to answer Rob's question). I haven't run into any
glitches.
>
> Okay, here's a question. How should I access the elements of a list in a
for
> loop? Right now, when I try to do it, I get a list that contains all of
the
> letters of each element in the list. Here's what I mean:
>
> >>> somewords = ['goo', 'foo', 'loo', 'moo', 'too']
> >>> fillme = []
> >>> for word in somewords:
>          fillme += word
> >>> fillme
> ['g', 'o', 'o', 'f', 'o', 'o', 'l', 'o', 'o', 'm', 'o', 'o', 't', 'o',
'o']
>
> How can I make the for loop work with whole strings at a time, instead of
> characters?
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



From virketis@fas.harvard.edu  Tue Mar 26 12:24:41 2002
From: virketis@fas.harvard.edu (Pijus Virketis)
Date: Tue, 26 Mar 2002 07:24:41 -0500
Subject: [Tutor] lists
References: <002201c1d498$b1b744e0$da494e18@cr536745a>
Message-ID: <006501c1d4c1$348f2ea0$18adf78c@virketis2>

Ian,

> How can I make the for loop work with whole strings at a time, instead of
> characters?

Try the following small adjustment:

>>> somewords = ['goo', 'foo', 'loo', 'moo', 'too']
>>> fillme = []
>>> for word in somewords:
...          fillme.append(word)    #using the append() method rather than
the increment operator
>>> fillme
['goo', 'foo', 'loo', 'moo', 'too']

This is a very typical task, and append() seems to me to be the best way of
doing it.

Cheers,

Pijus




From erikprice@mac.com  Tue Mar 26 13:04:03 2002
From: erikprice@mac.com (Erik Price)
Date: Tue, 26 Mar 2002 08:04:03 -0500
Subject: [Tutor] Python & windows XP professional
In-Reply-To: <004b01c1d489$ceaff290$18adf78c@virketis2>
Message-ID: <F2ABF358-40B9-11D6-98A3-00039351FE6A@mac.com>

On Tuesday, March 26, 2002, at 12:48  AM, Pijus Virketis wrote:

> course, stability is not everything, and I cannot, for instance, figure 
> out
> how to get rid of the accursed MS Messenger, plus a bunch of other 
> things,
> but that's most certainly a subject for another day and a different 
> list. :)

Reformat the drive, and I have a Slackware image I can send you.

:)


Erik



From bwinton@tor.dhs.org  Tue Mar 26 13:21:22 2002
From: bwinton@tor.dhs.org (Blake Winton)
Date: Tue, 26 Mar 2002 08:21:22 -0500
Subject: [Tutor] Python & windows XP professional
In-Reply-To: <200203260529.g2Q5Th527602@phyast.nhn.ou.edu>
References: <200203252009.AA1661141316@centralcatholic.org> <200203260529.g2Q5Th527602@phyast.nhn.ou.edu>
Message-ID: <20020326082122.A21127@tor.dhs.org>

* Ike Hall <hall@nhn.ou.edu> [020326 00:28]:
> you probably think Im a linux kook too (I am  :)

You are.  ;)

> you are the first person I know of to use python on XP. (This is
> because the XP'rs I know dont want to program, and the programmers I
> know dont want XP),

I guess that makes me the second.  I program under XP all day.  Not
programming for XP, programming for the PalmPilot, but under XP, and let
me just say that it's the best Microsoft OS since NT4.  It kicks the
living crap out of 2000, 95, and 98 all put together.  :)

> you are in the unique situation of what in my mind is treading new
> ground.

Yeah, but it's not _really_ new ground.  I, for instance, have had no
problems installing and using the base python 2.2.  Idle works, the
command line interpreter works.  I've even set up Python as the default
handler for .py files, so that I can just double-click them, and they
work.  I think that the original poster should just go ahead and install
it.  There's nothing to be afraid of, and even less that you need to
consider beforehand.

Later,
Blake.
-- 
  8:20am  up 13 days, 12:09,  4 users,  load average: 0.06, 0.05, 0.05


From pythontutor@venix.com  Tue Mar 26 13:43:04 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Tue, 26 Mar 2002 08:43:04 -0500
Subject: [Tutor] Comma Chameleon?
References: <XFMail.20020325220159.shalehperry@attbi.com>
Message-ID: <3CA07AE8.4000500@venix.com>

PythonWin 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32.
Portions Copyright 1994-2000 Mark Hammond (MarkH@ActiveState.com) - see 'Help/About PythonWin' for further copyright information.

 >>> import locale
 >>> locale.setlocale(locale.LC_ALL, 'US')
'English_United States.1252'
 >>> print locale.format('%s','123456789',1)
123,456,789

Actually, it may be a python version issue!

Sean 'Shaleh' Perry wrote:

>>I've had to use the "en_US" locale to get this to work:
>>
>>
> 
> yeah, simple typo on his part.
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582



From brad.reisfeld@colostate.edu  Tue Mar 26 14:01:27 2002
From: brad.reisfeld@colostate.edu (Brad Reisfeld)
Date: Tue, 26 Mar 2002 07:01:27 -0700
Subject: [Tutor] data structure and algorithm
Message-ID: <NGEALAODAKLOJADDLGPACEDBCBAA.brad.reisfeld@colostate.edu>

Hi,
I would appreciate some advice with regard to an algorithm and data
structure.

Suppose that I have a number of functions (f1,..., fn) each of which take a
'symbol' argument and return a list of such symbols. For example:

f1(A) = [B,C,D,E]
f2(B) = [F,G]
f2(C) = [H,I,J]
f3(G) = [K,L,B,N]

After applying the functions in a certain way, I would like to enumerate the
'linkage' between the various symbols. Each 'symbol' may not be unique, and
may appear at various points in a 'chain'.

For the example above, this linkage might be represented as

A -> B -> F
A -> B -> G -> K
A -> B -> G -> L
A -> B -> G -> B
A -> B -> G -> N
A -> C -> H
A -> C -> I
A -> C -> J
A -> D
A -> E

Although it is not necessary, it might be useful to have the functions
applied for each item enumerated as well, e.g.
	A -> B -> F : (f1,f2)   or	A --f1--> B --f2--> F

I'm not a computer scientist, but this seems as if this is basically a tree
structure in which we are moving from the 'trunk' to a given 'leaf'. Perhaps
this is something related to directory 'walking'.

Does anyone have any ideas as to how I should code this structure and
algorithm?

Thanks for your help.

-Brad



From budgester@budgester.com  Tue Mar 26 14:07:13 2002
From: budgester@budgester.com (Martin Stevens)
Date: Tue, 26 Mar 2002 14:07:13 +0000
Subject: [Tutor] bar code
In-Reply-To: <20020325151156.GB14261@dman.ddts.net>
References: <20020325141010.95909.qmail@web11301.mail.yahoo.com> <20020325151156.GB14261@dman.ddts.net>
Message-ID: <20020326140713.GA19018@akira.budgenet>

If i remember correctly there is some form of check sum in barcodes
to make sure they are correct and there are various different formats

i.e. 8 digit and 15 digits (iirc)

In the 15 digits one the country code is the first 5(i think) numbers
that the product was produced in.

Try

http://www.makebarcode.com/info/info.html

Budgester

On Mon, Mar 25, 2002 at 09:11:56AM -0600, dman wrote:
> On Mon, Mar 25, 2002 at 06:10:10AM -0800, Maximiliano Ichazo wrote:
> | Does anybody has experience or know about any module to work with
> | bar codes (like those in a supermarket) in Python?
> 
> The systems I've seen have a (physical) scanner that handles the
> optical part of interpreting a bar code and converts the bars into
> characters.  The characters are then input into the computer via a
> keyboard or serial port.  When the software gets the data it can't
> tell the difference between a bar code scanned automatically or a
> human operator pressing keys on a keyboard or another program feeding
> it data through a pipe.
> 
> Can you give any detail on how you intend to work with the bar codes?
> I ask because most likely you don't have to do anything different at
> the python level than you would for manual input via keyboard.
> 
> HTH,
> -D
> 
> -- 
> 
> All a man's ways seem innocent to him,
> but motives are weighed by the Lord.
>         Proverbs 16:2
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

-- 
Budgester Technologies Ltd
Office : 01992 718568
Mobile : 07815 982380
mailto:martin@budgester.com
http://www.budgester.com


From scarblac@pino.selwerd.nl  Tue Mar 26 14:15:04 2002
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 26 Mar 2002 15:15:04 +0100
Subject: [Tutor] data structure and algorithm
In-Reply-To: <NGEALAODAKLOJADDLGPACEDBCBAA.brad.reisfeld@colostate.edu>; from brad.reisfeld@colostate.edu on Tue, Mar 26, 2002 at 07:01:27AM -0700
References: <NGEALAODAKLOJADDLGPACEDBCBAA.brad.reisfeld@colostate.edu>
Message-ID: <20020326151504.A12075@pino.selwerd.nl>

On  0, Brad Reisfeld <brad.reisfeld@colostate.edu> wrote:
> Hi,
> I would appreciate some advice with regard to an algorithm and data
> structure.

Interesting problem, but I need clarification on two points:

> Suppose that I have a number of functions (f1,..., fn) each of which take a
> 'symbol' argument and return a list of such symbols. For example:
> 
> f1(A) = [B,C,D,E]
> f2(B) = [F,G]
> f2(C) = [H,I,J]
> f3(G) = [K,L,B,N]

This is odd - four different functions, four different arguments.

What happens with, say, f2(A)?

> After applying the functions in a certain way, I would like to enumerate the
> 'linkage' between the various symbols. Each 'symbol' may not be unique, and
> may appear at various points in a 'chain'.
> 
> For the example above, this linkage might be represented as
> 
> A -> B -> F
> A -> B -> G -> K
> A -> B -> G -> L
> A -> B -> G -> B

There is a problem here. If loops are possible (B -> G -> B) then there are
infinitely many chains possible - just repeat that loop as often as you
want. What to do? Don't loops occur in your data, or what?

> A -> B -> G -> N
> A -> C -> H
> A -> C -> I
> A -> C -> J
> A -> D
> A -> E
> 
> Although it is not necessary, it might be useful to have the functions
> applied for each item enumerated as well, e.g.
> 	A -> B -> F : (f1,f2)   or	A --f1--> B --f2--> F
> 
> I'm not a computer scientist, but this seems as if this is basically a tree
> structure in which we are moving from the 'trunk' to a given 'leaf'. Perhaps
> this is something related to directory 'walking'.

It reminds me of grammars for languages, like for simple expressions:

<expression> -> <atom>
<expression> -> <expression> + <expression>
<atom> -> 0..9

That's a grammar for a formal language that can produce strings of the form
'3', '3 + 5', '3 + 7 + 9 + 1', etc.

> Does anyone have any ideas as to how I should code this structure and
> algorithm?

I'm thinking dictionaries and recursion but I'd like to have the points
above clarified :)

-- 
Remco Gerlich


From dman@dman.ddts.net  Tue Mar 26 15:02:18 2002
From: dman@dman.ddts.net (dman)
Date: Tue, 26 Mar 2002 09:02:18 -0600
Subject: [Tutor] Comma Chameleon?
In-Reply-To: <3CA07AE8.4000500@venix.com>
References: <XFMail.20020325220159.shalehperry@attbi.com> <3CA07AE8.4000500@venix.com>
Message-ID: <20020326150218.GB28814@dman.ddts.net>

On Tue, Mar 26, 2002 at 08:43:04AM -0500, Lloyd Kvam wrote:
| PythonWin 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32.
| Portions Copyright 1994-2000 Mark Hammond (MarkH@ActiveState.com) - see 
| 'Help/About PythonWin' for further copyright information.
| 
| >>> import locale
| >>> locale.setlocale(locale.LC_ALL, 'US')
| 'English_United States.1252'
                         ^^^^
| >>> print locale.format('%s','123456789',1)
| 123,456,789
| 
| Actually, it may be a python version issue!

Or an OS issue -- CP1252 is a Microsoft/Windows thing.  That long name
is also non-standard.  The ISO spec follows this format : The language
has a two (lowercase) character code.  It is optionally followed by an
underscore and a 2-(uppercase)-character country code.  That is
optionally followed by a dot and a charset specification.  Thus en
en_US, en_UK, en_US.ISO8859-1 and en_US.UTF-8 are all valid (ISO)
locale specifications.

Do you know how annoying it is to receive emails where quotes appear
as superscript '2' and '3' or where punctuation is weird control
characters?  Some systems are just not interoperable, and it really
seems to be by design!

-D

-- 

If we claim to be without sin, we deceive ourselves and the truth is not
in us.
        I John 1:8



From nicole.seitz@urz.uni-hd.de  Tue Mar 26 15:22:03 2002
From: nicole.seitz@urz.uni-hd.de (Nicole Seitz)
Date: Tue, 26 Mar 2002 16:22:03 +0100
Subject: [Tutor] Extracting words(quest 2)
In-Reply-To: <4.3.2.7.2.20020325192321.00b9a810@pop3.norton.antivirus>
References: <4.3.2.7.2.20020325192321.00b9a810@pop3.norton.antivirus>
Message-ID: <02032611313700.00703@utopia>

Hi!

Thanx, this was very helpful! Though, there are some lines(see below) I d=
on't=20
understand.Hope you don't mind  explaining.

Am Montag, 25. M=E4rz 2002 19:35 schrieben Sie:

>
> import re, pprint
>
> def indexWord(filename):
>      wordDict =3D {}
>      lineCount =3D 0
>      file =3D open(filename)
>      expr =3D re.compile("\w+", re.LOCALE)

What's exactly the meaning of the flag LOCALE?

>      while 1:
>          line =3D file.readline()
>          if not line:
>              break
>          lineCount =3D lineCount + 1
>          resultList  =3D expr.findall(line)

So I can't use match()???


>
>
> if __name__ =3D=3D "__main__":
>      filename =3D r"c:\foo\bar\baz.txt"
>      wordDict =3D indexWord(filename)

What's happening here?
By the way, the program now works pretty well, though the output is somet=
imes=20
a bit awkward, for example, when there are many occurences of one=20
word.Doesn't look very nice. I'm trying to change this now.
Oh, I nearly forgot :
How come that the words in the output are alphabetically ordered?

Nicole


> - If a word occurs twice in the same line, it will be listed twice. To
> avoid this behaviour, you need to filter resultList (left as an exercic=
e
> :-).
>
> >Would be very thankful for suggestions!!
>
> HTH.
>
> Alex


From israel@lith.com  Tue Mar 26 15:19:29 2002
From: israel@lith.com (Israel Evans)
Date: Tue, 26 Mar 2002 07:19:29 -0800
Subject: [Tutor] Python & windows XP professional
Message-ID: <AF020C5FC551DD43A4958A679EA16A15017B405B@abbott.lith.com>

Hello there..

Due to the recent death of my computer, I am now using python, mysql,
apache, and wxPython on XP on my in-law's and work computers and I'm not
really having any problems.  XP isn't my favorite, but it seems pretty
decent, other than the Big Brother Privacy issues on the horizon with
passport and .net.  Hopefully I won't have to worry about that once I get my
Dual 1.6 GH PowerMac G5 with the 23' HD Cinema Display.  Then I'll have to
worry about choosing between MacPython and Mach-O python and having to
mingle Aqua and X just to play around...   


~Israel~


-----Original Message-----
From: Ike Hall [mailto:hall@nhn.ou.edu] 
Sent: 25 March 2002 9:46 PM
To: garber@centralcatholic.org; tutor@python.org
Subject: Re: [Tutor] Python & windows XP professional

due to a personal bias against microsoft (hey, at least Im telling you Im 
biased), my highest recommendation would be to get a better OS, however, I 
realize you probably think Im a linux kook too (I am  :)  ), so with that
out 
of the way I would say to you that you are the first person I know of to use

python on XP. (This is because the XP'rs I know dont want to program, and
the 
programmers I know dont want XP), so although I can't be of any real help 
now,(hopefully others here may be), you are in the unique situation of what 
in my mind is treading new ground.  My Suggestion to you would be to 
periodically keep this list informed of how well it works, the problems you 
encounter, and their solutions.  And to keep reading from this list as you 
will no doubt gain much experience that will help other who will want to be 
like you :) 
so although this message surely wont be of any real help, I do sincerely
want 
to wish you good luck.


Ike

PS.
on a side note I did a google search under python, windows, XP
and a curious article struck my eye about a privacy leak in python for 
windows (couldnt tell if this also applies to XP or not, but still may be 
helpful).  This may fall under the ounce of prevention you speak of.  the
URL 
is http://www.securiteam.com/windowsntfocus/5BP0N0U61G.html

On Monday 25 March 2002 07:09 pm, you wrote:
> I just built a new Athlon XP 1900+ system running windows XP professional.
> I want to install python (eiterh active state 2.1 or python 2.2 and the
> win32 extesions), any words of wisdom or warning before I do this? An
ounce
> of prevention is worth a pound of cure.
>
> Thanks
> Robert
>
>
> _______________________________________________
> 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 alex@gabuzomeu.net  Tue Mar 26 16:06:51 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Tue, 26 Mar 2002 17:06:51 +0100
Subject: [Tutor] Extracting words(quest 2)
In-Reply-To: <02032611313700.00703@utopia>
References: <4.3.2.7.2.20020325192321.00b9a810@pop3.norton.antivirus>
 <4.3.2.7.2.20020325192321.00b9a810@pop3.norton.antivirus>
Message-ID: <4.3.2.7.2.20020326163412.00e8ccf0@pop3.norton.antivirus>

Hi Nicole,


At 16:22 26/03/2002 +0100, Nicole Seitz wrote:
>Thanx, this was very helpful! Though, there are some lines(see below) I 
>don't understand.Hope you don't mind  explaining.

> > import re, pprint
> >
> > def indexWord(filename):
> >      wordDict = {}
> >      lineCount = 0
> >      file = open(filename)
> >      expr = re.compile("\w+", re.LOCALE)
>
>What's exactly the meaning of the flag LOCALE?

It will match extended characters (eg. French accents, German Umlaut 
letters, etc.). Here is a longer explanation:

\w
When the LOCALE and UNICODE flags are not specified, matches any 
alphanumeric character; this is equivalent to the set [a-zA-Z0-9_]. With 
LOCALE, it will match the set [0-9_] plus whatever characters are defined 
as letters for the current locale. If UNICODE is set, this will match the 
characters [0-9_] plus whatever is classified as alphanumeric in the 
Unicode character properties database.
Source: http://www.python.org/doc/current/lib/re-syntax.html


> >      while 1:
> >          line = file.readline()
> >          if not line:
> >              break
> >          lineCount = lineCount + 1
> >          resultList  = expr.findall(line)
>
>So I can't use match()???

match() only matches patterns at the beginning of strings. To match 
patterns anywhere in a string, use search() instead.

Besides, match() returns a match object and you need to use the group() 
method of this object to get the matches text.

I find it easier to user findall(), which directly returns a list of match 
text strings.

This howto is a good reference to understand Python regular expressions:
http://py-howto.sourceforge.net/regex/regex.html
http://py-howto.sourceforge.net/pdf/regex.pdf


> > if __name__ == "__main__":
> >      filename = r"c:\foo\bar\baz.txt"
> >      wordDict = indexWord(filename)
>What's happening here?

The if __name__ == "__main__" idiom allows you to easily test a code 
snippet. This code is only executed when you run the module directly, not 
when the module is imported into another one.

wordDict = indexWord(filename) just calls the indexWord() function with the 
source file name as a parameter. This function returns a Python dictionary 
of words.

>By the way, the program now works pretty well, though the output is 
>sometimes  a bit awkward, for example, when there are many occurences of 
>one word.Doesn't look very nice. I'm trying to change this now.

Yes, pprint is just a quick way to display the content of a dictionary or 
list. For a nicer output, you need to write some more code.

>Oh, I nearly forgot :
>How come that the words in the output are alphabetically ordered?

I was surprised too. The pprint function (prettyprint) seems to sort the 
output by default. If you change the line

         pprint.pprint(wordDict)

to
         print wordDict

you'll see that the output is unsorted (in dictionaries, entry order is 
randomized to speed up access).


Cheers.

Alexandre




From bmaicke@hotmail.com  Tue Mar 26 16:58:50 2002
From: bmaicke@hotmail.com (Brian Maicke)
Date: Tue, 26 Mar 2002 10:58:50 -0600
Subject: [Tutor] Using Select
Message-ID: <F90JZIqw15SEEouFDRg000169dd@hotmail.com>

Howdy all,
I have been playing around with writing a chat server
in Python, with the eventual goal of turning it into an
online game should I ever get ambitious enough to do so.

I currently have the code written to read the data from
the connection and display it back to the user.  What I
need a bit of help with is allowing multiple connections
to do so at the same time.  Currently I plan on using
select to allow the multiple connections.  I have a vague
idea of how to go about using select but I am looking for
a bit more info.  Does anyone know of a good walkthrough
for select that they could point me to?  Also is there a
better way to allow for the multiple connections in a
situation like this (fork, threads)?

I have a fairly good programming background having worked
with C for quite awhile, but I haven't done very much socket
or network related programming and any information that you
could point me to on either topic (python focused preferably)
would be greatly appreciated.

Thanks in advance,
Brian

_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx



From brad.reisfeld@colostate.edu  Tue Mar 26 17:09:19 2002
From: brad.reisfeld@colostate.edu (Brad Reisfeld)
Date: Tue, 26 Mar 2002 10:09:19 -0700
Subject: [Tutor] Re: data structure and algorithm
Message-ID: <NGEALAODAKLOJADDLGPAGEDCCBAA.brad.reisfeld@colostate.edu>

Hi,
Thank you for the response.

This is complicated so I'll try to clarify...

The application on which I am working has to do with chemical reactions. A
given 'generic' reaction (what I called a 'function') applied to a chemical
species (what I called a 'symbol'), can result in a number of products (what
I called 'a list of symbols'). If I apply a reaction to a different species,
I get a different set of products.

If I apply reaction 'f1' to species 'A', I get products 'B','C','D', and
'E'.
If I then apply a new reaction 'f2' to one of the products, 'B', I get
products 'F' and 'G'.
If I apply the same reaction 'f2' to another one of the products, 'C', I get
products 'H','I', and 'J'.
And so forth. I think that you can see that after a few of these reactions,
a very large 'tree' can be formed.
I'll attempt some ASCII art here for the simple example (I hope the spacing
is retained properly):

            --        --
            |         | F       --
            | B -f2-> |         | K
            |         | G -f3-> | L
            |         --        | B
            |                   | N
            |         --        --
   A -f1->  |         | H
		| C -f2-> | I
            |         | J
            |         --
            | D
            |
            | E
            --

So, I am looking at applying a reaction to a chemical species, and then a
different reaction to its products, and then a different reaction to its
products, and so forth. I am then trying to see all of the reaction 'chains'
(e.g. A --f1--> B --f2--> F).
Along the way, a product may be identical to a product in another reaction
from a completely different sequence of reactions, but I don't think that
loops can occur in such a system (I could be wrong).

Let me know if you would like more information. If I have confused you
further, I apologize.

Thanks.

-Brad



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


On  0, Brad Reisfeld <brad.reisfeld@colostate.edu> wrote:
> Hi,
> I would appreciate some advice with regard to an algorithm and data
> structure.

Interesting problem, but I need clarification on two points:

> Suppose that I have a number of functions (f1,..., fn) each of which take
a
> 'symbol' argument and return a list of such symbols. For example:
>
> f1(A) = [B,C,D,E]
> f2(B) = [F,G]
> f2(C) = [H,I,J]
> f3(G) = [K,L,B,N]

This is odd - four different functions, four different arguments.

What happens with, say, f2(A)?

> After applying the functions in a certain way, I would like to enumerate
the
> 'linkage' between the various symbols. Each 'symbol' may not be unique,
and
> may appear at various points in a 'chain'.
>
> For the example above, this linkage might be represented as
>
> A -> B -> F
> A -> B -> G -> K
> A -> B -> G -> L
> A -> B -> G -> B

There is a problem here. If loops are possible (B -> G -> B) then there are
infinitely many chains possible - just repeat that loop as often as you
want. What to do? Don't loops occur in your data, or what?

> A -> B -> G -> N
> A -> C -> H
> A -> C -> I
> A -> C -> J
> A -> D
> A -> E
>
> Although it is not necessary, it might be useful to have the functions
> applied for each item enumerated as well, e.g.
> 	A -> B -> F : (f1,f2)   or	A --f1--> B --f2--> F
>
> I'm not a computer scientist, but this seems as if this is basically a
tree
> structure in which we are moving from the 'trunk' to a given 'leaf'.
Perhaps
> this is something related to directory 'walking'.

It reminds me of grammars for languages, like for simple expressions:

<expression> -> <atom>
<expression> -> <expression> + <expression>
<atom> -> 0..9

That's a grammar for a formal language that can produce strings of the form
'3', '3 + 5', '3 + 7 + 9 + 1', etc.

> Does anyone have any ideas as to how I should code this structure and
> algorithm?

I'm thinking dictionaries and recursion but I'd like to have the points
above clarified :)

--
Remco Gerlich



From shalehperry@attbi.com  Tue Mar 26 17:10:55 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue, 26 Mar 2002 09:10:55 -0800 (PST)
Subject: [Tutor] Using Select
In-Reply-To: <F90JZIqw15SEEouFDRg000169dd@hotmail.com>
Message-ID: <XFMail.20020326091055.shalehperry@attbi.com>

> 
> I currently have the code written to read the data from
> the connection and display it back to the user.  What I
> need a bit of help with is allowing multiple connections
> to do so at the same time.  Currently I plan on using
> select to allow the multiple connections.  I have a vague
> idea of how to go about using select but I am looking for
> a bit more info.  Does anyone know of a good walkthrough
> for select that they could point me to?  Also is there a
> better way to allow for the multiple connections in a
> situation like this (fork, threads)?
> 
> I have a fairly good programming background having worked
> with C for quite awhile, but I haven't done very much socket
> or network related programming and any information that you
> could point me to on either topic (python focused preferably)
> would be greatly appreciated.
> 

While it is written in C, W. Richard Stevens "UNIX Network Programming" books
are one of the corner stones of the field.

There are advantages and disadvantages to any approach.  I think forking a
python server sounds like a bad idea.  If you use select you need to keep a
distinct record in memory for each connection and have a way to reference these
records with the socket that responded (a list or a dictionary probably). 
Threading is a nice approach as it gives you some of the clarity of a fork
design without the fork.  But you also have to deal with threading (-:

Since you are new to this, my recommendation would be to use a select loop and
make that work.  Then try to implement the threading method.  Since you will
already understand all of the things needed to support multiple connections you
will be able to focus on threading idiosynchracies when you get there.  It also
makes sense to start easy and work up.


From cheshire_cat_sf@yahoo.com  Tue Mar 26 17:51:33 2002
From: cheshire_cat_sf@yahoo.com (Britt Green)
Date: Tue, 26 Mar 2002 09:51:33 -0800 (PST)
Subject: [Tutor] Python & windows XP professional
In-Reply-To: <E16pjXy-0008Bj-00@mail.python.org>
Message-ID: <20020326175133.98178.qmail@web14108.mail.yahoo.com>

> Message: 14
> From: Ike Hall <hall@nhn.ou.edu>
> Reply-To: hall@nhn.ou.edu
> To: <garber@centralcatholic.org>, tutor@python.org
> Subject: Re: [Tutor] Python & windows XP professional
> Date: Mon, 25 Mar 2002 23:45:59 -0600
> 
> due to a personal bias against microsoft (hey, at least Im telling
> you Im 
> biased), my highest recommendation would be to get a better OS,

 While that's a good suggestion, I don't think Apple's OSX runs on the
x86 platform just yet! ;)

 Running away from the fire he may have started....

 Britt

=====
"The ocean, she is strange and wondrous, filled with animals that disturb even a Frenchman."

__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
http://movies.yahoo.com/


From urnerk@qwest.net  Tue Mar 26 18:07:03 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Tue, 26 Mar 2002 10:07:03 -0800
Subject: [Tutor] Re: data structure and algorithm
In-Reply-To: <NGEALAODAKLOJADDLGPAGEDCCBAA.brad.reisfeld@colostate.edu>
Message-ID: <4.2.0.58.20020326095507.019b9690@pop3.norton.antivirus>

>
>I'll attempt some ASCII art here for the simple example (I hope the 
>spacing is retained properly):
>
>             --        --
>             |         | F       --
>             | B -f2-> |         | K
>             |         | G -f3-> | L
>             |         --        | B
>             |                   | N
>             |         --        --
>    A -f1->  |         | H
>                 | C -f2-> | I
>             |         | J
>             |         --
>             | D
>             |
>             | E
>             --

Many solutions possible.  Here's one possibility (sorry
if indentation is a bit off -- cut 'n paste sometimes
dicey):

     class Function:
        """
        Defines named function using a dictionary with
        lists of products keyed by symbol e.g. name='f1'
        mapdict = {'A':['B','C','D']} means A->f1->B,C,D
        """
         def __init__(self,name,mapdict):
             self.name    = name
             self.mapdict = mapdict
         def __call__(self,symbol):
            return self.mapdict.get(symbol,[])

     def mapit(functions, symbol, offset=""):
          """
          Recursively explores the reaction chains,
          using each function in succession, against
          the products (symbols) from a previous function
          (offset used for indentation)
          """
          if len(functions)==0:
                 return []
          f = functions[0]
           products = f(symbol)
           if len(products)>0:
              for p in products:
                print offset + symbol + '->' + f.name + '->' + p
                mapit(functions[1:],p,offset+"  ")

  >>> f1 = Function('f1',{'A':['B','C','D']})  # objects
  >>> f2 = Function('f2',{'B':['E','F','G']})
  >>> f3 = Function('f3',{'E':['K','L','M']})
  >>> reactions = [f1,f2,f3]  # to be passed to mapit()

  >>> mapit(reactions,'A')
  A->f1->B
   B->f2->E
      E->f3->K
     E->f3->L
      E->f3->M
    B->f2->F
   B->f2->G
  A->f1->C
  A->f1->D

Kirby



From urnerk@qwest.net  Tue Mar 26 18:17:03 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Tue, 26 Mar 2002 10:17:03 -0800
Subject: [Tutor] Python & windows XP professional
In-Reply-To: <20020326175133.98178.qmail@web14108.mail.yahoo.com>
References: <E16pjXy-0008Bj-00@mail.python.org>
Message-ID: <4.2.0.58.20020326100802.019ba230@pop3.norton.antivirus>

>
> > due to a personal bias against microsoft (hey, at least Im telling
> > you Im > biased), my highest recommendation would be to get a
> > better OS,

>  While that's a good suggestion, I don't think Apple's OSX runs on the
>x86 platform just yet! ;)
>
>  Running away from the fire he may have started....
>
>  Britt

Brings up a good point though:  same hardware runs several OSs.
When someone asks about a Win*, one shouldn't automatically
jump to the conclusion that this same someone doesn't also
run a *nix, perhaps on the same box.  Some virtualizing
platforms even run different OSs in multiple session windows
-- like flipping channels with a TV remote.  Cool thing with
Python is it's a star on so many channels.

Kirby



From darnold02@sprynet.com  Mon Mar 25 23:51:36 2002
From: darnold02@sprynet.com (Don Arnold)
Date: Mon, 25 Mar 2002 17:51:36 -0600
Subject: [Tutor] Re: How to get a key from  dictionary?
References: <3C9FAFCC.20062.91741D@localhost>
Message-ID: <009501c1d458$0a5a86c0$3425fea9@0016314730>

>>> targetval = 2
>>> dict = {'aa':1, 'bb':2, 'cc': 3, 'dd': 1}
>>> targetval = 2
>>> for key in dict.keys():
          if dict[key] == targetval:
            print "found", targetval, "at key", key

found 2 at key bb
>>> targetval = 1
>>> for key in dict.keys():
          if dict[key] == targetval:
            print "found", targetval, "at key", key

found 1 at key aa
found 1 at key dd

----- Original Message -----
From: "A" <printers@sendme.cz>
To: <python-list@python.org>; <tutor@python.org>;
<activepython@listserv.activestate.com>; <python-help@python.org>
Sent: Monday, March 25, 2002 4:16 PM
Subject: How to get a key from dictionary?


> Hi,
> Is there a possibility to get, from a dictionary, a key according to a
> value ?
> For example
> I have a dictionary
>
> dict={'aa':1,'bb':2}
>
> and
> dict['aa']
> is 1
>
> But how can I for value 1 find out  key? (That is here  'aa')
>
> Thank you for help
> Ladislav
>
>
> _______________________________________________
> ActivePython mailing list
> ActivePython@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



From aleaxit@yahoo.com  Tue Mar 26 08:50:46 2002
From: aleaxit@yahoo.com (Alex Martelli)
Date: Tue, 26 Mar 2002 00:50:46 -0800 (PST)
Subject: [Tutor] Re: [Python-Help] How to get a key from  dictionary?
In-Reply-To: <3C9FAFCC.20062.91741D@localhost>
Message-ID: <20020326085046.6693.qmail@web9304.mail.yahoo.com>

--- A <printers@sendme.cz> wrote:
> Hi,
> Is there a possibility to get, from a dictionary, a
> key according to a value ?

In general, zero or more keys will correspond to
a given value, and it's easy to get the list of those
(but of course it takes time proportional to the
TOTAL number of items in the dictionary):

[ key for key in thedict if thedict[key] == avalue ]

This is Python 2.2, but it's not hard to do it in
Python 2.1 (or even 2.0) just as well, e.g.:

[ key for key, v in thedict.items() if v == avalue ]

just a bit slower for huge dictionaries given the
need to call .items().


> For example
> I have a dictionary
> 
> dict={'aa':1,'bb':2}

I STRONGLY suggest you don't use the name of built-in
types as the name of your variables.  Don't call your
variables: list, dict, tuple, int, long, float, str...
Python lets you do that, but sooner or later you'll
come a doozy.  Use alist, adict, ... or else
thelist, thedict, ....  dict is a built-in name
only since Python 2.2, by the way.


Alex


__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
http://movies.yahoo.com/


From arthur.siegel@rsmi.com  Tue Mar 26 15:36:34 2002
From: arthur.siegel@rsmi.com (arthur.siegel@rsmi.com)
Date: Tue, 26 Mar 2002 10:36:34 -0500
Subject: [Tutor] keyword args - subclassing built-ins
Message-ID: <OFBE1228BF.897DBA8F-ON85256B88.00544B9D@RSMi.com>

Using keyword args seems to be a no go when subbing at least
numeric type builtins.  This seems to hold even when introducing
**kw down the road in the chain in a class multi-inheriting from a
class derived from a builtin and a classic class.

Or else I'm just confused again.

Is anyone aware of documentation on the use of keywords
with subs of built-ins.

I am aware of the __new__ syntax, and expect my answer might
be there somewhere - but  I am not sure I can get the behavior
I am looking for since __new__ is static.


Art





From dman@dman.ddts.net  Tue Mar 26 18:44:20 2002
From: dman@dman.ddts.net (dman)
Date: Tue, 26 Mar 2002 12:44:20 -0600
Subject: [Tutor] Python & windows XP professional
In-Reply-To: <20020326175133.98178.qmail@web14108.mail.yahoo.com>
References: <E16pjXy-0008Bj-00@mail.python.org> <20020326175133.98178.qmail@web14108.mail.yahoo.com>
Message-ID: <20020326184420.GD30605@dman.ddts.net>

On Tue, Mar 26, 2002 at 09:51:33AM -0800, Britt Green wrote:
| > Message: 14
| > From: Ike Hall <hall@nhn.ou.edu>
| > Reply-To: hall@nhn.ou.edu
| > To: <garber@centralcatholic.org>, tutor@python.org
| > Subject: Re: [Tutor] Python & windows XP professional
| > Date: Mon, 25 Mar 2002 23:45:59 -0600
| > 
| > due to a personal bias against microsoft (hey, at least Im telling
| > you Im 
| > biased), my highest recommendation would be to get a better OS,
| 
|  While that's a good suggestion, I don't think Apple's OSX runs on the
| x86 platform just yet! ;)

I think OpenBSD runs on x86; and Darwin is a modified OpenBSD.  The
only thing you would lose is the non-open parts of OSX (the Aqua GUI,
I imagine, and the MacOS compatibility libraries).

Still, Debian rocks :-).  Not only that, but sawfish has several Aqua
themes, if you like those window decorations :-).

-D

-- 

Microsoft DNS service terminates abnormally when it receives a response
to a dns query that was never made.
Fix information: run your DNS service on a different platform.
                                                            -- bugtraq



From dman@dman.ddts.net  Tue Mar 26 18:54:14 2002
From: dman@dman.ddts.net (dman)
Date: Tue, 26 Mar 2002 12:54:14 -0600
Subject: [Tutor] Using Select
In-Reply-To: <F90JZIqw15SEEouFDRg000169dd@hotmail.com>
References: <F90JZIqw15SEEouFDRg000169dd@hotmail.com>
Message-ID: <20020326185414.GE30605@dman.ddts.net>

On Tue, Mar 26, 2002 at 10:58:50AM -0600, Brian Maicke wrote:
| Howdy all,
| I have been playing around with writing a chat server
| in Python, with the eventual goal of turning it into an
| online game should I ever get ambitious enough to do so.
| 
| I currently have the code written to read the data from
| the connection and display it back to the user.  What I
| need a bit of help with is allowing multiple connections
| to do so at the same time.  Currently I plan on using
| select to allow the multiple connections.  I have a vague
| idea of how to go about using select but I am looking for
| a bit more info.  Does anyone know of a good walkthrough
| for select that they could point me to?

I don't know of a walkthrough other than the manpage and "Linux
Programming Unleashed".  (the book isn't in-depth at all, though)

I just learned how to use select myself :-).  Basically you make a
list of files that you want to read from or write to.  Then you hand
it to select and wait for it to give you back a list of the files that
are ready to be read from or written to.  Kinda like this, but I only
had one file to read from :

    f = open( "/dev/ttyS0" , "r" )
    r , _ , e = select.select( [f] , [] , [f] )
    if r :
        # the file is ready for reading
        print os.read( r , 1 ) # you may need to call r.fileno() here
    if e :
        # an exceptional condition occurred,
        # I'm really not sure what that means because neither manpage
        # nor the book explained what exceptional conditions are.
        pass

The arguments and return values are lists of file descriptors (python
allows file objects too) for the following operations :
    read
    write
    exceptional condition

| Also is there a better way to allow for the multiple connections in
| a situation like this (fork, threads)?

Forking is probably a bit heavy weight for this, unless, perhaps, each
connection will require lots of independent processing

Threading is lighter weight (and in linux, threads map to lightweight
processes) and allows sharing the address space.  Just be careful with
regards to synchronization and deadlock.


I think Sean's suggestion of starting simple select() and building up
experience as you go is a good one.  For an example you can look at
the core of Zope's ZServer -- Medusa.  It is an HTTP and FTP server
written in python, and it uses select() to achieve high performance
without the resource overhead of forking or threading.  I don't know
how its complexity compares to a threading solution, but I do have a
fair amount of experience dealing with threads (in java) and they're
not quite trivial in the real world.

HTH,
-D

-- 

The wise in heart are called discerning,
and pleasant words promote instruction.
        Proverbs 16:21



From dman@dman.ddts.net  Tue Mar 26 18:57:33 2002
From: dman@dman.ddts.net (dman)
Date: Tue, 26 Mar 2002 12:57:33 -0600
Subject: [Tutor] Extracting words(quest 2)
In-Reply-To: <4.3.2.7.2.20020326163412.00e8ccf0@pop3.norton.antivirus>
References: <4.3.2.7.2.20020325192321.00b9a810@pop3.norton.antivirus> <4.3.2.7.2.20020325192321.00b9a810@pop3.norton.antivirus> <4.3.2.7.2.20020326163412.00e8ccf0@pop3.norton.antivirus>
Message-ID: <20020326185733.GF30605@dman.ddts.net>

On Tue, Mar 26, 2002 at 05:06:51PM +0100, Alexandre Ratti wrote:
... 
| (in dictionaries, entry order is randomized to speed up access).

This doesn't exactly say what you meant.  The entry order isn't
random; it follows a precise algorithm, which is what makes it fast.
>From our perspective, when we print a dict, it does appear to be a
random order.

Hope this clears up a potential confusion,
-D

-- 

If your life is a hard drive,
Christ can be your backup.



From hall@nhn.ou.edu  Tue Mar 26 18:42:59 2002
From: hall@nhn.ou.edu (Isaac Hall)
Date: Tue, 26 Mar 2002 12:42:59 -0600
Subject: [Tutor] Python & windows XP professional
In-Reply-To: <20020326184420.GD30605@dman.ddts.net>
References: <E16pjXy-0008Bj-00@mail.python.org> <20020326175133.98178.qmail@web14108.mail.yahoo.com> <20020326184420.GD30605@dman.ddts.net>
Message-ID: <02032612574000.32052@ouhep1>

Ok, I feel I must apologize for touching off a debate over OS's.  that was not
my intention.  My real intention was to maybe let people here know about
problems and solutions involved in Using python on the plethora of different
platforms out there.  I don't feel that this is the place to argue the pros and
cons of the many possible OS/Systems out there.  Most of us have found what is
comfortable, and will stick with it.  The point I was trying to make, although
it seemed to get lost somewhere in the translation (ok, so there was no
translation) was that its a good thing to discuss python on all OS's here, as
python is one of the few useful things that can be placed on almost any
system.  And we never know when (due to a job or otherwise) we may be forced
to operate on a platform we don't particularly like.  In that case, it would
be nice to know of the issues involving python on whatever OS is in question. 
That was my original intent in my original reply, and Im sorry to have created
an OS debate here...Python is for all (even windows).

Ike   

> On Tue, Mar 26, 2002 at 09:51:33AM -0800, Britt Green wrote:
> | > Message: 14
> | > From: Ike Hall <hall@nhn.ou.edu>
> | > Reply-To: hall@nhn.ou.edu
> | > To: <garber@centralcatholic.org>, tutor@python.org
> | > Subject: Re: [Tutor] Python & windows XP professional
> | > Date: Mon, 25 Mar 2002 23:45:59 -0600
> | > 
> | > due to a personal bias against microsoft (hey, at least Im telling
> | > you Im 
> | > biased), my highest recommendation would be to get a better OS,
> | 
> |  While that's a good suggestion, I don't think Apple's OSX runs on the
> | x86 platform just yet! ;)
> 

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


From israel@lith.com  Tue Mar 26 20:22:13 2002
From: israel@lith.com (Israel Evans)
Date: Tue, 26 Mar 2002 12:22:13 -0800
Subject: [Tutor] Launching a file programs from a python script?
Message-ID: <AF020C5FC551DD43A4958A679EA16A15017B405F@abbott.lith.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_01C1D503.EA31E94C
Content-Type: text/plain

 
Hello there...
 
I'm currently having difficulties launching programs from a python program.
 
What I'd like to do is set up a little python script that launches Apache,
mySQL, and WebKit for me without having to turn each one on individually.
 
I've been playing around with some of the os module functions but I don't
seem to quite grasp their proper uses.  From the reading I suppose I'd
probably wish to use one of the os.execX variants which supposedly replace
the first process.  Some of the programs (webkit) ask to be started with a
.bat file which I know I could probably replicate without using the console,
but having a console for each program is kind of nice due to the info they
spit out and due to the fact that both Apache and Webkit are attached to
their consoles and will perish without them.  
 
Any Ideas?
 
Thanks a bundle...
 
 
 
~Israel~
 

------_=_NextPart_001_01C1D503.EA31E94C
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:st1=3D"urn:schemas-microsoft-com:office:smarttags" =
xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">


<meta name=3DProgId content=3DWord.Document>
<meta name=3DGenerator content=3D"Microsoft Word 10">
<meta name=3DOriginator content=3D"Microsoft Word 10">
<link rel=3DFile-List href=3D"cid:filelist.xml@01C1D4C0.DBDFEF60">
<o:SmartTagType =
namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags"
 name=3D"country-region"/>
<o:SmartTagType =
namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags"
 name=3D"place"/>
<!--[if gte mso 9]><xml>
 <o:OfficeDocumentSettings>
  <o:DoNotRelyOnCSS/>
 </o:OfficeDocumentSettings>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:SpellingState>Clean</w:SpellingState>
  <w:GrammarState>Clean</w:GrammarState>
  <w:DocumentKind>DocumentEmail</w:DocumentKind>
  <w:EnvelopeVis/>
  <w:Compatibility>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
   <w:UseFELayout/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]--><!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:PMingLiU;
	panose-1:2 2 3 0 0 0 0 0 0 0;
	mso-font-alt:\65B0\7D30\660E\9AD4;
	mso-font-charset:136;
	mso-generic-font-family:roman;
	mso-font-pitch:variable;
	mso-font-signature:3 137232384 22 0 1048577 0;}
@font-face
	{font-family:"\@PMingLiU";
	panose-1:2 2 3 0 0 0 0 0 0 0;
	mso-font-charset:136;
	mso-generic-font-family:roman;
	mso-font-pitch:variable;
	mso-font-signature:3 137232384 22 0 1048577 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0in;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:PMingLiU;}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;
	text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;
	text-underline:single;}
p.MsoAutoSig, li.MsoAutoSig, div.MsoAutoSig
	{margin:0in;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";
	mso-fareast-language:EN-US;}
span.EmailStyle17
	{mso-style-type:personal-compose;
	mso-style-noshow:yes;
	mso-ansi-font-size:10.0pt;
	mso-bidi-font-size:10.0pt;
	font-family:Arial;
	mso-ascii-font-family:Arial;
	mso-hansi-font-family:Arial;
	mso-bidi-font-family:Arial;
	color:windowtext;}
span.SpellE
	{mso-style-name:"";
	mso-spl-e:yes;}
span.GramE
	{mso-style-name:"";
	mso-gram-e:yes;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;
	mso-header-margin:.5in;
	mso-footer-margin:.5in;
	mso-paper-source:0;}
div.Section1
	{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
 /* Style Definitions */=20
 table.MsoNormalTable
	{mso-style-name:"Table Normal";
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0in 5.4pt 0in 5.4pt;
	mso-para-margin:0in;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";}
</style>
<![endif]-->
</head>

<body lang=3DEN-US link=3Dblue vlink=3Dpurple =
style=3D'tab-interval:.5in'>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Hello there...<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>I'm currently having difficulties launching programs
from a python program.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>What I'd like to do is set up a little python script
that launches Apache, <span class=3DSpellE>mySQL</span>, and <span =
class=3DSpellE>WebKit</span>
for me without having to turn each one on =
individually.<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>I've been playing around with some of the <span
class=3DSpellE>os</span> module functions but I don't seem to quite =
grasp
their proper uses.<span style=3D'mso-spacerun:yes'>&nbsp; </span>From =
the reading
I suppose I'd probably wish to use one of the <span =
class=3DSpellE>os.execX</span>
variants which supposedly replace the first process. <span
style=3D'mso-spacerun:yes'>&nbsp;</span>Some of the programs (<span =
class=3DSpellE>webkit</span>)
ask to be started with a .bat file which I know I could probably =
replicate
without using the console, but having a console for each program is =
kind of
nice due to the info they spit out and due to the fact that both Apache =
and <span
class=3DSpellE>Webkit</span> are attached to their consoles and will =
perish
without them. <span =
style=3D'mso-spacerun:yes'>&nbsp;</span><o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><span class=3DGramE><font size=3D2 =
face=3DArial><span
style=3D'font-size:10.0pt;font-family:Arial'>Any =
Ideas?</span></font></span><font
size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;font-family:Arial'><o:p></o:p></span></font></=
p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Thanks a bundle...<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoAutoSig><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt;mso-no-proof:yes'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoAutoSig><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt;mso-no-proof:yes'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoAutoSig><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt;font-family:"Courier =
New";mso-no-proof:yes'>~</span></font><st1:country-region><st1:place><fo=
nt
  size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt;font-family:"Courier New";
  =
mso-no-proof:yes'>Israel</span></font></st1:place></st1:country-region><=
font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt;font-family:"Courier New";
mso-no-proof:yes'>~<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

</div>

</body>

</html>

------_=_NextPart_001_01C1D503.EA31E94C--


From luisnoelf@yahoo.es  Tue Mar 26 02:54:45 2002
From: luisnoelf@yahoo.es (Azrael)
Date: Mon, 25 Mar 2002 20:54:45 -0600
Subject: [Tutor] any easier way?
Message-ID: <5.1.0.14.2.20020325205414.00a78af0@pop.correo.yahoo.es>


>Hi, im working in a prog to rename files taking their previous name and 
>changing the capital letters to small letters; well this is the code i 
>have done to do this, my question is if somebody can tell me and easier or 
>alternative way of doing it, im trying to learn so anything u tell me will 
>be welcome :)
>
>(sorry but the vars are in spanish, didnt had the time to translate them)
>
>def cambio(palabra):
>     minusculas = 
> ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','n','o','p','q','r','s','t','u','v','w','x','y','z']
>     mayusculas = 
> ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
>     palabrac = ''
>     letras = []
>     x = 0
>     for n in range (len(palabra)):
>         letras.append(palabra[n])
>     final  = letras
>     while x < len(letras):
>         for zero in range(len(mayusculas)):
>             if letras[x] == mayusculas[zero]:
>                 m = mayusculas.index(mayusculas[zero])
>                 final.insert(x,minusculas[m])
>                 del final[x+1]
>             else:
>                 pass
>         x = x + 1
>     for z in range(len(final)):
>         palabrac = palabrac + final[z]
>     return palabrac
>
>Thnx for all
>Azrael


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com



From urnerk@qwest.net  Tue Mar 26 21:06:16 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Tue, 26 Mar 2002 13:06:16 -0800
Subject: [Tutor] any easier way?
In-Reply-To: <5.1.0.14.2.20020325205414.00a78af0@pop.correo.yahoo.es>
Message-ID: <4.2.0.58.20020326130307.015a3ba0@pop3.norton.antivirus>

More complicated than you need:

def cambio(palabra):
    return palabra.lower()

is all you need.

E.g.:

  >>> def cambio(palabra):
         return palabra.lower()

  >>> cambio("ElGato")
  'elgato'
  >>> cambio("AmirKabir")
  'amirkabir'

Kirby


At 08:54 PM 3/25/2002 -0600, Azrael wrote:

>>def cambio(palabra):
>>     minusculas = 
>> ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','n','o','p','q', 
>> 'r','s','t','u','v','w','x','y','z']
>>     mayusculas = 
>> ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','N','O','P','Q', 
>> 'R','S','T','U','V','W','X','Y','Z']
>>     palabrac = ''
>>     letras = []
>>     x = 0
>>     for n in range (len(palabra)):
>>         letras.append(palabra[n])
>>     final  = letras
>>     while x < len(letras):
>>         for zero in range(len(mayusculas)):
>>             if letras[x] == mayusculas[zero]:
>>                 m = mayusculas.index(mayusculas[zero])
>>                 final.insert(x,minusculas[m])
>>                 del final[x+1]
>>             else:
>>                 pass
>>         x = x + 1
>>     for z in range(len(final)):
>>         palabrac = palabrac + final[z]
>>     return palabrac



From scarblac@pino.selwerd.nl  Tue Mar 26 21:13:39 2002
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 26 Mar 2002 22:13:39 +0100
Subject: [Tutor] any easier way?
In-Reply-To: <5.1.0.14.2.20020325205414.00a78af0@pop.correo.yahoo.es>; from luisnoelf@yahoo.es on Mon, Mar 25, 2002 at 08:54:45PM -0600
References: <5.1.0.14.2.20020325205414.00a78af0@pop.correo.yahoo.es>
Message-ID: <20020326221339.A13881@pino.selwerd.nl>

On  0, Azrael <luisnoelf@yahoo.es> wrote:
> 
> 
> >Hi, im working in a prog to rename files taking their previous name and 
> >changing the capital letters to small letters; well this is the code i 
> >have done to do this, my question is if somebody can tell me and easier or 
> >alternative way of doing it, im trying to learn so anything u tell me will 
> >be welcome :)
> >
> >(sorry but the vars are in spanish, didnt had the time to translate them)

This sort of thing is builtin! You can change it to

def cambio(palabra):
   return palabra.upper()
   
or, if you have an older Python,

import string
def cambio(palabra):
   return string.upper(palabra)
   

But at least making the function was a good exercise :). I have some
comments on that code too.

> >def cambio(palabra):
> >     minusculas = 
> > ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','n','o','p','q','r','s','t','u','v','w','x','y','z']
> >     mayusculas = 
> > ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

These already exist (as strings), as string.lowercase and string.uppercase.

> >     palabrac = ''
> >     letras = []
> >     x = 0
> >     for n in range (len(palabra)):
> >         letras.append(palabra[n])

This bit just turns the string palabra into a list; you can do that with
letras = list(palabra) .

> >     final  = letras
> >     while x < len(letras):
> >         for zero in range(len(mayusculas)):
> >             if letras[x] == mayusculas[zero]:
> >                 m = mayusculas.index(mayusculas[zero])
> >                 final.insert(x,minusculas[m])
> >                 del final[x+1]
> >             else:
> >                 pass
> >         x = x + 1

Here, for every letter in letras, you go through all the letters in
mayusculas, and if they're equal, you find the index (you already know that,
it's in your 'zero' variable) and set m equal to it. You should have gone
through minusculas instead - now you're only changing upper case to upper
case.

And instead of final.insert(x, something) followed by del final[x+1], don't
you think that final[x] = something is a bit better? :)

> >     for z in range(len(final)):
> >         palabrac = palabrac + final[z]
> >     return palabrac

And to turn a list of characters into a strings, you can use ''.join(final)
(join the characters together, with '' (nothing) in between).

Your function, cleaned up, could look like this:

import string

def cambio(palabra):
   minusculas = string.lowercase
   mayusculas = string.uppercase
   final = []
   for character in palabra:
      index = minusculas.find(character)
      if index == -1:
         # Not in minusculas, add unchanged
	 final.append(character)
      else:
         # In minusculas, add uppercase
	 final.append(mayusculas[index])
   return ''.join(final)

But, of course, it's just an exercise, this is already builtin :)

-- 
Remco Gerlich


From scarblac@pino.selwerd.nl  Tue Mar 26 21:15:11 2002
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 26 Mar 2002 22:15:11 +0100
Subject: [Tutor] any easier way?
In-Reply-To: <5.1.0.14.2.20020325205414.00a78af0@pop.correo.yahoo.es>; from luisnoelf@yahoo.es on Mon, Mar 25, 2002 at 08:54:45PM -0600
References: <5.1.0.14.2.20020325205414.00a78af0@pop.correo.yahoo.es>
Message-ID: <20020326221511.B13881@pino.selwerd.nl>

On  0, Azrael <luisnoelf@yahoo.es> wrote:
> >Hi, im working in a prog to rename files taking their previous name and 
> >changing the capital letters to small letters; well this is the code i 
> >have done to do this, my question is if somebody can tell me and easier or 
> >alternative way of doing it, im trying to learn so anything u tell me will 
> >be welcome :)

In the mail I sent, I thought that you wanted to change to upper case; so it
may be a little confusing (but not much).

-- 
Remco Gerlich


From shalehperry@attbi.com  Tue Mar 26 21:23:13 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue, 26 Mar 2002 13:23:13 -0800 (PST)
Subject: [Tutor] Using Select
In-Reply-To: <20020326185414.GE30605@dman.ddts.net>
Message-ID: <XFMail.20020326132313.shalehperry@attbi.com>

> 
> I don't know of a walkthrough other than the manpage and "Linux
> Programming Unleashed".  (the book isn't in-depth at all, though)
> 
> I just learned how to use select myself :-).  Basically you make a
> list of files that you want to read from or write to.  Then you hand
> it to select and wait for it to give you back a list of the files that
> are ready to be read from or written to.  Kinda like this, but I only
> had one file to read from :
> 
>     f = open( "/dev/ttyS0" , "r" )
>     r , _ , e = select.select( [f] , [] , [f] )
>     if r :
>         # the file is ready for reading
>         print os.read( r , 1 ) # you may need to call r.fileno() here
>     if e :
>         # an exceptional condition occurred,
>         # I'm really not sure what that means because neither manpage
>         # nor the book explained what exceptional conditions are.
>         pass
> 

another use of select is "timeout after waiting N amount of time".  X Window
applications often use this for their event loop.  We wait on a file descriptor
the X server gives us.  But say this is a clock.  If we wait for events the
clock never updates.

// C++ code
select(xfd + 1, &rfds, 0, 0, timeout);

when select returns either the file descriptor has data or the timeout occured.
 This way we can update the clock face every second as well as handle the X
events.  All in one nice clean loop.

As I mentioned in my post, W. Richard Stevens books are THE source of knowledge
on networking and daemons.  He is clear, thorough and precise.  Yes it is C
code.  But what he says applies to most any other language.  His book "Advanced
Programming in the UNIX environment" is still very much alive and valid as
well.  If you write UNIX code, you should read the book.  I know colleges which
use it for their textbooks.  I often see new linux/bsd coders fighting with
things that are very clearly explained in one of these two books.


From jimmy_130@lycos.com  Tue Mar 26 19:41:57 2002
From: jimmy_130@lycos.com (James M Lang)
Date: Tue, 26 Mar 2002 14:41:57 -0500
Subject: [Tutor] Which programming language is better to start with
Message-ID: <HIIBPEACNMCONBAA@mailcity.com>

On one weeb site that I went to, it said that it was better to start with Python or Perl. It stated that Python was more easier and Perl was more useful. I have tried Python but, where I live, resources are very limited and I couln't find much to help learn Python. They did have a few Perl books at the library. The reason for which I started to learn to program was to program videogames for fun. Any ideas about what to do?


2,000,000,000 Web Pages--you only need 1. Save time with My Lycos.
http://my.lycos.com


From miracle@paradise.net.nz  Tue Mar 26 20:28:38 2002
From: miracle@paradise.net.nz (Matthew Sherborne)
Date: Wed, 27 Mar 2002 08:28:38 +1200
Subject: [Tutor] Re: How to get a key from  dictionary?
References: <3C9FAFCC.20062.91741D@localhost>
 <009501c1d458$0a5a86c0$3425fea9@0016314730>
Message-ID: <002d01c1d504$d0749010$08020196@Jonah>

This is a multi-part message in MIME format.

------=_NextPart_000_002A_01C1D569.652C29C0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Sorry to be a show off, but I reckon that this way may be faster. Sorry =
again. The other replies are very helpful.  :)

def findKey(val):
  for key, value in dict.items():
    if value =3D=3D val: return key
  return None
 =20
GBU
Matthew Sherborne

----- Original Message -----=20
From: "Don Arnold" <darnold02@sprynet.com>
To: <printers@sendme.cz>; <python-list@python.org>; <tutor@python.org>; =
<activepython@listserv.activestate.com>; <python-help@python.org>
Sent: Tuesday, March 26, 2002 11:51 AM
Subject: Re: How to get a key from dictionary?


> >>> targetval =3D 2
> >>> dict =3D {'aa':1, 'bb':2, 'cc': 3, 'dd': 1}
> >>> targetval =3D 2
> >>> for key in dict.keys():
>           if dict[key] =3D=3D targetval:
>             print "found", targetval, "at key", key
>=20
> found 2 at key bb
> >>> targetval =3D 1
> >>> for key in dict.keys():
>           if dict[key] =3D=3D targetval:
>             print "found", targetval, "at key", key
>=20
> found 1 at key aa
> found 1 at key dd
>=20
> ----- Original Message -----
> From: "A" <printers@sendme.cz>
> To: <python-list@python.org>; <tutor@python.org>;
> <activepython@listserv.activestate.com>; <python-help@python.org>
> Sent: Monday, March 25, 2002 4:16 PM
> Subject: How to get a key from dictionary?
>=20
>=20
> > Hi,
> > Is there a possibility to get, from a dictionary, a key according to =
a
> > value ?
> > For example
> > I have a dictionary
> >
> > dict=3D{'aa':1,'bb':2}
> >
> > and
> > dict['aa']
> > is 1
> >
> > But how can I for value 1 find out  key? (That is here  'aa')
> >
> > Thank you for help
> > Ladislav
> >
> >
> > _______________________________________________
> > ActivePython mailing list
> > ActivePython@listserv.ActiveState.com
> > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>=20
> _______________________________________________
> ActivePython mailing list
> ActivePython@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>=20

------=_NextPart_000_002A_01C1D569.652C29C0
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.2712.300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Sorry to be a show off, but I reckon =
that this way=20
may be faster. Sorry again. The other replies are very helpful.&nbsp;=20
:)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial =
size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DCourier size=3D2>def findKey(val):</FONT></DIV>
<DIV><FONT face=3DCourier size=3D2>&nbsp; for key, value in=20
dict.items():</FONT></DIV>
<DIV><FONT face=3DCourier size=3D2>&nbsp;&nbsp;&nbsp; if value =3D=3D =
val: return=20
key</FONT></DIV>
<DIV><FONT face=3DCourier size=3D2>&nbsp; return None</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>GBU</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Matthew Sherborne</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>----- Original Message ----- =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>From: "Don Arnold" &lt;</FONT><A=20
href=3D"mailto:darnold02@sprynet.com"><FONT face=3DArial=20
size=3D2>darnold02@sprynet.com</FONT></A><FONT face=3DArial =
size=3D2>&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>To: &lt;</FONT><A=20
href=3D"mailto:printers@sendme.cz"><FONT face=3DArial=20
size=3D2>printers@sendme.cz</FONT></A><FONT face=3DArial size=3D2>&gt;; =
&lt;</FONT><A=20
href=3D"mailto:python-list@python.org"><FONT face=3DArial=20
size=3D2>python-list@python.org</FONT></A><FONT face=3DArial =
size=3D2>&gt;;=20
&lt;</FONT><A href=3D"mailto:tutor@python.org"><FONT face=3DArial=20
size=3D2>tutor@python.org</FONT></A><FONT face=3DArial size=3D2>&gt;; =
&lt;</FONT><A=20
href=3D"mailto:activepython@listserv.activestate.com"><FONT face=3DArial =

size=3D2>activepython@listserv.activestate.com</FONT></A><FONT =
face=3DArial=20
size=3D2>&gt;; &lt;</FONT><A =
href=3D"mailto:python-help@python.org"><FONT face=3DArial=20
size=3D2>python-help@python.org</FONT></A><FONT face=3DArial=20
size=3D2>&gt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Sent: Tuesday, March 26, 2002 11:51 =
AM</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Subject: Re: How to get a key from=20
dictionary?</FONT></DIV>
<DIV><FONT face=3DArial><BR><FONT size=3D2></FONT></FONT></DIV><FONT =
face=3DArial=20
size=3D2>&gt; &gt;&gt;&gt; targetval =3D 2<BR>&gt; &gt;&gt;&gt; dict =3D =
{'aa':1,=20
'bb':2, 'cc': 3, 'dd': 1}<BR>&gt; &gt;&gt;&gt; targetval =3D 2<BR>&gt;=20
&gt;&gt;&gt; for key in dict.keys():<BR>&gt;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if dict[key] =
=3D=3D=20
targetval:<BR>&gt;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print =

"found", targetval, "at key", key<BR>&gt; <BR>&gt; found 2 at key =
bb<BR>&gt;=20
&gt;&gt;&gt; targetval =3D 1<BR>&gt; &gt;&gt;&gt; for key in =
dict.keys():<BR>&gt;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if dict[key] =
=3D=3D=20
targetval:<BR>&gt;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print =

"found", targetval, "at key", key<BR>&gt; <BR>&gt; found 1 at key =
aa<BR>&gt;=20
found 1 at key dd<BR>&gt; <BR>&gt; ----- Original Message -----<BR>&gt; =
From:=20
"A" &lt;</FONT><A href=3D"mailto:printers@sendme.cz"><FONT face=3DArial=20
size=3D2>printers@sendme.cz</FONT></A><FONT face=3DArial =
size=3D2>&gt;<BR>&gt; To:=20
&lt;</FONT><A href=3D"mailto:python-list@python.org"><FONT face=3DArial=20
size=3D2>python-list@python.org</FONT></A><FONT face=3DArial =
size=3D2>&gt;;=20
&lt;</FONT><A href=3D"mailto:tutor@python.org"><FONT face=3DArial=20
size=3D2>tutor@python.org</FONT></A><FONT face=3DArial =
size=3D2>&gt;;<BR>&gt;=20
&lt;</FONT><A =
href=3D"mailto:activepython@listserv.activestate.com"><FONT=20
face=3DArial =
size=3D2>activepython@listserv.activestate.com</FONT></A><FONT=20
face=3DArial size=3D2>&gt;; &lt;</FONT><A =
href=3D"mailto:python-help@python.org"><FONT=20
face=3DArial size=3D2>python-help@python.org</FONT></A><FONT =
face=3DArial=20
size=3D2>&gt;<BR>&gt; Sent: Monday, March 25, 2002 4:16 PM<BR>&gt; =
Subject: How to=20
get a key from dictionary?<BR>&gt; <BR>&gt; <BR>&gt; &gt; Hi,<BR>&gt; =
&gt; Is=20
there a possibility to get, from a dictionary, a key according to =
a<BR>&gt; &gt;=20
value ?<BR>&gt; &gt; For example<BR>&gt; &gt; I have a =
dictionary<BR>&gt;=20
&gt;<BR>&gt; &gt; dict=3D{'aa':1,'bb':2}<BR>&gt; &gt;<BR>&gt; &gt; =
and<BR>&gt;=20
&gt; dict['aa']<BR>&gt; &gt; is 1<BR>&gt; &gt;<BR>&gt; &gt; But how can =
I for=20
value 1 find out&nbsp; key? (That is here&nbsp; 'aa')<BR>&gt; =
&gt;<BR>&gt; &gt;=20
Thank you for help<BR>&gt; &gt; Ladislav<BR>&gt; &gt;<BR>&gt; =
&gt;<BR>&gt; &gt;=20
_______________________________________________<BR>&gt; &gt; =
ActivePython=20
mailing list<BR>&gt; &gt; </FONT><A=20
href=3D"mailto:ActivePython@listserv.ActiveState.com"><FONT face=3DArial =

size=3D2>ActivePython@listserv.ActiveState.com</FONT></A><BR><FONT =
face=3DArial=20
size=3D2>&gt; &gt; To unsubscribe: </FONT><A=20
href=3D"http://listserv.ActiveState.com/mailman/mysubs"><FONT =
face=3DArial=20
size=3D2>http://listserv.ActiveState.com/mailman/mysubs</FONT></A><BR><FO=
NT=20
face=3DArial size=3D2>&gt; <BR>&gt;=20
_______________________________________________<BR>&gt; ActivePython =
mailing=20
list<BR>&gt; </FONT><A =
href=3D"mailto:ActivePython@listserv.ActiveState.com"><FONT=20
face=3DArial =
size=3D2>ActivePython@listserv.ActiveState.com</FONT></A><BR><FONT=20
face=3DArial size=3D2>&gt; To unsubscribe: </FONT><A=20
href=3D"http://listserv.ActiveState.com/mailman/mysubs"><FONT =
face=3DArial=20
size=3D2>http://listserv.ActiveState.com/mailman/mysubs</FONT></A><BR><FO=
NT=20
face=3DArial size=3D2>&gt; </FONT></BODY></HTML>

------=_NextPart_000_002A_01C1D569.652C29C0--



From aleaxit@yahoo.com  Tue Mar 26 20:41:00 2002
From: aleaxit@yahoo.com (Alex Martelli)
Date: Tue, 26 Mar 2002 12:41:00 -0800 (PST)
Subject: [Tutor] Re: [Python-Help] Re: How to get a key from  dictionary?
In-Reply-To: <002d01c1d504$d0749010$08020196@Jonah>
Message-ID: <20020326204100.576.qmail@web9302.mail.yahoo.com>

--- Matthew Sherborne <miracle@paradise.net.nz> wrote:
> Sorry to be a show off, but I reckon that this way
> may be faster. Sorry again. The other replies are
> very helpful.  :)
> 
> def findKey(val):
>   for key, value in dict.items():
>     if value == val: return key
>   return None

Apart from the crucial defects of [a] returning a
"random" key if more than one has the sought-for
value and [b] not knowing when None is returned
if no key was found OR None was the "random" key,
this is NOT faster than looping on dict, or even, if
you are stuck with old (<2.2) Python, at least on
dict.keys().  dict.items() must prepare a list of N
tuples, and that's typically slower than it
takes to do N key-to-value lookups.  And let's not
even get into using the name of a built-in type
(dict) as a GLOBAL variable, as this code seems to
be doing.  dict is only a built-in in 2.2 and later,
but there's no reason to use it even for
earlier releases, and it does risk messing some
things up.  If you must have a global (and you
shouldn't), call it adict, thedict, somedict, ...

I keep suggesting:

def findKeys(adict, aval):
    return [k for k in adict if adict[k]==aval]

or the obvious equivalent with adict.keys() if
you're stuck with some old Python such as 2.1.

Returning a list is obviously the right approach
since you're returning something of which there
could be 0, 1, 2, ..., N occurrences.  And a
list is built easily and fast with a list
comprehension.  So, why not?


Alex


__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
http://movies.yahoo.com/


From shalehperry@attbi.com  Tue Mar 26 21:44:55 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue, 26 Mar 2002 13:44:55 -0800 (PST)
Subject: [Tutor] Which programming language is better to start with
In-Reply-To: <HIIBPEACNMCONBAA@mailcity.com>
Message-ID: <XFMail.20020326134455.shalehperry@attbi.com>

On 26-Mar-2002 James M Lang wrote:
> On one weeb site that I went to, it said that it was better to start with
> Python or Perl. It stated that Python was more easier and Perl was more
> useful. I have tried Python but, where I live, resources are very limited and
> I couln't find much to help learn Python. They did have a few Perl books at
> the library. The reason for which I started to learn to program was to
> program videogames for fun. Any ideas about what to do?
> 

you left out the operating system you program on.  Whichever it is, give
http://www.libsdl.org a look.  It makes game programming rather fun and easy. 
The library is written in C, but there are python (and perl and .....) bindings.

There are numerous web sites with lots of great python info.  Links from
http://www.python.org should be sufficient.  There is always mail order too.

python and perl are equal in their usefulness.  Both are good languages with
lots of great support both in the software and in people.  It really boils down
to which one feels right for you.  Obviously we all like python.  So we are a
little biased.  I learned perl first but never use it now.

I am sure others will list great online resources.


From dyoo@hkn.eecs.berkeley.edu  Tue Mar 26 21:54:24 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 26 Mar 2002 13:54:24 -0800 (PST)
Subject: [Tutor] Which programming language is better to start with
In-Reply-To: <HIIBPEACNMCONBAA@mailcity.com>
Message-ID: <Pine.LNX.4.44.0203261338450.29282-100000@hkn.eecs.berkeley.edu>

> On one weeb site that I went to, it said that it was better to start
> with Python or Perl.

Always take testimonials with a grain of salt.  *grin*

But that being said, I think that Python or Perl is a great place to
start.  Other possible languages include C or Java.  C is also a fairly
good starting language, and exposes much more of the raw machine to you.
(This may be a good or bad thing depending on your temper and
personality.)


> It stated that Python was more easier and Perl was more useful. I have
> tried Python but, where I live, resources are very limited and I couln't
> find much to help learn Python. They did have a few Perl books at the
> library.

You can find a lot of Python resources on the web site.  In particular,
here's a link to the "Beginners Tutorials" section:

    http://python.org/doc/Newbies.html

so there's a wealth of information you can use to learn Python.  And you
also have us.  *grin*

Feel free to pick a tutorial and start running with it, and when you have
questions, you're always welcome to ask here.  We'll be glad to talk about
them.

(Perl also provides pretty nice support at the web site:
http://learn.perl.org.  Both languages host user communities with helpful
folk.)


> The reason for which I started to learn to program was to program
> videogames for fun. Any ideas about what to do?

Python has a nice library called Pygame that you can use to make your
games:

    http://pygame.org

I'm not so sure about Perl, so you may want to ask on learn.perl.org on
that one.


Best of wishes to you!



From scarblac@pino.selwerd.nl  Tue Mar 26 21:57:40 2002
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 26 Mar 2002 22:57:40 +0100
Subject: [Tutor] Which programming language is better to start with
In-Reply-To: <HIIBPEACNMCONBAA@mailcity.com>; from jimmy_130@lycos.com on Tue, Mar 26, 2002 at 02:41:57PM -0500
References: <HIIBPEACNMCONBAA@mailcity.com>
Message-ID: <20020326225740.A14126@pino.selwerd.nl>

On  0, James M Lang <jimmy_130@lycos.com> wrote:
> On one weeb site that I went to, it said that it was better to start with
> Python or Perl. It stated that Python was more easier and Perl was more
> useful. I have tried Python but, where I live, resources are very limited
> and I couln't find much to help learn Python. They did have a few Perl books
> at the library. The reason for which I started to learn to program was to
> program videogames for fun. Any ideas about what to do?

Well, you ask here, the list for people who try to use Python to learn how
to program. Obviously I believe that Python is the best way to learn
programming, period.

I don't think you absolutely need books, if you have a good Internet
connection - go through one or a few tutorials for non-programmers (there
are links under Documentation at www.python.org), you can ask questions
here, the library reference is a very important resource and it is online,
etc.

For games, there is PyGame - www.pygame.org . Nice for developing games
using Python, and you can use the existing games as examples.

However, it's not *easy*. Learning to program enough to make a video game is
hard work, no matter what the language. In the end, your game will probably
want to use more than one language, like Python with parts done in C. But,
as the examples at pygame.org show, you can get quite far, in fact to a nice
working real game, with only Python.

And Python was, in part, *designed* to be used by newbie programmers. Perl
was designed for people who think strings of unix commands and regexes are
similar to a natural language - the opposite end of the spectrum.

And, Python is *FUN*. If you're going to do hard work and study a lot, this
is easily one of the most important things :-)

-- 
Remco Gerlich


From dman@dman.ddts.net  Tue Mar 26 22:09:19 2002
From: dman@dman.ddts.net (dman)
Date: Tue, 26 Mar 2002 16:09:19 -0600
Subject: [Tutor] tail -f
Message-ID: <20020326220919.GA5228@dman.ddts.net>

I need to make a portion of a certain operate like 'tail -f'[1].  When
fully deployed, program will be reading from the serial port and
storing the data in a SQL database.  For initial testing deployment I
want it to read from a log file.  The log file is currently created as
a side effect of running kermit on the port.  I skimmed through the
source for tail, but nothing unusual jumped out at me and said "this
is how it does that!".  I tried to simply continue reading from the
file, but that only chewed up the CPU and didn't yield any output when
I echoed new data into the file.

Does anyone here know how to follow a file efficiently and correctly?


<slaps forehead>
Duh!  I just realized that I can open a pipe to 'tail -f'!  (as long
as it doesn't ever yield EOF)  I'd still like to know how it's done.

TIA,
-D

[1]  For the non-Unix folks out there, the "tail" command reads the
     last N lines of a file and writes them on stdout.  The '-f' flag
     (follow) means to continue to follow EOF as other programs append
     more data to the file.  One use is for watching log files.

-- 

Folly delights a man who lacks judgement,
but a man of understanding keeps a straight course.
        Proverbs 15:21



From alex@gabuzomeu.net  Tue Mar 26 22:21:58 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Tue, 26 Mar 2002 23:21:58 +0100
Subject: [Tutor] Extracting words(quest 2)
In-Reply-To: <E16pxV9-00055l-00@mail.python.org>
Message-ID: <4.3.2.7.2.20020326231603.00df6e60@pop3.norton.antivirus>

Hello,


At 15:25 26/03/2002 -0500, tutor-request@python.org wrote:
>From: dman <dman@dman.ddts.net>
>To: tutor@python.org
>Subject: Re: [Tutor] Extracting words(quest 2)
>
>On Tue, Mar 26, 2002 at 05:06:51PM +0100, Alexandre Ratti wrote:
>...
>| (in dictionaries, entry order is randomized to speed up access).
>
>This doesn't exactly say what you meant.  The entry order isn't
>random; it follows a precise algorithm, which is what makes it fast.
> >From our perspective, when we print a dict, it does appear to be a
>random order.

Thanks dman; somehow I thought the entry order really was random. Do you 
know how this algorithm works? (eg. how are the entries organised?)


Cheers.

Alexandre



From hall@nhn.ou.edu  Tue Mar 26 22:12:50 2002
From: hall@nhn.ou.edu (Isaac Hall)
Date: Tue, 26 Mar 2002 16:12:50 -0600
Subject: [Tutor] Revving up Tkinter/PMW
Message-ID: <02032616253400.02189@ouhep1>

hi tutors, gurus, and newbies alike!

I have a question that has been eating at my sould for the past few weeks
(well, not quite eating, maybe sipping?).  Anyway, Im building a rather large
monitoring application that is supposed to take in a rather large ammount of
data (~10,000 objects....scalers, histograms, circular buffers(ie, pie charts),
and bitmasks) and display them graphically, and to be updated somewhere on the
order of once every 5 to 10 seconds.  Anyway,  Ive been working on this rather
on and off for the past few months and learning python (and SWIG) as I go, so
I don't feel like Im fully aware of many of the methods available for creating
faster graphics in python/Tkinter/PMW, and I haven't seen much in the way of
books and such that help in this area.  Currently, the graphics are displayed
in a multi-layered(tabbed) PMW notebook, and I was wondering this:

Is there any way to make the thing only update the page that is being viewed?

OR

Is there any way to make a composite picture of many pictures be drawn faster
(like maybe if it drew the whole thing in memory before putting it on the
screen?)

OR

is there any way to make python/tkinter update several pages SIMULTANEOUSLY??

anyway, I havent been able to find much help in these areas, so I thought I
would ask all of you, since Im almost sure someone has dealt with something
like this before.

Thanks alot

Ike


From dman@dman.ddts.net  Tue Mar 26 22:42:54 2002
From: dman@dman.ddts.net (dman)
Date: Tue, 26 Mar 2002 16:42:54 -0600
Subject: [Tutor] Which programming language is better to start with
In-Reply-To: <Pine.LNX.4.44.0203261338450.29282-100000@hkn.eecs.berkeley.edu>
References: <HIIBPEACNMCONBAA@mailcity.com> <Pine.LNX.4.44.0203261338450.29282-100000@hkn.eecs.berkeley.edu>
Message-ID: <20020326224254.GA5290@dman.ddts.net>

On Tue, Mar 26, 2002 at 01:54:24PM -0800, Danny Yoo wrote:
| > On one weeb site that I went to, it said that it was better to start
| > with Python or Perl.
| 
| Always take testimonials with a grain of salt.  *grin*
| 
| But that being said, I think that Python or Perl is a great place to
| start.  Other possible languages include C or Java.  C is also a fairly
| good starting language, and exposes much more of the raw machine to you.
| (This may be a good or bad thing depending on your temper and
| personality.)

I disagree with the view that C is a good starting language.  I think,
for someone starting out, that C is too low-level.  A beginner should
write code that has fewer punctuation symbols (that eliminates perl
and sh and gives C and C++ a hard time), and also provides somewhat
helpful error messages (that eliminates C and C++).  It is much more
helpful to tell a beginner 

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: len() of unsized object

than it is to tell them

Segmentation fault (core dumped)


In this example I tried finding the length of a null string.  (namely
'None' in python and 'NULL' in C).

Don't get me wrong here, languages other than python have their pros
as well and are even better suited for certain tasks.  I don't think
that they are as suited for an introduction to programming.

A beginner should start with something relatively natural and work
their way into thinking like a computer, then move on to more
complicated or low-level languages like C.

-D

-- 

If Microsoft would build a car...
... Occasionally your car would die on the freeway for no reason. You
would have to pull over to the side of the road, close all of the car
windows, shut it off, restart it, and reopen the windows before you
could continue. For some reason you would simply accept this.



From shalehperry@attbi.com  Tue Mar 26 22:46:31 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue, 26 Mar 2002 14:46:31 -0800 (PST)
Subject: [Tutor] Which programming language is better to start with
In-Reply-To: <20020326224254.GA5290@dman.ddts.net>
Message-ID: <XFMail.20020326144631.shalehperry@attbi.com>

> A beginner should start with something relatively natural and work
> their way into thinking like a computer, then move on to more
> complicated or low-level languages like C.
> 

I almost did not send this for fear it would devolve this thread but .....

In my experience people who start on the high level languages and then try to
go low level often find it hard to fit in.  They are too used to the language
doing everything for them.  Of course the opposite is sometimes true and we
find C coders trying to implement hashes themselves or who never check if a
python module exists before reinventing the wheel.

I started in C, worked up to C++ and then learned perl, lisp and python. 
Having started in C where I had nothing I learned to be good at managing
resources and careful planning.  It was hard though.  No doubt.

That said, I do believe python is a good place to start and do not disagree
with most of what dman said.  Just wanted to add some balance.


From wilson@isis.visi.com  Tue Mar 26 22:48:03 2002
From: wilson@isis.visi.com (Tim Wilson)
Date: Tue, 26 Mar 2002 16:48:03 -0600 (CST)
Subject: [Tutor] Which programming language is better to start with
In-Reply-To: <XFMail.20020326134455.shalehperry@attbi.com>
Message-ID: <Pine.GSO.4.10.10203261647240.2114-100000@isis.visi.com>

On Tue, 26 Mar 2002, Sean 'Shaleh' Perry wrote:

> you left out the operating system you program on.  Whichever it is, give
> http://www.libsdl.org a look.  It makes game programming rather fun and easy. 
> The library is written in C, but there are python (and perl and .....) bindings.

Pygame (http://pygame.org/) is the home of the Python bindings for
libsdl.

-Tim

--
Tim Wilson      |   Visit Sibley online:   | Check out:
Henry Sibley HS |  http://www.isd197.org   | http://www.zope.com
W. St. Paul, MN |                          | http://slashdot.org
wilson@visi.com |  <dtml-var pithy_quote>  | http://linux.com



From alan.gauld@bt.com  Tue Mar 26 23:26:05 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 26 Mar 2002 23:26:05 -0000
Subject: [Tutor] Extracting words..
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C49B@mbtlipnt02.btlabs.bt.co.uk>

> >   Lst = map(lambda item: item not in Lst, Lst)
> 
> Does this snippet work on your computer? I get "[0, 0, 0, 0, 0]".

Nope, its wrong on two counts.
1) I meant to use filter() not map() - map just returns the boolean 
   result of each test - false in this case!
2) It still doesn't work because you can't test the list being 
   built internally - you need to use an intermediate stage 
   - which kills performance - or an externally defined function 
   which is longer than the explicit loop of the earlier post....

I haven't tried it yet but will soon, but I do think you could do it 
on one line using a list comprehension...

Sheepishly,

Alan g.


From David@snowcrash.co.uk  Tue Mar 26 21:07:30 2002
From: David@snowcrash.co.uk (David)
Date: Tue, 26 Mar 2002 21:07:30 -0000
Subject: [Tutor] Launching a file programs from a python script?
In-Reply-To: <AF020C5FC551DD43A4958A679EA16A15017B405F@abbott.lith.com>
Message-ID: <001001c1d50a$3e2a3fb0$6500000a@HIRO>

I've usually just used os.system("command line") on windows box's seems
to work fine it spawns a console until the job passed to it is finished.

Not the most experienced python person so probably lots of better ways,
but this is simple and has been reliable for me on NT4/Win2k/WinXP
(assuming from the .bat you are running on Win??)

Cheers

David 

-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org] On Behalf
Of Israel Evans
Sent: 26 March 2002 20:22
To: 'tutor@python.org'
Subject: [Tutor] Launching a file programs from a python script?


  
Hello there... 
  
I'm currently having difficulties launching programs from a python
program. 
  
What I'd like to do is set up a little python script that launches
Apache, mySQL, and WebKit for me without having to turn each one on
individually.

  
I've been playing around with some of the os module functions but I
don't seem to quite grasp their proper uses.  From the reading I suppose
I'd probably wish to use one of the os.execX variants which supposedly
replace the first process.  Some of the programs (webkit) ask to be
started with a .bat file which I know I could probably replicate without
using the console, but having a console for each program is kind of nice
due to the info they spit out and due to the fact that both Apache and
Webkit are attached to their consoles and will perish without them.  

  
Any Ideas? 
  
Thanks a bundle... 
  
  
  
~Israel~ 
  




From moodykre8r@earthlink.net  Tue Mar 26 23:51:10 2002
From: moodykre8r@earthlink.net (binary_star)
Date: Tue, 26 Mar 2002 15:51:10 -0800
Subject: [Tutor] Need *Python Help* help
Message-ID: <LPBBLEMICOGCGHANJMACEENEDBAA.moodykre8r@earthlink.net>

When requesting help for "topics" (from within IDLE) I am receiving the
following message:

	"Sorry, topic and keyword documentation
	 is not available because the Python HTML
	 documentation files could not be found.
	 If you have installed them, please set
	 the environment variable PYTHONDOCS to
	 indicate their location."


Thing is, I installed Python via fink, and don't know if the HTML
documentation was included, nor do I know how to set the PYTHONDOCS env.
var. to indicate anything. I was not able to successfully google a simple
answer out of the Web, so I am asking for someone here to help me out.

I am still unsure how to locate all my Python files. That is, I don't know
what directories to look in, and I don't know *what* necessarily to look
for. If I haven't got the HTML docs, I'd like to know where to get them and
how to install them.

Thank you.


Sincerely,
James Pomeroy



From scarblac@pino.selwerd.nl  Wed Mar 27 00:42:44 2002
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 27 Mar 2002 01:42:44 +0100
Subject: [Tutor] Extracting words(quest 2)
In-Reply-To: <4.3.2.7.2.20020326231603.00df6e60@pop3.norton.antivirus>; from alex@gabuzomeu.net on Tue, Mar 26, 2002 at 11:21:58PM +0100
References: <E16pxV9-00055l-00@mail.python.org> <4.3.2.7.2.20020326231603.00df6e60@pop3.norton.antivirus>
Message-ID: <20020327014244.A14822@pino.selwerd.nl>

On  0, Alexandre Ratti <alex@gabuzomeu.net> wrote:
> Hello,
> 
> 
> At 15:25 26/03/2002 -0500, tutor-request@python.org wrote:
> >From: dman <dman@dman.ddts.net>
> >To: tutor@python.org
> >Subject: Re: [Tutor] Extracting words(quest 2)
> >
> >On Tue, Mar 26, 2002 at 05:06:51PM +0100, Alexandre Ratti wrote:
> >...
> >| (in dictionaries, entry order is randomized to speed up access).
> >
> >This doesn't exactly say what you meant.  The entry order isn't
> >random; it follows a precise algorithm, which is what makes it fast.
> > >From our perspective, when we print a dict, it does appear to be a
> >random order.
> 
> Thanks dman; somehow I thought the entry order really was random. Do you 
> know how this algorithm works? (eg. how are the entries organised?)

Dictionaries are implemented by means of a data structure called 
"hash table". It's a bit late at night here, so I can't spend much time on
finding a good reference... the third Google hit is
http://ciips.ee.uwa.edu.au/~morris/Year2/PLDS210/hash_tables.html .

That page looks like it's totally correct and therefore impossible to
understand, at first sight.

Basically, a dictionary of n items is an array of m items, were m is rather
larger than n. The keys are then put through a 'hashing function' - usually
the memory address is put through some complicated function so that it
yields a number between 0 and m-1; it's randomish so that different keys are
unlikely to give the same number. Then the key,value pair is stored at that
place in the array.

When you do a lookup in a dictionary, all that needs to be done is compute
the hash value of the key, and you know where the value is. There might be
more than one value there, and the algorithm handles that, but that is
unlikely by means of the construction of the hashing function, and because m
is large enough.

When you see the .keys() of a dictionary, it gives them in the order of
their hash values - which *is* related to the key values by means of the
hashing function, but which *looks* random because the hashing function is
designed to scatter them about as much as possible.

This little summary is proof that even uncomprehensible 2-year CS
explanations are preferable to the drunken ad hoc explanations of a
many-year CS student, no doubt...

Note that computing the hash function doesn't really depend on the number of
items in the dictionary - which is why they're fast, which is why they're so
cool.

-- 
Remco Gerlich


From scarblac@pino.selwerd.nl  Wed Mar 27 01:01:09 2002
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Wed, 27 Mar 2002 02:01:09 +0100
Subject: [Tutor] Languages, was Which programming language is better to start with
In-Reply-To: <XFMail.20020326144631.shalehperry@attbi.com>; from shalehperry@attbi.com on Tue, Mar 26, 2002 at 02:46:31PM -0800
References: <20020326224254.GA5290@dman.ddts.net> <XFMail.20020326144631.shalehperry@attbi.com>
Message-ID: <20020327020109.B14822@pino.selwerd.nl>

On  0, Sean 'Shaleh' Perry <shalehperry@attbi.com> wrote:
> I started in C, worked up to C++ and then learned perl, lisp and python. 
> Having started in C where I had nothing I learned to be good at managing
> resources and careful planning.  It was hard though.  No doubt.

Just some anecdotal stuff;

I started when I was 11, learning BASIC on a Commodore 64. I did learn a
*tiny* bit of machine language on it, but never made anything in it more
than 40 commands long or so.

Then my parents got a genuine IBM PC XT. I played with GW Basic for a while.
Then someone gave me Turbo Pascal 4.0. This was great. As a little computer
nerd I had gotten books from the library on Cobol, Fortran, and Pascal (all
they had) and the Pascal was enough to get me started, the TP help pages
helped a lot after that.

Later on I got to university, computer science, the big language was Pascal,
but without the TP extensions... I was good at it but it's not very
practical. Over the course of the study we also had C, Prolog, Haskell,
Atari ST machine language, Java, and a few more that I can't remember right
now (one for parallel programming, and some Modula thing at least).

Then I had to do some lab session with VTK, the Visualization Toolkit. It
had Tcl bindings, which were at the time reputedly slightly more mature than
the Python bindings, whatever Python was. So I learned Tcl.

Tcl was *great*. We could code pretty quickly, although lack of some things
(namespaces) was irritating. We needed a file format for movie scripts, and
a stroke of genius told me it was good to give the files the same syntax as
Tcl itself, define a few commands, and without much effort we had an
extremely powerful format. The teacher was much impressed.

Around this time I joined the ZAngband DevTeam, and Python integration was a
big buzzword. I wasn't working on it; but it was obvious I'd have to learn
it some day.

Then I met Perl. Perl beat Tcl in so many ways it wasn't pretty. Perl was so
great (I haven't mentioned so far - in the seven or so years since I joined
the uni [I am that slow] I had only used Unix and Linux - so Perl ruled for
me). For a few months I wrote everything I needed in Perl.

Then ZAngband Python support was slowly getting somewhere, I thought I
should learn it, and I went to the Tutorial. I think that's two years ago
now.

Apart from a little bit of C for ZAngband, I haven't written *anything* in a
language other than Python since then. It was love at first sight. I can
forget all of the above; Python obsoletes it, period. By now I'm finally
about to finish my study, there are thousands of lines of code for my
thesis, and they're all Python. And it's fun! I haven't had so much fun
coding since finding out about Turbo Pascal at the age of 13...

One caveat - recently some Perl program needed a package I didn't have. I
typed, as a first try, perl -CPAN install <package>, or something like that.
Screen upon screen of text scrolled by - I needed this package so it was
installed, that package was outdated so it was updated, hey I don't have
those yet but now I do, etc - all completely automatic. That was awesome,
and distutils aren't quite there yet. Perl leads there.

But for all else, Python is the best.

I have no idea why I'm posting this except it's late at night and I'd like
to know a bit about the language backgrounds of other people...

-- 
Remco Gerlich


From israel@lith.com  Wed Mar 27 01:08:09 2002
From: israel@lith.com (Israel Evans)
Date: Tue, 26 Mar 2002 17:08:09 -0800
Subject: [Tutor] Launching a file programs from a python script?
Message-ID: <AF020C5FC551DD43A4958A679EA16A15017B4060@abbott.lith.com>

I think the problem I'm running into is that I need to either launch a
program and give it it's own console, or launch a console and give the
console a command to launch the target program.

I've found that when I'm in the console I actually need to cd to the target
program's directory and launch it from there, rather than just enter the
full path from whatever directory the console just happens to be in.  If I
do just start up cmd and enter the full path of the program I want to
launch, the target program complains. I don't quite know why.

SO, in essence I think I need to launch a program from a specific working
directory and have that program assigned to a specific console (cmd.exe or
command.exe on windows).  I'm continuing to play around with the os calls so
if I find anything I'll be sure to post it, but maybe one of you kind,
intelligent people will know and get to it before me.  :)

Thanks.



~Israel~


-----Original Message-----
From: David [mailto:David@snowcrash.co.uk] 
Sent: 26 March 2002 1:08 PM
To: 'Israel Evans'; tutor@python.org
Subject: RE: [Tutor] Launching a file programs from a python script?

I've usually just used os.system("command line") on windows box's seems
to work fine it spawns a console until the job passed to it is finished.

Not the most experienced python person so probably lots of better ways,
but this is simple and has been reliable for me on NT4/Win2k/WinXP
(assuming from the .bat you are running on Win??)

Cheers

David 

-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org] On Behalf
Of Israel Evans
Sent: 26 March 2002 20:22
To: 'tutor@python.org'
Subject: [Tutor] Launching a file programs from a python script?


  
Hello there... 
  
I'm currently having difficulties launching programs from a python
program. 
  
What I'd like to do is set up a little python script that launches
Apache, mySQL, and WebKit for me without having to turn each one on
individually.

  
I've been playing around with some of the os module functions but I
don't seem to quite grasp their proper uses.  From the reading I suppose
I'd probably wish to use one of the os.execX variants which supposedly
replace the first process.  Some of the programs (webkit) ask to be
started with a .bat file which I know I could probably replicate without
using the console, but having a console for each program is kind of nice
due to the info they spit out and due to the fact that both Apache and
Webkit are attached to their consoles and will perish without them.  

  
Any Ideas? 
  
Thanks a bundle... 
  
  
  
~Israel~ 
  



From shalehperry@attbi.com  Wed Mar 27 01:25:02 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue, 26 Mar 2002 17:25:02 -0800 (PST)
Subject: [Tutor] Languages, was Which programming language is better
In-Reply-To: <20020327020109.B14822@pino.selwerd.nl>
Message-ID: <XFMail.20020326172502.shalehperry@attbi.com>

> 
> I have no idea why I'm posting this except it's late at night and I'd like
> to know a bit about the language backgrounds of other people...
> 

C

C++ and Delphi at the same time.  I loved Delphi a lot, in fact when I found
python it had everything I loved about Delphi -- which is Object Pascal.  I
think there is a very clear pascal -> python trend.  I miss 'with' a lot.  A
lot.

Perl (I worked at an ISP and wrote little else for two years)

Python

Today I either write python or C++ when it is from scratch, depends on the
itch.  But I still do a fair amount of C hacking.  I am a @debian.org fellow so
I tend to hack on a bunch of things in a small way instead of devote my time to
one thing.

I have dabbled in tcl and lisp and a few others.  tcl's syntax never sat right
with me.  Have to admit it is a powerful small language though.

My first instinct when I start a project is "can i do it in python".


From dman@dman.ddts.net  Wed Mar 27 01:37:16 2002
From: dman@dman.ddts.net (dman)
Date: Tue, 26 Mar 2002 19:37:16 -0600
Subject: [Tutor] Extracting words(quest 2)
In-Reply-To: <4.3.2.7.2.20020326231603.00df6e60@pop3.norton.antivirus>
References: <E16pxV9-00055l-00@mail.python.org> <4.3.2.7.2.20020326231603.00df6e60@pop3.norton.antivirus>
Message-ID: <20020327013716.GA8042@dman.ddts.net>

On Tue, Mar 26, 2002 at 11:21:58PM +0100, Alexandre Ratti wrote:
| At 15:25 26/03/2002 -0500, dman :
| >On Tue, Mar 26, 2002 at 05:06:51PM +0100, Alexandre Ratti wrote:
| >...
| >| (in dictionaries, entry order is randomized to speed up access).
| >
| >This doesn't exactly say what you meant.  The entry order isn't
| >random; it follows a precise algorithm, which is what makes it fast.
| >>From our perspective, when we print a dict, it does appear to be a
| >random order.
| 
| Thanks dman; somehow I thought the entry order really was random.

Randomly ordered data is always the worst, especially for counting.

Suppose you had a list of integers in random order.  You want to
determine if a certain integer is in the list.  How many comparisons
must you do?  On average, N/2, for numbers in the list (N is the
length of the list).  For numbers not in the list, you must compare
against every element.  This is because at any given point you have no
way of knowing if it is possible for the number to be farther down in
the list.

If you sort the list first, though, you can reduce the number of
comparisions by doing a binary search.  A binary search is just a
precise way of describing what you do when you open the phone book.
The algorithm is :

    o   start in the middle, see if the given data is less than or
        greater than the middle value

    o   if the number is greater, pick the middle of the upper half of
        the list and repeat

        if the number is less, pick the middle of the lower half of
        the list and repeat

    When the size of the sublist you are searching is small enough
    (say 3 or so elements) then just use a simple linear search.

The nice thing about a binary search is that for each iteration of the
algorithm you eliminate half of the remaining elements.  This
drastically improves the efficiency of the search.  The restriction is
that the data you are searching must have a transitive partial
ordering for the less-than operation.  (or greater-than if you prefer,
but one of them must be defined)  Integers, floats, and strings have
this property.  In fact, in python, all objects can be compared with
less-than.  The result is always consistent for a given interpreter,
but is effectively meaningless other than for sorting lists.

Binary Search Trees are a tree structure that allows for binary
searching.  Trees are nice because it is easier to insert into them
than lists.  However, binary search trees _can_ be just as bad as a
linear search, if the tree is built just right (or wrong).  There are
several variations such as AVL trees, Red-Black Trees and B-Trees that
work to solve that problem and introduce other performance gains.

| Do you know how this algorithm works? (eg. how are the entries
| organised?)

I don't know which algorithm or variant that python uses (read the
source! :-)) but I do know of a couple of hash table implementations.
In fact, I once had to implement a hash table using bucket chaining
for a lab in school.

As you know, the keys in a hash table (dict) must be hashable.  In
python that means the hash() function must be able to return an
integer for the object.  If you create your own classes you'll need to
define the __hash__ method, but for built-in types you don't need to
worry.  It is also worthwhile to note that the performance of a hash
table is directly related to the quality of the hashing function.

Before you feel overwhelmed with all this talk of hash and math (I
know I was the first time I learned this), just sit back and realize
that a hashing function is nothing more than a map (relation if you're
into discrete math) that converts an object to an integer.  For
example :
    >>> print hash( 1 )
    1
    >>> print hash( "foo bar baz spam eggs ham blah" )
    762522928
    >>> print hash( 762522928 )
    762522928
I put an object into the hash function and out comes a number.  A
decent hash function should have few "collisions"; IOW each object
should have a unique hash value.  The more collisions you have, the
worse the dict will behave.  Here's a pathological example of a really
bad hash function :
    class Pathological :
        def __hash__( self ) :
            return 1
You'll see why this is bad when we get through the explanation of
bucket chaining.


For this example we'll use the following hash function :
    ab -> 1
    cd -> 4
    ef -> 10
    gh -> 31


For bucket chaining, our hash table will contain an array of lists.
The size of the array will affect performance, and is a tradeoff of
space vs. time.  Different datasets will have different optimal sizes.
For this example lets use 5 as the size.  Our hash table looks like
this, if the array is horizontal :

(if you can invent a whiteboard that works across the internet you
could become rich!  whiteboards are easier to use than ascii-art :-))

+-+        +-+        +-+        +-+        +-+
|0|        |1|        |2|        |3|        |4|
+-+        +-+        +-+        +-+        +-+
 |          |          |          |          |
 v          v          v          v          v
null       null       null       null       null


Now insert 'ab' into the hash table with the value 'spam'.  The hash
function returns 1, so we'll put it at the end of the list in slot 1.

+-+        +-+        +-+        +-+        +-+
|0|        |1|        |2|        |3|        |4|
+-+        +-+        +-+        +-+        +-+
 |          |          |          |          |
 v          v          v          v          v
null       +-------+  null       null       null
           | key   |
           |  ab   |
           | val   |
           |  spam | 
           +-------+  


Now insert 'cd' with the value 'eggs'.  Since the hash function
returns 4, we'll add it to the list in slot 4.


+-+        +-+        +-+        +-+        +-+
|0|        |1|        |2|        |3|        |4|
+-+        +-+        +-+        +-+        +-+
 |          |          |          |          |
 v          v          v          v          v
null       +-------+  null       null       +-------+  
           | key   |                        | key   | 
           |  ab   |                        |  cd   | 
           | val   |                        | val   | 
           |  spam |                        |  eggs | 
           +-------+                        +-------+  


This is good, but what happens if the hash code is greater than our
array's maximum index?  We use modulo division to "wrap" around.  For
the key 'ef' the hash code is 10.  10%5 == 0, so we put it in slot 0.


+-+        +-+        +-+        +-+        +-+
|0|        |1|        |2|        |3|        |4|
+-+        +-+        +-+        +-+        +-+
 |          |          |          |          |
 v          v          v          v          v
+-------+  +-------+  null       null       +-------+  
| key   |  | key   |                        | key   | 
|  ef   |  |  ab   |                        |  cd   | 
| val   |  | val   |                        | val   | 
|  ham  |  |  spam |                        |  eggs | 
+-------+  +-------+                        +-------+  


Now an example where there is a collision.  In this case the collision
occurs becuase the hash table is too small, rather than due to a bad
hash function.  Either way the effect is the same.  

Since the key 'gh' has a hash code of 31 we insert it in slot 1
(31%5 == 1).

+-+        +-+        +-+        +-+        +-+
|0|        |1|        |2|        |3|        |4|
+-+        +-+        +-+        +-+        +-+
 |          |          |          |          |
 v          v          v          v          v
+-------+  +-------+  null       null       +-------+  
| key   |  | key   |                        | key   | 
|  ef   |  |  ab   |                        |  cd   | 
| val   |  | val   |                        | val   | 
|  ham  |  |  spam |                        |  eggs | 
+-------+  +-------+                        +-------+  
               |
               v
           +-------+
           | key   |
           |  gh   |
           | val   |
           |  bar  |
           +-------+


This is how the "bucket chains" work.  Each list is a chain of
buckets.  Each bucket contains a key-value pair.  They are indexed in
the array by the hash code.


To lookup an item we do basically the same thing as inserting.  If you
want to lookup the key 'ef', start by finding the hash code -- 10.
Then find the index into the array -- 0 -- and iterate over the bucket
chain until you find a key that compares equal with the key you're
looking for.  (this is why keys must be unique)  In the case of the
key 'ef', there is only one bucket and it is equal, so the result is
'ham'.

In the case of looking up 'gh', we find that the hash code 31 yields
an array index of 1.  We iterate over the buckets.  First 'ab' is not
equal to 'gh', so we move on and find the value 'bar'.


You can see that this hash table still involves a linear search, but
the search is performed on a much smaller dataset where the
performance is acceptable.  Conceivably one could use AVL trees
instead of linked lists for the bucket chains if that helps
performance.  Ideally, though, there are few enough collisions that it
doesn't matter.

Also you'll notice that this hash table is too small to be useful in
practice.  Taking a look at java's java.util.HashMap reveals that the
default array size is 11, and the default "load factor" is .75.  The
load factor controls how the hash table will grow -- whether you are
more concerned about space or speed.  A bigger array will be faster
due to fewer collisions; but also have more empty slots which wastes
memory.  A smaller array (like the one above) will have many
collisions but have fewer empty slots.

As you can see, data structures are as important, if not more
important, than algorithms.  With the right data struct, the algorithm
can almost right itself and have good performance.  With the wrong
data structure, the code could be obfuscated, error-prone, and have
poor performance.

Hope this isn't too confusing :-).

-D

-- 

Pride only breeds quarrels,
but wisdom is found in those who take advice.
        Proverbs 13:10



From dman@dman.ddts.net  Wed Mar 27 01:40:54 2002
From: dman@dman.ddts.net (dman)
Date: Tue, 26 Mar 2002 19:40:54 -0600
Subject: [Tutor] Need *Python Help* help
In-Reply-To: <LPBBLEMICOGCGHANJMACEENEDBAA.moodykre8r@earthlink.net>
References: <LPBBLEMICOGCGHANJMACEENEDBAA.moodykre8r@earthlink.net>
Message-ID: <20020327014054.GB8042@dman.ddts.net>

On Tue, Mar 26, 2002 at 03:51:10PM -0800, binary_star wrote:
| When requesting help for "topics" (from within IDLE) I am receiving the
| following message:
| 
| 	"Sorry, topic and keyword documentation
| 	 is not available because the Python HTML
| 	 documentation files could not be found.
| 	 If you have installed them, please set
| 	 the environment variable PYTHONDOCS to
| 	 indicate their location."

I can't help with getting IDLE's menu to be useful, but you can obtain
the docs from 

    http://python.org/ftp/python/doc/2.2/html-2.2.zip

I simply unpacked them on my hard drive and made a bookmark in my web
browser.

If you just want to read them on-line, see

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

-D

-- 

Pride only breeds quarrels,
but wisdom is found in those who take advice.
        Proverbs 13:10



From dman@dman.ddts.net  Wed Mar 27 01:48:19 2002
From: dman@dman.ddts.net (dman)
Date: Tue, 26 Mar 2002 19:48:19 -0600
Subject: [Tutor] Which programming language is better to start with
In-Reply-To: <XFMail.20020326144631.shalehperry@attbi.com>
References: <20020326224254.GA5290@dman.ddts.net> <XFMail.20020326144631.shalehperry@attbi.com>
Message-ID: <20020327014819.GC8042@dman.ddts.net>

On Tue, Mar 26, 2002 at 02:46:31PM -0800, Sean 'Shaleh' Perry wrote:
| > A beginner should start with something relatively natural and work
| > their way into thinking like a computer, then move on to more
| > complicated or low-level languages like C.
| 
| I almost did not send this for fear it would devolve this thread but .....

no worries,

| In my experience people who start on the high level languages and then try to
| go low level often find it hard to fit in.  They are too used to the language
| doing everything for them.  Of course the opposite is sometimes true and we
| find C coders trying to implement hashes themselves or who never check if a
| python module exists before reinventing the wheel.

Yes, some people fall into one category or the other.  Determine which
one you are in and pick the suitable type of language to start with
:-).

| I started in C, worked up to C++ and then learned perl, lisp and python. 
| Having started in C where I had nothing I learned to be good at managing
| resources and careful planning.  It was hard though.  No doubt.

Just for some perspective, here's approximately how I learned
programming languages :

Eiffel, some C, C++ and Java (at the same time in different courses),
Python, M68K assembly, more C, a subset of Common Lisp and a little
Scheme, Perl, Java threads, more Java and Python

I have a basic understanding of quite a few languages, but my
experience and comfort is really deep only in Java and Python.  I can
handle C and C++, but I haven't done any sizable projects with them in
a two years.  (and I have done any large projects in pure C)

I definitely agree with Sean that knowing how the hardware works
(learn assembly, but not x86 -- it is too ugly and messy) really helps
for writing decent software in higher level languages.

HTH,
-D

-- 

Microsoft DNS service terminates abnormally when it receives a response
to a dns query that was never made.
Fix information: run your DNS service on a different platform.
                                                            -- bugtraq



From erikprice@mac.com  Wed Mar 27 02:04:46 2002
From: erikprice@mac.com (Erik Price)
Date: Tue, 26 Mar 2002 21:04:46 -0500
Subject: [Tutor] Python & windows XP professional
In-Reply-To: <20020326175133.98178.qmail@web14108.mail.yahoo.com>
Message-ID: <033BC174-4127-11D6-A371-00039351FE6A@mac.com>

On Tuesday, March 26, 2002, at 12:51  PM, Britt Green wrote:

>  While that's a good suggestion, I don't think Apple's OSX runs on the
> x86 platform just yet! ;)
>
>  Running away from the fire he may have started....

The full "Mac OS X" may not run on x86 (and probably never will), but 
Darwin supposedly does.  I haven't met anyone who has actually succeeded 
in installing it yet, but here's the release info:

http://www.opensource.apple.com/projects/darwin/1.3/release.html



Erik



From joejava@dragoncat.net  Wed Mar 27 02:23:39 2002
From: joejava@dragoncat.net (Joel Ricker)
Date: Tue, 26 Mar 2002 21:23:39 -0500
Subject: [Tutor] Which programming language is better to start with
References: <XFMail.20020326134455.shalehperry@attbi.com>
Message-ID: <000e01c1d536$69f37e00$d4a2d6d1@x9k7y2>

From: Sean 'Shaleh' Perry <shalehperry@attbi.com>
> python and perl are equal in their usefulness.  Both are good languages
with
> lots of great support both in the software and in people.  It really boils
down
> to which one feels right for you.  Obviously we all like python.  So we
are a
> little biased.  I learned perl first but never use it now.

I have to disagree on one point regarding perl, the people.  Trying to get a
little assistance with scripts when I was learning perl was like pulling
teeth.  From newsgroups to chat rooms to mailing lists, I got nothing but
terse responses and bad attitudes. I started to feel like they should change
the name of Perl to RTFM.

Then I tried Python.  I got immediate and toughtful responses from the
newsgroups from everyone, including the greats like Tim. After a time I
learned of this mailing list and migrated over and received even more help.
You won't see the any bad attitudes here.

For me, that was the difference.  Sold all of my perl books, deleted the
binaries off my machine, and never looked at perl again.  Even rewrote all
of my perl code. A great programming language and a great community is worth
a lot more to me and than a language with a poor community.  You won't find
any that are better (I haven't.)

Joel




From SWidney@ci.las-vegas.nv.us  Wed Mar 27 02:33:57 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Tue, 26 Mar 2002 18:33:57 -0800
Subject: [Tutor] Launching a file programs from a python script?
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F5A55@SOVEREIGN>

> I think the problem I'm running into is that I need to either launch a
> program and give it it's own console, or launch a console and give the
> console a command to launch the target program.

As David mentioned in another post, your answer is os.system(), BUT...
instead of specifying your application, you're going to use START to launch
a new console window (with a few parameters):

# Let's use DIR for an example
    os.system("start /DC:\\winnt\\temp dir")

Here, START launches a new instance of cmd.exe, switches to C:\winnt\temp,
and runs DIR. Since DIR is an internal command, the window stays open.

If I had named a console-based application, it would have run in the new
console window and closed when done. If I had named a gui-based application,
it would have launched that in its own window.

# OK, let's launch notepad!
    os.system("start notepad")

Cool!

For more info on START, type "help start" at the command prompt (try "help
cmd", too)
.
.
.
> if I find anything I'll be sure to post it, but maybe one of you kind,
> intelligent people will know and get to it before me.  :)

Aw, shucks.


Scott


From erikprice@mac.com  Wed Mar 27 02:50:35 2002
From: erikprice@mac.com (Erik Price)
Date: Tue, 26 Mar 2002 21:50:35 -0500
Subject: [Tutor] Which programming language is better to start with
In-Reply-To: <XFMail.20020326144631.shalehperry@attbi.com>
Message-ID: <69752892-412D-11D6-A371-00039351FE6A@mac.com>

On Tuesday, March 26, 2002, at 05:46  PM, Sean 'Shaleh' Perry wrote:

> In my experience people who start on the high level languages and then 
> try to
> go low level often find it hard to fit in.  They are too used to the 
> language
> doing everything for them.  Of course the opposite is sometimes true 
> and we
> find C coders trying to implement hashes themselves or who never check 
> if a
> python module exists before reinventing the wheel.
>
> I started in C, worked up to C++ and then learned perl, lisp and python.
> Having started in C where I had nothing I learned to be good at managing
> resources and careful planning.  It was hard though.  No doubt.

I'm afraid of this very same thing.

I never received any formal instruction in programming.  A few months 
ago, I started learning PHP, and feel very comfortable doing basic tasks 
with that language (data processing, database access, typical web app 
stuff).  I have always wanted to learn Python, though, for even longer 
than I've known of PHP, so I am tackling that too.  But often -- REALLY 
often -- I see a lot of references to things that I know are C-related.  
It can be anything from "this language is based on C's construct..." to 
"similar to the C function 'printf' ..." or even simple references like 
"garbage collection", which I now know that a Python programmer can 
pretty much get by without ever hearing in their life but it is an issue 
that is of concern to C programmers.

Yet, if C is the language that Unix and operating systems and games are 
written in, then it must truly be a complex thing, right?  Like assembly 
language, only a little higher?

A few weeks ago I was in a library and saw a book on C programming, so I 
started reading it.  It was "a C Primer" or something (there's probably 
fifty of those).  I was pleased to find that it wasn't really that 
intimidating at all, and in fact the syntax strongly resembled that of 
PHP.  It was a strange feeling, to understand what was going on in the 
simple examples of the first few chapters that I read.

I would really like to learn more about it, if only to get a more 
foundational education in the way programming is done, but when I 
consider how little time I have for hobbyist programming, I am convinced 
that I am best off learning something like Python, which will hopefully 
let me get off the ground more quickly in terms of writing useful 
scripts and programs.

One of these days I shall surely have to take a class in programming.



Erik



From SWidney@ci.las-vegas.nv.us  Wed Mar 27 02:46:07 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Tue, 26 Mar 2002 18:46:07 -0800
Subject: [Tutor] Python & windows XP professional
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F5A56@SOVEREIGN>

> The full "Mac OS X" may not run on x86 (and probably never will), but 
> Darwin supposedly does.  I haven't met anyone who has 
> actually succeeded 
> in installing it yet, but here's the release info:
> 
> http://www.opensource.apple.com/projects/darwin/1.3/release.html
> 
> 
> 
> Erik

What the Heck, I'll take a stab at it! Following your link... here's a newer
release:

http://www.opensource.apple.com/projects/darwin/1.4/release.html

I'll download it right now and tomorrow morning I'll burn it and start
toying with it. Should be educational....


Scott


From shalehperry@attbi.com  Wed Mar 27 02:49:40 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue, 26 Mar 2002 18:49:40 -0800 (PST)
Subject: [Tutor] Which programming language is better to start with
In-Reply-To: <20020327014819.GC8042@dman.ddts.net>
Message-ID: <XFMail.20020326184940.shalehperry@attbi.com>

> 
> I definitely agree with Sean that knowing how the hardware works
> (learn assembly, but not x86 -- it is too ugly and messy) really helps
> for writing decent software in higher level languages.
> 

the college I attended but never graduated (silly mistakes of the young) taught
mips and solaris assembly.  It was fun to really touch the guts.  Also made you
appreciate little things like a for loop (-:

for(int i = 0; i < value; i++) {
  count += i;
}

that is a lot of assembler.  Then again the experience of wrapping your head
around a new language is fundamental to being a real coder.  If you just want
to write that little glue to get your physics or bio working, great.  But to
really be a hacker you need to constantly try out new languages.

A friend of mine once said every programmer should learn a machine's
assembler, a functional langauge, a stack language, a procedural language, and
an object language.  Doesn't really matter which ones.  it is the act of
learning them that is worthwhile.

Another comment I have is to always program in the idiom of a language.  In
college several of my professors were obviously long time C coders forced to
learn C++ and Java.  I relearned all of my C++ after leaving school.

Back to the thread, is python the right place to start.  I think it is a good
place to give people what they need to not be scared off.  Once they have
written a few real programs they can start to play with one of the other
languages.  For me a programming language is like a writing style.  Some of us
like to write haiku others are into Shakespeare.  Some people write horror
others write fantasy.  Each genre gives you certain things and sets up certain
guidelines.  Trying to write a horror story entirely in haiku would be
interesting but painful.  Python is just a style.  A way to make the words you
type become something meaningful for the computer.  At the same time how many
of us have tried to write a haiku and found it really difficult because all we
could think was "5 7 5, 5 7 5" instead of "snow fell on my nose; I like the way
it feels cold; wet as it melts down" (hey I just made that up - wow).  The
point is if you try to write a sonnet and get bogged down in the rhyme and
metre you never write the sonnet.  For me, python gives me all I want and gets
out of my way.  Then again, my favourite poetry is haiku and e.e. cummings, so
I am a little weird (-:


From dyoo@hkn.eecs.berkeley.edu  Wed Mar 27 02:53:45 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 26 Mar 2002 18:53:45 -0800 (PST)
Subject: [Tutor] Extracting words(quest 2)
In-Reply-To: <4.3.2.7.2.20020326231603.00df6e60@pop3.norton.antivirus>
Message-ID: <Pine.LNX.4.44.0203261848170.394-100000@hkn.eecs.berkeley.edu>

On Tue, 26 Mar 2002, Alexandre Ratti wrote:

> Hello,
>
>
> At 15:25 26/03/2002 -0500, tutor-request@python.org wrote:
> >From: dman <dman@dman.ddts.net>
> >To: tutor@python.org
> >Subject: Re: [Tutor] Extracting words(quest 2)
> >
> >On Tue, Mar 26, 2002 at 05:06:51PM +0100, Alexandre Ratti wrote:
> >...
> >| (in dictionaries, entry order is randomized to speed up access).
> >
> >This doesn't exactly say what you meant.  The entry order isn't
> >random; it follows a precise algorithm, which is what makes it fast.
> > >From our perspective, when we print a dict, it does appear to be a
> >random order.
>
> Thanks dman; somehow I thought the entry order really was random. Do you
> know how this algorithm works? (eg. how are the entries organised?)

I had a small mini-tutorial on hashing here:

    http://mail.python.org/pipermail/tutor/2002-January/011281.html

For a comprehensive explanation on how dictionaries work, you'll find
relevant information under the topic of "hashing".


Good luck!



From shalehperry@attbi.com  Wed Mar 27 02:54:55 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Tue, 26 Mar 2002 18:54:55 -0800 (PST)
Subject: [Tutor] Which programming language is better to start with
In-Reply-To: <69752892-412D-11D6-A371-00039351FE6A@mac.com>
Message-ID: <XFMail.20020326185455.shalehperry@attbi.com>

> 
> One of these days I shall surely have to take a class in programming.
> 

I wish you the best of luck.  None of the CS my school taught was worth
remembering.  My skills all have come from books and from open source hacking
as well as a lot of help from coworkers and friends.

It is REALLY important to let people read your code.  It is just like writing
class in school.  "peer review" they call it.  Knowing people will read what
you wrote makes you focus a little more on making it worthwhile.  Plus you get
peoplke asking you "why did you use a while instead of a for loop?".  This is
especially handy if you can find people better than you are.

My other suggestion is to find books on the act of programming, not the
language.  Learn about fundamental algorithms.  Why is one sort better than
another?  Is this function wortyh optimizing?  What is this "big O notation" I
keep hearing about?  What does "takes logarithmic time" mean to me?  This is
the only thing I kept from college classes.  The art of programming I learned
there, the choice of a hammer or a screw driver I learned in life.


From dman@dman.ddts.net  Wed Mar 27 03:59:21 2002
From: dman@dman.ddts.net (dman)
Date: Tue, 26 Mar 2002 21:59:21 -0600
Subject: [Tutor] Which programming language is better to start with
In-Reply-To: <69752892-412D-11D6-A371-00039351FE6A@mac.com>
References: <XFMail.20020326144631.shalehperry@attbi.com> <69752892-412D-11D6-A371-00039351FE6A@mac.com>
Message-ID: <20020327035921.GA9733@dman.ddts.net>

On Tue, Mar 26, 2002 at 09:50:35PM -0500, Erik Price wrote:
| On Tuesday, March 26, 2002, at 05:46  PM, Sean 'Shaleh' Perry wrote:
| 
| >In my experience people who start on the high level languages and
| >then try to go low level often find it hard to fit in.  They are
| >too used to the language doing everything for them.  Of course the
| >opposite is sometimes true and we find C coders trying to implement
| >hashes themselves or who never check if a python module exists
| >before reinventing the wheel.
| >
| >I started in C, worked up to C++ and then learned perl, lisp and python.
| >Having started in C where I had nothing I learned to be good at managing
| >resources and careful planning.  It was hard though.  No doubt.
| 
| I'm afraid of this very same thing.

Keep working at it, little by little.  As you go, though, do things
that are interesting to you.  If you aren't interested in the task it
will be boring and tedious.  If you are interested in it, then you
will be driven to work it out.

| I never received any formal instruction in programming.  A few months 
| ago, I started learning PHP, and feel very comfortable doing basic tasks 
| with that language (data processing, database access, typical web app 
| stuff).

That's good.  You know how to think in concrete abstract terms.  (if
that makes any sense)  You think concrete enough to explicitly list
all the steps needed to be done, but abstractly enough that your steps
work for more than one particular input.  This is the core of
programming.

| I have always wanted to learn Python, though, for even longer 
| than I've known of PHP, so I am tackling that too.  But often -- REALLY 
| often -- I see a lot of references to things that I know are C-related.  
| It can be anything from "this language is based on C's construct..." to 
| "similar to the C function 'printf' ..." or even simple references like 
| "garbage collection", which I now know that a Python programmer can 
| pretty much get by without ever hearing in their life but it is an issue 
| that is of concern to C programmers.

C is historically very important, and is still very important today.
For one thing, python is implemented in C.  Some of the C libraries
are good enough that redesigning them is not very beneficial.  Thus
the python interface closely matches the C interface.  For older
programmers (not me, btw) their C background helps here.

| Yet, if C is the language that Unix and operating systems and games are 
| written in, then it must truly be a complex thing, right?  Like assembly 
| language, only a little higher?

C is like a portable assembly, but it isn't all that complex.  The
beauty of C and UNIX is their elegance and simplicity.  Performing
regex searches on strings without any nasty memory corruption or leaks
is much harder than in python, but that's not what C is designed for
doing.  C was designed for system-level programming.  Creating kernels
and the like.  It gives you direct unprotected access to system
resources (namely memory).  This is like handing you a .357 magnum
fully loaded.  If you don't know how to handle it (which way points
away from you) then you're liable to shoot yourself.  One you graps
the basics, however, it isn't terrible, it just isn't high-level.

| A few weeks ago I was in a library and saw a book on C programming, so I 
| started reading it.  It was "a C Primer" or something (there's probably 
| fifty of those).  I was pleased to find that it wasn't really that 
| intimidating at all, and in fact the syntax strongly resembled that of 
| PHP.  It was a strange feeling, to understand what was going on in the 
| simple examples of the first few chapters that I read.

Yeah, perl and php borrowed a lot of their syntactic structure from C
(as did Java).  I expect that is largely because C (C++, Java) is
familiar to many programmers.

The main difficulties with C, compared to python or php, are :
    o   no OO support built-in,  an OO style can be used, but it is
        more awkward (though the standard FILE operations are rather
        OO)

    o   memory management,  when do I free this pointer to prevent a
        memory leak, but not create a dangling reference?

    o   string and other high-level operations;  in C a string is a
        "char*".  That is, it's a pointer to the beginning of an array
        of characters.  The last character in the string has the value
        NULL.  If you forget to NULL-terminate a string, you can have
        functions that do nasty things to memory.  Same goes for
        trying to copy a string into an array that is too small.  It's
        the memory management that all the effort goes into.

| I would really like to learn more about it, if only to get a more 
| foundational education in the way programming is done, but when I 
| consider how little time I have for hobbyist programming, I am convinced 
| that I am best off learning something like Python, which will hopefully 
| let me get off the ground more quickly in terms of writing useful 
| scripts and programs.

As Sean said, knowing data structures and algorithms is more useful
than knowing a plethora of languages.  Definitely go get "The Practice
of Programming" by Kernighan and Pike.  It will help you in both areas
at once!  It is a highly recommended book, kind of a classic.  I have
it, but haven't gotten very far with it yet.  The book discusses how
to program; how to develop software.  It doesn't focus on any given
technology or library, but rather the process.  It will teach how to
go about developing software in an effective way.  For their examples,
they use C with some C++ and Java sprinkled in.  You can begin to pick
up C while you learn how to program effectively!  With your
syntactical familiarity with a C-ish languge you should have little
difficulty in picking it up (especially if you have a decent C
reference handy).
 
| One of these days I shall surely have to take a class in
| programming.

Some classes are more helpful than others.  In one of my classes the
prof. spent a lot of time covering the details of C semantics.
Everyone in the class had already learned C++.  It was a waste of
time.  The remainder of the class was spent discussing mathmatical
algorithms like Netwon's Method and matrix mutliplication.  The
homework assignments were to implement the math in C.  They were
extremely easy.

Other classes are very helpful.  For example I learned about hash
tables, AVL trees, and other data structures in some of my early CS
courses.  Also, since I'm a Software Engineering major (not CS), many
of my courses have focused on the process of software development and
things like Design Patterns and Architecture.  These are the classes
that I'm glad I've taken so I don't need to rediscover these concepts
the hard way.  ("Design Patterns" by the GoF is a must for anyone who
intends to do any serious programming)

Are there any programmer-type groups in your area?  Any LUGs or PIGs,
etc?  You will probably get just as much out of personal interaction
with a "guru" as you would from a class.  The realtime responses and
the ability to diagram concepts and react to your expressions of
confusion or enlightenment can be very helpful.

Good luck to you!

-D

-- 

A)bort, R)etry, B)ang it with a large hammer



From dyoo@hkn.eecs.berkeley.edu  Wed Mar 27 03:57:34 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 26 Mar 2002 19:57:34 -0800 (PST)
Subject: [Tutor] tail -f
In-Reply-To: <20020326220919.GA5228@dman.ddts.net>
Message-ID: <Pine.LNX.4.44.0203261941110.394-100000@hkn.eecs.berkeley.edu>


On Tue, 26 Mar 2002, dman wrote:

> source for tail, but nothing unusual jumped out at me and said "this
> is how it does that!".  I tried to simply continue reading from the
> file, but that only chewed up the CPU and didn't yield any output when
> I echoed new data into the file.
>

> Does anyone here know how to follow a file efficiently and correctly?



GNU tail actually does something like busy waiting/polling, at least
according to the comments in it's code.

/***/
* Tail NFILES files forever, or until killed.
   The pertinent information for each file is stored in an entry of F.
   Loop over each of them, doing an fstat to see if they have changed
   size,
   and an occasional open/fstat to see if any dev/ino pair has changed.
   If none of them have changed size in one iteration, sleep for a
   while and try again. */

static void
tail_forever (struct File_spec *f, int nfiles)
{
  int last;
  int writer_is_dead = 0;

  last = nfiles - 1;

  while (1)
    {
    [ some code cut ]


/* If none of the files changed size, sleep.  */
      if (!any_changed)
        {
          if (writer_is_dead)
            break;
          sleep (sleep_interval);
/***/


So basically, they open the file, and just stare at it's size, forever (or
until the user gets tired).  Whenever the file size changes, it just
prints the remainder out to screen.  They do something like a time.sleep()
to make the busy waiting look less bad.  *grin* By default, they poll
every 1 second:

/***/
static unsigned int sleep_interval = 1;
/***/



Good luck to you!



From dyoo@hkn.eecs.berkeley.edu  Wed Mar 27 04:13:38 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 26 Mar 2002 20:13:38 -0800 (PST)
Subject: [Tutor] tail -f
In-Reply-To: <Pine.LNX.4.44.0203261941110.394-100000@hkn.eecs.berkeley.edu>
Message-ID: <Pine.LNX.4.44.0203262010111.394-100000@hkn.eecs.berkeley.edu>

> So basically, they open the file, and just stare at it's size, forever (or
> until the user gets tired).  Whenever the file size changes, it just
> prints the remainder out to screen.  They do something like a time.sleep()
> to make the busy waiting look less bad.  *grin* By default, they poll
> every 1 second:
>
> /***/
> static unsigned int sleep_interval = 1;
> /***/


Here's an example of how we might do it in Python:


###
#!/usr/local/bin/python

"""A demonstration of file following.

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

"""

import os.path, time, sys

DELAY=1

def follow(filename):
    f = open(filename)
    size = 0
    while 1:
        new_size = os.path.getsize(filename)
        if new_size > size:
            f.seek(size)
            sys.stdout.write(f.read())
        elif new_size < size:
            print "=== File truncation ==="
        size = new_size
        time.sleep(DELAY)


if __name__ == '__main__':
    if len(sys.argv) != 2:
        print "We need a file!"
    else:
        follow(sys.argv[1])
###



Hope this helps!



From SWidney@ci.las-vegas.nv.us  Wed Mar 27 04:39:57 2002
From: SWidney@ci.las-vegas.nv.us (Scott Widney)
Date: Tue, 26 Mar 2002 20:39:57 -0800
Subject: [Tutor] Which programming language is better to start with
Message-ID: <D4EB5574F4A7D2119C9E00A0C9EA408D059F5A58@SOVEREIGN>

> For me a programming language is like a writing style.

I would suggest the term "medium". As equations to Mathematicians,
instruments to Musicians, color and shape to Artists, etc., programming
languages are the medium by which we express ourselves. Our ideas are given
form in code. And there are varying degrees of skill and sophistication in
expressing oneself: from clay ashtrays in Kindergarten to Michelangelo.

I was just thinking of list comprehensions. They're everything Strunk and
White could ever have wanted in an iteration.

In terms of language, Python has shown itself to scale very well from baby
talk to adolescent expression to mature speech to
communication-at-a-level-that-I-will-never-understand. Even street talk.
Just like my native tongue. Looking at the other programming languages, I
see one of two shortcomings:

1) you grow out of them -- you leave them behind because they can't follow
you to the next level.

2) prerequisites -- "Before you begin learning this language, there are a
few key concepts you should be familiar with. We'll cover those in chapters
1 through 15...."

Another parallel between Python and verbal(?) languages, is borrowing from
other languages. When they find that there is a more concise or precise or
beautiful way of expressing something in another language, they adopt it as
their own.


"What's not to like?"
Scott


From dyoo@hkn.eecs.berkeley.edu  Wed Mar 27 04:42:38 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Tue, 26 Mar 2002 20:42:38 -0800 (PST)
Subject: [Tutor] Which programming language is better for ... [MMIX
 machine language!]
In-Reply-To: <20020327035921.GA9733@dman.ddts.net>
Message-ID: <Pine.LNX.4.44.0203262024590.394-100000@hkn.eecs.berkeley.edu>

> | Yet, if C is the language that Unix and operating systems and games are
> | written in, then it must truly be a complex thing, right?  Like assembly
> | language, only a little higher?
>
> C is like a portable assembly, but it isn't all that complex.  The
> beauty of C and UNIX is their elegance and simplicity.


[way way way off topic]

By the way, if you're interested in what "assembly language" is like, you
may want to look at Knuth's description of the "MMIX" machine:

    http://www-cs-faculty.stanford.edu/~knuth/mmix.html
    http://www-cs-faculty.stanford.edu/~knuth/fasc1.ps.gz

MMIX is a theoretical machine that models the design of modern "Reduced
Instruction Set Computers" (RISC) machines, and the fascicle above is a
tutorial on programming MMIX.

It's not Python, and it's not "practical", but it really does help us
understand how computers work.  As dman mentions, programming in assembly
makes one really appreciate 'for' loops.  *grin*


****************************
	PRINTER	EQL	18
	OUT	MSG(PRINTER)
	HLT
MSG	CON "Good "
	CON " luck"
	CON "!   "
****************************



From paulsid@shaw.ca  Wed Mar 27 05:49:31 2002
From: paulsid@shaw.ca (Paul Sidorsky)
Date: Tue, 26 Mar 2002 22:49:31 -0700
Subject: [Tutor] Assembly Language (was Re: Which programming language...)
References: <Pine.LNX.4.44.0203262024590.394-100000@hkn.eecs.berkeley.edu>
Message-ID: <3CA15D6B.29086FC@shaw.ca>

Danny Yoo wrote:

> [way way way off topic]

Ditto...

> By the way, if you're interested in what "assembly language" is like, you
> may want to look at Knuth's description of the "MMIX" machine:

I would also suggest examining PDP-11 assembly language.  Googling will
turn up some emulators.  It has a relatively small core instruction set
and the code is quite clean.  Here's a snippet from the start of an
implementation of C's puts() function:

puts:   mov     R0, START
        mov     #OUTBUF, R1
loop:   cmpb    (R0), #0
        beq     print
        movb    (R0)+, (R1)+
        br      loop

PDP-11 is still taught here for the reasons I mentioned above - it's
used as a springboard to learning 80x86 assembler.  If you look at Intel
code and then look at PDP-11 code it's hard not to wonder "what do they
[Intel] need all that extra crap for?!?"  Besides it's cool to learn how
to program a machine that is so prominent in computing history!

> It's not Python, and it's not "practical", but it really does help us
> understand how computers work.  As dman mentions, programming in assembly
> makes one really appreciate 'for' loops.  *grin*

Not to mention data types, variables, functions, etc.  :-)

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/


From erikprice@mac.com  Wed Mar 27 12:58:49 2002
From: erikprice@mac.com (Erik Price)
Date: Wed, 27 Mar 2002 07:58:49 -0500
Subject: [Tutor] lists vs dicts
Message-ID: <62065361-4182-11D6-AA23-00039351FE6A@mac.com>

I have a quick question --

I understand lists (and tuples) to be what I call numerically-indexed 
arrays.  And dictionaries to be associatively-indexed arrays.  Is there 
ever a compelling reason to use one over the other?  In other words, if 
I am referring to a finite array of say, six elements, and it helps me 
to assign English indexes to these elements rather than 0 thru 5, it's 
okay to use a dictionary, right?  (Even if I don't plan to -do- anything 
with these English index names.)  I see lists being useful for things 
like arrays where you may not know the number of elements that may be 
generated, etc.  But there's no reason to choose a list over a 
dictionary if I have no interest in the number order of the array, right?

A rhetorical question to help me decide which type to use when -- I'm 
used to being able to access an array by its numeric index OR its 
associative index.

Thanks,

Erik



From rob@jam.rr.com  Wed Mar 27 13:30:04 2002
From: rob@jam.rr.com (Rob Andrews)
Date: Wed, 27 Mar 2002 07:30:04 -0600
Subject: [Tutor] Which programming language is better to start with
References: <XFMail.20020326144631.shalehperry@attbi.com>
Message-ID: <3CA1C95C.9060600@jam.rr.com>

Any language you can make any amount of progress with is a good place to 
begin. Python is a truly great language to grapple with for beginners in 
a number of ways. The syntax is relatively natural, the language is 
closer to humanspeak than computerspeak, and you can see instant results 
in an interpreter window to find out if your idea works.

Last time I checked, Perl 6 is slated to include python syntax. If they 
do a clean job of this, I believe both communities will benefit. And 
Jython is a pure-Java Python, which makes Rob very happy. And, as others 
have pointed out, you can code your program with parts done in different 
languages, allowing you to take advantage of strengths (and modules 
already written by others) of each language.

Once in a great while I mention Lego MindStorms robotics kits. Now that 
the new 2.0 kits are available, the old 1.5 kits are available quite 
cheaply in some stores. This is great, because the hardware is identical 
between the two versions. Only the firmware is different, and this is 
downloaded without charge from Lego.

Aside from the fact that MindStorms bots can be programmed in a wide 
variety of languages (including Python), they come with their own 
proprietary language (Windows only) that a 12-year-old could use 
(literally). This language consists of "lego bricks" of programming code 
that you drag and drop together to control different robotic functions.

These are good days to be learning programming.

Rob

Sean 'Shaleh' Perry wrote:

<snip />
> In my experience people who start on the high level languages and then try to
> go low level often find it hard to fit in.  They are too used to the language
> doing everything for them.  Of course the opposite is sometimes true and we
> find C coders trying to implement hashes themselves or who never check if a
> python module exists before reinventing the wheel.
> 

<snip />



From moodykre8r@earthlink.net  Wed Mar 27 15:21:39 2002
From: moodykre8r@earthlink.net (binary_star)
Date: Wed, 27 Mar 2002 07:21:39 -0800
Subject: [Tutor] Need *Python Help* help
In-Reply-To: <20020327014054.GB8042@dman.ddts.net>
Message-ID: <LPBBLEMICOGCGHANJMACGENLDBAA.moodykre8r@earthlink.net>

Thank you. This satisfied my need for *help* files. Unfortunately, I still
am at a loss as regards setting Python's /environment variable/ to reflect
the location of said *help* files. There was some documentation about it in
the *help* files themselves (naturally enough), but even what was there did
not actually tell me how to find it or access it (at least, not so I was
able to tell; I realize that it is very likely an incredibly easy thing to
find if one has knowledge of such things).

Anyway, at least now I have access to Python's *help* files when I need it.


Sincerely,
James Pomeroy


> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> dman
> Sent: Tuesday, March 26, 2002 5:41 PM
> To: Python Tutor
> Subject: Re: [Tutor] Need *Python Help* help
>
> I can't help with getting IDLE's menu to be useful, but you can obtain
> the docs from
>
>     http://python.org/ftp/python/doc/2.2/html-2.2.zip



From dman@dman.ddts.net  Wed Mar 27 15:50:44 2002
From: dman@dman.ddts.net (dman)
Date: Wed, 27 Mar 2002 09:50:44 -0600
Subject: [Tutor] Need *Python Help* help
In-Reply-To: <LPBBLEMICOGCGHANJMACGENLDBAA.moodykre8r@earthlink.net>
References: <20020327014054.GB8042@dman.ddts.net> <LPBBLEMICOGCGHANJMACGENLDBAA.moodykre8r@earthlink.net>
Message-ID: <20020327155044.GA13396@dman.ddts.net>

On Wed, Mar 27, 2002 at 07:21:39AM -0800, binary_star wrote:
| Thank you. This satisfied my need for *help* files. Unfortunately, I still
| am at a loss as regards setting Python's /environment variable/ to reflect

*Python* doesn't do anything with help files.  *IDLE* (or Pythonwin or
whatever IDE you choose) might.

| the location of said *help* files. There was some documentation about it in
| the *help* files themselves (naturally enough), but even what was there did
| not actually tell me how to find it or access it (at least, not so I was
| able to tell; I realize that it is very likely an incredibly easy thing to
| find if one has knowledge of such things).

Setting environment variables is an OS thing, not a python thing.  Are
you using Win9x/ME?  If so (actually, I'm not sure about ME) then put
    set NAME value
in c:\autoexec.bat and reboot.  For example

    set PYTHONDOCS c:\the\directory\i\downloaded\the\docs\to

| Anyway, at least now I have access to Python's *help* files when I
| need it.

Yeah, I just use my web browser to view them.  (I failed to mention,
too, that I don't use windows and I use 'gvim' as my editor.  The
"help" menu there talks about gvim, not python or C or java :-))

-D

-- 

Python is executable pseudocode. Perl is executable line noise.



From shalehperry@attbi.com  Wed Mar 27 15:49:50 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Wed, 27 Mar 2002 07:49:50 -0800 (PST)
Subject: [Tutor] lists vs dicts
In-Reply-To: <62065361-4182-11D6-AA23-00039351FE6A@mac.com>
Message-ID: <XFMail.20020327074950.shalehperry@attbi.com>

> 
> A rhetorical question to help me decide which type to use when -- I'm 
> used to being able to access an array by its numeric index OR its 
> associative index.
> 

use a list when it is just that, a list.  The name dictionary should give a
clue to its preferred usage.  YOu have one word and you want to use it as an
index for some data.

A shopping list is a list.  You just walk it and deal with the items.  An
addressbook is likely a dictionary.  You have 'Tom Thumb' and you want to know
his phone number.

Basically use whatever data structure makes the code easiest.  In python you
generally do not use the integer list indexes in a loop.


From dman@dman.ddts.net  Wed Mar 27 16:06:08 2002
From: dman@dman.ddts.net (dman)
Date: Wed, 27 Mar 2002 10:06:08 -0600
Subject: [Tutor] lists vs dicts
In-Reply-To: <62065361-4182-11D6-AA23-00039351FE6A@mac.com>
References: <62065361-4182-11D6-AA23-00039351FE6A@mac.com>
Message-ID: <20020327160608.GB13396@dman.ddts.net>

On Wed, Mar 27, 2002 at 07:58:49AM -0500, Erik Price wrote:
| I have a quick question --
| 
| I understand lists (and tuples) to be what I call numerically-indexed 
| arrays.  And dictionaries to be associatively-indexed arrays. 

That is a good description of the interfaces to them.

| Is there ever a compelling reason to use one over the other?

Yes!

If you need ordered data, use a list.
If you need duplicate entries use a list.
If you don't care much about the data but have no "key", use a list.
If you need the above, but don't need to ever modify your collection a
    tuple will work just as well.

If you need a key->value mapping, use a dict.
If you need fast searching on the key, use a dict.  (sometimes, for
    this reason alone, I use a dict with the key being the data I want
    to store and the value being meaningless (usually None))

The structures are radically different internally, as my hash table
description last night explains.  (however it doesn't seem to have
make it to the list)

| In other words, if I am referring to a finite array of say, six
| elements, and it helps me to assign English indexes to these
| elements rather than 0 thru 5, it's okay to use a dictionary, right?
| (Even if I don't plan to -do- anything with these English index
| names.) 

You can do that if you like.  It all depends on whether or not that
model fits your data and how you want to use it.  Iterating over a
dictionary isn't always quite as natural as iterating over a list, and
the order isn't guaranteed (unless you sort the keys yourself or
something).

| I see lists being useful for things like arrays where you may not
| know the number of elements that may be generated, etc.  But there's
| no reason to choose a list over a dictionary if I have no interest
| in the number order of the array, right?

Yes.  Also, there's no reason to choose a dict over a list if you
don't have key-value pairs.

| A rhetorical question to help me decide which type to use when -- I'm 
| used to being able to access an array by its numeric index OR its 
| associative index.

Yeah, PHP is kinda odd like that.  I looked through some PHP tutorials
recently because quite a bit of the web stuff here is PHP.  They (PHP)
uses the term "array" rather loosely.  Python doesn't have "arrays",
per se, but lists are like the php concept of array.  When I think of
array I think of the C/C++/Java meaning.  There it is a contiguous
chunck of memory containing uniform data types.  It is only accessible
via indexing and can't grow.  If you need to make the array bigger you
need to allocate a new chunk of memory and copy all the existing data
to it, then free the old array.  I think this is why python calls
lists "lists".  Lists have the connotation that they can grow, and
also may not be contiguous (ie a linked list where a node has a
reference to the next node and so on).  A linked list is easy (and
efficient) to extend or insert into the middle of.  However it is
slower to iterate over it.

This is where knowing the low-level aspects of how a computer and the
various data structures work is really useful in desigining your
programs.

FYI, python lists are implemented as C arrays.  I did look at the
source for that once during a discussion on python-list.

If this brings up more questions, fire away :-).

-D

-- 

It took the computational power of three Commodore 64s to fly to the moon.
It takes at least a 486 to run Windows 95.
Something is wrong here.



From dman@dman.ddts.net  Wed Mar 27 16:09:54 2002
From: dman@dman.ddts.net (dman)
Date: Wed, 27 Mar 2002 10:09:54 -0600
Subject: [Tutor] tail -f
In-Reply-To: <Pine.LNX.4.44.0203262010111.394-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.44.0203261941110.394-100000@hkn.eecs.berkeley.edu> <Pine.LNX.4.44.0203262010111.394-100000@hkn.eecs.berkeley.edu>
Message-ID: <20020327160954.GC13396@dman.ddts.net>

On Tue, Mar 26, 2002 at 08:13:38PM -0800, Danny Yoo wrote:
| > So basically, they open the file, and just stare at it's size, forever (or
| > until the user gets tired).  Whenever the file size changes, it just
| > prints the remainder out to screen.  They do something like a time.sleep()
| > to make the busy waiting look less bad.  *grin* By default, they poll
| > every 1 second:
| >
| > /***/
| > static unsigned int sleep_interval = 1;
| > /***/
| 
| Here's an example of how we might do it in Python:
...

Thanks Danny!  I guess I did my searching the wrong way.  I started
with the argument parsing to see what flags would be different when
'-f' is passsed, and then seeing where those flags are used.  I also
assumed it wasn't busy-waiting since it puts almost no load on the
system.  I think the size thing is important since asking for the size
of an open file is likely faster than trying to read from it and
hitting EOF.  Hmm, it's also probably important to _not_ hit EOF when
reading the stream so that when the size increases the fread() won't
fail.

Seeing the essence of the algorithm without all the other "noise"
around it makes it much clearer.

-D

-- 

Only two things are infinite, the universe and human stupidity, and I'm
not sure about the former.
        Albert Einstein



From moodykre8r@earthlink.net  Wed Mar 27 16:21:03 2002
From: moodykre8r@earthlink.net (binary_star)
Date: Wed, 27 Mar 2002 08:21:03 -0800
Subject: [Tutor] Need *Python Help* help
In-Reply-To: <20020327155044.GA13396@dman.ddts.net>
Message-ID: <LPBBLEMICOGCGHANJMACIENMDBAA.moodykre8r@earthlink.net>

Yeah, I actually use IDLE on Mac OS X. OS X/Unix is still a somewhat
unfamiliar beast to me, so I can only go by whatever the messages I receive
(in this case from IDLE itself) say. I think that part of the issue I am
dealing with here is my having installed Python via fink, because fink
installs things in its own directory (usually a perfectly okay state of
affairs; fink is really a godsend). However, in this case IDLE does not know
where to look for the docs.

But, no biggie. I am using the browser to get to the files, now. I guess I
just want to know how to set the /environment variable/ because I don't know
how, and I don't like not knowing how to do something. Especially when it
appears to be something simple (like setting up tcsh.rc was).

Thanks again for your help. (-:


Sincerely,
James Pomeroy


> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> dman
> Sent: Wednesday, March 27, 2002 7:51 AM
> To: Python Tutor
> Subject: Re: [Tutor] Need *Python Help* help
>
>
> *Python* doesn't do anything with help files.  *IDLE* (or Pythonwin or
> whatever IDE you choose) might.
>
>
> Setting environment variables is an OS thing, not a python thing.  Are
> you using Win9x/ME?
>
>
> Yeah, I just use my web browser to view them.  (I failed to mention,
> too, that I don't use windows and I use 'gvim' as my editor.  The
> "help" menu there talks about gvim, not python or C or java :-))
>
> -D



From babu@bessy.de  Wed Mar 27 16:37:08 2002
From: babu@bessy.de (Dr. Babu A. Manjasetty)
Date: Wed, 27 Mar 2002 17:37:08 +0100 (CET)
Subject: [Tutor] HTML module
Message-ID: <Pine.LNX.4.33.0203271726300.23794-100000@t6.psf.bessy.de>

Hi there,

How to make HTML interface forms using python to interact with MySQL
database? Is there any html template module is available? So that I can
modify it for my purpose.

Thanks in advance,

Bye,

Babu

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

Dr. Babu A. Manjasetty
Protein Structure Factory
C/o Bessy GmbH
Albert-Einstein-Str.15
12489 Berlin Germany
Phone	: +49 (0)30 6392 4920
Fax	: +49 (0)30 6392 4975
e-mail	: babu@bessy.de

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



From shendric@arches.uga.edu  Wed Mar 27 16:06:49 2002
From: shendric@arches.uga.edu (shendric@arches.uga.edu)
Date: Wed, 27 Mar 2002 11:06:49 -0500
Subject: [Tutor] Application Error
Message-ID: <1017245209.smmsdV1.1.1@mail.arches.uga.edu>

Hi all,

I've been working on an application in Python and Tkinter and, for some 
reason, when I close the program, I get an Application Error that looks 
like the following:

The instruction at "0x62af8d54" referenced memory at "0x7ffddfff".  The 
memory could not be "read".

Click on OK to terminate the program

Any ideas as to what might cause such a thing?  The program uses Python 
2.2, and it isn't very complex.  It just has a Pmw Menubar, a 
QuickTimeTcl widget, and a Pmw ScrolledText widget.  It doesn't even 
have any commands yet.

The program seems to work fine, but this is kind of an annoyance, that 
I'm afraid could turn into something more.

I know most of you are working with Python, not Tkinter, but since 
Tkinter came up recently, I thought someone might have an idea.

Thanks,
Sean




From alex@gabuzomeu.net  Wed Mar 27 17:41:43 2002
From: alex@gabuzomeu.net (Alexandre Ratti)
Date: Wed, 27 Mar 2002 18:41:43 +0100
Subject: [Tutor] Extracting words(quest 2)
In-Reply-To: <E16qFde-00022O-00@mail.python.org>
Message-ID: <4.3.2.7.2.20020327175628.00d777c0@pop3.norton.antivirus>

Danny, dman, Remco,


Thanks for your tutorials on Python dictionaries and hashing. (dman, your 
tuturial did make it to the list; I found it in this morning's digest).

At 21:52 26/03/2002 -0500, dman wrote:
>Hope this isn't too confusing :-).

No; I followed your explanations; they were very clear.


Cheers.

Alexandre




From urnerk@qwest.net  Wed Mar 27 18:05:48 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Wed, 27 Mar 2002 10:05:48 -0800
Subject: [Tutor] Application Error
In-Reply-To: <1017245209.smmsdV1.1.1@mail.arches.uga.edu>
Message-ID: <4.2.0.58.20020327100315.019c6bd0@pop3.norton.antivirus>

>
>I know most of you are working with Python, not Tkinter, but since
>Tkinter came up recently, I thought someone might have an idea.

Note:  Tkinter is part of Python -- is the Python module
used to wrap Tk functionality.  So saying "Python, not
Tkinter" is a bit confusing.

You'll probably need to post your code if you want serious
help debugging.

Kirby



From cheshire_cat_sf@yahoo.com  Wed Mar 27 19:07:19 2002
From: cheshire_cat_sf@yahoo.com (Britt Green)
Date: Wed, 27 Mar 2002 11:07:19 -0800 (PST)
Subject: [Tutor] Mailling list like this for C/C++/Java
In-Reply-To: <E16qFdg-00022W-00@mail.python.org>
Message-ID: <20020327190719.24201.qmail@web14106.mail.yahoo.com>

I was wondering if anyone knew of a list similar to this for C, but
also for C++ or Java.

=====
"The ocean, she is strange and wondrous, filled with animals that disturb even a Frenchman."

__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
http://movies.yahoo.com/


From vcardon@siue.edu  Wed Mar 27 20:59:50 2002
From: vcardon@siue.edu (Victor R. Cardona)
Date: Wed, 27 Mar 2002 14:59:50 -0600
Subject: [Tutor] Mailling list like this for C/C++/Java
In-Reply-To: <20020327190719.24201.qmail@web14106.mail.yahoo.com>; from cheshire_cat_sf@yahoo.com on Wed, Mar 27, 2002 at 11:07:19AM -0800
References: <E16qFdg-00022W-00@mail.python.org> <20020327190719.24201.qmail@web14106.mail.yahoo.com>
Message-ID: <20020327145950.A3254@client156-52.ll.siue.edu>

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

On Wed, Mar 27, 2002 at 11:07:19AM -0800, Britt Green wrote:
> I was wondering if anyone knew of a list similar to this for C, but
> also for C++ or Java.

I don't know of any mailing lists, but there is a newsgroup for learning
C and C++. It is alt.comp.lang.learn.c-c++ .=20

-v
--=20
Victor R. Cardona
Powered by SuSE Linux 7.1 (i386) Professional
GPG key ID E81B3A1C
Key fingerprint =3D 0147 A234 99C3 F4C5 BC64  F501 654F DB49 E81B 3A1C

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

iD8DBQE8ojLFZU/bSegbOhwRAr4sAJ9gPFgCUMxHcXx1UUPysz4QFDb5TACZAZOK
7j/b3+2QT5+QHKI7QY93JdI=
=f5na
-----END PGP SIGNATURE-----

--bp/iNruPH9dso1Pn--


From shendric@arches.uga.edu  Wed Mar 27 20:55:02 2002
From: shendric@arches.uga.edu (shendric@arches.uga.edu)
Date: Wed, 27 Mar 2002 15:55:02 -0500
Subject: [Tutor] Application Error
Message-ID: <1017262502.smmsdV1.1.1@mail.arches.uga.edu>

Hi all,

I apologize if you get this twice, my email went a little haywire, so 
I'm resending.

I also apologize for the faux pas about Tkinter.  I suppose what I meant 
was that most of what I've seen on this list doesn't involve GUI 
programming.

Anyway, as suggested, I'm posting the code for this.  Any suggestions 
would be appreciated:

"""
QTMod.py

Sean Hendricks, based on Kazuaki Maeda
Requires QuickTimeTcl (http://hem.fyristorg.com/matben/qt/)
It also calls for a movie file, which I didn't include, so you might 
want to comment out the lines referring to the function loadmov, if you 
decide to run the program.
"""

from Tkinter import *
try:
    import Pmw
except ImportError:
    print "No Pmw available"
    Pmw = None

class QuickTime(Widget):
    """ Class definition for QuickTimeTcl widget """
    
    def __init__(self, master=None):
        master.tk.eval('package require QuickTimeTcl')	
	Widget.__init__(self, master, 'movie')
    def play(self):
	self.tk.call(self._w, 'play')
    def stop(self):
	self.tk.call(self._w, 'stop')
    def gettime(self):
        return self.tk.call(self._w, 'gettime')
    def loadmov(self):
	  return self.tk.call(self._w, 'configure', '-file', 
'HazenIrreg21PDTest.mov')
    # end of class definition for QuickTime

if __name__ == "__main__":
	root = Tk()
	root.tk.eval('package require QuickTimeTcl')
	a = QuickTime(root)
	a.pack()
	a.loadmov()
	root.mainloop()

Thanks,
Sean

>>
>>I know most of you are working with Python, not Tkinter, but since
>>Tkinter came up recently, I thought someone might have an idea.
>
>Note:  Tkinter is part of Python -- is the Python module
>used to wrap Tk functionality.  So saying "Python, not
>Tkinter" is a bit confusing.
>
>You'll probably need to post your code if you want serious
>help debugging.
>
>Kirby
>
>
---------End of Included Message----------




From urnerk@qwest.net  Wed Mar 27 22:17:07 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Wed, 27 Mar 2002 14:17:07 -0800
Subject: [Tutor] Application Error
In-Reply-To: <1017262502.smmsdV1.1.1@mail.arches.uga.edu>
Message-ID: <4.2.0.58.20020327141230.00d15b80@pop3.norton.antivirus>

>
> >>
> >>I know most of you are working with Python, not Tkinter, but since
> >>Tkinter came up recently, I thought someone might have an idea.
> >

I was able to load and run a movie in Windows, by giving
your program a .pyw extension and clicking on it directly
in the file manager.  It seemed to terminate normally,
however I don't think it did, as other apps later had
problems and the shutdown routine informed me of various
tasks not ended, including one about Quicktime.  Also, if
I launch in a DOS box, when I close the movie window
after play, I don't be my prompt back -- more evidence of
an irregular termination.

That's not much help, I realize -- just confirmation that
there appears to be a problem.  I haven't studied this
Quicktime-in-Tk module enough to see if there's something
messed up in the Python code.  Could well be lower level
than that.

Cool package though.  Thanks for bringing it to my
attention.

In the meantime, perhaps someone else will be of more help.

Kirby



From urnerk@qwest.net  Wed Mar 27 22:38:57 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Wed, 27 Mar 2002 14:38:57 -0800
Subject: [Tutor] Application Error
In-Reply-To: <1017262502.smmsdV1.1.1@mail.arches.uga.edu>
Message-ID: <4.2.0.58.20020327143623.00d0ec70@pop3.norton.antivirus>

>
>class QuickTime(Widget):
>     """ Class definition for QuickTimeTcl widget """
>
>     def __init__(self, master=None):
>         master.tk.eval('package require QuickTimeTcl')
>         Widget.__init__(self, master, 'movie')

<<SKIP>>

>if __name__ == "__main__":
>         root = Tk()
>         root.tk.eval('package require QuickTimeTcl')  # ???

One thing I'll add is that this first invocation
of a tcl command would appear redundant, given you
have the same invocation as a part of your class
constructor (above).  Indeed, when I comment out
the line marked with a ???, the code still runs with
no detectable difference -- right down to the failure
to terminate properly. :-(

Kirby



From canadense@telus.net  Thu Mar 28 01:00:14 2002
From: canadense@telus.net (J or M Montgomery)
Date: Wed, 27 Mar 2002 17:00:14 -0800
Subject: [Tutor] RE: assembler language
Message-ID: <3CA26B1E.5000103@telus.net>

Paul Sidorsky wrote:

  > I would also suggest examining PDP-11 assembly language.


This stirs up old, old memories.
I began programming on an IBM 360 using Fortran and PL1. Then we got a
PDP 8e (8kb memory - iron core type - and a tape drive and teletype. To
get much done on those machines you pretty well had to learn assembler
so I learned PAL3 assembler.  Never had so much fun although those paper
tapes from the tty were a pain.

Now I guess you have a good idea of my age [:-)]

Cheers

John Montgomery




From stan@coolquiz.com  Wed Mar 27 09:46:10 2002
From: stan@coolquiz.com (STAN)
Date: Wed, 27 Mar 2002 01:46:10 -0800 (PST)
Subject: [Tutor] Threading in Python
Message-ID: <20020327094610.AA92336FA@sitemail.everyone.net>

Hi Tim,

Hi,

I tried it and its working. Thanks a lot.But there seems to be a problem. After the thread's target prints a few lines, the interpreter seems to hang (I have been using the IDLE Python GUI on Windows). I experimented with this for a few times and the problem is pretty consistent. I have a feeling that there may be a flaw in my management of the thread's memory, synchronization etc.

Can you please address the problem ? In the feature what I am trying to do, I need to print atleast 8 lines of data - at random intervals over and over. This problem is stopping me from doing this .....

The data is returned to Python as char * from a C++ extension.

Do you have a better solution to this problem .. 

Thanks and Regards
  Shiva

--- Tim Peters <tim.one@comcast.net> wrote:
>[STAN]
>> How is it possible to run a seperate process in the background
>> using Python ?
>
>Sounds like you actually want a thread (!= process), and actually don't mean
>much of anything by "background" <wink>.
>
>> I have a main process that is console based, that gives the user
>> a few options and acts according to their choice.
>>
>> But I want a process to be running in the background, which
>> sleeps for x secs and keeps checking for some data [ Contacts a
>> C++ extension].
>>
>> I tried thread.start_new_thread(...) and also the Thread class
>> but was unsuccessful :
>
>The good news is that this is easy to fix.
>
>> This is what I tried ( a very simple and abstract simulation of
>> what I intend to do)::
>>
>> *****************************************************
>> from threading import *
>> from random import Random
>
>You're missing an "import time" here.
>
>> def printResult():
>> 	r = Random(68)
>> 	while 1:
>> 		time.sleep(0.5)   # Is there a wait method I can
>>                             # use here for more efficiency ?
>
>What do you want it to wait *for*?  Not enough information.  Sleeping is
>very efficient, btw, if the best answer you've got is "wait for half a
>second".
>
>> 		x = r.random()
>> 		if (x > 0.75):
>
>The parentheses aren't needed here, and are rarely seen in Python.
>
>> 			print "The Event has occured"
>>
>> # End of printResult()
>>
>>
>> def startit():
>> 	t = Thread(target = printResult(),args=())
>                                     ^^
>
>The parentheses there are the cause of your problem:  you're *calling*
>printResult here, and since printResult() never returns, neither does the
>call to Thread (your main thread never gets beyond this line).  Delete the
>parentheses and you'll be much happier.
>
>> 	t.start()
>> 	while 1:
>> 		ch = raw_input("Continue ?")
>> 		if (ch not in ('y',)):
>> 			break
>>
>> # End of startit()
>>
>> >>> startit()
>> ...
>> I wanted printResult to be running in the background ..... But it
>> is the only one that is running !!!
>
>That's explained above -- your main thread is waiting for the printResult()
>call to return; you never actually got so far as to create a second thread.
>But you're close:  remove the parens and you'll have two threads.

_____________________________________________________________
Cool Quiz - Websites That Keep You Guessing! http://www.coolquiz.com

_____________________________________________________________
Run a small business? Then you need professional email like you@yourbiz.com from Everyone.net  http://www.everyone.net?tag


From miracle@paradise.net.nz  Wed Mar 27 21:40:55 2002
From: miracle@paradise.net.nz (Matthew Sherborne)
Date: Thu, 28 Mar 2002 09:40:55 +1200
Subject: [Tutor] Re: [Python-Help] Re: How to get a key from  dictionary?
References: <20020326204100.576.qmail@web9302.mail.yahoo.com>
Message-ID: <003b01c1d5d8$13b86b70$08020196@Jonah>

Yes. Good response. Your code is best :)

GBU
Matthew Sherborne



From jimmy_130@lycos.com  Wed Mar 27 23:16:20 2002
From: jimmy_130@lycos.com (James M Lang)
Date: Wed, 27 Mar 2002 18:16:20 -0500
Subject: [Tutor] How do I do square roots and exponents?
Message-ID: <DOGBPMMFCBNDOBAA@mailcity.com>

While toying around in Python, I decided to make a program that calculates the hypotenuse. I ran into a problem when I realized that I had no idea what the command was for square roots and exponents. Does anyone know?


See Dave Matthews Band live or win a signed guitar
http://r.lycos.com/r/bmgfly_mail_dmb/http://win.ipromotions.com/lycos_020201/splash.asp 


From dyoo@hkn.eecs.berkeley.edu  Thu Mar 28 01:26:50 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed, 27 Mar 2002 17:26:50 -0800 (PST)
Subject: [Tutor] How do I do square roots and exponents?
In-Reply-To: <DOGBPMMFCBNDOBAA@mailcity.com>
Message-ID: <Pine.LNX.4.44.0203271721530.17734-100000@hkn.eecs.berkeley.edu>


> While toying around in Python, I decided to make a program that
> calculates the hypotenuse. I ran into a problem when I realized that I
> had no idea what the command was for square roots and exponents. Does
> anyone know?

Hi James,

Python has an exponentiation operator using the double stars "**", so you
can do something like this:

###
>>> 2 ** (0.5)
1.4142135623730951
>>> 2 ** 8
256
###


If you'd rather like to use functions to do this, you may also find the
functions in the 'math' module very useful:

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

###
>>> math.sqrt(2)
1.4142135623730951
>>> math.pow(2, 8)
256.0
###

(Notice that math.pow is defined to return a floating point value.)



Finally, if you know about complex numbers, then you'll definitely want to
look at the cmath module:

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

since it properly supports things like taking the square root of negative
numbers:

###
>>> (-1) ** (0.5)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: negative number cannot be raised to a fractional power
>>> import cmath
>>> cmath.sqrt(-1)
1j
###



Good luck!



From urnerk@qwest.net  Thu Mar 28 01:40:47 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Wed, 27 Mar 2002 17:40:47 -0800
Subject: [Tutor] How do I do square roots and exponents?
In-Reply-To: <DOGBPMMFCBNDOBAA@mailcity.com>
Message-ID: <4.2.0.58.20020327173520.019bdee0@pop3.norton.antivirus>

At 06:16 PM 3/27/2002 -0500, you wrote:
>While toying around in Python, I decided to make a program
>that calculates the hypotenuse. I ran into a problem when
>I realized that I had no idea what the command was for
>square roots and exponents. Does anyone know?

Actually, there's a built in function for this, in the
math library:

  >>> import math
  >>> math.hypot(3,4)
  5.0
  >>> math.hypot(5,6)
  7.810249675906654

Here's a challenge:  write a function that takes the
square root of the sum of the squares of a *list* of
numbers (a list of arbitrary length) e.g.

  >>> f([3,4,5])
  7.0710678118654755
  >>> math.sqrt(3**2 + 4**2 + 5**2)
  7.0710678118654755

The hypotenuse would fall out as a special case when
you have a list of only two numbers.  Otherwise, you
can think of this as a measure of the distance of
(a,b,c...) from (0,0,0...) in n-dimensional Euclidean
space (or something).

Kirby



From dyoo@hkn.eecs.berkeley.edu  Thu Mar 28 01:46:54 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Wed, 27 Mar 2002 17:46:54 -0800 (PST)
Subject: [Tutor] HTML module
In-Reply-To: <Pine.LNX.4.33.0203271726300.23794-100000@t6.psf.bessy.de>
Message-ID: <Pine.LNX.4.44.0203271742410.18477-100000@hkn.eecs.berkeley.edu>

On Wed, 27 Mar 2002, Dr. Babu A. Manjasetty wrote:

> How to make HTML interface forms using python to interact with MySQL
> database? Is there any html template module is available? So that I can
> modify it for my purpose.

Hello,

Yes, you may want to look at:

    http://www.python.org/topics/web/HTML.html

for a list of resources to generate HTML with Python.  I've heard that
HTMLgen is pretty nice for this purpose.  Does anyone have experience with
other templating engines for Python?


Best of wishes to you!



From python@rcn.com  Thu Mar 28 04:08:04 2002
From: python@rcn.com (Raymond Hettinger)
Date: Wed, 27 Mar 2002 23:08:04 -0500
Subject: [Tutor] Threading in Python
References: <20020327094610.AA92336FA@sitemail.everyone.net>
Message-ID: <005801c1d60e$297675c0$f4e97ad1@othello>

Hello Shiva,

Whenever Python hangs and a C++ extension is being used, it is good idea to
make a quick test to see whether the Python code or the C++ code is the
culprit.  Replace the call to the extension with some regular Python code,
say time.ctime( time.time() ) for example.  If the new code crashes, then
you've got a threading problem.  If not, then the C++ code may be flawed
(reference counting errors, bad pointer assignments, etc).

Once you've done that, post your code so we can take a look at it.


Raymond Hettinger



----- Original Message -----
From: "STAN" <stan@coolquiz.com>
To: <tutor@python.org>
Sent: Wednesday, March 27, 2002 4:46 AM
Subject: RE: [Tutor] Threading in Python


> Hi Tim,
>
> Hi,
>
> I tried it and its working. Thanks a lot.But there seems to be a problem.
After the thread's target prints a few lines, the interpreter seems to hang
(I have been using the IDLE Python GUI on Windows). I experimented with this
for a few times and the problem is pretty consistent. I have a feeling that
there may be a flaw in my management of the thread's memory, synchronization
etc.
>
> Can you please address the problem ? In the feature what I am trying to
do, I need to print atleast 8 lines of data - at random intervals over and
over. This problem is stopping me from doing this .....
>
> The data is returned to Python as char * from a C++ extension.
>
> Do you have a better solution to this problem ..
>
> Thanks and Regards
>   Shiva
>
> --- Tim Peters <tim.one@comcast.net> wrote:
> >[STAN]
> >> How is it possible to run a seperate process in the background
> >> using Python ?
> >
> >Sounds like you actually want a thread (!= process), and actually don't
mean
> >much of anything by "background" <wink>.
> >
> >> I have a main process that is console based, that gives the user
> >> a few options and acts according to their choice.
> >>
> >> But I want a process to be running in the background, which
> >> sleeps for x secs and keeps checking for some data [ Contacts a
> >> C++ extension].
> >>
> >> I tried thread.start_new_thread(...) and also the Thread class
> >> but was unsuccessful :
> >
> >The good news is that this is easy to fix.
> >
> >> This is what I tried ( a very simple and abstract simulation of
> >> what I intend to do)::
> >>
> >> *****************************************************
> >> from threading import *
> >> from random import Random
> >
> >You're missing an "import time" here.
> >
> >> def printResult():
> >> r = Random(68)
> >> while 1:
> >> time.sleep(0.5)   # Is there a wait method I can
> >>                             # use here for more efficiency ?
> >
> >What do you want it to wait *for*?  Not enough information.  Sleeping is
> >very efficient, btw, if the best answer you've got is "wait for half a
> >second".
> >
> >> x = r.random()
> >> if (x > 0.75):
> >
> >The parentheses aren't needed here, and are rarely seen in Python.
> >
> >> print "The Event has occured"
> >>
> >> # End of printResult()
> >>
> >>
> >> def startit():
> >> t = Thread(target = printResult(),args=())
> >                                     ^^
> >
> >The parentheses there are the cause of your problem:  you're *calling*
> >printResult here, and since printResult() never returns, neither does the
> >call to Thread (your main thread never gets beyond this line).  Delete
the
> >parentheses and you'll be much happier.
> >
> >> t.start()
> >> while 1:
> >> ch = raw_input("Continue ?")
> >> if (ch not in ('y',)):
> >> break
> >>
> >> # End of startit()
> >>
> >> >>> startit()
> >> ...
> >> I wanted printResult to be running in the background ..... But it
> >> is the only one that is running !!!
> >
> >That's explained above -- your main thread is waiting for the
printResult()
> >call to return; you never actually got so far as to create a second
thread.
> >But you're close:  remove the parens and you'll have two threads.
>
> _____________________________________________________________
> Cool Quiz - Websites That Keep You Guessing! http://www.coolquiz.com
>
> _____________________________________________________________
> Run a small business? Then you need professional email like
you@yourbiz.com from Everyone.net  http://www.everyone.net?tag
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



From kojo@hal-pc.org  Thu Mar 28 06:02:20 2002
From: kojo@hal-pc.org (Kojo Idrissa)
Date: Thu, 28 Mar 2002 00:02:20 -0600
Subject: [Tutor] Which programming language is better to start with
In-Reply-To: <20020327035921.GA9733@dman.ddts.net>
References: <69752892-412D-11D6-A371-00039351FE6A@mac.com>
 <XFMail.20020326144631.shalehperry@attbi.com>
 <69752892-412D-11D6-A371-00039351FE6A@mac.com>
Message-ID: <5.1.0.14.0.20020327234809.020ecfa8@Pop3.norton.antivirus>

First,
At 06:54 PM 3/26/2002 -0800, Sean 'Shaleh' Perry wrote:
>My other suggestion is to find books on the act of programming, not the
>language.  Learn about fundamental algorithms.  Why is one sort better than
>another?  Is this function wortyh optimizing?  What is this "big O notation" I
>keep hearing about?  What does "takes logarithmic time" mean to me?  This is
>the only thing I kept from college classes.  The art of programming I learned
>there, the choice of a hammer or a screw driver I learned in life.

Then...

At 09:59 PM 3/26/2002 -0600, dman wrote:
>As Sean said, knowing data structures and algorithms is more useful
>than knowing a plethora of languages.  Definitely go get "The Practice
>of Programming" by Kernighan and Pike.  It will help you in both areas
>at once!  It is a highly recommended book, kind of a classic.  I have
>it, but haven't gotten very far with it yet.  The book discusses how
>to program; how to develop software.  It doesn't focus on any given
>technology or library, but rather the process.

So, I thought I'd add my $.0002 to this line of thought, late though I may be.

I told a friend who's trying to learn Python (Hi Peter!) something similar 
(although without as much erudition as the previous responses).  He's new 
to programming altogether, so I suggested he read "Simple Program Design"
<http://www.amazon.com/exec/obidos/ASIN/061901590X/qid=1017207840/sr=1-1/ref=sr_1_1/002-2743688-6192040>
A good, small (288 pages) book on how to think about creating programs for 
a non-programmer.  Almost all PseudoCode.  Later chapters deal with making 
your code modular, OO, Flowcharts, but it starts out very simply.  How do 
you THINK about how to make a program?  Great for someone new to 
programming.  I started with Basic at 12, (but haven't been consistent 
since then) so I've spent enough time thinking about how to program that 
learning a new language is a matter of learning the syntax.  I'm not 
expert...not even too talented of a novice...but I know how to learn a 
programming lanuage and what I can do with it.

I'd recommend this book to all the people who are worried about their lack 
of "formal" training, and/or to the people who've never programmed 
before.  No matter what languge you start with (of course, I'd say 
Python...), I think this book is a good way to get started, especially if 
you've never programmed before or are worried about no "formal" 
foundation.   YMMV.

Anyone else have any opinions on the book?  Anyone else familiar with it?

****************************
Kojo Idrissa

kojo@hal-pc.org
http://www.hal-pc.org/~kojo/
****************************



From imcmeans@shaw.ca  Thu Mar 28 06:25:00 2002
From: imcmeans@shaw.ca (Ian!)
Date: Wed, 27 Mar 2002 22:25:00 -0800
Subject: [Tutor] How do I do square roots and exponents?
References: <E16qREh-0008CL-00@mail.python.org>
Message-ID: <001701c1d621$4a411a90$da494e18@cr536745a>

Here's my attempt. I was wondering if there was a more elegant way of doing
it?

>>> def f(alist):
 sum = 0
 for elem in alist:
  sum += elem**2
 return sum**0.5

>>> f([3,4])
5.0



From python@rcn.com  Thu Mar 28 06:52:02 2002
From: python@rcn.com (Raymond Hettinger)
Date: Thu, 28 Mar 2002 01:52:02 -0500
Subject: [Tutor] How do I do square roots and exponents?
References: <E16qREh-0008CL-00@mail.python.org> <001701c1d621$4a411a90$da494e18@cr536745a>
Message-ID: <001901c1d625$11537260$cfd8accf@othello>

I like:

def hypot(a,b):
   return( a*a + b*b ) ** 0.5

or for numerical types who hate unnecessay truncation error and overflow:

def hypot(a,b):
   a, b = abs(a), abs(b)
   if a > b:  return a * (1.0+(b/a)**2)**0.5
   elif a == 0.0: return b
   else:  return b * (1.0+(aa/bb)**2)**0.5


Raymond


----- Original Message -----
From: "Ian!" <imcmeans@shaw.ca>
To: <tutor@python.org>
Sent: Thursday, March 28, 2002 1:25 AM
Subject: Re: [Tutor] How do I do square roots and exponents?


> Here's my attempt. I was wondering if there was a more elegant way of
doing
> it?
>
> >>> def f(alist):
>  sum = 0
>  for elem in alist:
>   sum += elem**2
>  return sum**0.5
>
> >>> f([3,4])
> 5.0
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



From jonikas@ldr.lt  Thu Mar 28 08:22:20 2002
From: jonikas@ldr.lt (Jonikas Valdemaras)
Date: Thu, 28 Mar 2002 10:22:20 +0200
Subject: [Tutor] Python for WindosCE
Message-ID: <00f401c1d631$ae412110$12f6c50a@LDR.local>

Hi all,

I've installed Python for WindowsCE on my handheld,
and after entering, for exaple:

s = input()

I receive "ValueError: I/O operation on closed file"
What's wrong? Is it bug or feature? :)

Best regards,
Valdas



From alan.gauld@bt.com  Thu Mar 28 16:31:57 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 28 Mar 2002 16:31:57 -0000
Subject: [Tutor] FYI
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4B6@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C1D676.1434E3A0
Content-type: text/plain; charset="iso-8859-1"

 >  Also does anyone use the commandline version of python that much?   
 
Yes, I use it more than I use IDLE to be honest.
 
>  It has some really neat help stuff built into  
 
Yes that came out in v2.x. 
There was a similar non standard module available for older versions but 
its now built in to python which is nice.
 
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_01C1D676.1434E3A0
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=050533816-28032002><FONT 
face="Courier New" color=#0000ff>&nbsp;&gt; &nbsp;</FONT></SPAN>Also does anyone 
use the commandline version of python that much?&nbsp;&nbsp;<SPAN 
class=050533816-28032002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=050533816-28032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=050533816-28032002>Yes, I use it 
more than I use IDLE to be honest.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=050533816-28032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=050533816-28032002>&gt; 
&nbsp;</SPAN>It has some really neat help stuff built into&nbsp;<SPAN 
class=050533816-28032002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=050533816-28032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=050533816-28032002>Yes that came 
out in v2.x. </SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=050533816-28032002>There was a 
similar non standard module available for older versions but 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=050533816-28032002>its now built 
in to python which is nice.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=050533816-28032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=050533816-28032002><FONT 
face="Courier New" color=#0000ff>
<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>&nbsp;</FONT></SPAN></FONT></FONT></DIV></BODY></HTML>

------_=_NextPart_001_01C1D676.1434E3A0--


From alan.gauld@bt.com  Thu Mar 28 16:37:48 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 28 Mar 2002 16:37:48 -0000
Subject: [Tutor] Python & windows XP professional
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4B7@mbtlipnt02.btlabs.bt.co.uk>

> due to a personal bias against microsoft 

I used to feel like that but I'm gradually coming round.

Win2000 and XP are actually pretty decent OSs. The activation 
stuff is fine if you don't change your PC config very often 
but for me its a pain - I've had to reactivate twice since 
I first installed in October last year.... I'm always messing 
with my hardware! But XP has proved solid and fast and 
memory efficient. I'm seriously considering deleting 
Linux from my main box - I'll still use a modified Smoothwall 
as my DHCP/firewall and local Web server.

> of the way I would say to you that you are the first person I 
> know of to use python on XP. 

I've been using v2.0 since I installed XP and Cygwin v2.1 since
December. No problems.

Alan g.


From alan.gauld@bt.com  Thu Mar 28 16:51:43 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 28 Mar 2002 16:51:43 -0000
Subject: [Tutor] Launching a file programs from a python script?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4B8@mbtlipnt02.btlabs.bt.co.uk>

>  I'm currently having difficulties launching programs from a python
program. 

Since you mention .bat files I assiume your running some Windoze variant?
 
> but having a console for each program is kind of nice  

And since you want a console I guess the command line you want to execute
is:

command.com /c <your command here>

You could do that in Python using os.system()
If you want you could use an exec() call for the last one to save 
opening and closing a window unnecessarily... 

BUT I'd just use a batch file for all of them to be honest and
leave Python out of it, iunlsss you do some other processing too.

Alan g


From alan.gauld@bt.com  Thu Mar 28 17:27:45 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 28 Mar 2002 17:27:45 -0000
Subject: [Tutor] Languages, was Which programming language is better
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4BA@mbtlipnt02.btlabs.bt.co.uk>

> C++ and Delphi at the same time.  I loved Delphi a lot, in 

Oh yes, I forgot Delphi. I still use it as my primary Windoze 
environment when doing GUI intensive things - and am getting 
into Kylix on Linux for the same things.

> think there is a very clear pascal -> python trend.  

I agree, especially the object models.

> I miss 'with' a lot.  

me too ;-)

> tcl's syntax never sat right

I hate the syntax but love the concept of everything being 
a command - even control loops. Its so powerful but the 
downside is the wierd parsing rules...

Alan g.


From alan.gauld@bt.com  Thu Mar 28 17:35:14 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 28 Mar 2002 17:35:14 -0000
Subject: [Tutor] Launching a file programs from a python script?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4BB@mbtlipnt02.btlabs.bt.co.uk>

> As David mentioned in another post, your answer is os.system(), BUT...
> instead of specifying your application, you're going to use 
> START to launch

Thanks for posting that, I had suggested command /c but that doesn't work
as I thought, it just fills the current window. Start is indeed the 
solution and I've never heard of it till now,

Thanks again,

Alan g.


From alan.gauld@bt.com  Thu Mar 28 17:42:53 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 28 Mar 2002 17:42:53 -0000
Subject: [Tutor] Which programming language is better to start with
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4BC@mbtlipnt02.btlabs.bt.co.uk>

> Yet, if C is the language that Unix and operating systems and 
> games are written in, then it must truly be a complex thing, right?  

It can be, but the basics aren't. Its a very small language 
- just 16 keywords in the original version.

> intimidating at all, and in fact the syntax strongly 
> resembled that of PHP.  

Yes many languages use the syntax of C.
Even Python uses some conventions like string formatting 
rules etc - C inytroduces many great ideas into programming 
culture. In its day it was a very brief language too 
- less lines of code to write(compared to assembler which 
was, at the time, the only alternative for the tasks C did)

> I would really like to learn more about it, if only to get a more 
> foundational education in the way programming is done, 

Get the original reference book

The C Programming Language by Kernighan & Ritchie

It is the model text book for teaching a language to other programmers.
The first chapter is a complete language overview with subsequent ones 
focussing on the details. Its also quite short at about 200 pages 
in the 1st edition.

> that I am best off learning something like Python, which will 
> hopefully let me get off the ground more quickly in terms of 
> writing useful scripts and programs.

Exactly so, you become productive more quickly and produce 
more once productive. But when peformance becomes all important 
then is the time to dip into C - and I don't mean C++ because 
in Python C is adequate IMHO since you should only be writing 
a few fundamental functions...

Alan g.


From garber@centralcatholic.org  Thu Mar 28 18:14:02 2002
From: garber@centralcatholic.org (Robert Garber)
Date: Thu, 28 Mar 2002 13:14:02 -0500
Subject: [Tutor] Python & windows XP professional
Message-ID: <200203281314.AA550371908@centralcatholic.org>

oday is the day I take my plunge. i just have to decide if it's going to 2.2 from python.org or the active state version of 2.2. Since I do everything on windows I am leaning towardsActive State since the win32 extension come built in. Any thoughts on htis?

Robert
---------- Original Message ----------------------------------
From: alan.gauld@bt.com
Date: Thu, 28 Mar 2002 16:37:48 -0000

>> due to a personal bias against microsoft 
>
>I used to feel like that but I'm gradually coming round.
>
>Win2000 and XP are actually pretty decent OSs. The activation 
>stuff is fine if you don't change your PC config very often 
>but for me its a pain - I've had to reactivate twice since 
>I first installed in October last year.... I'm always messing 
>with my hardware! But XP has proved solid and fast and 
>memory efficient. I'm seriously considering deleting 
>Linux from my main box - I'll still use a modified Smoothwall 
>as my DHCP/firewall and local Web server.
>
>> of the way I would say to you that you are the first person I 
>> know of to use python on XP. 
>
>I've been using v2.0 since I installed XP and Cygwin v2.1 since
>December. No problems.
>
>Alan g.
>


From urnerk@qwest.net  Thu Mar 28 22:08:00 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 28 Mar 2002 14:08:00 -0800
Subject: [Tutor] Languages, was Which programming language is
 better
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4BA@mbtlipnt02.btlabs
 .bt.co.uk>
Message-ID: <4.2.0.58.20020328140145.0199cf00@pop3.norton.antivirus>

At 05:27 PM 3/28/2002 +0000, alan wrote:

> > I miss 'with' a lot.
>
>me too ;-)

What's this 'with'?

In FoxPro we have the following (maybe similar):

If writing

    this.parent.parent.otherwidget.subwidget1.value = 1
    this.parent.parent.otherwidget.subwidget2.value = 2
    this.parent.parent.otherwidget.subwidget3.value = 3
    ...

(long parts repeat) you can instead do:

with this.parent.parent.otherwidget
     .subwidget1.value = 1
     .subwidget2.value = 2
     .subwidget3.value = 3
     ...
endwith

i.e. I capture a lot of the repetitious "path" type
stuff with the 'with' (note:  parent.parent... refers to
a containment hierarchy i.e. what's inside what in a
GUI, not to a subclass/superclass hierarchy).

But in Python you can do something very similar just by
assigning the unchanging part of the path to a variable
e.g.

o = container.otherobject.containedobject
o.property1.value = 1
o.property2.value = 2
o.property3.value = 3
     ...

Kirby



From shalehperry@attbi.com  Thu Mar 28 22:24:18 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Thu, 28 Mar 2002 14:24:18 -0800 (PST)
Subject: [Tutor] Languages, was Which programming language is better
In-Reply-To: <4.2.0.58.20020328140145.0199cf00@pop3.norton.antivirus>
Message-ID: <XFMail.20020328142418.shalehperry@attbi.com>

> 
> What's this 'with'?
> 
> In FoxPro we have the following (maybe similar):
> 

basically:

with my_really_long_name
  foo = 1
  bar = 2
end

> 
> But in Python you can do something very similar just by
> assigning the unchanging part of the path to a variable
> e.g.
> 
> o = container.otherobject.containedobject
> o.property1.value = 1
> o.property2.value = 2
> o.property3.value = 3
>      ...
> 

I liked it for GUI coding where I got tired of typing things like
'HelpMenuButtonPressEvent'.

it is solely a way to make coding faster and easier -- pure sugar.


From tim@johnsons-web.com  Thu Mar 28 22:56:20 2002
From: tim@johnsons-web.com (Tim Johnson)
Date: Thu, 28 Mar 2002 13:56:20 -0900
Subject: [Tutor] Languages, was Which programming language is  better
In-Reply-To: <4.2.0.58.20020328140145.0199cf00@pop3.norton.antivirus>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4BA@mbtlipnt02.btlabs.bt.co.uk> <4.2.0.58.20020328140145.0199cf00@pop3.norton.antivirus>
Message-ID: <20020328225620.GX1475@johnsons-web.com>

I've programmed in at least 10 languages, from VAX basic to dBase
to C,rebol,python, various flavors of c/c++, VBA, flavors of Assembler,
Linux shell script, perl, pascal, now am starting smalltalk..... 

In my area, we have set up an online High School criteria, teaching
the following in sequence:
rebol, python, perl c/c++. 
We choose rebol as the starting, because it is highly stable and
felt that it was very easy for the non-programmer to get started with.

We have only one textbook in this series and it is Alan's 
Good work Alan!

In the C/C++ course, I started out by teaching Abstract Data
types using Ansi C, before I even introduced the students to
C+++. I will also use case studies with Little SmallTalk.

In my professional life, I've moved from C/C++ to rebol
for the most part, but Python mediates with perl (my
partner's language of choice) better than does rebol.
Even though rebol seems to outstrip python in terms
of performance and can be less verbose codewise, python
code seems to "do what it's supposed to" more so than rebol
due to it's more disciplined format.

I expect to be doing more projects in python in the future.
Besides, I just "love" that little snake.

> >> I miss 'with' a lot.
  With C/C++'s preprocessor you can actually create new 
  control constructs by "obfuscation", that is you can
  define a 'with' control statement by #define'ing 'for'
  and an example. And the purists just hate that!

  rebol's control constructs are really just functions,
  so you can "roll your own" very easily.

  Tim
* Kirby Urner <urnerk@qwest.net> [020328 13:22]:
> At 05:27 PM 3/28/2002 +0000, alan wrote:
> 
> >
> >me too ;-)
> 
> What's this 'with'?
> 
> In FoxPro we have the following (maybe similar):
> 
> If writing
> 
>    this.parent.parent.otherwidget.subwidget1.value = 1
>    this.parent.parent.otherwidget.subwidget2.value = 2
>    this.parent.parent.otherwidget.subwidget3.value = 3
>    ...
> 
> (long parts repeat) you can instead do:
> 
> with this.parent.parent.otherwidget
>     .subwidget1.value = 1
>     .subwidget2.value = 2
>     .subwidget3.value = 3
>     ...
> endwith
> 
> i.e. I capture a lot of the repetitious "path" type
> stuff with the 'with' (note:  parent.parent... refers to
> a containment hierarchy i.e. what's inside what in a
> GUI, not to a subclass/superclass hierarchy).
> 
> But in Python you can do something very similar just by
> assigning the unchanging part of the path to a variable
> e.g.
> 
> o = container.otherobject.containedobject
> o.property1.value = 1
> o.property2.value = 2
> o.property3.value = 3
>     ...
> 
> Kirby
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com
      http://www.johnsons-web.com


From urnerk@qwest.net  Thu Mar 28 22:52:13 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 28 Mar 2002 14:52:13 -0800
Subject: [Tutor] Languages, was Which programming language is better
In-Reply-To: <XFMail.20020328142418.shalehperry@attbi.com>
References: <4.2.0.58.20020328140145.0199cf00@pop3.norton.antivirus>
Message-ID: <4.2.0.58.20020328144932.019c7740@pop3.norton.antivirus>


>basically:
>
>with my_really_long_name
>   foo = 1
>   bar = 2
>end

What would the long way look like?  Are foo and bar
properties of my_really_long_name object?  Then why
not go:

o = my_really_long_name
o.foo = 1
o.bar = 2


>I liked it for GUI coding where I got tired of typing things like
>'HelpMenuButtonPressEvent'.
>
>it is solely a way to make coding faster and easier -- pure sugar.

So you're saying there's no similar keystroke-saving
solution in Python?

Kirby



From shalehperry@attbi.com  Thu Mar 28 22:52:55 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Thu, 28 Mar 2002 14:52:55 -0800 (PST)
Subject: [Tutor] Languages, was Which programming language is better
In-Reply-To: <4.2.0.58.20020328144932.019c7740@pop3.norton.antivirus>
Message-ID: <XFMail.20020328145255.shalehperry@attbi.com>

On 28-Mar-2002 Kirby Urner wrote:
> 
> 
>>basically:
>>
>>with my_really_long_name
>>   foo = 1
>>   bar = 2
>>end
> 
> What would the long way look like?  Are foo and bar
> properties of my_really_long_name object?  Then why
> not go:
> 
> o = my_really_long_name
> o.foo = 1
> o.bar = 2
> 

Sure, I could do that.  But that feels like a hack to me.  Besides, does o.foo
= 1 also set my_realy_long_name.foo to 1?  What if these are attributes which
call functions?
 


From urnerk@qwest.net  Thu Mar 28 23:13:18 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 28 Mar 2002 15:13:18 -0800
Subject: [Tutor] Languages, was Which programming language is better
In-Reply-To: <XFMail.20020328145255.shalehperry@attbi.com>
References: <4.2.0.58.20020328144932.019c7740@pop3.norton.antivirus>
Message-ID: <4.2.0.58.20020328150603.019cc300@pop3.norton.antivirus>

At 02:52 PM 3/28/2002 -0800, Sean 'Shaleh' Perry wrote:

> > What would the long way look like?  Are foo and bar
> > properties of my_really_long_name object?  Then why
> > not go:
> >
> > o = my_really_long_name
> > o.foo = 1
> > o.bar = 2
> >
>
>Sure, I could do that.  But that feels like a hack to me.

Well, it doesn't involve inventing any new syntax
i.e. with...end blocks -- so in a way it's simpler.

>Besides, does o.foo = 1 also set my_realy_long_name.foo to 1?

Yes of course, if my_really_long_name is an object,
then o = my_really_long_name just sets up an alternative
pointer to the same object.  Not a copy or anything.

  >>> class Test:
         pass

  >>> myreallylongname = Test()
  >>> o = myreallylongname
  >>> id(o)
  10939472
  >>> id(myreallylongname)  # same id means same object
  10939472

>What if these are attributes which call functions?
>

Well, if they're class methods, then you probably don't
want to obliterate them by making them integers --
it's up to you.

  >>> class Test:
          def f(self):
             return "!"


  >>> myreallylongname = Test()
  >>> o = myreallylongname
  >>> o.f()
  '!'
  >>> o.f = 1
  >>> o.f()
  Traceback (most recent call last):
    File "<pyshell#14>", line 1, in ?
      o.f()
  TypeError: 'int' object is not callable

But you can certainly use the reassignment "hack" to
shorten the typing needed to invoke methods, as shown
by o.f() -> '!' above.

Kirby




From dman@dman.ddts.net  Thu Mar 28 23:15:12 2002
From: dman@dman.ddts.net (dman)
Date: Thu, 28 Mar 2002 17:15:12 -0600
Subject: [Tutor] Languages, was Which programming language is better
In-Reply-To: <XFMail.20020328145255.shalehperry@attbi.com>
References: <4.2.0.58.20020328144932.019c7740@pop3.norton.antivirus> <XFMail.20020328145255.shalehperry@attbi.com>
Message-ID: <20020328231512.GA27299@dman.ddts.net>

On Thu, Mar 28, 2002 at 02:52:55PM -0800, Sean 'Shaleh' Perry wrote:
| On 28-Mar-2002 Kirby Urner wrote:
[...]
| > Then why not go:
| > 
| > o = my_really_long_name
| > o.foo = 1
| > o.bar = 2
| 
| Sure, I could do that.  But that feels like a hack to me.

| Besides, does o.foo = 1 also set my_realy_long_name.foo to 1?  What
| if these are attributes which call functions?

It's not a problem.  What is "my_really_long_name" anyways?  It is a
reference to an object.  When you do
    o = my_really_long_name
you make a copy of the _reference_ call 'o'.  Now 'o' and
'my_really_long_name' are synonomous.  (the references themselves are
immutable, you can only change a name's binding)  If you wanted to,
you could write
  
o = my_really_long_name
del my_really_long_name
o.foo = 1
o.bar = 2
my_really_long_name = o 
del o 

and it would be semantically the same as

my_really_long_name.foo = 1
my_really_long_name.bar = 2

I tend to write code like this (in python, c, c++, java, whatever) if
I'm going to use the name a lot in the function.  Within the short
scope of a function, a short name is more readable and more writable
than a long one.  In python it happens to give you a slight
performance boost as a side effect (it's a local name so you skip the
search through enclosing scopes).  The nice thing about python is
that, unlike c/c++/java, you can 'del' the short name when you are
done and leave no extra local names laying around.

-D

-- 

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



From urnerk@qwest.net  Thu Mar 28 23:14:33 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 28 Mar 2002 15:14:33 -0800
Subject: [Tutor] Languages, was Which programming language is
 better
In-Reply-To: <20020328225620.GX1475@johnsons-web.com>
References: <4.2.0.58.20020328140145.0199cf00@pop3.norton.antivirus>
 <5104D4DBC598D211B5FE0000F8FE7EB20E66C4BA@mbtlipnt02.btlabs.bt.co.uk>
 <4.2.0.58.20020328140145.0199cf00@pop3.norton.antivirus>
Message-ID: <4.2.0.58.20020328151335.019ce860@pop3.norton.antivirus>

At 01:56 PM 3/28/2002 -0900, you wrote:

>In my area, we have set up an online High School criteria, teaching
>the following in sequence:
>rebol, python, perl c/c++.

Interesting that you'd start with rebol -- that's creative.

Played with the language some, found lots to like (way
more original than Ruby).

Kirby



From shalehperry@attbi.com  Thu Mar 28 23:11:44 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Thu, 28 Mar 2002 15:11:44 -0800 (PST)
Subject: [Tutor] Languages, was Which programming language is better
In-Reply-To: <4.2.0.58.20020328150603.019cc300@pop3.norton.antivirus>
Message-ID: <XFMail.20020328151144.shalehperry@attbi.com>

> 
> Well, it doesn't involve inventing any new syntax
> i.e. with...end blocks -- so in a way it's simpler.
> 

I said I missed them, not writing a PEP to add them (-:


From urnerk@qwest.net  Thu Mar 28 23:16:30 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 28 Mar 2002 15:16:30 -0800
Subject: [Tutor] Languages, was Which programming language is better
In-Reply-To: <XFMail.20020328151144.shalehperry@attbi.com>
References: <4.2.0.58.20020328150603.019cc300@pop3.norton.antivirus>
Message-ID: <4.2.0.58.20020328151548.00d1cd80@pop3.norton.antivirus>

At 03:11 PM 3/28/2002 -0800, Sean 'Shaleh' Perry wrote:
> >
> > Well, it doesn't involve inventing any new syntax
> > i.e. with...end blocks -- so in a way it's simpler.
> >
>
>I said I missed them, not writing a PEP to add them (-:

OK.  I just don't see why you miss them, given it seems
you can do pretty much the same thing without them.

Kirby



From urnerk@qwest.net  Thu Mar 28 23:29:13 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Thu, 28 Mar 2002 15:29:13 -0800
Subject: [Tutor] Languages, was Which programming language is better
In-Reply-To: <20020328231512.GA27299@dman.ddts.net>
References: <XFMail.20020328145255.shalehperry@attbi.com>
 <4.2.0.58.20020328144932.019c7740@pop3.norton.antivirus>
 <XFMail.20020328145255.shalehperry@attbi.com>
Message-ID: <4.2.0.58.20020328152119.00d162d0@pop3.norton.antivirus>

>
>I tend to write code like this (in python, c, c++, java, whatever) if
>I'm going to use the name a lot in the function.  Within the short
>scope of a function, a short name is more readable and more writable
>than a long one.  In python it happens to give you a slight
>performance boost as a side effect (it's a local name so you skip the
>search through enclosing scopes).  The nice thing about python is
>that, unlike c/c++/java, you can 'del' the short name when you are
>done and leave no extra local names laying around.
>
>-D

But a local var goes out of scope when a function returns.

You're not advocating del *in addition* to taking advantage
of local scope cleanup are you?  E.g.

    class T:
         def do(self,x):
           return x + 1


    myreallylongname = T()

    def foo(x,y):
       o = myreallylongname # defined globally, o local
       print o.do(x)
       print o.do(y)
       return

is actually better than:

    def foo(x,y):
       o = myreallylongname # defined globally, o local
       print o.do(x)
       print o.do(y)
       del o  # not needed!
       return

(I'm sure you're quite aware of all this given your
sophisticated posts, just wanting to make this thread
instructive on the topic of scoping).

Kirby



From shalehperry@attbi.com  Thu Mar 28 23:26:49 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Thu, 28 Mar 2002 15:26:49 -0800 (PST)
Subject: [Tutor] Languages, was Which programming language is better
In-Reply-To: <4.2.0.58.20020328151548.00d1cd80@pop3.norton.antivirus>
Message-ID: <XFMail.20020328152649.shalehperry@attbi.com>

> 
> OK.  I just don't see why you miss them, given it seems
> you can do pretty much the same thing without them.
> 

when I say 'with foo' it is syntactically obvious what I am doing.  When I
assign 'o = my_long_...' it is not.  No big deal.


From paulsid@shaw.ca  Thu Mar 28 23:46:41 2002
From: paulsid@shaw.ca (Paul Sidorsky)
Date: Thu, 28 Mar 2002 16:46:41 -0700
Subject: [Tutor] Languages, was Which programming language is better
References: <XFMail.20020328152649.shalehperry@attbi.com>
Message-ID: <3CA3AB61.D71D7292@shaw.ca>

Sean 'Shaleh' Perry wrote:

> > OK.  I just don't see why you miss them, given it seems
> > you can do pretty much the same thing without them.

> when I say 'with foo' it is syntactically obvious what I am doing.  

Not if it's a long function and the with declaration has scrolled off
the screen.  I've been doing some VB recently and it didn't take me logn
to run into this problem with other people's code.

> When I assign 'o = my_long_...' it is not.  No big deal.

How about:

with = my_long_variable
with.whatever = x
with.somefunc()

At least this way you get a reminder that you're emulating a with block.

If you really want to go nuts with this you could even give the with its
own indentation level:

for with in [my_long_variable]:
    with.whatever = x
    with.somefunc()

Figuring out whether or not this is actually worse than simply not using
the with in the first place is left as an exercise for the reader.

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/


From dman@dman.ddts.net  Fri Mar 29 00:32:44 2002
From: dman@dman.ddts.net (dman)
Date: Thu, 28 Mar 2002 18:32:44 -0600
Subject: [Tutor] Languages, was Which programming language is better
In-Reply-To: <4.2.0.58.20020328152119.00d162d0@pop3.norton.antivirus>
References: <XFMail.20020328145255.shalehperry@attbi.com> <4.2.0.58.20020328144932.019c7740@pop3.norton.antivirus> <XFMail.20020328145255.shalehperry@attbi.com> <4.2.0.58.20020328152119.00d162d0@pop3.norton.antivirus>
Message-ID: <20020329003244.GA29431@dman.ddts.net>

On Thu, Mar 28, 2002 at 03:29:13PM -0800, Kirby Urner wrote:
| 
| >I tend to write code like this (in python, c, c++, java, whatever) if
| >I'm going to use the name a lot in the function.  Within the short
| >scope of a function, a short name is more readable and more writable
| >than a long one.  In python it happens to give you a slight
| >performance boost as a side effect (it's a local name so you skip the
| >search through enclosing scopes).  The nice thing about python is
| >that, unlike c/c++/java, you can 'del' the short name when you are
| >done and leave no extra local names laying around.
| 
| But a local var goes out of scope when a function returns.

Yes.

| 
| You're not advocating del *in addition* to taking advantage
| of local scope cleanup are you? 

Depends on the function.

| E.g.
| 
|    class T:
|         def do(self,x):
|           return x + 1
| 
| 
|    myreallylongname = T()
| 
|    def foo(x,y):
|       o = myreallylongname # defined globally, o local
|       print o.do(x)
|       print o.do(y)
|       return
| 
| is actually better than:
| 
|    def foo(x,y):
|       o = myreallylongname # defined globally, o local
|       print o.do(x)
|       print o.do(y)
|       del o  # not needed!
|       return

Right.  In that function I wouldn't use the del (nor the return).

| (I'm sure you're quite aware of all this given your
| sophisticated posts, just wanting to make this thread
| instructive on the topic of scoping).

No problem.

The case where I would use the del is if the function is rather long
and the variable isn't used in the rest of it.  Then it is clear that
the variable isn't used in the rest of it since it doesn't exist
there.

-D

-- 

Commit to the Lord whatever you do,
and your plans will succeed.
        Proverbs 16:3



From jeff@ccvcorp.com  Fri Mar 29 00:29:09 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Thu, 28 Mar 2002 16:29:09 -0800
Subject: [Tutor] 'with foo' was Languages
References: <E16qjLI-0006zX-00@mail.python.org>
Message-ID: <3CA3B555.F2003AD1@ccvcorp.com>

> "Sean 'Shaleh' Perry" <shalehperry@attbi.com> wrote:
>
> > OK.  I just don't see why you miss them, given it seems
> > you can do pretty much the same thing without them.
>
> when I say 'with foo' it is syntactically obvious what I am doing.  When I
> assign 'o = my_long_...' it is not.  No big deal.

I disagree.  The lines following 'with foo' have unqualified names, which look to me like local variables rather than object attributes.  When I see 'o.bar', I know I'm accessing an object, and it's not that hard to glance up and see what 'o' has been bound to.

Matter of taste and previous experience, I suppose.

Jeff Shannon
Technician/Programmer
Credit International




From dman@dman.ddts.net  Fri Mar 29 00:40:18 2002
From: dman@dman.ddts.net (dman)
Date: Thu, 28 Mar 2002 18:40:18 -0600
Subject: [Tutor] Languages, was Which programming language is better
In-Reply-To: <4.2.0.58.20020328150603.019cc300@pop3.norton.antivirus>
References: <4.2.0.58.20020328144932.019c7740@pop3.norton.antivirus> <4.2.0.58.20020328150603.019cc300@pop3.norton.antivirus>
Message-ID: <20020329004018.GB29431@dman.ddts.net>

On Thu, Mar 28, 2002 at 03:13:18PM -0800, Kirby Urner wrote:
 
| Well, if they're class methods, then you probably don't
| want to obliterate them by making them integers --
| it's up to you.

How about this?

class Demo( object ) :
    def _set_f( self , v ) :
        self._f = v

    def _get_f( self ) :
        return self._f

    f = property( _get_f , _set_f , None , "the 'f' property" )

myreallylongname = Demo()
o = myreallylongname
o.f = 1
o.f


In versions of python prior to 2.2 this can be achieved by a not so
pretty __getattr__ and __setattr__ pair.

-D

-- 

Stay away from a foolish man,
for you will not find knowledge on his lips.
        Proverbs 14:7



From dman@dman.ddts.net  Fri Mar 29 00:43:08 2002
From: dman@dman.ddts.net (dman)
Date: Thu, 28 Mar 2002 18:43:08 -0600
Subject: [Tutor] 'with foo' was Languages
In-Reply-To: <3CA3B555.F2003AD1@ccvcorp.com>
References: <E16qjLI-0006zX-00@mail.python.org> <3CA3B555.F2003AD1@ccvcorp.com>
Message-ID: <20020329004308.GC29431@dman.ddts.net>

On Thu, Mar 28, 2002 at 04:29:09PM -0800, Jeff Shannon wrote:
| > "Sean 'Shaleh' Perry" <shalehperry@attbi.com> wrote:
| >
| > > OK.  I just don't see why you miss them, given it seems
| > > you can do pretty much the same thing without them.
| >
| > when I say 'with foo' it is syntactically obvious what I am doing.  When I
| > assign 'o = my_long_...' it is not.  No big deal.
| 
| I disagree.  The lines following 'with foo' have unqualified names,
| which look to me like local variables rather than object attributes.
| When I see 'o.bar', I know I'm accessing an object, and it's not
| that hard to glance up and see what 'o' has been bound to.

I think this applies equally well to the magic "this" in C++ and Java.
After spending some time in python where instance members and methods
are explicitly qualified, I have more trouble following C++/Java that
relies on the automatic (unqualified) scoping of members.  Now my
C++/Java style is to always use 'this.' (or 'this->' for C++) when
accessing members.

(for those unfamiliar with "this", it is a keyword that serves the
same purpose as the "self" notation in python convention; another
difference is that methods don't declare it as an argument, it
automagically is present)

| Matter of taste and previous experience, I suppose.

Agreed.

-D

-- 

If Microsoft would build a car...
... Occasionally your car would die on the freeway for no reason. You
would have to pull over to the side of the road, close all of the car
windows, shut it off, restart it, and reopen the windows before you
could continue. For some reason you would simply accept this.



From tim@johnsons-web.com  Fri Mar 29 03:02:19 2002
From: tim@johnsons-web.com (Tim Johnson)
Date: Thu, 28 Mar 2002 18:02:19 -0900
Subject: [Tutor] Languages, was Which programming language is  better
In-Reply-To: <4.2.0.58.20020328151335.019ce860@pop3.norton.antivirus>
References: <4.2.0.58.20020328140145.0199cf00@pop3.norton.antivirus> <5104D4DBC598D211B5FE0000F8FE7EB20E66C4BA@mbtlipnt02.btlabs.bt.co.uk> <4.2.0.58.20020328140145.0199cf00@pop3.norton.antivirus> <4.2.0.58.20020328151335.019ce860@pop3.norton.antivirus>
Message-ID: <20020329030219.GZ1475@johnsons-web.com>

* Kirby Urner <urnerk@qwest.net> [020328 14:23]:
> At 01:56 PM 3/28/2002 -0900, you wrote:
> 
> >In my area, we have set up an online High School criteria, teaching
> >the following in sequence:
> >rebol, python, perl c/c++.
> 
> Interesting that you'd start with rebol -- that's creative.

  Hey Kirby:
  
  My first degree was philosophy of language, and (to my mind)
  rebol has a very language-like syntax. Even tho' rebol's
  paradigms were difficult for me to grasp (being practically
  "hard-coded" by C and ASM), I gambled that the new programmer
  would have an easier time of it than say, "C", I think
  I was correct in my asumption, - it was a tossup with
  Python actually.

> 
> Played with the language some, found lots to like (way
> more original than Ruby).
 
  One thing that I found is that rebol (like pure assembler
  and lisp) blurs the distinction betwen code and data.

  Now if I could just find a way to make my C preprocessor
  redefine myobj->mymethod to myobj/mymethod :)

-- 
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com
      http://www.johnsons-web.com


From alan.gauld@bt.com  Fri Mar 29 11:07:29 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 29 Mar 2002 11:07:29 -0000
Subject: [Tutor] Languages, was Which programming language is better
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4C2@mbtlipnt02.btlabs.bt.co.uk>

> What's this 'with'?
> 
> In FoxPro we have the following (maybe similar):
> with this.parent.parent.otherwidget
>      .subwidget1.value = 1
>      .subwidget2.value = 2
>      .subwidget3.value = 3
>      ...
> endwith

Exactly the same(but without the preceding dot. 
Syntactic sugar but saves some typing.

> But in Python you can do something very similar just by
> assigning the unchanging part of the path to a variable

Yes, and I do that in extreme cases but it clutters up 
the namespace a bit. (You use the same trick in Java/C++ 
with a temporary pointer assigned to the nested target)

Alan g.


From bryce@bembry.org  Fri Mar 29 14:27:41 2002
From: bryce@bembry.org (Bryce Embry)
Date: Fri, 29 Mar 2002 08:27:41 -0600
Subject: [Tutor] OOPs?
Message-ID: <5.1.0.14.0.20020329080427.00a69270@bembry.org>

Howdy,
I'm trying to get the hang of classes and would like to tap into the wealth 
of this tutorial for some guidance.  I've looked through a number of books 
and tutorials, so I understand how to construct a class, but I'm not sure 
how and why to use one. So, I am creating a small "stock tracker" program 
specifically to learn how to use classes.  I'm not going to use it for 
anything (I don't have the money to own stock), this is really just a 
pedantic example for learning. I've started building it, but run into a 
problem.  Can anyone give me an idea of where my understanding has gone off 
track, or how to make this concept work?

I have made a class that looks like the following:

class Stock:
         stocklist = []
         def __init__(self, name, price, shares):
                 # get name of stock, initial price, initial number of shares
                 # stick the new stock name in Stock.stocklist
         def update (self, newprice, newshares):
                 # change the shares in a stock
         def otherstuff(self):
                 # do other stuff, like print current value, etc.

My thought was to design the program so that each time the user added a 
stock to the portfolio, the program would create a new instance of the 
class.  I don't know how to do that, though.  I want what in PHP is a 
"variable variable", where I can do something like this:

newstock = raw_input("Enter name of new stock: ")
newstock = Stock()

So, if the person chose IBM, I would have an instance called 
IBM.Stock().  If he typed in RHAT, I'd have another instance called 
RHAT.Stock().   Then, I could update, track, and do other stuff by calling 
the instance of the class.  And, if I want a list of all my stocks, I'd 
just call Stock.stocklist  .

Is this even the right way to use a class?  I know I could get the job done 
with functions, dictionaries and lists without using a class, but I'm 
trying to understand classes.  Any suggestions or insights?

Thanks,

Bryce Embry
Geek-Of-All-Trades / Master-Of-None


--------------------------------------------------
"Lord, you have established peace for us.
All that we have accomplished you have done for us" -- Isaiah 26:12



From rhseabrook@mail.aacc.cc.md.us  Fri Mar 29 14:50:49 2002
From: rhseabrook@mail.aacc.cc.md.us (Seabrook, Richard)
Date: Fri, 29 Mar 2002 09:50:49 -0500
Subject: [Tutor] OOPs?
Message-ID: <B4B00B1CCF9795449A4AC24C63AAFFB493D17E@aacc-mail1.aacc.cc.md.us>

-----Original Message-----
From: Bryce Embry

  Can anyone give me an idea of where my understanding has gone
off 
track, or how to make this concept work?

I have made a class that looks like the following:

class Stock:
         stocklist = []
         def __init__(self, name, price, shares):
                 # get name of stock, initial price, initial number of
shares
                 # stick the new stock name in Stock.stocklist
         def update (self, newprice, newshares):
                 # change the shares in a stock
         def otherstuff(self):
                 # do other stuff, like print current value, etc.

My thought was to design the program so that each time the user added a 
stock to the portfolio, the program would create a new instance of the 
class.  I don't know how to do that, though.  I want what in PHP is a 
"variable variable", where I can do something like this:

newstock = raw_input("Enter name of new stock: ")
newstock = Stock()

So, if the person chose IBM, I would have an instance called 
IBM.Stock().  If he typed in RHAT, I'd have another instance called 
RHAT.Stock().   Then, I could update, track, and do other stuff by
calling 
the instance of the class.  And, if I want a list of all my stocks, I'd 
just call Stock.stocklist  .

Is this even the right way to use a class?  I know I could get the job
done 
with functions, dictionaries and lists without using a class, but I'm 
trying to understand classes.  Any suggestions or insights?
====================================================================

Well, it is one way, but why should a stock contain a list of anything,
except perhaps its own price history, and other data about that particular
stock.  It seems to me that, rather a stock-list should contain an instance
of a stock, and that you'd most often want to process the stock-list to
create or find out about particular stocks.  Think about two classes:

class Stocklist:
   def __init__(self):
      self.theList=[]
   def addStock(self,stk):
      self.theList.append(stk)
   etc.

Then you can create a new stock and give it to the stocklist to store away,
like this

name = raw_input("What is the name of the new stock?")
stock = Stock(name)  (You'll have to change your Stock constructor)
stocklist = Stocklist()
stocklist.addStock(stock)

In this way, instances of Stock are maintained by an instance of Stocklist.
Remember to use the 'self' reference in a class definition to create and
store data in the instance.
Dick S.
=====================================================================


From emarin@justice.com  Fri Mar 29 15:10:30 2002
From: emarin@justice.com (Eric Marin)
Date: Fri, 29 Mar 2002 07:10:30 -0800 (PST)
Subject: [Tutor] Beginner books and tutorials
Message-ID: <20020329071031.26867.c014-h005.c014.wm@mail.justice.com.criticalpath.net>

Hi, folks.  I am presently trying to teach myself
Python with no programming background at all.  I am
using Josh Cogliati's "Non-Programmer's Tutorial for
Python" right now, and I'm just finishing Chapter 10:
Boolean Expressions.  After I finish the tutorial, I'd
like to know where to go next for a tutorial or book to
continue the learning process.  Any suggestions? 
Thanks in advance.

Eric Marin


_________________________________________________
FindLaw - Free Case Law, Jobs, Library, Community
http://www.FindLaw.com
Get your FREE @JUSTICE.COM email!
http://mail.Justice.com


From wilson@isis.visi.com  Fri Mar 29 15:33:52 2002
From: wilson@isis.visi.com (Tim Wilson)
Date: Fri, 29 Mar 2002 09:33:52 -0600 (CST)
Subject: [Tutor] OOPs?
In-Reply-To: <5.1.0.14.0.20020329080427.00a69270@bembry.org>
Message-ID: <Pine.GSO.4.10.10203290931580.21110-100000@isis.visi.com>

On Fri, 29 Mar 2002, Bryce Embry wrote:

> So, I am creating a small "stock tracker" program 
> specifically to learn how to use classes.

Hi Bryce,

I gave a similar assignment to my students this year although a non-OOP
one. After we finished it, I converted my version to an OO one so the
kids could see an example. You're welcome to have a look at it. You'll
see a link at http://www.qwerk.org/tim/

-Tim

--
Tim Wilson      |   Visit Sibley online:   | Check out:
Henry Sibley HS |  http://www.isd197.org   | http://www.zope.com
W. St. Paul, MN |                          | http://slashdot.org
wilson@visi.com |  <dtml-var pithy_quote>  | http://linux.com



From pythonhack@yahoo.com  Fri Mar 29 15:56:33 2002
From: pythonhack@yahoo.com (pythonhack@yahoo.com)
Date: Fri, 29 Mar 2002 07:56:33 -0800
Subject: [Tutor] Beginner books and tutorials
In-Reply-To: <20020329071031.26867.c014-h005.c014.wm@mail.justice.com.criticalpath.net>
References: <20020329071031.26867.c014-h005.c014.wm@mail.justice.com.criticalpath.net>
Message-ID: <1411379081744.20020329075633@yahoo.com>

The documentation on www.python.org is excellent, but if you're
looking for a book that will take you deeper, i really like
Programming Python from O'Reilly.

brett

EM> Hi, folks.  I am presently trying to teach myself
EM> Python with no programming background at all.  I am
EM> using Josh Cogliati's "Non-Programmer's Tutorial for
EM> Python" right now, and I'm just finishing Chapter 10:
EM> Boolean Expressions.  After I finish the tutorial, I'd
EM> like to know where to go next for a tutorial or book to
EM> continue the learning process.  Any suggestions? 
EM> Thanks in advance.

EM> Eric Marin


EM> _________________________________________________
EM> FindLaw - Free Case Law, Jobs, Library, Community
EM> http://www.FindLaw.com
EM> Get your FREE @JUSTICE.COM email!
EM> http://mail.Justice.com

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


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com



From urnerk@qwest.net  Fri Mar 29 17:49:05 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Fri, 29 Mar 2002 09:49:05 -0800
Subject: [Tutor] OOPs?
In-Reply-To: <5.1.0.14.0.20020329080427.00a69270@bembry.org>
Message-ID: <4.2.0.58.20020329084737.019d2850@pop3.norton.antivirus>

At 08:27 AM 3/29/2002 -0600, Bryce Embry wrote:
>Howdy,
>I'm trying to get the hang of classes and would like to tap into the wealth
>of this tutorial for some guidance.

You could have a stock class and then stuff stock objects made
from it into a dictionary (similar to a stock list -- but just
for looking up by ticker code).

Here's a simple module, for pedagogical purposes only, as you
say (not to make a mint).

Note that I use a dictionary-like file to store my stock objects,
in order to gain persistence from one Python session to the next.

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

import time, shelve

class Stock:
    "Simple stock class, keeps history using current time"

    def __init__(self,code,price,datetime):
        self.code = code
        self.history = [(price,datetime)]
        self.price = price

    def newprice(self,price,datetime):
        self.history.append((price,datetime))

    def showhist(self):
        return self.history

def getcode():
     "Handle cases where user inputs code we don't have"
     code  = raw_input("Code?  > ")
     try:
        stockobj = stockdict[code]
     except:
        print "Not a legal code"
        return 0
     return stockobj

def addstock():
     "Add new stock, any code OK"
     code  = raw_input("Code?  > ")
     price = raw_input("Price? > ")
     stockdict[code] = Stock(code,price,time.asctime())

def update():
     obj  = getcode()
     if obj:
         price = raw_input("Price? > ")
         obj.newprice(price,time.asctime())
         print "%s prices on file" % len(obj.history)
         # would have to do next step if using real dictionary
         stockdict[obj.code]=obj # overwrites old copy

def dumphist():
     obj  = getcode()
     if obj:
         hist = obj.showhist()
         print hist

def quit():
     stockdict.close()
     print "Stocks saved"

def mainmenu():
     "Using dictionary-like syntax to do file i/o"
     global stockdict
     stockdict = shelve.open("mystocks")
     callables = [quit,addstock,update,dumphist]
     while 1:
         print \
         """
         (1) add new stock
         (2) update price of stock
         (3) dump history of stock
         (0) save/quit
         """
         sel = raw_input("yr choice: > ")
         try:
            sel = int(sel)
            assert int(sel) <= 3 and int(sel) >= 0
            callables[int(sel)]()
            if int(sel)==0:  break
        except:
            print "Not a legal choice"

=============
Usage (in shell mode):

  >>> import stocks
  >>> stocks.mainmenu()

         (1) add new stock
         (2) update price of stock
         (3) dump history of stock
         (0) save/quit

  yr choice: > 1
  Code?  > CISCO
  Price? > 23.12

         (1) add new stock
         (2) update price of stock
         (3) dump history of stock
         (0) save/quit

  yr choice: > 3
  Code?  > IBM   [saved in an earlier session ]
  [('12.75', 'Fri Mar 29 09:40:45 2002'), ('12.10', 'Fri Mar 29 09:40:54 
2002'),
  ('45', 'Fri Mar 29 09:41:50 2002')]

         (1) add new stock
         (2) update price of stock
         (3) dump history of stock
         (0) save/quit

  yr choice: > 2
  Code?  > CISCO
  Price? > 14.10
  2 prices on file

         (1) add new stock
         (2) update price of stock
         (3) dump history of stock
         (0) save/quit

  yr choice: > 3
  Code?  > CISCO
  [('23.12', 'Fri Mar 29 09:44:16 2002'), ('14.10', 'Fri Mar 29 09:44:35 
2002')]

         (1) add new stock
         (2) update price of stock
         (3) dump history of stock
         (0) save/quit

  yr choice: > 0
  Stocks saved

Kirby



From jeff@ccvcorp.com  Fri Mar 29 17:53:26 2002
From: jeff@ccvcorp.com (Jeff Shannon)
Date: Fri, 29 Mar 2002 09:53:26 -0800
Subject: [Tutor] 'with foo' was Languages
References: <E16qzlN-0000I6-00@mail.python.org>
Message-ID: <3CA4AA16.200618B4@ccvcorp.com>

> dman <dman@dman.ddts.net> wrote:
>
> On Thu, Mar 28, 2002 at 04:29:09PM -0800, Jeff Shannon wrote:
> | I disagree.  The lines following 'with foo' have unqualified names,
> | which look to me like local variables rather than object attributes.
> | When I see 'o.bar', I know I'm accessing an object, and it's not
> | that hard to glance up and see what 'o' has been bound to.
>
> I think this applies equally well to the magic "this" in C++ and Java.
> After spending some time in python where instance members and methods
> are explicitly qualified, I have more trouble following C++/Java that
> relies on the automatic (unqualified) scoping of members.  Now my
> C++/Java style is to always use 'this.' (or 'this->' for C++) when
> accessing members.

I totally agree.  I haven't done any significant C/C++ since I started using Python (no call for it at work, and I'd much rather use Python for hobby stuff), but when I did use it, the magic "this" was one of the things that always confused me.  Since I was far
from expert, I spent a fair amount of time reading others' code, and I had a horrible time trying to figure out what was an object attribute and what was a local variable -- really, the only way to do it is to have *both* the .cpp and the .h file open, and keep
scrolling around in both of them (and this in the days when a 15" monitor was considered average) ....  Python's explicit 'self' has saved me endless amounts of grief, in this respect, and I'd hate to see anything that heads Python back in the direction of that
magic "this" ...


> | Matter of taste and previous experience, I suppose.
>
> Agreed.

As a minor reference point (since this thread started on this topic ;) ) my programming experience started with Basic on an Apple //e, at an age of about 12.  I then did nothing with programming for 5 or 6 years, took a Fortran/Basic class in college and did
poorly... but, after leaving college, I decided to pick up a book on C and toyed with that for a little while, and had a lot of fun with it.  I went a couple of years with no computer access after that, then in the early 90s got my own PC, started up with C again,
then taught myself C++ and looked at Assembler (x86) a bit.  As my job has moved more and more into programming, I've been using mostly Basic (some VB, but mostly a proprietary dialect for our Pick/D3 database), a truly horrid proprietary scripting language for
that database (I'd describe it as combining the worst aspects of shell scripting and SQL, but that makes it sound better than it is)... and Python.  Needless to say, I try to keep myself working on the projects for which Python is the most useful.   :)

Jeff Shannon
Technician/Programmer
Credit International




From alan.gauld@bt.com  Fri Mar 29 18:31:45 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 29 Mar 2002 18:31:45 -0000
Subject: [Tutor] OOPs?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4CB@mbtlipnt02.btlabs.bt.co.uk>

> newstock = raw_input("Enter name of new stock: ")
> newstock = Stock()

[ This is an idiom I've never seen in OOP beginners in 
  C++ or Java or Smalltalk but this is at least the 3rd 
  time its happened on this list - wierd!]

The easiest way to have named objects is probanbly to create 
a dictionary and store them there indexed by the name:

stocks = {}
newstock = raw_input("Enter name of new stock: ")
stocks[newstock] = Stock()

later...

stocks["IBM"].update()

> the instance of the class.  And, if I want a list of all my 
> stocks, I'd just call Stock.stocklist.

You can do that by making the class contain a list of objects 
and make the init method add self to that list. Or use

stocks.keys() to return the list of names...

> with functions, dictionaries and lists without using a class, but I'm 
> trying to understand classes.  Any suggestions or insights?

I can see why you migt do this but personally I'd usually 
include the name as an attribute of the class and as a 
parameter of the constructor(init). Then you can iterate 
over your stocks asking them their names. It seems like 
only occasionally (in this app) would you index by company 
name - but if you think you do that a lot then a dictionary 
is the sensible option.

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


From alan.gauld@bt.com  Fri Mar 29 18:34:09 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 29 Mar 2002 18:34:09 -0000
Subject: [Tutor] Beginner books and tutorials
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4CC@mbtlipnt02.btlabs.bt.co.uk>

> Boolean Expressions.  After I finish the tutorial, I'd
> like to know where to go next for a tutorial or book to

The logical next step is to go thru the official tutor 
that comes with Python in the documentation.

Then get one of the several advanced/reference books, 
like:

Programming Python by Lutz or
Python Essential Ref by Beasley

My 2 cents,

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


From urnerk@qwest.net  Fri Mar 29 20:32:55 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Fri, 29 Mar 2002 12:32:55 -0800
Subject: [Tutor] OOPs? (oops)
In-Reply-To: <4.2.0.58.20020329084737.019d2850@pop3.norton.antivirus>
References: <5.1.0.14.0.20020329080427.00a69270@bembry.org>
Message-ID: <4.2.0.58.20020329121517.00cdbbd0@pop3.norton.antivirus>

>
>         # would have to do next step if using real dictionary
                  ^
                 not

>         stockdict[obj.code]=obj # overwrites old copy

Meant to say would NOT have to do next step if using
real dictionary.  It's just that stockdict-as-file
needs to be explicitly told to update the disk image
when the object changes.

Another (probably better) approach would be to read the
shelve file at the start, port its contents into a
dictionary, and refile everything upon closing, i.e. for
the duration of the session, we'd be using a real dictionary.

E.g.

def mainmenu():
    "Using dictionary-like syntax to do file i/o"
    global stockdict
     stockdict = {}
     f = shelve.open('mystocks')
     for k in f.keys():
        stockdict[k]=f[k]
     f.close()
    callables = [quit,addstock,update,dumphist]
    while 1:
     ...

and when closing:

def quit():
     f = shelve.open('mystocks')
     for k in stockdict:
        f[k]=stockdict[k]
     f.close()
     print "Stocks saved"

Tested it.  Works OK.

Lots of other enhancements will suggest themselves.  For
example the stock histories could be printed in a prettier
way (but of course, really, you'll want to graph 'em :-D).

def dumphist():
     obj  = getcode()
     if obj:
         hist = obj.showhist()
         print "Price     Date/time"
         for pricepoint in hist:
              print "%s     %s" % pricepoint

Kirby




From hysterix240@yahoo.com  Fri Mar 29 21:44:40 2002
From: hysterix240@yahoo.com (Galen Senogles)
Date: Fri, 29 Mar 2002 13:44:40 -0800 (PST)
Subject: [Tutor] simple problem
Message-ID: <20020329214440.15306.qmail@web11706.mail.yahoo.com>

hello, i just sent an e-mail with the same subject,
and at the time when i sent it i wasnt a member, but
now i am so i will send it again.  I am using python
for on mac os 10, and i am using it through terminal
and then through fink.  My very simple problem is when
i try to put a line of code and and then try to put
another underneath it, i have to hit return, and
python runs through the code, so what happens if i
want to put more than 1 line of code before i want
python to run through it.  I think i have to use the
python GUI, or the IDLE, but i dont think I can use
that sence i am using terminal, and think fink.  If
there is a way I can write the more than just 1 line
of code before python runs through it, please let me
know, im gussing its just a certain button or
something. thank you

__________________________________________________
Do You Yahoo!?
Yahoo! Greetings - send holiday greetings for Easter, Passover
http://greetings.yahoo.com/


From dyoo@hkn.eecs.berkeley.edu  Fri Mar 29 22:11:55 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 29 Mar 2002 14:11:55 -0800 (PST)
Subject: [Tutor] simple problem
In-Reply-To: <20020329214440.15306.qmail@web11706.mail.yahoo.com>
Message-ID: <Pine.LNX.4.44.0203291350410.21700-100000@hkn.eecs.berkeley.edu>


On Fri, 29 Mar 2002, Galen Senogles wrote:

> and then through fink.  My very simple problem is when i try to put a
> line of code and and then try to put another underneath it, i have to
> hit return, and python runs through the code, so what happens if i want
> to put more than 1 line of code before i want python to run through it.
> I think i have to use the python GUI, or the IDLE, but i dont think I
> can use that sence i am using terminal, and think fink.  If there is a
> way I can write the more than just 1 line of code before python runs
> through it, please let me know, im gussing its just a certain button or
> something. thank you

Hi Galen!

Yes, when you start up Python in interactive mode, it acts almost like a
calculator --- it'll run commands as we type them in.  But if we want to
write something more than one line long, we can do this by preparing a
text file with our commands.

IDLE is a great text editor for writing Python, and I have a small
tutorial on using it here:

    http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro

It should show you how to write prepared programs for Python.  I have to
admit, though, that the tutorial is somewhat tailored for Windows users,
though I hope it's not too platform dependent.


There are some people here on Tutor that use Mac OS X, so perhaps they can
comment on their experiences with it?



From python.org@pooryorick.com  Fri Mar 29 15:28:08 2002
From: python.org@pooryorick.com (python.org@pooryorick.com)
Date: Fri, 29 Mar 2002 08:28:08 -0700
Subject: [Tutor] Beginner books and tutorials
Message-ID: <1D0833CB3B1D7244B617A0DC8399C27E01F2DAA3@vega>

I had almost no programming experience before I started reading "Core =
Python Programming", by Wesley Chun, and have found it very easy to =
understand.  The coverage is broad, so I think it is an excellent =
reference book for beginners (like me).

-----Original Message-----
From: Eric Marin [mailto:emarin@justice.com]
Sent: Friday, March 29, 2002 8:11 AM
To: tutor@python.org
Subject: [Tutor] Beginner books and tutorials


Hi, folks.  I am presently trying to teach myself
Python with no programming background at all.  I am
using Josh Cogliati's "Non-Programmer's Tutorial for
Python" right now, and I'm just finishing Chapter 10:
Boolean Expressions.  After I finish the tutorial, I'd
like to know where to go next for a tutorial or book to
continue the learning process.  Any suggestions?=20
Thanks in advance.

Eric Marin


_________________________________________________
FindLaw - Free Case Law, Jobs, Library, Community
http://www.FindLaw.com
Get your FREE @JUSTICE.COM email!
http://mail.Justice.com

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


From hysterix240@yahoo.com  Fri Mar 29 21:16:22 2002
From: hysterix240@yahoo.com (Galen Senogles)
Date: Fri, 29 Mar 2002 13:16:22 -0800 (PST)
Subject: [Tutor] simple problem
Message-ID: <20020329211622.11185.qmail@web11706.mail.yahoo.com>

Hello, I am using python on my mac os 10.  I am using
it through terminal, and then through the program
fink.  I finally got python up and running but
everytime I put a line in, and hit return, it runs
that program, but what happends if i want to put more
than just 1 line of code? something like this:
print " Hello world"
print " Goodbye world"
I cant put something like this, because after I am
done putting in the hello world line, and i hit
return, it runs through the program, and i am not able
to put in the goodbye world line, is there somethin i
am not doing? i know i am able to put more than 1 line
in before python runs through it..what should i do?

__________________________________________________
Do You Yahoo!?
Yahoo! Greetings - send holiday greetings for Easter, Passover
http://greetings.yahoo.com/


From dyoo@hkn.eecs.berkeley.edu  Fri Mar 29 22:25:41 2002
From: dyoo@hkn.eecs.berkeley.edu (Danny Yoo)
Date: Fri, 29 Mar 2002 14:25:41 -0800 (PST)
Subject: [Tutor] Revving up Tkinter/PMW
In-Reply-To: <02032616253400.02189@ouhep1>
Message-ID: <Pine.LNX.4.44.0203261921250.394-100000@hkn.eecs.berkeley.edu>


On Tue, 26 Mar 2002, Isaac Hall wrote:

> hi tutors, gurus, and newbies alike!
>
> I have a question that has been eating at my sould for the past few
> weeks (well, not quite eating, maybe sipping?).  Anyway, Im building a
> rather large monitoring application that is supposed to take in a rather
> large ammount of data (~10,000 objects....scalers, histograms, circular
> buffers(ie, pie charts), and bitmasks) and display them graphically, and
> to be updated somewhere on the order of once every 5 to 10 seconds.
> Anyway, Ive been working on this rather on and off for the past few
> months and learning python (and SWIG) as I go, so I don't feel like Im
> fully aware of many of the methods available for creating faster
> graphics in python/Tkinter/PMW, and I haven't seen much in the way of
> books and such that help in this area.  Currently, the graphics are
> displayed in a multi-layered(tabbed) PMW notebook, and I was wondering
> this:
>
> Is there any way to make the thing only update the page that is being
> viewed?

Has anyone responded to your question yet?

Fredrik Lundh (effbot) has been working on revamping Tkinter to make it
faster:

    http://effbot.org/tkinter/index.htm

so you may want to try Tkinter 3000 to see if it helps performance any.
The technique you're thinking of is "double buffering", but I haven't been
able to pull anything in about it from Google yet.



From Bruce Gollng" <bwgolling@attbi.com  Fri Mar 29 17:44:55 2002
From: Bruce Gollng" <bwgolling@attbi.com (Bruce Gollng)
Date: Fri, 29 Mar 2002 17:44:55 -0000
Subject: [Tutor] importing a subprocess in dos
Message-ID: <000d01c1d749$70c18640$5523e30c@attbi.com>

Hello all,
I'm missing this part in the mans, so some help would be appreciated.  How
do I run a process in dos (btw my os is win98) and import the result to my
python interpreter?




From urnerk@qwest.net  Fri Mar 29 23:06:43 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Fri, 29 Mar 2002 15:06:43 -0800
Subject: [Tutor] importing a subprocess in dos
In-Reply-To: <000d01c1d749$70c18640$5523e30c@attbi.com>
Message-ID: <4.2.0.58.20020329150404.00d1ff00@pop3.norton.antivirus>

At 05:44 PM 3/29/2002 +0000, Bruce Gollng wrote:
>Hello all,
>I'm missing this part in the mans, so some help would be appreciated.  How
>do I run a process in dos (btw my os is win98) and import the result to my
>python interpreter?

Here's one way (I'm using shell mode):

  >>> import os
  >>> def dodos(cmd):
         f = os.popen(cmd)
         return f.readlines()

  >>> mydir = dodos('dir')

  >>> for i in mydir: print i,


  Volume in drive D is CAROL
  Volume Serial Number is 38D6-68D3
  Directory of D:\Program Files\Python22

  .              <DIR>        07-22-01 10:40p .
  ..             <DIR>        07-22-01 10:40p ..
  DLLS           <DIR>        07-22-01 10:40p DLLs
  LIBS           <DIR>        07-22-01 10:40p libs
  LIB            <DIR>        07-22-01 10:40p Lib
  INCLUDE        <DIR>        07-22-01 10:40p include
  TOOLS          <DIR>        07-22-01 10:40p Tools
  DOC            <DIR>        07-22-01 10:40p Doc
  TCL            <DIR>        07-22-01 10:40p tcl
  WORK           <DIR>        08-29-01  1:33a work

etc.

Kirby



From apython101@yahoo.com  Sat Mar 30 01:07:10 2002
From: apython101@yahoo.com (john public)
Date: Fri, 29 Mar 2002 17:07:10 -0800 (PST)
Subject: [Tutor] Beginner books and tutorials
In-Reply-To: <20020329071031.26867.c014-h005.c014.wm@mail.justice.com.criticalpath.net>
Message-ID: <20020330010710.28745.qmail@web21106.mail.yahoo.com>

--0-1831701401-1017450430=:85503
Content-Type: text/plain; charset=us-ascii


  I am a begginer and the books that are helping me the most are Alan Gaulds book and How to think like a computer scientist. Both available from the Python website.  After I have read those through three times or so and type in all the code three times or so, I am then looking into Learning Python. After having gone through several tutorials it seems to me that authors fall into two categories. Those that are people that write code and people that teach classes for a living. The styles are different. At first I found the only tutorials that made sense were written by teachers. It's slowly sinking in and I am finding the tutorial that are written by non teachers work for me now also. At this point I can't articulately describe the difference except to say that they flow differently and have a different focus. I switch back and forth depending on my mood. I think perhaps the most valuable tool is this thread. Ask a question, get an awnser, or ten or twenty awnsers. :)
John
  Eric Marin <emarin@justice.com> wrote: Hi, folks. I am presently trying to teach myself
Python with no programming background at all. I am
using Josh Cogliati's "Non-Programmer's Tutorial for
Python" right now, and I'm just finishing Chapter 10:
Boolean Expressions. After I finish the tutorial, I'd
like to know where to go next for a tutorial or book to
continue the learning process. Any suggestions? 
Thanks in advance.

Eric Marin


_________________________________________________
FindLaw - Free Case Law, Jobs, Library, Community
http://www.FindLaw.com
Get your FREE @JUSTICE.COM email!
http://mail.Justice.com

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


---------------------------------
Do You Yahoo!?
Yahoo! Greetings - send greetings for Easter,  Passover
--0-1831701401-1017450430=:85503
Content-Type: text/html; charset=us-ascii

<P>&nbsp; I am a begginer and the books that are helping me the most are Alan Gaulds book and How to think like a computer scientist. Both available from the Python website.  After I have read those through three times or so and type in all the code three times or so, I am then looking into Learning Python. After having gone through several tutorials it seems to me that authors fall into two categories. Those that are&nbsp;people that write code and people that teach classes for a living. The styles are different. At first I found the only tutorials that made sense were written by teachers. It's slowly sinking in and I am finding the tutorial that are written by non teachers work for me now also. At this point I can't articulately describe the difference except to say that they flow differently and have a different focus. I switch back and forth depending on my mood. I think perhaps the most valuable tool is this thread. Ask a question, get an awnser, or ten or twenty awnsers. :)
<P>John
<P>&nbsp; <B><I>Eric Marin &lt;emarin@justice.com&gt;</I></B> wrote: 
<BLOCKQUOTE style="BORDER-LEFT: #1010ff 2px solid; MARGIN-LEFT: 5px; PADDING-LEFT: 5px">Hi, folks. I am presently trying to teach myself<BR>Python with no programming background at all. I am<BR>using Josh Cogliati's "Non-Programmer's Tutorial for<BR>Python" right now, and I'm just finishing Chapter 10:<BR>Boolean Expressions. After I finish the tutorial, I'd<BR>like to know where to go next for a tutorial or book to<BR>continue the learning process. Any suggestions? <BR>Thanks in advance.<BR><BR>Eric Marin<BR><BR><BR>_________________________________________________<BR>FindLaw - Free Case Law, Jobs, Library, Community<BR>http://www.FindLaw.com<BR>Get your FREE @JUSTICE.COM email!<BR>http://mail.Justice.com<BR><BR>_______________________________________________<BR>Tutor maillist - Tutor@python.org<BR>http://mail.python.org/mailman/listinfo/tutor</BLOCKQUOTE><p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href="$rd_url/welcome/?http://greetings.yahoo.com">Yahoo! Greetings</a> - send greetings for <a href="$rd_url/welcome/?http://greetings.yahoo.com/browse/Holidays/Easter/">Easter</a>, <a href="$rd_url/welcome/?http://greetings.yahoo.com/browse/Holidays/Passover/"> Passover
--0-1831701401-1017450430=:85503--


From apython101@yahoo.com  Sat Mar 30 01:13:00 2002
From: apython101@yahoo.com (john public)
Date: Fri, 29 Mar 2002 17:13:00 -0800 (PST)
Subject: [Tutor] idle
Message-ID: <20020330011300.35030.qmail@web21104.mail.yahoo.com>

--0-1429207074-1017450780=:34486
Content-Type: text/plain; charset=us-ascii


I created a module( I think I am using the right word ) in Idle called trash.py, I use it for my throw away code. However I just noticed something, when I delete all the code to write some more throw away code  the variables and I think also other things do not get deleted. How do I delete them? 

 

 John



---------------------------------
Do You Yahoo!?
Yahoo! Greetings - send greetings for Easter,  Passover
--0-1429207074-1017450780=:34486
Content-Type: text/html; charset=us-ascii

<P>I created a module( I think I am using the right word ) in Idle called trash.py, I use it for my throw away code. However I just noticed something, when I delete all the code to write some more throw away code  the variables and I think also other things do not get deleted. How do I delete them? </P>
<P>&nbsp;</P>
<P>&nbsp;John</P><p><br><hr size=1><b>Do You Yahoo!?</b><br>
<a href="$rd_url/welcome/?http://greetings.yahoo.com">Yahoo! Greetings</a> - send greetings for <a href="$rd_url/welcome/?http://greetings.yahoo.com/browse/Holidays/Easter/">Easter</a>, <a href="$rd_url/welcome/?http://greetings.yahoo.com/browse/Holidays/Passover/"> Passover
--0-1429207074-1017450780=:34486--


From jimmy_130@lycos.com  Fri Mar 29 23:48:21 2002
From: jimmy_130@lycos.com (James M Lang)
Date: Fri, 29 Mar 2002 18:48:21 -0500
Subject: [Tutor] Problem with exponents and square roots
Message-ID: <GCILGDKPGPLNOBAA@mailcity.com>

I followed everyone's instructions for using square roots and exponents and got this.

Traceback (most recent call last):
  File "C:\WINDOWS\Desktop\Jimmy's Folder\Python Source\hypotenuse", line 9, in ?
    c = (a**2+b**2)**.5
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'


Here's the original source

print "Program for solving hypotenuse of right triangle"
a = raw_input("What is the length of A? ")
b = raw_input("What is the length of B? ")
c = (a**2+b**2)**.5
print "The hypotenuse is", c

the question is, of course, why did I get this?


See Dave Matthews Band live or win a signed guitar
http://r.lycos.com/r/bmgfly_mail_dmb/http://win.ipromotions.com/lycos_020201/splash.asp 


From shalehperry@attbi.com  Sat Mar 30 05:50:46 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Fri, 29 Mar 2002 21:50:46 -0800 (PST)
Subject: [Tutor] Problem with exponents and square roots
In-Reply-To: <GCILGDKPGPLNOBAA@mailcity.com>
Message-ID: <XFMail.20020329215046.shalehperry@attbi.com>

On 29-Mar-2002 James M Lang wrote:
> I followed everyone's instructions for using square roots and exponents and
> got this.
> 
> Traceback (most recent call last):
>   File "C:\WINDOWS\Desktop\Jimmy's Folder\Python Source\hypotenuse", line 9,
> in ?
>     c = (a**2+b**2)**.5
> TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
> 

the answer is right there "unsupport type".  raw_input returns a string, not a
number.

num_a = float(a)
num_b = float(b)
c = (a**2 + b**2)
c = c**.5



From wolf_binary@hotmail.com  Sat Mar 30 17:03:35 2002
From: wolf_binary@hotmail.com (Cameron Stoner)
Date: Sat, 30 Mar 2002 11:03:35 -0600
Subject: [Tutor] command line
Message-ID: <DAV331Fjxe0ymQ1WE9q000078bf@hotmail.com>

This is a multi-part message in MIME format.

------=_NextPart_000_001D_01C1D7DA.89A02220
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

hi all,

Why would you use the command line Python instead of the IDLE?

Cameron Stoner

------=_NextPart_000_001D_01C1D7DA.89A02220
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.2713.1100" 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>Why would you use the command line =
Python instead=20
of the IDLE?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Cameron =
Stoner</FONT></DIV></BODY></HTML>

------=_NextPart_000_001D_01C1D7DA.89A02220--


From dman@dman.ddts.net  Sat Mar 30 17:36:22 2002
From: dman@dman.ddts.net (dman)
Date: Sat, 30 Mar 2002 11:36:22 -0600
Subject: [Tutor] command line
In-Reply-To: <DAV331Fjxe0ymQ1WE9q000078bf@hotmail.com>
References: <DAV331Fjxe0ymQ1WE9q000078bf@hotmail.com>
Message-ID: <20020330173622.GC20525@dman.ddts.net>

On Sat, Mar 30, 2002 at 11:03:35AM -0600, Cameron Stoner wrote:
| hi all,
| 
| Why would you use the command line Python instead of the IDLE?

'cause it's the way to go <wink>

I don't know about you, but I'm a unix fan.  Unix shells allow
starting a text file with "#!/path/to/interpreter" to make the file a
script that is executed by the given interpreter.  When I make a
script, I use this technique so that it "just works".  I also use the
shell a lot (X exists primarily for having many shell windows and a web
browser :-), and to have little penguins running around in the
background while xmms cranks out some tunes).  For me, typing
"python foo.py" is the quickest and most natural way to run a script
that either doesn't have the "shebang" line or doesn't have the
executable bit set.  I also use (g)vim as my preferred editor.  It, in
conjunction with every unix utility I am familiar with, comprise my
IDE.

IDLE has no advantages for me.  If I want an interactive interpreter,
I'll just run "python" in my shell.  I get the same shell I'm familiar
with (with GNU readline too!) in the same gnome-terminal window I'm
familiar with.  (the window already exists too)  If I want to edit
files, I'll use vim for quick editing inside a terminal, or gvim for
extended editing.

I understand, though, that people with a windows background are often
unfamiliar with the "command line" and want a nice-looking window to
work with.  In addition, many windows users underestimate the
usefulness and power of a text editor and may not even be familiar
with the term "text editor".  IDLE provides both of these things for
that target audience.

-D

-- 

After you install Microsoft Windows XP, you have the option to create
user accounts.  If you create user accounts, by default, they will have
an account type of administrator with no password.
                                                            -- bugtraq



From urnerk@qwest.net  Sat Mar 30 18:12:58 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Sat, 30 Mar 2002 10:12:58 -0800
Subject: [Tutor] command line
In-Reply-To: <20020330173622.GC20525@dman.ddts.net>
References: <DAV331Fjxe0ymQ1WE9q000078bf@hotmail.com>
 <DAV331Fjxe0ymQ1WE9q000078bf@hotmail.com>
Message-ID: <4.2.0.58.20020330095205.019ea660@pop3.norton.antivirus>

>
>I understand, though, that people with a windows background
>are often unfamiliar with the "command line" and want a
>nice-looking window to work with.  In addition, many windows
>users underestimate the usefulness and power of a text editor
>and may not even be familiar with the term "text editor".
>IDLE provides both of these things for that target audience.
>
>-D

There's also the fact that the term window in most Win*
systems is anemic.  Having a command line history is only
an option (doskey) and it's not very searchable.  But
that's irrelevant too, because once in the term window's
Python shell, there's no uparrow ability to grab previously
written commands or functions, nor any scroll bar, and
that about destroys its usability as an interactive
environment.  Maybe it's different in Win2k, where uparrow
history is somehow available.

Something like IDLE is the only usable way to access the
Python shell in most versions of Win* (doesn't have to
be IDLE -- e.g. PyCrust is another option, or the
PythonWin IDE from ActiveState).

What's nice in shell mode is to have textbox prompts for
function args, e.g. when I type in IDLE or some other
relatively sophisticated shell:

  >>> wpack(

I immediately get a yellow rectangle next to the function
telling me what arguments are expected and what their default
values are.  That's nice -- even a pro doesn't want to
memorize all the arg lists for every function.  I also like
the color coding of key words.

I prefer shell mode to the command line (by which I mean
starting python scripts by passing a script as an argument
to python) because I like the granular control over
the contents of a module, without having to write any
menus with raw_input prompts (a command I rarely use) or
parse sys args.  Being in shell vis-a-vis a module or
modules is more like being at the command line in an OS,
whereas scripts have a "canned" feeling -- too scripted
(not that I don't run them -- just not my preferred mode
of using Python).

I like to have a text editor open (could be Vim) wherein
I edit modules and reload them in the shell, debugging and
enhancing as I go.  The open module shows me what the
functions and classes are (or I can enter help(module)),
and if I want a new one, I stick it in.  But I'm usually
interacting with these functions from the shell, e.g.

   >>> from wmproject import *
   >>> wpack(10,abc=1)

will generate a povray file of close packed, color coded
balls starting at distance sqrt(10) from the origin and
working inward, and rotated in a particular way vis-a-vis
the xyz axes.  I'd rather run it this way than parse sys.args
in a script (I rarely use sys.args).

In *nix systems, you can use bang notation to tie a file
to the executing interpreter (#!python) while in Win* you
have to use file association, in which case you can run
a python script by just clicking on it in the Windows GUI.

Kirby



From urnerk@qwest.net  Sat Mar 30 18:41:11 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Sat, 30 Mar 2002 10:41:11 -0800
Subject: [Tutor] command line
In-Reply-To: <4.2.0.58.20020330095205.019ea660@pop3.norton.antivirus>
References: <20020330173622.GC20525@dman.ddts.net>
 <DAV331Fjxe0ymQ1WE9q000078bf@hotmail.com>
 <DAV331Fjxe0ymQ1WE9q000078bf@hotmail.com>
Message-ID: <4.2.0.58.20020330103408.015da380@pop3.norton.antivirus>

At 10:12 AM 3/30/2002 -0800, Kirby Urner wrote:

>environment.  Maybe it's different in Win2k, where uparrow
>history is somehow available.

I just fired up my WinXP box (a laptop) and checked the
Python term shell there -- yes, uparrow gets me previous
commands.  But it's still not as useful a shell as IDLE
(or similar) by a long shot.

For example, in IDLE I can scroll up to any previous line
and select it, hit enter, and get a copy available for
editing (that's great for re-executing some function
with lots of args, just changing one of 'em).  The mouse
lets me go directly to any line in the history; I don't
have to arrow through all commands in between.

And when I enter a quick and dirty function or class
definition right in the shell (becomes 2nd nature when
it's easy to do -- might just be a simple loop to do
something in a module several times) I can modify the
whole thing as a block -- it gets copied down as a
whole.  The DOS box shell doesn't do that, not in XP,
not in any Win* -- probably not in Linux either (although
I haven't restored my dual boot setup on the upstairs
box since the hard drive upgrade, so I can't double
check that now).  Perhaps dman will let us know.

Kirby




From shalehperry@attbi.com  Sat Mar 30 18:56:09 2002
From: shalehperry@attbi.com (Sean 'Shaleh' Perry)
Date: Sat, 30 Mar 2002 10:56:09 -0800 (PST)
Subject: [Tutor] command line
In-Reply-To: <4.2.0.58.20020330103408.015da380@pop3.norton.antivirus>
Message-ID: <XFMail.20020330105609.shalehperry@attbi.com>

> 
> And when I enter a quick and dirty function or class
> definition right in the shell (becomes 2nd nature when
> it's easy to do -- might just be a simple loop to do
> something in a module several times) I can modify the
> whole thing as a block -- it gets copied down as a
> whole.  The DOS box shell doesn't do that, not in XP,
> not in any Win* -- probably not in Linux either (although
> I haven't restored my dual boot setup on the upstairs
> box since the hard drive upgrade, so I can't double
> check that now).  Perhaps dman will let us know.
> 

no, the python shell is just a shell like bash.  IDLE does have some of those
nifty IDE features people used to Window's coding expect.

in the end to idle or not to idle is a matter of history and taste.  The
important lesson to walk away with is this: if you are not using an interactive
python interpreter while coding and experimenting you are missing out on one of
the key benefits python offers.


From dman@dman.ddts.net  Sat Mar 30 20:07:21 2002
From: dman@dman.ddts.net (dman)
Date: Sat, 30 Mar 2002 14:07:21 -0600
Subject: [Tutor] command line
In-Reply-To: <4.2.0.58.20020330095205.019ea660@pop3.norton.antivirus>
References: <DAV331Fjxe0ymQ1WE9q000078bf@hotmail.com> <DAV331Fjxe0ymQ1WE9q000078bf@hotmail.com> <4.2.0.58.20020330095205.019ea660@pop3.norton.antivirus>
Message-ID: <20020330200721.GC21408@dman.ddts.net>

On Sat, Mar 30, 2002 at 10:12:58AM -0800, Kirby Urner wrote:
 
| >I understand, though, that people with a windows background are
| >often unfamiliar with the "command line" and want a nice-looking
| >window to work with.  In addition, many windows users underestimate
| >the usefulness and power of a text editor and may not even be
| >familiar with the term "text editor".  IDLE provides both of these
| >things for that target audience.
| 
| There's also the fact that the term window in most Win*
| systems is anemic.

It's only anemic?  I thought it had massive brain damage too.  <0.1 wink>

| Having a command line history is only an option (doskey) and it's
| not very searchable.  But that's irrelevant too, because once in the
| term window's Python shell, there's no uparrow ability to grab
| previously written commands or functions, nor any scroll bar, and
| that about destroys its usability as an interactive environment.

GNU readline.  Not a win32 thing, though.  Unless I actually need a
win32 extension (to make MS Access dbs available via our web server) I
use the cygwin built python.  That one also respsonds to EOF properly
(not only is ^D the escape character, but I don't have to press
"enter" after it!).

| Maybe it's different in Win2k, where uparrow history is somehow
| available.

Not that I've noticed.  cmd.exe is far superior to command.com but
still ages behind bash.  The "DOS" terminal is only slightly better in
that it can remember output lines beyond what fits in the window.

| What's nice in shell mode is to have textbox prompts for
| function args,

Might be nice.  Probably better for beginners.  I kinda think of that
as training wheels.  JBuilder did that (for java code).  While I was
trying out JBuilder, I really didn't remember the arguments to
methods.  It didn't matter how many times I used it, either, because
it would always prompt me.  When I went back to using gvim, I had to
look up the API reference a couple times, then I'd remember the method
and could use it without those prompts.

| I immediately get a yellow rectangle next to the function
| telling me what arguments are expected and what their default
| values are.  That's nice -- even a pro doesn't want to
| memorize all the arg lists for every function. 

If there is enough consistency and intuitiveness then it isn't as bad
as it seems.  Just a personal style, I guess.

| I also like the color coding of key words.

gvim :-).  Any serious text editor will syntax highlight.

| In *nix systems, you can use bang notation to tie a file
| to the executing interpreter (#!python)

You can also do
    python -i <filename>
to drop into an interactive shell after executing the file.  You'll
have the same namespace as the file's module too.

-D

-- 

"640K ought to be enough for anybody" -Bill Gates, 1981



From dman@dman.ddts.net  Sat Mar 30 20:09:13 2002
From: dman@dman.ddts.net (dman)
Date: Sat, 30 Mar 2002 14:09:13 -0600
Subject: [Tutor] command line
In-Reply-To: <4.2.0.58.20020330103408.015da380@pop3.norton.antivirus>
References: <20020330173622.GC20525@dman.ddts.net> <DAV331Fjxe0ymQ1WE9q000078bf@hotmail.com> <DAV331Fjxe0ymQ1WE9q000078bf@hotmail.com> <4.2.0.58.20020330103408.015da380@pop3.norton.antivirus>
Message-ID: <20020330200913.GD21408@dman.ddts.net>

On Sat, Mar 30, 2002 at 10:41:11AM -0800, Kirby Urner wrote:
| At 10:12 AM 3/30/2002 -0800, Kirby Urner wrote:
| 
| >environment.  Maybe it's different in Win2k, where uparrow
| >history is somehow available.
 
| For example, in IDLE I can scroll up to any previous line
| and select it, hit enter, and get a copy available for
| editing (that's great for re-executing some function
| with lots of args, just changing one of 'em).  The mouse
| lets me go directly to any line in the history; I don't
| have to arrow through all commands in between.
| 
| And when I enter a quick and dirty function or class
| definition right in the shell (becomes 2nd nature when
| it's easy to do -- might just be a simple loop to do
| something in a module several times) I can modify the
| whole thing as a block -- it gets copied down as a
| whole.  The DOS box shell doesn't do that, not in XP,
| not in any Win* -- probably not in Linux either (although
| I haven't restored my dual boot setup on the upstairs
| box since the hard drive upgrade, so I can't double
| check that now).  Perhaps dman will let us know.

Python uses the GNU readline library just like bash and any other
decent shell.  If I am writing a block of code in the interactive
interpreter, I'll fire up gvim and write the code there and
copy-n-paste it to the interpreter.  With X, copy-n-paste is even more
convenient than in windows.

-D

-- 

(A)bort, (R)etry, (T)ake down entire network?



From hall@nhn.ou.edu  Sat Mar 30 21:31:03 2002
From: hall@nhn.ou.edu (Ike Hall)
Date: Sat, 30 Mar 2002 15:31:03 -0600
Subject: [Tutor] Revving up Tkinter/PMW
In-Reply-To: <Pine.LNX.4.44.0203261921250.394-100000@hkn.eecs.berkeley.edu>
References: <Pine.LNX.4.44.0203261921250.394-100000@hkn.eecs.berkeley.edu>
Message-ID: <200203302114.g2ULE5530388@phyast.nhn.ou.edu>

Thanks Danny,
I don't think that I'll be able to introduce a new version of Tkinter, as I 
am doing this for a large collaboration, and getting new base software 
introduced takes some time, but I will make that suggestion.  I will however 
look into the prospects for double buffering

thanks

Ike 

On Friday 29 March 2002 04:25 pm, you wrote:
> On Tue, 26 Mar 2002, Isaac Hall wrote:
> > hi tutors, gurus, and newbies alike!
> >
> > I have a question that has been eating at my sould for the past few
> > weeks (well, not quite eating, maybe sipping?).  Anyway, Im building a
> > rather large monitoring application that is supposed to take in a rather
> > large ammount of data (~10,000 objects....scalers, histograms, circular
> > buffers(ie, pie charts), and bitmasks) and display them graphically, and
> > to be updated somewhere on the order of once every 5 to 10 seconds.
> > Anyway, Ive been working on this rather on and off for the past few
> > months and learning python (and SWIG) as I go, so I don't feel like Im
> > fully aware of many of the methods available for creating faster
> > graphics in python/Tkinter/PMW, and I haven't seen much in the way of
> > books and such that help in this area.  Currently, the graphics are
> > displayed in a multi-layered(tabbed) PMW notebook, and I was wondering
> > this:
> >
> > Is there any way to make the thing only update the page that is being
> > viewed?
>
> Has anyone responded to your question yet?
>
> Fredrik Lundh (effbot) has been working on revamping Tkinter to make it
> faster:
>
>     http://effbot.org/tkinter/index.htm
>
> so you may want to try Tkinter 3000 to see if it helps performance any.
> The technique you're thinking of is "double buffering", but I haven't been
> able to pull anything in about it from Google yet.
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


From erikprice@mac.com  Sat Mar 30 21:28:23 2002
From: erikprice@mac.com (Erik Price)
Date: Sat, 30 Mar 2002 16:28:23 -0500
Subject: [Tutor] OOPs?
In-Reply-To: <4.2.0.58.20020329084737.019d2850@pop3.norton.antivirus>
Message-ID: <10BEB767-4425-11D6-B06D-00039351FE6A@mac.com>

On Friday, March 29, 2002, at 12:49  PM, Kirby Urner wrote:

> You could have a stock class and then stuff stock objects made
> from it into a dictionary (similar to a stock list -- but just
> for looking up by ticker code).
>
> Here's a simple module, for pedagogical purposes only, as you
> say (not to make a mint).

Kirby,

Perhaps it was this example (something I could understand), or perhaps 
it was that I was paying better attention, or perhaps it's that I know a 
bit more about Python now, but the example code you gave was excellent, 
and really helped me understand a thing or two about the process of 
constructing programs in Python.  I always do better when I have someone 
else's work to imitate than when I try to forge off on my own (I'm not 
very original).  I'm curious -- how long did it take you to come up with 
this module?  Although I'm new to programming, even still I think it 
would have taken me a long time to come up with something like this.

Just curious,


Erik



From erikprice@mac.com  Sat Mar 30 21:35:26 2002
From: erikprice@mac.com (Erik Price)
Date: Sat, 30 Mar 2002 16:35:26 -0500
Subject: [Tutor] simple problem
In-Reply-To: <Pine.LNX.4.44.0203291350410.21700-100000@hkn.eecs.berkeley.edu>
Message-ID: <0C5CA8D6-4426-11D6-B06D-00039351FE6A@mac.com>

On Friday, March 29, 2002, at 05:11  PM, Danny Yoo wrote:

> IDLE is a great text editor for writing Python, and I have a small
> tutorial on using it here:
>
>     http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro
>
> It should show you how to write prepared programs for Python.  I have to
> admit, though, that the tutorial is somewhat tailored for Windows users,
> though I hope it's not too platform dependent.
>
>
> There are some people here on Tutor that use Mac OS X, so perhaps they 
> can
> comment on their experiences with it?

I actually have to confess that I haven't had time to try IDLE on OS X.  
I don't have Xwindows installed on my home machine, but I only do Python 
on my home machine right now, so I pretty much use BBEdit for text 
editing and the interpreter for playing.

AFAIK you need Xwindows or you need to install the Tk libraries (no idea 
how to do that) if you want to use IDLE on Mac OS X.


Erik



From urnerk@qwest.net  Sat Mar 30 21:39:02 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Sat, 30 Mar 2002 13:39:02 -0800
Subject: [Tutor] command line
In-Reply-To: <XFMail.20020330105609.shalehperry@attbi.com>
References: <4.2.0.58.20020330103408.015da380@pop3.norton.antivirus>
Message-ID: <4.2.0.58.20020330133655.00d269f0@pop3.norton.antivirus>

At 10:56 AM 3/30/2002 -0800, Sean 'Shaleh' Perry wrote:

>no, the python shell is just a shell like bash.  IDLE does have
>some of those nifty IDE features people used to Window's coding
>expect.

Nifty IDE features are not specific to Windows (nor is IDLE).
In my experience, pro programmers appreciate time-saving
and productivity-enhancing features, and Windows has no
monopoly on these.

>The important lesson to walk away with is this: if you are not
>using an interactive python interpreter while coding and
>experimenting you are missing out on one of the key benefits
>python offers.

This I heartily agree with.

Kirby



From dman@dman.ddts.net  Sat Mar 30 21:46:29 2002
From: dman@dman.ddts.net (dman)
Date: Sat, 30 Mar 2002 15:46:29 -0600
Subject: [Tutor] command line
In-Reply-To: <4.2.0.58.20020330133655.00d269f0@pop3.norton.antivirus>
References: <4.2.0.58.20020330103408.015da380@pop3.norton.antivirus> <4.2.0.58.20020330133655.00d269f0@pop3.norton.antivirus>
Message-ID: <20020330214629.GB22149@dman.ddts.net>

On Sat, Mar 30, 2002 at 01:39:02PM -0800, Kirby Urner wrote:
| At 10:56 AM 3/30/2002 -0800, Sean 'Shaleh' Perry wrote:
| 
| >no, the python shell is just a shell like bash.  IDLE does have
| >some of those nifty IDE features people used to Window's coding
| >expect.
| 
| Nifty IDE features are not specific to Windows (nor is IDLE).

Do you know of any non-windows IDEs that have these features?  (apart
from IDLE since I assume that has the same features everywhere it is)
New converts to *nix often ask (in deb-user at least) where the IDEs
are and why it's so hard to find a fully functional/stable IDE.  The
usual answer is "unix _is_ an IDE -- pick your (advanced) editor and
learn the rest of the OS for the full effect".

| In my experience, pro programmers appreciate time-saving
| and productivity-enhancing features,

Right.

| and Windows has no monopoly on these.

Given that stability and reliability are, IMHO, the most critical
time-saving and productivity-enhancing features, that's an
understatement.  <wink> <duck>

| >The important lesson to walk away with is this: if you are not
| >using an interactive python interpreter while coding and
| >experimenting you are missing out on one of the key benefits
| >python offers.
| 
| This I heartily agree with.

I don't know anyone who doesn't :-).

-D

-- 

"640K ought to be enough for anybody" -Bill Gates, 1981



From erikprice@mac.com  Sat Mar 30 21:46:39 2002
From: erikprice@mac.com (Erik Price)
Date: Sat, 30 Mar 2002 16:46:39 -0500
Subject: [Tutor] command line
In-Reply-To: <20020330200721.GC21408@dman.ddts.net>
Message-ID: <9D8FA3A4-4427-11D6-B06D-00039351FE6A@mac.com>

On Saturday, March 30, 2002, at 03:07  PM, dman wrote:

> You can also do
>     python -i <filename>
> to drop into an interactive shell after executing the file.  You'll
> have the same namespace as the file's module too.

Can I ask an unrelated question?  What does that mean -- "you'll have 
the same namespace as the file's module too".

I understand the difference between local/global/builtin namespaces (I 
think): the local namespace is for names specific to the current context 
(a function or class or module, for instance), the global namespace is 
for names available to all contexts, and the builtin namespace is for 
names that are predefined by Python and often start with two underscores.

I'm guessing that the quote above means that the names available to the 
script are now available to the user in the shell, when the shell is 
invoked in this fashion, such that if the script imported from module 
"Stock", all of the names in "Stock" are available and don't need to be 
imported.  But if someone could confirm this it would help me grasp the 
concept of namespaces better.

Thanks,
Erik



From urnerk@qwest.net  Sat Mar 30 21:47:25 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Sat, 30 Mar 2002 13:47:25 -0800
Subject: [Tutor] command line
In-Reply-To: <20020330200721.GC21408@dman.ddts.net>
References: <4.2.0.58.20020330095205.019ea660@pop3.norton.antivirus>
 <DAV331Fjxe0ymQ1WE9q000078bf@hotmail.com>
 <DAV331Fjxe0ymQ1WE9q000078bf@hotmail.com>
 <4.2.0.58.20020330095205.019ea660@pop3.norton.antivirus>
Message-ID: <4.2.0.58.20020330133919.00951f00@pop3.norton.antivirus>

At 02:07 PM 3/30/2002 -0600, you wrote:


>It's only anemic?  I thought it had massive brain damage
>too.  <0.1 wink>

Severe limitations, no question.

>| What's nice in shell mode is to have textbox prompts for
>| function args,
>
>Might be nice.  Probably better for beginners.  I kinda think of that
>as training wheels.  JBuilder did that (for java code).  While I was
>trying out JBuilder, I really didn't remember the arguments to
>methods.  It didn't matter how many times I used it, either, because
>it would always prompt me.  When I went back to using gvim, I had to
>look up the API reference a couple times, then I'd remember the method
>and could use it without those prompts.

But then there's all the functions you code yourself over
the years -- not just talking about Standard Library API
(of whatever language).  Arg prompts are not just mickey-mouse
add-ons for beginners IMO, nor is keyword color-coding.


>If there is enough consistency and intuitiveness then it isn't as bad
>as it seems.  Just a personal style, I guess.

One can never memorize all the args.  Tips help, save
time.

>| I also like the color coding of key words.
>
>gvim :-).  Any serious text editor will syntax highlight.

Sure, but IDLE and other similar shells color code the syntax
as you enter it at the prompt -- text editors aren't
interactive like that, e.g. don't do Python list comprehensions
on the fly, in "calculator mode".

>| In *nix systems, you can use bang notation to tie a file
>| to the executing interpreter (#!python)
>
>You can also do
>     python -i <filename>
>to drop into an interactive shell after executing the file.  You'll
>have the same namespace as the file's module too.

Yeah, same in Windows.

Kirby



From urnerk@qwest.net  Sat Mar 30 21:52:08 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Sat, 30 Mar 2002 13:52:08 -0800
Subject: [Tutor] OOPs?
In-Reply-To: <10BEB767-4425-11D6-B06D-00039351FE6A@mac.com>
References: <4.2.0.58.20020329084737.019d2850@pop3.norton.antivirus>
Message-ID: <4.2.0.58.20020330134818.00adf920@pop3.norton.antivirus>

At 04:28 PM 3/30/2002 -0500, Erik wrote:

>I'm curious -- how long did it take you to come up with
>this module?  Although I'm new to programming, even still
>I think it would have taken me a long time to come up
>with something like this.
>
>Just curious,

I'm glad you found the code useful Erik.  I learned
something too.  I don't usually code menu loops around
raw_input, so this helped me explore doing that, and
I haven't used the shelve module a lot (to achieve
persistence -- shelve uses pickle and some generic
dbm, whatever the system supports, in the background).

So there was some pausing to read docs re shelve and
then I went back and recoded a bit to make the data
live in a dictionary during the menu loop.  Lots of
testing and reloading in IDLE as I debugged.  So all
told I'd say 45 mins to an hour, something like that.
But time flies when you're having fun -- coulda been
longer.

Kirby




From urnerk@qwest.net  Sat Mar 30 22:05:03 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Sat, 30 Mar 2002 14:05:03 -0800
Subject: [Tutor] command line
In-Reply-To: <20020330214629.GB22149@dman.ddts.net>
References: <4.2.0.58.20020330133655.00d269f0@pop3.norton.antivirus>
 <4.2.0.58.20020330103408.015da380@pop3.norton.antivirus>
 <4.2.0.58.20020330133655.00d269f0@pop3.norton.antivirus>
Message-ID: <4.2.0.58.20020330140039.019d58e0@pop3.norton.antivirus>

>
>Do you know of any non-windows IDEs that have these features?

Maybe Kylix2 for Linux (Delphi).

Then of course there's KDevelop for C/C++
http://www.kdevelop.org/graphics/pic_corner/kdevelop-2.0.gif

Certainly this list could be extended.

Kirby



From erikprice@mac.com  Sat Mar 30 23:16:41 2002
From: erikprice@mac.com (Erik Price)
Date: Sat, 30 Mar 2002 18:16:41 -0500
Subject: [Tutor] OOPs?
In-Reply-To: <4.2.0.58.20020330134818.00adf920@pop3.norton.antivirus>
Message-ID: <31F47506-4434-11D6-B06D-00039351FE6A@mac.com>

On Saturday, March 30, 2002, at 04:52  PM, Kirby Urner wrote:

> I'm glad you found the code useful Erik.  I learned
> something too.  I don't usually code menu loops around
> raw_input, so this helped me explore doing that, and
> I haven't used the shelve module a lot (to achieve
> persistence -- shelve uses pickle and some generic
> dbm, whatever the system supports, in the background).

So, I rewrote your code with extra comments so that I could map what 
exactly is going on in this module.  I've attached the commented code to 
the end of this email, if you have a minute and don't mind reading the 
comments and letting me know if any of them are off-base that would be 
great -- I've made some assumptions about what some things mean.  But 
you don't have to if you're busy.  (Also, do you need to add the shebang 
line to the top of modules, or just executable scripts?)

BUT... despite that, I'm finding that I can't seem to get the code to 
work right.  I can import 'stocks' because I am firing up the 
interpreter from the directory where I keep my homemade (or tutored as 
in this case) modules.  And I can call the mainmenu() function of the 
'stocks' module.  Once there, I can call the quit() function just fine.  
But it seems that my addstock() function, or perhaps it's my getcode() 
function, aren't working right.

If I choose "1", then I am prompted for a stock name and a price -- 
seems to work great.  I enter each.  But if I choose "3" to call the 
dumphist() function, I am always greeted with the exception message from 
the try block in getcode():  "Not a legal code"  Then the main menu 
comes back again (as expected, since getcode() returned a zero).

So, looking into the getcode() function, I can see that the try block is 
failing because the value of 'stockdict[code]' cannot be assigned to the 
'stockobj' name.  Since I'm assuming my Python (2.2) program is working 
fine, it must be due to the lack of a 'stockdict[code]' element in the 
stockdict dictionary.  So I go and look to see where this is generated, 
to see if my code is erroneous there.

Well, sure enough, the stockdict dictionary is assigned its associative 
indexes and its values at the end of the addstock() function.  
Essentially, the value of the 'code' variable (which is the result of 
raw_input()) is used as the index, and the value of the element is a new 
instance of the Stock class, with 'code' (the user input), 'price' (the 
second user input), 'time' (where did this come from?), and 'asctime()' 
provided as arguments to the new instance.

Here is where I've discovered my problem.  I'm going to continue with 
this email anyway, even though just now in writing it I figured out what 
was wrong, so hopefully this lesson will go into the archives and can 
help someone else someday (I'm a big fan of being a historian when I 
can).

There is no 'time' argument to the Stock class.  I mis-typed the code 
Kirby posted as I was reading it from my mail reader into my text 
editor.  I don't like copy and paste for the same reason I don't like 
hi-liting textbooks -- too easy, and too easy to miss details.  But the 
drawbacks are that you can make mistakes, and it looks like I did.  I 
had written this line as

stockdict[code] = Stock(code, price, time, asctime())

instead of the way I should have written it

stockdict[code] = Stock(code, price, time.asctime())

Now I'm going to correct my error and test the code again....

Yup!  It works!  I assigned the stock of the company I work for a measly 
11 cents per share, and then assigned them an even lower 8 cents per 
share, then I dumped the data -- here it is:

[('$0.11', 'Sat Mar 30 18:13:30 2002'), ('$0.08', 'Sat Mar 30 18:13:57 
2002')]



Okay, so I should probably save bandwidth by not posting this now but 
it's not like there's no value in this, and I still have the questions 
from the very top... thanks in advance Kirby (and spending an hour using 
this code has really taught me a lot!).



Erik


(The following is the code I was using, including the error [this means 
that this code won't work!  There's a typo in the addstock() function]:)





#!/usr/bin/python

import time, shelve

class Stock:
	"Simple stock class, keeps history using current time"
	
	# the constructor defines some attributes of the instance
	def __init__(self, code, price, datetime):
		self.code = code
		
		# the history is a dictionary that tracks the instance's
		# prices and the datetimes of those prices
		self.history = [(price, datetime)]
		self.price = price
	
	# the newprice() method adds a new price/datetime to the
	# instance's history dictionary
	def newprice(self, price, datetime):
		self.history.append((price, datetime))
	
	# the showhist() method prints the history of the instance
	# (a dictionary)
	def showhist(self):
		return self.history

def getcode():
	"Handle cases where user inputs code we don't have"
	
	# accept a stock code
	code = raw_input("Code? > ")
	
	# check to see if stock code is in the dictionary
	try:
		stockobj = stockdict[code]
	# if it can't be done, print an error message and exit
	except:
		print "Not a legal code"
		return 0
	# if it is, return the object represented by the 'stockdict[code]'
	# element of the dictionary that keeps track of stock objects by code
	return stockobj

def addstock():
	"Add new stock, any code acceptable"
	
	# accept a stock code
	code = raw_input("Code? > ")
	# accept a price
	price = raw_input("Price? > ")	
	# assign an instance of the Stock class to 'stockdict[code]'
	stockdict[code] = Stock(code, price, time, asctime())

def update():
	# assign to 'obj' an instance of the Stock class from getcode()
	obj = getcode()
	
	# if a Stock class instance was pulled and assigned to 'obj'
	if obj:
		# accept a price
		price = raw_input("Price? > ")
		# call the newprice() method of the instance
		obj.newprice(price, time.asctime())
		# print the number of items in the instance's history dictionary
		print "%s prices on file" % len(obj.history)
		# would not have to do next step if using real dictionary
		stockdict[obj.code] = obj	# overwrites old copy

def dumphist():
	# assign to 'obj' an instance of the Stock class from getcode()
	obj = getcode()
	# if a Stock class instance was pulled and assigned to 'obj'
	if obj:
		# call the 'showhist()' method of the Stock instance 'obj',
		# and assign it to the 'hist' variable
		hist = obj.showhist()
		# print the value of the 'hist' variable
		print hist

def quit():
	# call the close() method of the stockdict object
	stockdict.close()
	print "Stocks saved"

def mainmenu():
	"Using dictionary-like syntax to do file i/o"
	
	# globalize the stockdict name
	global stockdict
	# create a 'stockdict' object and give it the current value
	# of 'shelve.open("mystocks")'
	stockdict = shelve.open("mystocks")
	# create a tuple called 'callables'
	callables = [quit, addstock, update, dumphist]
	# display the menu
	while 1:
		print \
		"""
		(1) add new stock
		(2) update price of stock
		(3) dump history of stock
		(0) save/quit
		"""
		
		# accept a selection
		sel = raw_input("Your choice: > ")
		try:
			# make sel an integer
			sel = int(sel)
			# test that sel is less than or equal to 3
			# and greater than or equal to 0
			assert int(sel) <= 3 and int(sel) >= 0
			# call whichever function is represented by sel
			callables[int(sel)]()
			if int(sel) == 0:
				break
		# if the try fails
		except:
			print "Not a legal choice"



From pythontutor@venix.com  Sat Mar 30 23:24:52 2002
From: pythontutor@venix.com (Lloyd Kvam)
Date: Sat, 30 Mar 2002 18:24:52 -0500
Subject: [Tutor] command line
References: <9D8FA3A4-4427-11D6-B06D-00039351FE6A@mac.com>
Message-ID: <3CA64944.20200@venix.com>

I'll take a stab at answering this.
(Dman, thanks for the -i tip.  Yet another useful tidbit learned
from this list.)

 >>> print __name__
__main__
 >>> import DB		# DB contains line print __name__
DB

The python interpreter provides a namespace called __main__.  Each imported
module (file) has a namespace named for the module.  When a module (file) is
run directly it is using the __main__ namespace.  With the -i argument,
the interpreter will continue operating, hooking itself to the keyboard
and monitor for interactive use.

Only names in the builtin name space can be accessed from anywhere without
qualifiers.  To access something in DB, I must use "DB.something".  In C,
functions and extern variables are truly global, accessible anywhere
without qualifiers.  In Python a name is accessible without qualifiers
only if it is local, in the module, or in builtins.  The globals
keyword sounded to me like it could cross module boundaries.  It doesn't.

Namespace names generally seem to be interpreted relative to __main__.  I
have a module DB.py with some useful database functions.  Other modules
a and b can import DB.  If module a causes DB.x to bind to a value of 3,
I can use module b to print DB.x and see that value.  Using the syntax,
	from <module> import *
muddles how namespaces work.  Wesley Chun's book has an example of this
muddling on page 391.

I do not yet have a solid handle on how namespaces, files and packages
interact.

Erik Price wrote:

> 
> On Saturday, March 30, 2002, at 03:07  PM, dman wrote:
> 
>> You can also do
>>     python -i <filename>
>> to drop into an interactive shell after executing the file.  You'll
>> have the same namespace as the file's module too.
> 
> 
> Can I ask an unrelated question?  What does that mean -- "you'll have 
> the same namespace as the file's module too".
> 
> I understand the difference between local/global/builtin namespaces (I 
> think): the local namespace is for names specific to the current context 
> (a function or class or module, for instance), the global namespace is 
> for names available to all contexts, and the builtin namespace is for 
> names that are predefined by Python and often start with two underscores.
> 
> I'm guessing that the quote above means that the names available to the 
> script are now available to the user in the shell, when the shell is 
> invoked in this fashion, such that if the script imported from module 
> "Stock", all of the names in "Stock" are available and don't need to be 
> imported.  But if someone could confirm this it would help me grasp the 
> concept of namespaces better.
> 
> Thanks,
> Erik
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582



From dman@dman.ddts.net  Sat Mar 30 23:37:25 2002
From: dman@dman.ddts.net (dman)
Date: Sat, 30 Mar 2002 17:37:25 -0600
Subject: FW: Re: [Tutor] command line
Message-ID: <20020330233725.GE22889@dman.ddts.net>

I sent this privately because I missed the Cc: in the headers.  Here
it is for the benefit of the rest of you.

-D


----- Forwarded message from dman <dman@dman.ddts.net> -----
From: dman <dman@dman.ddts.net>
To: Erik Price <erikprice@mac.com>
Subject: Re: [Tutor] command line
Date: Sat, 30 Mar 2002 16:50:25 -0600

On Sat, Mar 30, 2002 at 05:02:04PM -0500, Erik Price wrote:
| 
| On Saturday, March 30, 2002, at 04:54  PM, dman wrote:
| 
| >If the script did
| >    import Stock
| >then you would have the name "Stock" in your namespace and it would
| >refer to the Stock module.
| >
| >If the script did (bad!)
| >    from Stock import *
| >then you would have all the names from Stock in your namespace.
| 
| Why is the second one bad?  Doesn't it achieve the same effect?  The two 
| are not the same?

No, they're not the same.  One of them creates lots of names in your
namespace and the other one doesn't.  The problem with that is
several-fold :
    1)  when you use a name, you can no longer immediately tell if it
        is a local variable, module-level variable, or something from
        a separate module

    2)  what if some (future) version of that module adds additional
        names to its namespace?  Now they are in yours as well, and
        may have a conflict with other names in your module

    3)  if the name in the module's namespace is rebound, your name
        isn't also rebound.

For a first example, here's a mistake quite a few newbies do :


#### newbie_mod

# this part is ok,
a_file = open( "data" , "r" )
print a_file
print a_file.read()

# oops
from os import *

# this doesn't mean what it seems to
another_file = open( "data" , "r" )
print another_file 
print another_file.read()



Here's another example that illustrates the other points :


######### mod1_good
import mod2

# note that the name is misleading, it really only lists the names in
# this module
print globals()
print mod2.foo
mod2.bar()
print mod2.foo


######### mod1_bad
from mod2 import *

print globals()
print mod2.foo
print foo
mod2.bar()
print mod2.foo
print foo


######### mod2

foo = "spam"
def bar() :
    global foo
    foo = "eggs"


-D

-- 

He who belongs to God hears what God says.  The reason you do not hear
is that you do not belong to God.
        John 8:47


----- End forwarded message -----

-- 

Through love and faithfulness sin is atoned for;
through the fear of the Lord a man avoids evil.
        Proverbs 16:6



From urnerk@qwest.net  Sun Mar 31 00:34:01 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Sat, 30 Mar 2002 16:34:01 -0800
Subject: [Tutor] OOPs?
In-Reply-To: <31F47506-4434-11D6-B06D-00039351FE6A@mac.com>
References: <4.2.0.58.20020330134818.00adf920@pop3.norton.antivirus>
Message-ID: <4.2.0.58.20020330161652.00d246f0@pop3.norton.antivirus>

>
>#!/usr/bin/python
>
>import time, shelve
>
>class Stock:
>         "Simple stock class, keeps history using current time"
>
>         # the constructor defines some attributes of the instance
>         def __init__(self, code, price, datetime):
>                 self.code = code
>
>                 # the history is a dictionary that tracks the instance's

Actually, history is just a simple list [], containing
(price, datetime) tuples () -- not a dictionary {}.

>                 # prices and the datetimes of those prices
>                 self.history = [(price, datetime)]
>                 self.price = price
>
>         # the newprice() method adds a new price/datetime to the
>         # instance's history dictionary

history *list* -- I won't keep saying it, now that you've
got it.

>         def newprice(self, price, datetime):
>                 self.history.append((price, datetime))
>
>         # the showhist() method prints the history of the instance
>         # (a dictionary)
>         def showhist(self):
>                 return self.history
>
>def getcode():
>         "Handle cases where user inputs code we don't have"
>
>         # accept a stock code
>         code = raw_input("Code? > ")
>
>         # check to see if stock code is in the dictionary
>         try:
>                 stockobj = stockdict[code]
>         # if it can't be done, print an error message and exit
>         except:
>                 print "Not a legal code"
>                 return 0

Another way of doing this is stockobj = stockdict.get(code,0)
-- would have to rewrite the calling function a tiny bit.
This latter syntax becomes an option only in version 2,
where I substituted a real dictionary for the shelve file
pseudo-dictionary.

>         # if it is, return the object represented by the 'stockdict[code]'
>         # element of the dictionary that keeps track of stock objects by code
>         return stockobj
>
>def addstock():
>         "Add new stock, any code acceptable"
>
>         # accept a stock code
>         code = raw_input("Code? > ")
>         # accept a price
>         price = raw_input("Price? > ")
>         # assign an instance of the Stock class to 'stockdict[code]'
>         stockdict[code] = Stock(code, price, time, asctime())

More error check could go here, if you wanted to guard
the price from being assigned some nonsense.

>def update():
>         # assign to 'obj' an instance of the Stock class from getcode()
>         obj = getcode()
>
>         # if a Stock class instance was pulled and assigned to 'obj'
>         if obj:

Actually, not that I look at it,

    stockobj = stockdict.get(code,0)

in getcode (without a try block) wouldn't require any
rewrite.  In other words, getcode could be:

def getcode():
     "Handle cases where user inputs code we don't have"
     code = raw_input("Code? > ")
     stockobj = stockdict.get(code,0)
     return stockobj

>                 # accept a price
>                 price = raw_input("Price? > ")
>                 # call the newprice() method of the instance
>                 obj.newprice(price, time.asctime())
>                 # print the number of items in the instance's history 
> dictionary
>                 print "%s prices on file" % len(obj.history)
>                 # would not have to do next step if using real dictionary
>                 stockdict[obj.code] = obj       # overwrites old copy

OK, so you're using the older version.  In the revamp, stockdict
becomes a real dictionary {}, with the shelve construct
only being used at the start and end of mainloop, to read
from and write to disk.

>def dumphist():
>         # assign to 'obj' an instance of the Stock class from getcode()
>         obj = getcode()
>         # if a Stock class instance was pulled and assigned to 'obj'
>         if obj:
>                 # call the 'showhist()' method of the Stock instance 'obj',
>                 # and assign it to the 'hist' variable
>                 hist = obj.showhist()
>                 # print the value of the 'hist' variable
>                 print hist

I also made this prettier.  Here's the up to date
version of this tutorial code:

http://www.inetarena.com/~pdx4d/ocn/python/stocks.py

>def quit():
>         # call the close() method of the stockdict object
>         stockdict.close()
>         print "Stocks saved"
>
>def mainmenu():
>         "Using dictionary-like syntax to do file i/o"
>
>         # globalize the stockdict name
>         global stockdict
>         # create a 'stockdict' object and give it the current value
>         # of 'shelve.open("mystocks")'
>         stockdict = shelve.open("mystocks")
>         # create a tuple called 'callables'
>         callables = [quit, addstock, update, dumphist]
>         # display the menu

No, wait, you *are* using the more recent.  OK, well then
update() could be simpler -- check link.  I see I failed to
simplify it in my post to this list.

>         while 1:
>                 print \
>                 """
>                 (1) add new stock
>                 (2) update price of stock
>                 (3) dump history of stock
>                 (0) save/quit
>                 """
>
>                 # accept a selection
>                 sel = raw_input("Your choice: > ")
>                 try:
>                         # make sel an integer
>                         sel = int(sel)

Note that this will fail if the user type in 'a' or something
that can't convert to int.

>                         # test that sel is less than or equal to 3
>                         # and greater than or equal to 0

But if it passes this first test then....

>                         assert int(sel) <= 3 and int(sel) >= 0
>                         # call whichever function is represented by sel
>                         callables[int(sel)]()
>                         if int(sel) == 0:
>                                 break
>                 # if the try fails
>                 except:
>                         print "Not a legal choice"

Looks like you understand quite well.

Thanks for sharing your comments.

Kirby



From urnerk@qwest.net  Sun Mar 31 00:42:35 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Sat, 30 Mar 2002 16:42:35 -0800
Subject: [Tutor] command line
In-Reply-To: <20020330233145.GC22889@dman.ddts.net>
References: <4.2.0.58.20020330133919.00951f00@pop3.norton.antivirus>
 <4.2.0.58.20020330095205.019ea660@pop3.norton.antivirus>
 <DAV331Fjxe0ymQ1WE9q000078bf@hotmail.com>
 <DAV331Fjxe0ymQ1WE9q000078bf@hotmail.com>
 <4.2.0.58.20020330095205.019ea660@pop3.norton.antivirus>
 <4.2.0.58.20020330133919.00951f00@pop3.norton.antivirus>
Message-ID: <4.2.0.58.20020330163432.00d26dc0@pop3.norton.antivirus>

At 05:31 PM 3/30/2002 -0600, dman wrote:

>Don't you use consistency there too?

Not so much that I don't appreciate having call tips.

>One rule of thumb : don't pass a million arguments to
>a function.

Good advice.

>If you (think you) need to, it needs some redesign
>and refactoring.  (I haven't gone there, but I've heard
>of MFC)

gcc takes plenty of command line args too -- of course
many are optional (and Python makes it very easy to
have lots of optional args -- way cool).


>| Arg prompts are not just mickey-mouse add-ons for beginners IMO,
>
>Not to try and dispute you, but vim has this neat feature
>where if you press "K" on a word, it invokes man on that
>word.  This is great for stuff like the C library that has
>a manpage for each function.

Agreed.


>| nor is keyword color-coding.
>
>Not at all.  Syntax highlighting (number, strings, built-in names,
>standard exceptions, the notes 'XXX' 'FIXME' and 'TODO' in a comment,
>in addition to keywords) is a must for any editor.

Nice to have in an interactive shell too.  Is there a version
of bash the color codes key words as you enter them on
the command line?  Like grep comes up in blue, maybe with
call tips?  Could be done, as an X term window is as much a
GUI window as any (it's painted).


>| >| I also like the color coding of key words.
>| >
>| >gvim :-).  Any serious text editor will syntax highlight.
>|
>| Sure, but IDLE and other similar shells color code the syntax
>| as you enter it at the prompt -- text editors aren't
>| interactive like that, e.g. don't do Python list comprehensions
>| on the fly, in "calculator mode".
>
>If I'm just doing some tests interactively I usually don't notice so
>much.  Just some quick-n-dirty typing.  Readline's vi bindings aren't
>quite as good as vim's, but it works.  (actually, I'd rather have vi
>keys than color, if I have to make a choice)

I like vim's color bindings too -- especially after I wrote
my own to match IDLE color scheme :-D (cite some earlier
post).

BTW, I notice in the latest issue of Linux Journal that
Alex Martelli has an article on Python and the coolness
thereof.  Of course the expected audience is Linux users.
He shows them IDLE, but mentions "old timers" sometimes
prefer just the shell and a text editor.  Guess that makes
you an old timer ("damn straight, and proud of it").  :-D

Kirby



From ak@silmarill.org  Sun Mar 31 10:14:37 2002
From: ak@silmarill.org (Andrei Kulakov)
Date: Sun, 31 Mar 2002 05:14:37 -0500
Subject: [Tutor] command line
In-Reply-To: <DAV331Fjxe0ymQ1WE9q000078bf@hotmail.com>
References: <DAV331Fjxe0ymQ1WE9q000078bf@hotmail.com>
Message-ID: <20020331101437.GA8142@ak.silmarill.org>

On Sat, Mar 30, 2002 at 11:03:35AM -0600, Cameron Stoner wrote:
> hi all,
> 
> Why would you use the command line Python instead of the IDLE?
> 
> Cameron Stoner
>
I like to use vim commands to edit any substantial amount of code - hjkl
and the like for movement, I can't stand cursor keys. 

No place like home (row) :-). 

Python interpreter is plenty enough for me to look things up quickly.

I'd recommend people to at least try IDLE if they use windows (I use
debian), and particularly if they don't use vim.


 - Andrei

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org


From seedseven@home.nl  Sun Mar 31 15:40:24 2002
From: seedseven@home.nl (ingo)
Date: Sun, 31 Mar 2002 17:40:24 +0200
Subject: [Tutor] regular expression
Message-ID: <200203311740240328.01E5AFD0@mail>

>From an HTML-file I want to strip all css related stuff. Using re.sub
looks ideal because in some cases the css has to be replaced by
something else.
The problem I run into is that I can't find a way to match 'class=".."'
with one expression, without matching the string when it is outside a
tag.

in t I don't want to have a match for class="Three"

>>> import re
>>> t=r'<table class="One"><tr><td class="Two"> class="Three" </td>'
>>> pat1=re.compile(r'<.*?class=".*?".*?>')
>>> pat2=re.compile(r'class=".*?"')
>>> p=pat1.search(t)
>>> p=pat2.search(t,p.start(),p.end())
>>> p.group()
'class="One"'
>>> 

Doing it in two steps is possible but now re.sub can't be used. Is
there a way to do it in one go?

Ingo



From erikprice@mac.com  Sun Mar 31 16:09:31 2002
From: erikprice@mac.com (Erik Price)
Date: Sun, 31 Mar 2002 11:09:31 -0500
Subject: [Tutor] command line
In-Reply-To: <20020331101437.GA8142@ak.silmarill.org>
Message-ID: <AF7F3569-44C1-11D6-8BD4-00039351FE6A@mac.com>

On Sunday, March 31, 2002, at 05:14  AM, Andrei Kulakov wrote:

> I like to use vim commands to edit any substantial amount of code - hjkl
> and the like for movement, I can't stand cursor keys.
>
> No place like home (row) :-).
>
> Python interpreter is plenty enough for me to look things up quickly.

Similarly, but differently, I can't stand cursor keys -- but I prefer 
the emacs bindings (nkpf).  I use the interpreter/shell (IOW call python 
from the command line with no args), but I've noticed that I can't use 
the typical emacs key bindings to move backward and forward through my 
history.  Is this the way it is, or is there some way I can configure 
the interpreter to return lines from my command history using these 
bindings?  I have my bash shell environment variable 
EDITOR=/usr/bin/emacs and this works for all of my other programs, but 
not for Python.

Does anyone know if this feature exists?


TIA,

Erik



From idiot1@netzero.net  Sun Mar 31 01:18:47 2002
From: idiot1@netzero.net (kirk Bailey)
Date: Sat, 30 Mar 2002 20:18:47 -0500
Subject: [Tutor] hacking 101
Message-ID: <3CA663F7.9D143E1B@netzero.net>

OK, comes now before you an unuual question.

I want to learn about hacking a computer.

See, I Want to complete the program for creating a list using a web
form. BUT I kow that it is possible to insert escape codes and such to
take over control and do unintended things, but I know nothing of how
this is done. I WANT TO UNDERSTAND IT SO I CAN WATCH FOR SUCH ATTEMPTS
AND ABORT THE PROCESS if they are detected. To PREVENT hcking, one
must UNDERSTAND hacking. Any takers? Feel free to reply to me off list
if you preferr.


-- 
 
end
	    Respectfully,
			 Kirk D Bailey


+---------------------"Thou Art Free." -Eris----------------------+
| http://www.howlermonkey.net mailto:highprimate@howlermonkey.net |
| http://www.tinylist.org  +--------+  mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking---------------------+
                           +--------+

NOTE: By sending SPAM to this address you agree to pay me a service
fee of $100 for the service of receiving,  storing,  examining, and
deleting your piece of SPAM. I am a postmaster, and take a dim view
of such.



From python@rcn.com  Sun Mar 31 19:27:02 2002
From: python@rcn.com (Raymond Hettinger)
Date: Sun, 31 Mar 2002 14:27:02 -0500
Subject: [Tutor] hacking 101
References: <3CA663F7.9D143E1B@netzero.net>
Message-ID: <000701c1d8ea$09ad8c40$ec61accf@othello>

If your goal is to increase security, your best bet is to stick with the
basics:

-- use virus protection software
-- increase the security level on your browser
-- disable automatic scripts in Outlook and Word
-- limit physical access to you machine
-- make regular backups
-- don't run software from an untrusted source
-- use firewalls for your server
-- avoid python's eval, exec, and input like the plague
-- be nice and don't make any real hackers mad

Raymond Hettinger



----- Original Message -----
From: "kirk Bailey" <idiot1@netzero.net>
To: "tutor" <tutor@python.org>
Sent: Saturday, March 30, 2002 8:18 PM
Subject: [Tutor] hacking 101


> OK, comes now before you an unuual question.
>
> I want to learn about hacking a computer.
>
> See, I Want to complete the program for creating a list using a web
> form. BUT I kow that it is possible to insert escape codes and such to
> take over control and do unintended things, but I know nothing of how
> this is done. I WANT TO UNDERSTAND IT SO I CAN WATCH FOR SUCH ATTEMPTS
> AND ABORT THE PROCESS if they are detected. To PREVENT hcking, one
> must UNDERSTAND hacking. Any takers? Feel free to reply to me off list
> if you preferr.
>
>
> --
>
> end
>     Respectfully,
> Kirk D Bailey
>
>
> +---------------------"Thou Art Free." -Eris----------------------+
> | http://www.howlermonkey.net mailto:highprimate@howlermonkey.net |
> | http://www.tinylist.org  +--------+  mailto:grumpy@tinylist.org |
> +------------------Thinking| NORMAL |Thinking---------------------+
>                            +--------+
>
> NOTE: By sending SPAM to this address you agree to pay me a service
> fee of $100 for the service of receiving,  storing,  examining, and
> deleting your piece of SPAM. I am a postmaster, and take a dim view
> of such.
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



From python@rcn.com  Sun Mar 31 20:07:24 2002
From: python@rcn.com (Raymond Hettinger)
Date: Sun, 31 Mar 2002 15:07:24 -0500
Subject: [Tutor] regular expression
References: <200203311740240328.01E5AFD0@mail>
Message-ID: <001101c1d8ef$ad11e8e0$ec61accf@othello>

If I'm understanding what you want correctly, this should work:

>>> re.sub( r'(<[^>]+)( class[^>]+)(>)' , r'\1\3', t
'<table><tr><td> class="Three" </td>'

The strategy is find three consequetive groups and keep on the first and
third.

The first group is the tag start, an open angle bracket  followed by
anything except a close bracket.

The second group is the class assignment, a space followed  by 'class'
followed by anything other than an angle close bracket.

The third group is the close angle bracket.

When found together, the three groups are a full tag definition containing a
class definition.  Drop the middle group (the class definition) and you're
left with a classless tag.

If for some reason you want to kill the whole tag, replace r'\1\3'  with
r''.


Raymond Hettinger


Grasshopper:  'I have a problem I want to solve with regular expressions'
Master: 'Now you have two problems'


----- Original Message -----
From: "ingo" <seedseven@home.nl>
To: <tutor@python.org>
Sent: Sunday, March 31, 2002 10:40 AM
Subject: [Tutor] regular expression


> From an HTML-file I want to strip all css related stuff. Using re.sub
> looks ideal because in some cases the css has to be replaced by
> something else.
> The problem I run into is that I can't find a way to match 'class=".."'
> with one expression, without matching the string when it is outside a
> tag.
>
> in t I don't want to have a match for class="Three"
>
> >>> import re
> >>> t=r'<table class="One"><tr><td class="Two"> class="Three" </td>'
> >>> pat1=re.compile(r'<.*?class=".*?".*?>')
> >>> pat2=re.compile(r'class=".*?"')
> >>> p=pat1.search(t)
> >>> p=pat2.search(t,p.start(),p.end())
> >>> p.group()
> 'class="One"'
> >>>
>
> Doing it in two steps is possible but now re.sub can't be used. Is
> there a way to do it in one go?
>
> Ingo
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>




From i812@iname.com  Sun Mar 31 20:11:44 2002
From: i812@iname.com (Rob McGee)
Date: Sun, 31 Mar 2002 14:11:44 -0600
Subject: [Tutor] hacking 101
In-Reply-To: <3CA663F7.9D143E1B@netzero.net>
References: <3CA663F7.9D143E1B@netzero.net>
Message-ID: <20020331201144.GA22376@hal>

On Sat, Mar 30, 2002 at 08:18:47PM -0500, kirk Bailey wrote:
> OK, comes now before you an unuual question.

Not unusual at all. Quite ordinary. IIRC it's addressed somewhat in the
FAQ for the Tutor list. ;) :)

> I want to learn about hacking a computer.

I'll split a hair here and point out that the correct term is "cracking"
(hackers are honourable people who build systems, not destroy them.)

The answer varies WIDELY depending upon what OS and services are
running on your server. Common, good advice for Windows systems probably
doesn't apply to UNIX-like systems. For example, I'm not aware of any
serious anti-virus software for Linux. (Because of the underlying design
of UNIX, we're not vulnerable in the same way as Windows systems are.
No, I'm not a Linux bigot claiming that we're not vulnerable, but the
fact remains that an attacker has to look for specific holes on a Linux
box, rather than casting viral spores to the wind.)

If you're trying to secure a Win9x box, all I can say is "good luck". I
don't think it is possible. It's based on DOS, and DOS is insecure by
design. If you're trying to secure a WinNT/2K/XP box, it *may* be
possible, but you have to keep on top of all known vulnerabilities, and
apply all the patches as soon as they're announced. (That's pretty much
the right approach for UNIX systems too.)

There are many excellent sites for security of UNIX systems, and at
least to some extent those sites also address security concerns of the
NT family as well. See the "Miscellaneous Resources" links at LWN -- the
Security page for this week is at:
    http://lwn.net/2002/0328/security.php3
There are mailing lists which will keep you apprised of every security-
related development as soon as it is known.

Me, I'm just an amateur. By following the LWN Security news and
subscribing to the security mailing list for my distro (Slackware) I can
feel pretty secure. The bottom line is to consider your threat model and
act accordingly. A backbone server has more exposure than a home machine
on an intermittent dialup connection. :)

HTH,
    Rob - /dev/rob0



From glingl@aon.at  Sun Mar 31 20:44:06 2002
From: glingl@aon.at (Gregor Lingl)
Date: Sun, 31 Mar 2002 22:44:06 +0200
Subject: [Tutor] idle - namespaces (was idle)
References: <20020330011300.35030.qmail@web21104.mail.yahoo.com>
Message-ID: <004401c1d8f4$cd1af3c0$1664a8c0@mega>

This is a multi-part message in MIME format.

------=_NextPart_000_0041_01C1D905.907F24C0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

From: john public=20
To: tutor@python.org=20
I created a module( I think I am using the right word ) in Idle called =
trash.py, I use it for my throw away code. However I just noticed =
something, when I delete all the code to write some more throw away code =
the variables and I think also other things do not get deleted. How do I =
delete them?  John

I find this an interesting question. (Although it probably
does not concern only IDLE but will also occur when working
with the interactive interpreter)=20
If you start IDLE, you can look for existing names:

>>> dir()
['__builtins__', '__doc__', '__name__']
>>> __name__
'__main__'
>>>=20

If you have, say, the following in trash:

a =3D 3

def foo(x):
    return x*x

and then run trash, you will find:

>>> dir()
['__builtins__', '__doc__', '__name__', 'a', 'foo']
>>>=20

Now you can

>>> del a
>>> dir()
['__builtins__', '__doc__', '__name__', 'foo']
>>>=20


But if you try to delete several items from a list, this doesn't work,
because of the difference between the string 'a' and the name a, I =
think:

>>> dir()
['__builtins__', '__doc__', '__name__', 'a', 'foo']
>>> dir()[3:]
['a', 'foo']
>>> for name in dir()[3:]:
     del name

=20
>>> dir()
['__builtins__', '__doc__', '__name__', 'a', 'foo']
>>> for name in dir()[3:]:
    del eval(name)
=20
Apparently eval('a') returns 3 and not a.
So how do I get acces to the Variable a via dir() ?

These reveals that there is much very mysterious to me.

Moreover if I do not run but import trash, I find:

>>> dir()
['__builtins__', '__doc__', '__name__', 'trash']
>>> dir(trash)
['__builtins__', '__doc__', '__file__', '__name__', 'a', 'foo']
>>>=20

What is this exactly?

Does=20
>>> del trash=20
>>>

now delete the names a and foo?
=20
Hopefully this thread may reveal a little bit of the inner working
as well as management of namespaces.

Gregor

P.S.: I remember that in Logo (in acient times) it was very easy to =
delete
names


------=_NextPart_000_0041_01C1D905.907F24C0
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><B>From:</B> <A title=3Dapython101@yahoo.com=20
href=3D"mailto:apython101@yahoo.com">john public</A> </DIV>
<DIV style=3D"FONT: 10pt arial">
<DIV><B>To:</B> <A title=3Dtutor@python.org=20
href=3D"mailto:tutor@python.org">tutor@python.org</A> <BR>I created a =
module( I=20
think I am using the right word ) in Idle called trash.py, I use it for =
my throw=20
away code. However I just noticed something, when I delete all the code =
to write=20
some more throw away code the variables and I think also other things do =
not get=20
deleted. How do I delete them?&nbsp;&nbsp;John</DIV></DIV>
<DIV><FONT size=3D2></FONT><FONT face=3DArial><FONT face=3D"Courier New" =

size=3D2></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial><FONT face=3D"Courier New" =
size=3D2></FONT></FONT><FONT=20
face=3DArial><FONT face=3D"Courier New" size=3D2>I find this an =
interesting question.=20
(Although it probably</FONT></FONT></DIV>
<DIV><FONT size=3D2>does not concern only IDLE but will also occur when=20
working</FONT></DIV>
<DIV><FONT size=3D2>with the interactive interpreter)</FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>If you start IDLE, you can look for existing=20
names:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT><FONT face=3DArial><FONT face=3D"Courier New" =

size=3D2>&gt;&gt;&gt; dir()<BR>['__builtins__', '__doc__',=20
'__name__']<BR>&gt;&gt;&gt; __name__<BR>'__main__'<BR>&gt;&gt;&gt;=20
</FONT></FONT></DIV>
<DIV><FONT face=3DArial><FONT face=3D"Courier New" =
size=3D2></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial><FONT face=3D"Courier New" size=3D2>If you have, =
say, the=20
following in trash:</FONT></FONT></DIV>
<DIV><FONT face=3DArial><FONT face=3D"Courier New" =
size=3D2></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial><FONT face=3D"Courier New" size=3D2>a =3D =
3</FONT></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial><FONT face=3D"Courier New" size=3D2>def=20
foo(x):<BR>&nbsp;&nbsp;&nbsp; return x*x</FONT></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial><FONT face=3D"Courier New" size=3D2>and then run =
trash, you=20
will find:</FONT></FONT></DIV>
<DIV><FONT face=3DArial><FONT face=3D"Courier New" =
size=3D2></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial><FONT face=3D"Courier New" size=3D2>&gt;&gt;&gt; =

dir()<BR>['__builtins__', '__doc__', '__name__', 'a', =
'foo']<BR>&gt;&gt;&gt;=20
</FONT></FONT></DIV>
<DIV><FONT face=3DArial><FONT face=3D"Courier New" =
size=3D2></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial><FONT face=3D"Courier New" size=3D2>Now you=20
can</FONT></FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial><FONT face=3D"Courier New" size=3D2>&gt;&gt;&gt; =
del=20
a<BR>&gt;&gt;&gt; dir()<BR>['__builtins__', '__doc__', '__name__',=20
'foo']<BR>&gt;&gt;&gt; </DIV>
<DIV><BR></DIV></FONT></FONT>
<DIV><FONT size=3D2>But if you try to delete several items from a list, =
this=20
doesn't work,</FONT></DIV>
<DIV><FONT size=3D2>because of the difference between the&nbsp;string =
'a' and the=20
name a, I think:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>&gt;&gt;&gt; dir()<BR>['__builtins__', '__doc__', =
'__name__',=20
'a', 'foo']<BR>&gt;&gt;&gt; dir()[3:]<BR>['a', 'foo']<BR>&gt;&gt;&gt; =
for name=20
in dir()[3:]:<BR>&nbsp;&nbsp;&nbsp;&nbsp; del name</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>&nbsp;<BR>&gt;&gt;&gt; dir()<BR>['__builtins__', =
'__doc__',=20
'__name__', 'a', 'foo']<BR>&gt;&gt;&gt; for name in=20
dir()[3:]:<BR>&nbsp;&nbsp;&nbsp; del eval(name)<BR>&nbsp;<BR>Apparently=20
eval('a') returns 3 and not a.</FONT></DIV>
<DIV><FONT size=3D2>So how do I get acces to the Variable a via dir()=20
?</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>These reveals that there is much very mysterious to=20
me.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Moreover if I do not run but import trash, I=20
find:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>&gt;&gt;&gt; dir()<BR>['__builtins__', '__doc__', =
'__name__',=20
'trash']<BR>&gt;&gt;&gt; dir(trash)<BR>['__builtins__', '__doc__', =
'__file__',=20
'__name__', 'a', 'foo']<BR>&gt;&gt;&gt; </FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>What is this exactly?</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Does </FONT></DIV>
<DIV><FONT size=3D2>&gt;&gt;&gt; del trash </FONT></DIV>
<DIV><FONT size=3D2>&gt;&gt;&gt;</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>now delete the names a and foo?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>Hopefully this thread may reveal a little bit of the =
inner=20
working</FONT></DIV>
<DIV><FONT size=3D2>as well as management of namespaces.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Gregor</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>P.S.: I remember that in Logo (in acient times) it =
was very=20
easy to delete</FONT></DIV>
<DIV><FONT size=3D2>names</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0041_01C1D905.907F24C0--




From idiot1@netzero.net  Sun Mar 31 21:03:08 2002
From: idiot1@netzero.net (kirk Bailey)
Date: Sun, 31 Mar 2002 16:03:08 -0500
Subject: [Tutor] hacking 101
References: <3CA663F7.9D143E1B@netzero.net> <20020331201144.GA22376@hal>
Message-ID: <3CA7798C.9F4BD2F3@netzero.net>

ok, I will imbed answers.

Rob McGee wrote:
> 
> On Sat, Mar 30, 2002 at 08:18:47PM -0500, kirk Bailey wrote:
> > OK, comes now before you an unuual question.
> 
> Not unusual at all. Quite ordinary. IIRC it's addressed somewhat in the
> FAQ for the Tutor list. ;) :)
> 
> > I want to learn about hacking a computer.
> 
> I'll split a hair here and point out that the correct term is "cracking"
> (hackers are honourable people who build systems, not destroy them.)
>
Right.
 
> The answer varies WIDELY depending upon what OS and services are
> running on your server. Common, good advice for Windows systems probably
> doesn't apply to UNIX-like systems. For example, I'm not aware of any
> serious anti-virus software for Linux. (Because of the underlying design
> of UNIX, we're not vulnerable in the same way as Windows systems are.
> No, I'm not a Linux bigot claiming that we're not vulnerable, but the
> fact remains that an attacker has to look for specific holes on a Linux
> box, rather than casting viral spores to the wind.)
>
FreeBSD
 
> If you're trying to secure a Win9x box, all I can say is "good luck". I
> don't think it is possible. It's based on DOS, and DOS is insecure by
> design. If you're trying to secure a WinNT/2K/XP box, it *may* be
> possible, but you have to keep on top of all known vulnerabilities, and
> apply all the patches as soon as they're announced. (That's pretty much
> the right approach for UNIX systems too.)
> 
> There are many excellent sites for security of UNIX systems, and at
> least to some extent those sites also address security concerns of the
> NT family as well. See the "Miscellaneous Resources" links at LWN -- the
> Security page for this week is at:
>     http://lwn.net/2002/0328/security.php3
> There are mailing lists which will keep you apprised of every security-
> related development as soon as it is known.
> 
> Me, I'm just an amateur. By following the LWN Security news and
> subscribing to the security mailing list for my distro (Slackware) I can
> feel pretty secure. The bottom line is to consider your threat model and
> act accordingly. A backbone server has more exposure than a home machine
> on an intermittent dialup connection. :)
>
24/7 box wired into local network at a cohosting firm. My worry is
feeding input to the script throught he form and taking control, or
disrupting operations, so it screws itself, creates backdoors, or does
other evil.
 
> HTH,
>     Rob - /dev/rob0
> 
> _______________________________________________
> 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 |
| http://www.tinylist.org  +--------+  mailto:grumpy@tinylist.org |
+------------------Thinking| NORMAL |Thinking---------------------+
                           +--------+

NOTE: By sending SPAM to this address you agree to pay me a service
fee of $100 for the service of receiving,  storing,  examining, and
deleting your piece of SPAM. I am a postmaster, and take a dim view
of such.



From i812@iname.com  Sun Mar 31 21:19:42 2002
From: i812@iname.com (Rob McGee)
Date: Sun, 31 Mar 2002 15:19:42 -0600
Subject: [Tutor] hacking 101
In-Reply-To: <3CA7798C.9F4BD2F3@netzero.net>
References: <3CA663F7.9D143E1B@netzero.net> <20020331201144.GA22376@hal> <3CA7798C.9F4BD2F3@netzero.net>
Message-ID: <20020331211942.GB22376@hal>

On Sun, Mar 31, 2002 at 04:03:08PM -0500, kirk Bailey wrote:
> FreeBSD

Oh, that's probably a pretty good choice. I'm sure they have a security
mailing list which you could join by looking around their Web site. The
links from the LWN page I gave you will have very good information for
FreeBSD. Make sure everything is current for your release version. Make
sure that no unnecessary (unused) services are running. Portscan your
box and consider the results. (There are online services which will do
the scanning for you, if you don't want to do it yourself -- a good idea
in part because they also give you some free advice.) If your
collocation provider is trustworthy you can sleep well. :)

    Rob - /dev/rob0



From dman@dman.ddts.net  Sun Mar 31 21:45:09 2002
From: dman@dman.ddts.net (dman)
Date: Sun, 31 Mar 2002 15:45:09 -0600
Subject: [Tutor] command line
In-Reply-To: <AF7F3569-44C1-11D6-8BD4-00039351FE6A@mac.com>
References: <20020331101437.GA8142@ak.silmarill.org> <AF7F3569-44C1-11D6-8BD4-00039351FE6A@mac.com>
Message-ID: <20020331214509.GA30387@dman.ddts.net>

On Sun, Mar 31, 2002 at 11:09:31AM -0500, Erik Price wrote:
| 
| On Sunday, March 31, 2002, at 05:14  AM, Andrei Kulakov wrote:
| 
| >I like to use vim commands to edit any substantial amount of code - hjkl
| >and the like for movement, I can't stand cursor keys.
| >
| >No place like home (row) :-).
| >
| >Python interpreter is plenty enough for me to look things up quickly.
| 
| Similarly, but differently, I can't stand cursor keys -- but I prefer 
| the emacs bindings (nkpf).  I use the interpreter/shell (IOW call python 
| from the command line with no args), but I've noticed that I can't use 
| the typical emacs key bindings to move backward and forward through my 
| history.  Is this the way it is, or is there some way I can configure 
| the interpreter to return lines from my command history using these 
| bindings?

Depends on how it was compiled.

| I have my bash shell environment variable 
| EDITOR=/usr/bin/emacs and this works for all of my other programs,

That is for programs that want to invoke an editor on a temporary file
and then read that data back in.  For example 'cvs' uses this.

| but not for Python.

Python doesn't invoke editors at all,

| Does anyone know if this feature exists?

I see you're using "Apple Mail".  Are you on OSX?  If so fire up a
shell and try 
    ldd `which python`

and see if "libreadline" is mentioned anywhere in the output.  My
guess is that it won't be.  GNU readline is a library (made by the GNU
folks) for reading a lines of input from a terminal.  bash uses it and
python _can_ use it if it was compiled with it.  This is what gives
command history and line editing with emacs or vi style keybindings.
The default for readline is 'emacs' style.

-D

-- 

The righteous hate what is false,
but the wicked bring shame and disgrace.
        Proverbs 13:5




From python@rcn.com  Sun Mar 31 21:52:15 2002
From: python@rcn.com (Raymond Hettinger)
Date: Sun, 31 Mar 2002 16:52:15 -0500
Subject: [Tutor] hacking 101
References: <3CA663F7.9D143E1B@netzero.net> <000701c1d8ea$09ad8c40$ec61accf@othello> <3CA77742.D4EBA460@netzero.net>
Message-ID: <001c01c1d8fe$52d57c20$b6f7a4d8@othello>

----- Original Message ----- 
From: "kirk Bailey" <idiot1@netzero.net>
To: "Raymond Hettinger" <python@rcn.com>

> > -- avoid python's eval, exec, and input like the plague
> I MUST use input, the form has to provide all the relevant informatiom
> for
> the script to use in creating a new list.

Use raw_input() instead.  Otherwise, you've got security
hole big enough for the Titanic.

--R




From scarblac@pino.selwerd.nl  Sun Mar 31 21:56:20 2002
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Sun, 31 Mar 2002 23:56:20 +0200
Subject: [Tutor] hacking 101
In-Reply-To: <3CA663F7.9D143E1B@netzero.net>; from idiot1@netzero.net on Sat, Mar 30, 2002 at 08:18:47PM -0500
References: <3CA663F7.9D143E1B@netzero.net>
Message-ID: <20020331235620.A10302@pino.selwerd.nl>

On  0, kirk Bailey <idiot1@netzero.net> wrote:
> OK, comes now before you an unuual question.
> 
> I want to learn about hacking a computer.
> 
> See, I Want to complete the program for creating a list using a web
> form. BUT I kow that it is possible to insert escape codes and such to
> take over control and do unintended things, but I know nothing of how
> this is done. I WANT TO UNDERSTAND IT SO I CAN WATCH FOR SUCH ATTEMPTS
> AND ABORT THE PROCESS if they are detected. To PREVENT hcking, one
> must UNDERSTAND hacking. Any takers? Feel free to reply to me off list
> if you preferr.

I had my being a cracker period when I used to play MUDs. For every piece of
code we got to see accidentally, we automatically thought, "How can I abuse
this?", and that's basically all there is to it.

At every place where you get user input, *in any form*, try to think of the
weirdest form it could take, the syntax you don't expect. Question your
assumptions - if it's user input, they're not held to your assumptions.

Input length is part of the input (but not as critical in Python as it often
is in C). Input timing is part of the input. Etc.

Get into the mindset of someone who sees a set of rules for a game, and
tries to figure out how to cheat at it. 

Focus at user input. Everything that comes from outside is suspect. Trace
the path of this data through your code.

And get some other people to look at your code. You'll never see
*everything*.

For the same reason, always assume there's some leak left somewhere.

If you can point me at a few files of concrete code for me to look at, I can
probably free a few hours in a week or so, I'll probably just find the
obvious things in that time though. To find the real exploits needs a touch
of inspiration, and they're rare for everyone.

-- 
Remco Gerlich



From bwcarver@earthlink.net  Sun Mar 31 22:05:19 2002
From: bwcarver@earthlink.net (Brian W. Carver)
Date: Sun, 31 Mar 2002 14:05:19 -0800
Subject: [Tutor] Teach Yourself Python in 24 Hours Website
References: <E16rnLr-0008PU-00@mail.python.org>
Message-ID: <3CA7881F.4B2D0391@earthlink.net>

Hi,

I recently bought Ivan Van Laningham's book: Teach Yourself Python in 24 Hours.
Throughout the book he makes reference to a website for the book that includes
files to download.  When I go to the website indicated ( http://www.pauahtun.org
) I find his personal pages but nothing related to the book, and very little
related to Python.  Anyone else used this book, had this problem, and eventually
found the files?  If so, can you point me in the right direction?  I've sent a
similar e-mail to what appears to be the author's address, but didn't know
whether I'd get a response.  Thanks for any help.

Brian W. Carver




From alan.gauld@bt.com  Sun Mar 31 22:08:06 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 31 Mar 2002 23:08:06 +0100
Subject: [Tutor] simple problem
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4CD@mbtlipnt02.btlabs.bt.co.uk>

> for on mac os 10, and i am using it through terminal

MacOS X is catching on...

> i try to put a line of code and and then try to put
> another underneath it, i have to hit return, and
> python runs through the code, so what happens if i
> want to put more than 1 line of code 

You can put your code in a file. Use textedit to create 
a file with a .py extension(by convention). Then in terminal type:

$ python foo.py

where $ is the unix prompt
python is the interpreter
foo.py is the file you created.

Yu can also use vi or emacs within terminal which is how real 
unix heads do it, but textedit will suffice - just make 
sure you save as plain text.

> python GUI, or the IDLE, 

I'm sure someone will have pointed you to Danny's IDLE tutor 
by now. Just remember you need to run an Xserver like XonX 
to use IDLE on MacOS X.

Alan g



From alan.gauld@bt.com  Sun Mar 31 22:12:04 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 31 Mar 2002 23:12:04 +0100
Subject: [Tutor] importing a subprocess in dos
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4CE@mbtlipnt02.btlabs.bt.co.uk>

> do I run a process in dos (btw my os is win98) and import the 
> result to my python interpreter?

Use popen() or one of its variants - look min os module.

BUT it used to be on DOS that you had to use the one 
from the winall package(or ActiveState's python).
Does anyone know if this is still true in V2.xx?

Alan G



From paulsid@shaw.ca  Sun Mar 31 22:14:03 2002
From: paulsid@shaw.ca (Paul Sidorsky)
Date: Sun, 31 Mar 2002 15:14:03 -0700
Subject: [Tutor] hacking 101
References: <3CA663F7.9D143E1B@netzero.net>
 <20020331235620.A10302@pino.selwerd.nl>
Message-ID: <3CA78A2B.1C5231EE@shaw.ca>

Remco Gerlich wrote:

> At every place where you get user input, *in any form*, try to think of the
> weirdest form it could take, the syntax you don't expect. Question your
> assumptions - if it's user input, they're not held to your assumptions.

Better yet, have somebody else do the questioning.  I never had the
cracker mentality but I knew a guy who did and the holes he found in my
software were rather remarkable to me.  I just never would have thought
to do the things he did.  Most of the time they weren't even
unconscionable or devious things, they were just fairly routine things
that ordinary programmers wouldn't think anybody would do.

--
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/



From bwcarver@earthlink.net  Sun Mar 31 22:16:09 2002
From: bwcarver@earthlink.net (Brian W. Carver)
Date: Sun, 31 Mar 2002 14:16:09 -0800
Subject: [Tutor] Re: Teach Yourself Python in 24 Hours Website
References: <E16rnLr-0008PU-00@mail.python.org>
Message-ID: <3CA78AA9.1047B51D@earthlink.net>

I thought I'd answer my own question, since the author responded with lightning
speed.

The files are at: http://www.pauahtun.org/TYPython/

Sorry for the wasted bandwidth.  Next time I write, I'll have a good Python
question for the group.

Brian W. Carver

> Hi,
>
> I recently bought Ivan Van Laningham's book: Teach Yourself Python in 24 Hours.
> Throughout the book he makes reference to a website for the book that includes
> files to download.  When I go to the website indicated ( http://www.pauahtun.org
> ) I find his personal pages but nothing related to the book, and very little
> related to Python.  Anyone else used this book, had this problem, and eventually
> found the files?  If so, can you point me in the right direction?  I've sent a
> similar e-mail to what appears to be the author's address, but didn't know
> whether I'd get a response.  Thanks for any help.
>
> Brian W. Carver
>




From alan.gauld@bt.com  Sun Mar 31 22:21:20 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 31 Mar 2002 23:21:20 +0100
Subject: [Tutor] command line
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4CF@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C1D902.62330F80
Content-type: text/plain; charset="iso-8859-1"

 >  Why would you use the command line Python instead of the IDLE? 
 
1) It uses less machine resources
 
2) It starts faster
 
3) My text editor is better than IDLE's so edit run 
   is better than edit, switch program, run
 
 4) IDLE sets up its own environment python at 
    the command prompt python executes like the 
    production environment so less spurious errors
 
5) Tkinter does strange things in IDLE, not at the 
   python prompt.
 
Some of that relates to using the interpreter from the 
OS prompt, some to the cython interpreter prompt. 
The latter assumes as a minimum NT level editing 
functions and getline by preference.
 
Alan G

------_=_NextPart_001_01C1D902.62330F80
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=830241622-31032002><FONT 
face="Courier New" color=#0000ff>&nbsp;&gt; &nbsp;</FONT></SPAN>Why would you 
use the command line Python instead of the IDLE?<SPAN 
class=830241622-31032002><FONT face="Courier New" 
color=#0000ff>&nbsp;</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=830241622-31032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=830241622-31032002><FONT 
face="Courier New" color=#0000ff>1) It uses less machine 
resources</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=830241622-31032002><FONT 
face="Courier New" color=#0000ff>2) It starts 
faster</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=830241622-31032002><FONT 
face="Courier New" color=#0000ff></FONT></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=830241622-31032002><FONT 
face="Courier New" color=#0000ff>3) My text editor is better than IDLE's so edit 
run </FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=830241622-31032002><FONT 
face="Courier New" color=#0000ff>&nbsp;&nbsp; is better than edit, switch 
program, run</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=830241622-31032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=830241622-31032002>&nbsp;<FONT 
face="Courier New" color=#0000ff>4) IDLE sets up its own environment python at 
</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=830241622-31032002><FONT 
face="Courier New" color=#0000ff>&nbsp;&nbsp;&nbsp; the command prompt python 
executes like the </FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN class=830241622-31032002><FONT 
face="Courier New" color=#0000ff>&nbsp;&nbsp;&nbsp; production environment so 
less spurious errors</FONT></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002>5) Tkinter does strange things in IDLE, not at the 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002>&nbsp;&nbsp; python prompt.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002>Some of that relates to using the interpreter from the 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002>OS prompt, some to the cython interpreter prompt. 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002>The latter assumes as a minimum NT level editing 
</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002>functions and getline by 
preference.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=830241622-31032002>Alan G</SPAN></FONT></FONT></DIV></BODY></HTML>

------_=_NextPart_001_01C1D902.62330F80--



From alan.gauld@bt.com  Sun Mar 31 22:26:58 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 31 Mar 2002 23:26:58 +0100
Subject: [Tutor] command line
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4D0@mbtlipnt02.btlabs.bt.co.uk>

Wayyyy off topic but...

> After you install Microsoft Windows XP, you have the option to create
> user accounts.  If you create user accounts, by default, they 
> will have an account type of administrator with no password.

<RANT>
True on XP Home and a really terrible decision by MS.
Why not a single administrator and new users either 
Poweruser or restricted user? The latter is too restricted 
for most users but admin is simply insane! Bang goes much
of XPs security protection! I am seriously considering 
upgrading from Home to Pro just because of this issue.
</RANT>

Otherwise its not bad....

Alan G.



From alan.gauld@bt.com  Sun Mar 31 22:32:23 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 31 Mar 2002 23:32:23 +0100
Subject: [Tutor] command line
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4D1@mbtlipnt02.btlabs.bt.co.uk>

> environment.  Maybe it's different in Win2k, where uparrow
> history is somehow available.

Yes, you get the minimal up arrow functions in Win2000 and XP

But a better option is to install cygwin which provides 
full getline() functionality.

IDLE still has advantages and if I'm doing a big session 
I use it:

function hints as mentioned, 
color coding(!)
Save a session

But for quick tests and all Tkinter work I use the command 
line version

Alan g.



From bwinton@tor.dhs.org  Sun Mar 31 22:29:16 2002
From: bwinton@tor.dhs.org (Blake Winton)
Date: Sun, 31 Mar 2002 17:29:16 -0500
Subject: [Tutor] hacking 101
In-Reply-To: <20020331235620.A10302@pino.selwerd.nl>
References: <3CA663F7.9D143E1B@netzero.net> <20020331235620.A10302@pino.selwerd.nl>
Message-ID: <20020331172916.A23568@tor.dhs.org>

* Remco Gerlich <scarblac@pino.selwerd.nl> [020331 16:54]:
> At every place where you get user input, *in any form*, try to think of the
> weirdest form it could take, the syntax you don't expect. Question your
> assumptions - if it's user input, they're not held to your assumptions.
> 
> Focus at user input. Everything that comes from outside is suspect. Trace
> the path of this data through your code.

For web-based applications, change your username to "<!--" and see if
the rest of the page gets displayed correctly.  If you suspect it's
using a SQL backend, change your name to "name' OR name='aaa" and see if
that breaks anything.  On most of the projects I work on, I test for
stuff like that, and even though it's a PITA to handle it, you've got
to, cause people will mess you up (not even on purpose) if they can.
Heck, that isn't even hacking or cracking, it's just good testing.

Try subscribing to a mailing list as "foo@bar.com\nyahoo@bad.com" (even
better would be if the \n was the actual new-line character, perhaps
copied into the clipboard and pasted into the app).  Or maybe make your
name "test@bad.com;print 'This isnt good!!!'"  Stuff like that.  You
know better than the rest of us what you do with your input, so take
that knowledge, and see if you can create input that breaks your code.

(And email me a link to the code, and I'll look it over, and see what I
can come up with.  *grin*  ;)

Later,
Blake.
-- 
  5:28pm  up 18 days, 21:17,  2 users,  load average: 0.00, 0.01, 0.04



From bwinton@tor.dhs.org  Sun Mar 31 22:34:48 2002
From: bwinton@tor.dhs.org (Blake Winton)
Date: Sun, 31 Mar 2002 17:34:48 -0500
Subject: [Tutor] command line
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4CF@mbtlipnt02.btlabs.bt.co.uk>
References: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4CF@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <20020331173448.A23820@tor.dhs.org>

* alan.gauld@bt.com <alan.gauld@bt.com> [020331 17:23]:
>  >  Why would you use the command line Python instead of the IDLE? 
> 1)
[...]  
> 5) 

6)

[~ bwinton] /opt/python/src/Tools/idle/idle.py
Traceback (most recent call last):
  File "/opt/python/src/Tools/idle/idle.py", line 4, in ?
    PyShell.main()
  File "/opt/python/src/Tools/idle/PyShell.py", line 747, in main
    root = Tk(className="Idle")
  File "/opt/python/lib/python2.2/lib-tk/Tkinter.py", line 1480, in
__init__
    self.tk = _tkinter.create(screenName, baseName, className)
TclError: no display name and no $DISPLAY environment variable


[~ bwinton] /opt/python/bin/python
Python 2.2a3 (#1, Sep 16 2001, 12:18:17)
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

(I can't run idle, but the command line works just fine...
 I don't run X by default.  Just cause.)

Later,
Blake.
-- 
9:40pm up 52 days, 21:07, 2 users, load average: 0.02, 0.09, 0.07



From alan.gauld@bt.com  Sun Mar 31 22:46:00 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Sun, 31 Mar 2002 23:46:00 +0100
Subject: [Tutor] command line
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4D2@mbtlipnt02.btlabs.bt.co.uk>

> Do you know of any non-windows IDEs that have these features?  

Depending on the language there are lot of them in Unix 
but they tend to cost megeabucks. (HP SoftBench, 
Sun WorkBench, ObjectCenter, Sniff++ etc etc)

There are some new ones coming along for Linux etc 
too Kdevelop, Blackadder, and some others(Activestates tool?)

> New converts to *nix often ask (in deb-user at least) where the IDEs
> usual answer is "unix _is_ an IDE -- 

And that is the correct answer. Most of our windows programmers 
do their development on Unix and then move the code to Windows 
(VC++ or JBuilder) for final build & test. but the tools on 
Unix surpass any of the Windows tools commercial or otherwise.
(trace, gdb, tcov, [g]prof, ctags, xref, gplot, cflow, etc etc)

> | In my experience, pro programmers appreciate time-saving
> | and productivity-enhancing features,

Not in my experience, most long term pros stick by the tools 
they know really well, editor and debugger mainly and just 
carve out the code. They know the language etc so well they 
hardly ever use the "toys". There's nothing so productive 
as just typing the code in and it works first time! Many 
experienced pros reach that level of quality after 10 years 
or so...

> | >The important lesson to walk away with is this: if you are not
> | >using an interactive python interpreter while coding and
> | >experimenting you are missing out on one of the key benefits
> | >python offers.

This is true and is where Python development differs from 
traditional style coding.

Alan G



From alan.gauld@bt.com  Sun Mar 31 23:03:28 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 1 Apr 2002 00:03:28 +0100
Subject: [Tutor] hacking 101
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4D3@mbtlipnt02.btlabs.bt.co.uk>

Rob,

> On Sun, Mar 31, 2002 at 04:03:08PM -0500, kirk Bailey wrote:
> > FreeBSD
> 
> Oh, that's probably a pretty good choice. I'm sure they have 
> a security mailing list which you could join 

I think the thing Kirk is interested in is how to make the 
mailing list registration form he has written in Python 
secure, not how to make his BSD box secure. That's why he 
needs to know how crackers operate so he can guard against 
it in his code.

Kirk,

There are some sites around covering secure code techniques 
but many are biased to C/C++ in my experience. Things like 
buffer overruns etc are not such an issue in Python because 
we can't read a string into a fixed length byte array etc.

But there are plenty other things to look out for I'm sure, 
and I'd be interested if you do find a good source of info.

Alan g.



From alan.gauld@bt.com  Sun Mar 31 23:16:39 2002
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 1 Apr 2002 00:16:39 +0100
Subject: [Tutor] idle - namespaces (was idle)
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4D4@mbtlipnt02.btlabs.bt.co.uk>

------_=_NextPart_001_01C1D90A.1CCDBC30
Content-type: text/plain; charset="iso-8859-1"

I may have missed the answer to this but here goes anyway...
 
>  away code. However I just noticed something, when I delete all the code  
>  to write some more throw away code the variables and I think also other  
>  things do not get deleted. How do I delete them?  
 
With great difficulty.
 
When you import names from a module they get stored 
in a dictionary. When you reload a module it simply 
adds the names - which is why reload doesn't work 
for the "from f import x" form.
 
The only reliable way to do this is to exit and restart
(Cameron another reason I use the OS command line...)
 
Of course avoiding the from f inmoprt x style helps a lot.
 

>>> dir()
['__builtins__', '__doc__', '__name__']
 

dir() returns a list but its built up from the underlying 
dictionary. deleting from the list doesn't affect the 
dictionary underneath.
 

>>> del a


This deletes the name from the underlying dictionary...

 >>> dir()
['__builtins__', '__doc__', '__name__', 'foo']

 so its gone from dir() too... 


But if you try to delete several items from a list, this doesn't work,
because of the difference between the string 'a' and the name a, I think:
 
>>> dir()
['__builtins__', '__doc__', '__name__', 'a', 'foo']
>>> dir()[3:]  
['a', 'foo']
>>> for name in dir()[3:]:
     del name 
 

This deletes the string that was in the list (I think, 
I admit I'm getting more shaky here...)

>>> for name in dir()[3:]:
    del eval(name) 

This uses the string to eval which returns the alue of 
the variable named by the string - ie 3 in this case.
 
 >  So how do I get acces to the Variable a via dir() ? 
 
I don't think you can. You have to go to the Builtins 
dictionary and grub about in the innards - not recommended! 
 
Alan G.
 

------_=_NextPart_001_01C1D90A.1CCDBC30
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><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>I may have missed the answer to this but here goes 
anyway...</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002></SPAN><SPAN class=050230623-31032002><FONT 
face="Courier New" color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>&gt; </FONT>&nbsp;</SPAN>away code. However I just noticed something, 
when I delete all the code&nbsp;<SPAN class=050230623-31032002><FONT 
face="Courier New" color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>&gt; </FONT>&nbsp;</SPAN>to write some more throw away code the variables 
and I think also other&nbsp;<SPAN class=050230623-31032002><FONT 
face="Courier New" color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>&gt; </FONT>&nbsp;</SPAN>things do not get deleted. How do I delete 
them?&nbsp;<SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002></SPAN>&nbsp;</DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>With great difficulty.</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002></SPAN>&nbsp;</DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>When you import names from a module they get stored </FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>in a dictionary. When you reload a module it simply </FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>adds the names - which is why reload doesn't work </FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>for the "from f import x" form.</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>The only reliable way to do this is to exit and 
restart</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>(Cameron another reason I use the OS command line...)</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2>Of course avoiding the from f inmoprt x style helps a 
lot.</FONT></SPAN></DIV>
<DIV><SPAN class=050230623-31032002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
  <DIV><FONT face="Courier New" size=2>&gt;&gt;&gt; dir()<BR>['__builtins__', 
  '__doc__', '__name__']<BR><SPAN class=050230623-31032002><FONT 
  color=#0000ff>&nbsp;</FONT></SPAN></FONT></DIV></BLOCKQUOTE>
<DIV dir=ltr><FONT face="Courier New" size=2><SPAN 
class=050230623-31032002>dir() returns a list but its built up from the 
underlying </SPAN></FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2><SPAN 
class=050230623-31032002>dictionary. deleting from the list doesn't affect the 
</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2><SPAN 
class=050230623-31032002>dictionary underneath.</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" size=2><SPAN 
class=050230623-31032002></SPAN></FONT>&nbsp;</DIV>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
  <DIV><FONT face=Arial><FONT face="Courier New" size=2>&gt;&gt;&gt; del 
  a<BR><SPAN class=050230623-31032002><FONT 
  color=#0000ff></FONT></SPAN></FONT></FONT></DIV></BLOCKQUOTE>
<DIV dir=ltr><FONT face=Arial><FONT face="Courier New" size=2><SPAN 
class=050230623-31032002><FONT color=#0000ff>This deletes the name from the 
underlying dictionary...</FONT></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><FONT face="Courier New"><FONT size=2><SPAN 
  class=050230623-31032002>&nbsp;</SPAN>&gt;&gt;&gt; dir()<BR>['__builtins__', 
  '__doc__', '__name__', 'foo']</FONT></FONT></FONT></DIV></BLOCKQUOTE>
<DIV dir=ltr><FONT face=Arial><FONT face="Courier New"><FONT size=2><SPAN 
class=050230623-31032002>&nbsp;</SPAN><SPAN class=050230623-31032002><FONT 
color=#0000ff>so its&nbsp;gone from dir() 
too...&nbsp;</FONT></SPAN></FONT><BR></DIV><FONT size=2></FONT></FONT>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px"></FONT>
  <DIV><FONT size=2>But if you try to delete several items from a list, this 
  doesn't work,</FONT></DIV>
  <DIV><FONT size=2>because of the difference between the&nbsp;string 'a' and 
  the name a, I think:</FONT></DIV>
  <DIV><FONT size=2></FONT>&nbsp;</DIV>
  <DIV><FONT size=2>&gt;&gt;&gt; dir()<BR>['__builtins__', '__doc__', 
  '__name__', 'a', 'foo']<BR>&gt;&gt;&gt; dir()[3:]<SPAN 
  class=050230623-31032002><FONT face="Courier New" 
  color=#0000ff>&nbsp;</FONT></SPAN><SPAN 
  class=050230623-31032002>&nbsp;</SPAN><BR>['a', 'foo']<BR>&gt;&gt;&gt; for 
  name in dir()[3:]:<BR>&nbsp;&nbsp;&nbsp;&nbsp; del name<SPAN 
  class=050230623-31032002><FONT face="Courier New" 
  color=#0000ff>&nbsp;</FONT></SPAN></FONT></DIV>
  <DIV><FONT size=2><SPAN 
class=050230623-31032002>&nbsp;</SPAN></FONT></DIV></BLOCKQUOTE>
<DIV dir=ltr><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=050230623-31032002>This deletes the string that was in the list (I think, 
</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=050230623-31032002>I admit I'm getting more shaky 
here...)</SPAN></FONT></DIV>
<BLOCKQUOTE dir=ltr 
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
  <DIV><FONT size=2>&gt;&gt;&gt; for name in dir()[3:]:<BR>&nbsp;&nbsp;&nbsp; 
  del eval(name)<SPAN class=050230623-31032002><FONT face="Courier New" 
  color=#0000ff>&nbsp;</FONT></SPAN></FONT></DIV></BLOCKQUOTE>
<DIV dir=ltr><FONT size=2><SPAN class=050230623-31032002><FONT 
face="Courier New" color=#0000ff>This uses the string to eval which returns the 
alue of </FONT></SPAN></FONT></DIV>
<DIV dir=ltr><FONT size=2><SPAN class=050230623-31032002><FONT 
face="Courier New" color=#0000ff>the variable named by the string - ie 3 in this 
case.</FONT></SPAN></FONT></DIV>
<DIV dir=ltr><FONT size=2><SPAN class=050230623-31032002>&nbsp;</SPAN><BR><SPAN 
class=050230623-31032002><FONT face="Courier New" color=#0000ff>&nbsp;<FONT 
face="Times New Roman" color=#000000>&gt; </FONT>&nbsp;</FONT></SPAN>So how do I 
get acces to the Variable a via dir() ?<SPAN class=050230623-31032002><FONT 
face="Courier New" color=#0000ff>&nbsp;</FONT></SPAN></FONT></DIV>
<DIV dir=ltr><FONT size=2><SPAN 
class=050230623-31032002></SPAN></FONT>&nbsp;</DIV>
<DIV dir=ltr><FONT size=2><SPAN class=050230623-31032002><FONT 
face="Courier New" color=#0000ff>I don't think you can. You have to go to the 
Builtins </FONT></SPAN></FONT></DIV>
<DIV dir=ltr><FONT size=2><SPAN class=050230623-31032002><FONT 
face="Courier New" color=#0000ff>dictionary and grub about in the innards - not 
recommended!</FONT>&nbsp;</SPAN></FONT></DIV>
<DIV dir=ltr><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=050230623-31032002></SPAN></FONT>&nbsp;</DIV>
<DIV dir=ltr><FONT face="Courier New" color=#0000ff size=2><SPAN 
class=050230623-31032002>Alan G.</SPAN></FONT></DIV>
<DIV dir=ltr><FONT size=2><SPAN 
class=050230623-31032002></SPAN></FONT>&nbsp;</DIV></BODY></HTML>

------_=_NextPart_001_01C1D90A.1CCDBC30--



From urnerk@qwest.net  Sun Mar 31 23:44:39 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Sun, 31 Mar 2002 15:44:39 -0800
Subject: [Tutor] command line
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4D2@mbtlipnt02.btlabs
 .bt.co.uk>
Message-ID: <4.2.0.58.20020331151629.019d2860@pop3.norton.antivirus>

At 11:46 PM 3/31/2002 +0100, alan.gauld@bt.com wrote:

> > | In my experience, pro programmers appreciate time-saving
> > | and productivity-enhancing features,
>
>Not in my experience, most long term pros stick by the tools
>they know really well, editor and debugger mainly and just
>carve out the code. They know the language etc so well they
>hardly ever use the "toys". There's nothing so productive
>as just typing the code in and it works first time! Many
>experienced pros reach that level of quality after 10 years
>or so...

Depends what you include in the "toy" category.

I like project management utilities that keep classes,
forms, reports, data tables in order, and compile only
changes (ala make).  Templates and dialog box driven
builders of various types also save time.

Helpful and useful:  a visual class browser, code rollups,
and, of course, a way to develop GUI forms by simply
dragging and dropping widgets from a palette ala VB
(an IDE I've never used).  WYSIWYG interface design saves
hours, can't be sidelined as "just a Windows thing".

I've been coding this way ever ever since my Xbase IDEs
went GUI (not quite 10 years I guess -- but as a programmer
I go back to punch cards on an IBM mainframe).  I wouldn't
want to go back to the text-only tools of my past.  But I
can understand sticking with what you know best.

I appreciate that the high-powered *nix editors (emacs
and vi/vim) are so code-aware that a lot of the IDE perks
we're talking about are simply folded into the program
editor (color coding, auto-completion, call tips).  Vim
not only knows about HTML, but DTML (Zope) and just about
every other language under the sun.

The idea that a *nix environment is itself an IDE makes
plenty of sense (I should have my *nix back up by the end
of the day -- doing the spade work creating new partitions
at the moment).

I also appreciate that *nix gives you more high powered
tools at an affordable price (which wasn't true before the
free *nixes (not just Linux in that category) and cheap-
enough hardware powerful enough to use em (and Windows
helped make Wintel big enough to drive the cost per
Pentium way way down)).

But it's also true that the *nix OS is a platform for
expensive, proprietary, closed source software development
IDEs and applications.  This idea that having an open source
OS means what you run on top of it is necessarily likewise
is, of course, not true.  Yet it seems some evangelists
want us to believe that only Windows users ever run closed
source, expensive stuff.

What I really like about Python, on all the platforms it
supports, is that batteries are included.  If you want a
GUI shell, you've got one.  If your plan is to write a
bunch of cgi scripts or other daemon-type stuff and walk
away (i.e. not much interactivity required), then it'll
support that too.  And all for no cost.  Wonderful.

 >> | >The important lesson to walk away with is this: if you
 >> | >are not using an interactive python interpreter while
 >> | >coding and experimenting you are missing out on one
 >> | >of the key benefits python offers.
 >
 > This is true and is where Python development differs from
 > traditional style coding.

Some languages have a builtin shell mode, and take advantage
of it, whereas others don't.  APL, Logo, Scheme, many Lisps,
Xbase, MATLAB, Mathematica, ISETL and Python are very shell-
oriented (to name but a few).  FORTRAN, Pascal, C/C++, Java
are not (again, to name but a few).

Probably I'm more into IDLE and/or shell than script mode
because I'm happier with shell-based languages in general,
starting with APL (my first language, unless you count the
HP65 calculator).

Kirby




From urnerk@qwest.net  Sun Mar 31 23:49:32 2002
From: urnerk@qwest.net (Kirby Urner)
Date: Sun, 31 Mar 2002 15:49:32 -0800
Subject: [Tutor] idle - namespaces (was idle)
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20E66C4D4@mbtlipnt02.btlabs
 .bt.co.uk>
Message-ID: <4.2.0.58.20020331154559.019dd340@pop3.norton.antivirus>

At 12:16 AM 4/1/2002 +0100, alan.gauld@bt.com wrote:
>I may have missed the answer to this but here goes anyway...
>
> > away code. However I just noticed something, when I delete all the code
> > to write some more throw away code the variables and I think also other
> > things do not get deleted. How do I delete them?
>
>With great difficulty.
>
>When you import names from a module they get stored
>in a dictionary. When you reload a module it simply
>adds the names - which is why reload doesn't work
>for the "from f import x" form.
>
>The only reliable way to do this is to exit and restart
>(Cameron another reason I use the OS command line...)
>

But note that you can do both, i.e.

import xxx
from xxx import a,b,c

Then if you change the code in xxx, you can have
a routine in your shell to reload(xxx) and reimport
a,b,c.  The code changes will now be reflected in
your current namespace, without exiting and re-entering.

Kirby