From stalnaker@acm.org  Tue Jun  1 06:45:19 1999
From: stalnaker@acm.org (Max M. Stalnaker)
Date: Mon, 31 May 1999 22:45:19 -0700
Subject: [Tutor] compile
References: <199906010503.BAA03900@python.org>
Message-ID: <3753736F.BED95208@acm.org>

What you want to do is to "freeze" your program.  First thing to ask yourself is
"do you have MSVC++ 5.0?".  6.0 should work too.  If not, then for our purposes,
you cannot do it.  Suppose you have that compiler.  Then you have a set of sub
projects to perform.

1) you need to be a little comfortable using the c++ compiler (optional).
2) you need to download the python source
3) compile it to prove you can (optional, but a good test that the compiler is
setup right)
4) read the txt file and the html in tools/freeze, which you downloaded with the
source (optional)
5) use python and freeze.py on your little program
    python freeze.py littleprogram.py
6) compile the results
    nmake
7) test it.

Since this is a first language tutorial, chances are you do not have the vc++
compiler.   On the other hand, if you do, sometimes it is as simple as the above.
Main issues are getting vc++ to work, and cluttering up your source tree, which is
bad for future compiles.  The above purposely did not deal with specifying where
the freeze.py puts the source.  Also, freezing has limitations on win machines.
But these are outside the scope of this note.  See the doc.





> Message: 3
> From: "Marek Polanski" <junior@supermedia.pl>
> To: tutor@python.org
> Date:   31 May 1999 16:54:14
> Reply-To: "Marek Polanski" <junior@supermedia.pl>
> Subject: [Tutor] compile
>
> I have finished my small program, and I would like to compile it to .exe file.
> How can I do this?
> I'm running W98, Python 1.5.2c1
>
>   Marek Polanski
>
> e-mail: junior@supermedia.pl                              fidonet: 2:480/112.12
> --- GoldED/W32 3.0.1
>  * Origin: Today's magic number is:  14 (2:480/112.12)
>
> --__--__--
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor
>
> --__--__----
>
> End of Tutor Digest

--
Max M. Stalnaker  stalnaker@acm.org
Astar Computer Consulting:  Networking and Custom Accounting Software




From michael@mediamanager.com.sg  Tue Jun  1 08:08:41 1999
From: michael@mediamanager.com.sg (Michael Ang)
Date: Tue, 1 Jun 1999 15:8:41 +0800
Subject: [Tutor] Email Attachment
Message-ID: <19990601064744245.AAA154@michael>

Hi,
	How do I write a script that send a email with attachment (ascii or binary), tried smtplib but doesn't 
support attachment, tried MimeWriter.py but couldn't send mail. Just need a simple component or wrapper to do 
the job, please help or any useful links.

Thanks

Michael Ang



From 010.Werkstudent@MCHF.SIEMENS.DE  Tue Jun  1 15:01:30 1999
From: 010.Werkstudent@MCHF.SIEMENS.DE (Werkstudent 010)
Date: Tue, 1 Jun 1999 16:01:30 +0200
Subject: [Tutor] WG:
Message-ID: <809AE76DB183D111BE1300005A40E070CA538D@mail.mchf.siemens.de>

> Hi, this  is an appeal to Pythonwin experts!
> 
> I> ´m having no luck creating a COMBOBOX  within a PythonWin Dialog. What are the basic steps? I don´t understand the only example I found in framework/editor/edit.py. There seem to be essential pieces of info missing. Through use of the win32con.CBS_* constants, I´ve finally managed to get a visible combobox, but it seems to ignore my adding entries or wanting to see/select them.
> 
> def MakeThreadGeneratorDlg(title):
> 	style = win32con.DS_MODALFRAME | win32con.WS_POPUP | win32con.WS_VISIBLE | win32con.WS_CAPTION | win32con.WS_SYSMENU | win32con.DS_SETFONT
> 	cs = win32con.WS_CHILD | win32con.WS_VISIBLE
> 
> 	# Window frame and title
> 	dlg = [ [title, (0, 0, 200, 45), style, None, (8, "MS Sans Serif")], ]
>  s])
> 
> 	# select thread from list to delete
> 	dlg.append([130, "delete thread:", -1, (7, 22, 69, 9), cs | win32con.SS_LEFT])
> 	s = cs | win32con.WS_TABSTOP  | win32con.WS_VSCROLL | win32con.CBS_DROPDOWN | win32con.CBS_HASSTRINGS
> 	dlg.append(['COMBOBOX', None, win32ui.IDC_COMBO1, (65, 20, 60, 12), s ])
> 
> 	# ...
> 
> 
> class ThreadGeneratorDlg(dialog.Dialog):
> 	Cancel = 0
> 	def __init__(self, title):
> 		dialog.Dialog.__init__(self, MakeThreadGeneratorDlg(title) )
> 		self.AddDDX(win32ui.IDC_COMBO1,'expiringThread')
> 
> 	# ...
> 
> 	def OnInitDialog(self):
> 		self.edit1NewThread = self.GetDlgItem(win32ui.IDC_EDIT1)
> 		self.deleteOldThread = self.GetDlgItem(win32ui.IDC_COMBO1)
> 		
> 		# following just a test!!!!!!!!
> 		self.deleteOldThread.AddString("aasdf")
> 		self.deleteOldThread.AddString("basdf")
> 		self.deleteOldThread.AddString("casdf")
> 		self.deleteOldThread.AddString("dasdf")
> 
> eturbulently yours,
> 
> 
> David Ungemach
> (Munich, Germ-money)
> 


From ivanlan@callware.com  Tue Jun  1 15:48:29 1999
From: ivanlan@callware.com (Ivan Van Laningham)
Date: Tue, 01 Jun 1999 08:48:29 -0600
Subject: [Tutor] Help with ARGV parsing
References: <E10oXkJ-000090-00@tardis.quansoo.com>
Message-ID: <3753F2BC.B4AF5C30@callware.com>

Hi All00

Jerry Alexandratos wrote:
> 
> I'm new to Python.  But I really like what I see so far.  I'm looking to
> write and rewrite some scripts.  I'm having some trouble trying to
> figure out how to parse command-line arguments under Python.
> 
> Can anyone provide me with some pointers?
> 
> Thanks in advance...
> 

Try downloading getargspy.zip from
	
	http://www.pauahtun.org/ftp.html

(near the bottom of the page).  Read the docstrings in the supplied
module, which gives you not only instructions on how to use getargs.py
but a (brief) introduction to command-line parsing.  I'm trying to put
together an HTML page for just getargs, which will be clearer (and more
tutorial-like) than the present docstrings.  Give it a try.

<shameless-self-promotion>-ly y'rs,
Ivan 
----------------------------------------------
Ivan Van Laningham
Callware Technologies, Inc.
ivanlan@callware.com
http://www.pauahtun.org
See also: 
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
----------------------------------------------


From ivanlan@callware.com  Tue Jun  1 16:17:01 1999
From: ivanlan@callware.com (Ivan Van Laningham)
Date: Tue, 01 Jun 1999 09:17:01 -0600
Subject: [Tutor] Re: proposal: new mailing list
References: <37519172.55C86D95@acm.org>
Message-ID: <3753F96D.9E784D90@callware.com>

Hi All--

"Max M. Stalnaker" wrote:
> 
> I have taught some programming classes.  It seems to me python is a good
> choice for an introductory CS class since it has minimal key words, a
> clean syntax, and lots of CS structures available.  It also has good
> object orientation..  No texts, though.
> 
> It is also starting to attract a little attention from non-programmers
> who want to be programmers.  It seems to me, in an evangelical mode,
> that it is worthwhile addressing their needs, which are different than
> the typical programmer who is discovering Python.  The newsgroup may not
> be appropriate for these people?  Maybe python.org should start a
> mailing list just for them?  Python-eggs?
> 
> Over time, this mailing list, if archived, would develop a good
> reference set for the clientele.   The clientele would be partially
> self-servicing.
> 
> Mandate:
> 
> Discussion of programming issues and techniques in Python for people for
> whom Python is a first programming language.
> 

[N.B.:  I've not finished reading all of my email this morning, so have
undoubtedly missed some others' replies on this topic.]

1)  We already have the Python Tutor mailing list, which really is aimed
at people just getting started with Python.  Too many Python lists would
dilute our energies, I think.

2)  Re ``no texts, though.''  That is a situation which I am attempting
to remedy.  I've just signed a contract with SAMS to write _Teach
Yourself Python in 24 Hours_.  I am deliberately aiming the book at
people who do not know how to program, as I believe that Python is a
very nearly ideal first programming language.  The existing books are
targetted at those who know at least something about programming, but
mine will be for the true programming beginner.

Naturally, I can't speak to SAMS' scheduling or production, so do not
take what I say here as legally binding in any way (I disclaim
everything!), but my feeling is that the book *might* be in the stores
this year.

<yet-more-totally-shameless-self-promotion>-ly y'rs,
Ivan
----------------------------------------------
Ivan Van Laningham
Callware Technologies, Inc.
ivanlan@callware.com
http://www.pauahtun.org
See also: 
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
----------------------------------------------


From skip@mojam.com (Skip Montanaro)  Tue Jun  1 17:37:06 1999
From: skip@mojam.com (Skip Montanaro) (Skip Montanaro)
Date: Tue,  1 Jun 1999 12:37:06 -0400 (EDT)
Subject: [Tutor] Help with ARGV parsing
In-Reply-To: <E10oXkJ-000090-00@tardis.quansoo.com>
References: <E10oXkJ-000090-00@tardis.quansoo.com>
Message-ID: <14164.2101.403812.547431@cm-29-94-19.nycap.rr.com>

    Jerry> I'm new to Python.  But I really like what I see so far.  I'm
    Jerry> looking to write and rewrite some scripts.  I'm having some
    Jerry> trouble trying to figure out how to parse command-line arguments
    Jerry> under Python.

Jerry,

The getopt module is pretty general, and not difficult to use once you get
used to how it works.  Getopt splits command line arguments up into a list
of tuples, grouped as (argname, value).  For example, if I have a script
that accepts two arguments, "t" and "q", and that "t" takes a value,  I
could invoke getopt.getopt as

    >>> import getopt
    >>> getopt.getopt(["-t", "4", "-q"], "t:q")
    ([('-t', '4'), ('-q', '')], [])

and then massage its results.  The first argument is an input list,
typically sys.argv[1:].  The second argument is a format specifier that
tells the getopt function which arguments require values.  Typical usage
goes something like:

    import getopt, sys
    nthreads = 1
    quiet = 0
    for arg, val in getopt.getopt(sys.argv[1:], "t:q"):
	if arg == "-t": nthreads = int(val)
	if arg == "-q": quiet = 1

There's more to the getopt module.  For details, check out its section in
the library manual:

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

A quick doc tip for everyone: Over time, as you get more familiar with
Python, you'll find you have less and less need for the tutorial and
reference manual documentation.  You'll know (most of the time) which module
does what you want.  Instead, what you find yourself asking are questions
like, "What function in the string module transfrobnicates Martian strings?"
or, "What is the order of the arguments to re.sub?"  To easily find the
answers to these sorts of questions, I maintain a bookmark to the library
manual's module index:

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

Though the list is fairly large, the sections I tend to refer to are
generally marked as "visited", so it's easily to pick out "re", "string",
etc from the bunch.  Instead of clicking through the Python home page,
documentation page, library manual front page and scanning the table of
contents, I can generally get to what I'm after in two or three clicks.

Skip Montanaro	| Mojam: "Uniting the World of Music" http://www.mojam.com/
skip@mojam.com  | Musi-Cal: http://www.musi-cal.com/
518-372-5583


From teroc@zianet.com  Tue Jun  1 18:23:20 1999
From: teroc@zianet.com (K P)
Date: Tue, 1 Jun 1999 12:23:20 -0500
Subject: [Tutor] compile
Message-ID: <17213543700960@zianet.com>

-------Phoenix-Boundary-07081998-
Content-type: text/plain; charset=ISO-8859-1
Content-transfer-encoding: Quoted-printable

Hi Max M. Stalnaker, you wrote on 6/1/99 12.45.19 AM:

>What you want to do is to "freeze" your program.  First thing to ask 
>yourself is "do you have MSVC++ 5.0=3F".  6.0 should work too.  If not, 
then for our 
>purposes, you cannot do it.

What about Cygwin=3F Or DJGPP=3F Mingw32=3F Not to mention the slew of 
commercial compilers. Is it possible to 'convert' the process to use 
another compiler=3F Is there any work in progress toward that=3F What about 
gcc, creating the program on *nix and compiling it for distribution in Win 
platforms=3F Many questions, any answers or pointers=3F
Ken

-------Phoenix-Boundary-07081998---




From da@ski.org  Tue Jun  1 18:44:12 1999
From: da@ski.org (David Ascher)
Date: Tue, 1 Jun 1999 10:44:12 -0700 (Pacific Daylight Time)
Subject: [Tutor] compile
In-Reply-To: <17213543700960@zianet.com>
Message-ID: <Pine.WNT.4.04.9906011039580.64-100000@rigoletto.ski.org>

> Hi Max M. Stalnaker, you wrote on 6/1/99 12.45.19 AM:
> 
> > What you want to do is to "freeze" your program.  First thing to ask
> > yourself is "do you have MSVC++ 5.0?".  6.0 should work too.  If not,
> > then for our purposes, you cannot do it.
> 
> What about Cygwin? Or DJGPP? Mingw32? Not to mention the slew of
> commercial compilers. Is it possible to 'convert' the process to use
> another compiler? Is there any work in progress toward that? What about
> gcc, creating the program on *nix and compiling it for distribution in Win
> platforms? Many questions, any answers or pointers?

Cross-compilation isn't going to work -- it might be logically possible,
but it's so much work that it's just not doable.

Freezing with cygwin, djgpp or mingw32 might be more reasonable, but I
don't know that anyone has tried it.  The reason is simple -- the point of
freezing a program is to make installation easy on the user's machine.
Requiring those tools to be installed is not significantly simpler (in my
and other's experience) than requiring the user to run the Python binary
installer (it's what I do, and it works fine for most users).

There are alternatives as well, such as the "small distribution" by Gordon
McMillan, which I haven't investigated.

To get freezing to work with unix-like compilers, I'd suggest starting
from the Unix version of freeze.  I suspect that deep knowledge of the
various issues (relocatable DLLs, etc.) is helpful to get that project to
completion.  If you are successful, please let others know.

--david ascher



From stalnaker@acm.org  Wed Jun  2 07:24:52 1999
From: stalnaker@acm.org (Max M. Stalnaker)
Date: Tue, 01 Jun 1999 23:24:52 -0700
Subject: [Tutor] Compile
References: <199906020507.BAA20845@python.org>
Message-ID: <3754CE33.A89D5990@acm.org>

>

David said it well.  But maybe some more details on the state of the art are acceptable.  As David said, the purpose of freezing is to have a single executable.  This works on Unix, but not quite on Win.  Here are problems as I see them, and I am definitely subject to correction:

1) shared libaries do not freeze.  These are sort-of-dll's and sit in pyd files.  But they could be compiled statically.  Then there are dlls.
2) winall is probably dependent on some MFC stuff and would need to be rewritten in places to port to an alternative compiler.  Borland is an exception, since they licensed MFC at one point, but no one in the community is providing support for that compiler.
3) tkinter does not freeze on win platforms

If you were to solve any one of the three items then it would be a significant contribution to the community.  But I think you need msvc++ 6.0 around to solve these problems, even if only as a reference compiler.

The cgipython project does not have win ports yet and item 1 is relevant there.  If you get msvc++ 6.0 and read every scrap of doc you can find, you will eventually be faced with item 1 within the confines of the existing cgipython project.  This would be a reasonable project.  I think your enthusiasm is carrying you in the direction of unreasonable projects.



>
>
> Subject: RE: [Tutor] compile
> Date: Tue, 1 Jun 1999 12:23:20 -0500
> From: K P <teroc@zianet.com>
> To: tutor <tutor@python.org>
>
> Hi Max M. Stalnaker, you wrote on 6/1/99 12.45.19 AM:
>
> >What you want to do is to "freeze" your program.  First thing to ask
> >yourself is "do you have MSVC++ 5.0?".  6.0 should work too.  If not,
> then for our
> >purposes, you cannot do it.
>
> What about Cygwin? Or DJGPP? Mingw32? Not to mention the slew of
> commercial compilers. Is it possible to 'convert' the process to use
> another compiler? Is there any work in progress toward that? What about
> gcc, creating the program on *nix and compiling it for distribution in Win
> platforms? Many questions, any answers or pointers?
> Ken
>
>   ------------------------------------------------------------------------
>
> Subject: RE: [Tutor] compile
> Date: Tue, 1 Jun 1999 10:44:12 -0700 (Pacific Daylight Time)
> From: David Ascher <da@ski.org>
> To: K P <teroc@zianet.com>
> CC: tutor <tutor@python.org>
>
> > Hi Max M. Stalnaker, you wrote on 6/1/99 12.45.19 AM:
> >
> > > What you want to do is to "freeze" your program.  First thing to ask
> > > yourself is "do you have MSVC++ 5.0?".  6.0 should work too.  If not,
> > > then for our purposes, you cannot do it.
> >
> > What about Cygwin? Or DJGPP? Mingw32? Not to mention the slew of
> > commercial compilers. Is it possible to 'convert' the process to use
> > another compiler? Is there any work in progress toward that? What about
> > gcc, creating the program on *nix and compiling it for distribution in Win
> > platforms? Many questions, any answers or pointers?
>
> Cross-compilation isn't going to work -- it might be logically possible,
> but it's so much work that it's just not doable.
>
> Freezing with cygwin, djgpp or mingw32 might be more reasonable, but I
> don't know that anyone has tried it.  The reason is simple -- the point of
> freezing a program is to make installation easy on the user's machine.
> Requiring those tools to be installed is not significantly simpler (in my
> and other's experience) than requiring the user to run the Python binary
> installer (it's what I do, and it works fine for most users).
>
> There are alternatives as well, such as the "small distribution" by Gordon
> McMillan, which I haven't investigated.
>
> To get freezing to work with unix-like compilers, I'd suggest starting
> from the Unix version of freeze.  I suspect that deep knowledge of the
> various issues (relocatable DLLs, etc.) is helpful to get that project to
> completion.  If you are successful, please let others know.
>
> --david ascher
>
>   ------------------------------------------------------------------------
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor
>
> --__--__----

--
Max M. Stalnaker  stalnaker@acm.org
Astar Computer Consulting:  Networking and Custom Accounting Software




From teroc@zianet.com  Wed Jun  2 15:26:17 1999
From: teroc@zianet.com (K P)
Date: Wed, 2 Jun 1999 09:26:17 -0500
Subject: [Tutor] Compile
Message-ID: <14253623423216@zianet.com>

-------Phoenix-Boundary-07081998-
Content-type: text/plain; charset=ISO-8859-1
Content-transfer-encoding: Quoted-printable

Thank you for the input. Actually I wanted to know if using other win-based 
compilers was possible. The extra info is much appreciated though, gives me 
something to ponder, and even a little guidance on pursueing this. I've had 
limited success in compiling Python with cygwin, and haven't tried it with 
borland. If I understand correctly, if your compiler can't compile Python, 
don't even try a 'freeze'. Off to the drawing board.
Ken
Hi Max M. Stalnaker, you wrote on 6/2/99 01.24.52 AM:

>
>
>David said it well.  But maybe some more details on the state of the art 
>are acceptable.  As David said, the purpose of 
>freezing is to have a single executable.  This works on Unix, but not 
>quite on Win.  Here are problems as I see them, 
>and I am definitely subject to correction:
>
>1) shared libaries do not freeze.  These are sort-of-dll's and sit in pyd 
>files.  But they could be compiled 
>statically.  Then there are dlls.
>2) winall is probably dependent on some MFC stuff and would need to be 
>rewritten in places to port to an alternative 
>compiler.  Borland is an exception, since they licensed MFC at one point, 
>but no one in the community is providing 
>support for that compiler.
>3) tkinter does not freeze on win platforms
>
>If you were to solve any one of the three items then it would be a 
>significant contribution to the community.  But I 
>think you need msvc++ 6.0 around to solve these problems, even if only as 
>a reference compiler.
>
>The cgipython project does not have win ports yet and item 1 is relevant 
>there.  If you get msvc++ 6.0 and read every 
>scrap of doc you can find, you will eventually be faced with item 1 within 
>the confines of the existing cgipython 
>project.  This would be a reasonable project.  I think your enthusiasm is 
>carrying you in the direction of unreasonable 
>projects.





-------Phoenix-Boundary-07081998---




From arcege@shore.net  Wed Jun  2 16:29:00 1999
From: arcege@shore.net (Michael P. Reilly)
Date: Wed, 2 Jun 1999 11:29:00 -0400 (EDT)
Subject: [Tutor] Te: [Tutor] Email Attachment
Message-ID: <199906021529.LAA15333@northshore.shore.net>

> Hi,
> 
>  How do I write a script that send a email with attachment (ascii or
> binary), tried smtplib but doesn't support attachment, tried
> MimeWriter.py but couldn't send mail. Just need a simple component or
> wrapper to do the job, please help or any useful links.
> 
> Thanks
> 

I would suggest a combination of (c)StringIO, smtplib and MimeWriter.

from smtplib import SMTP
from MimeWriter import MimeWriter
try:
  from cStringIO import StringIO
except ImportError:
  from StringIO import StringIO

tempfile = StringIO()
mw = MimeWriter(tempfile)
mw.addheader('to', 'tutor@python.org')
mw.addheader('from', 'arcege@shore.net')
mw.addheader('subject', '[Tutor] Email attachment')
mw.startmultipartbody('mixed')
for filename in files_to_attach:
  sw = mw.nextpart()
  f = sw.startbody('application/x-python')
  f.write(open(filename).read())
mw.lastpart()

message = tempfile.getvalue()
SMTP('mailhost').sendmail('arcege@shore.net', 'tutor@python.org', message)

Gee, I hope I haven't given too much of the fun stuff away. :)

You can also look at my mimecntl module to do some more of this for you.
(http://www.shore.net/~arcege/python/mimecntl.py)

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Engineer | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From teroc@zianet.com  Wed Jun  2 19:44:28 1999
From: teroc@zianet.com (K P)
Date: Wed, 2 Jun 1999 13:44:28 -0500
Subject: [Tutor] Hopefully OT
Message-ID: <18510287549717@zianet.com>

-------Phoenix-Boundary-07081998-
Content-type: text/plain; charset=ISO-8859-1
Content-transfer-encoding: Quoted-printable

Disclaimer: Begining programmer question!

	How would a GUi be implemented=3F This is not a question about which 
GUI/TK library to use (I happen to be using wxPython), but more on, how to 
give a program more than a CLI. Mayeb a quick example with this:

-------->Begin sample program

class Spam:
   __init__(self, meat1, meat2):
      self.ingredient1 =3D meat1
      self.ingredient2 =3D meat2
   def switch(self):
      self.temp =3D self.ingredient1
      self.ingredient1 =3D self.ingredient2
      self.ingredient2 =3D self.temp

def main():
   type1 =3D raw_input("What kind of meat for ingredient 1: ")
   type2 =3D raw_input("What kind of meat for ingredient 2: ")
   tasty =3D Spam(type1, type2)
   print tasty.ingredient1, tasty.ingredient2
   tasty.switch()
   print tasty.ingredient1, tasty.ingredient2


End sample program<------------

Ok, dumb program. My question then would be, if I gave this 'program' a 
gui, how would I write it to use my self-made class=3F After looking at the 
docs for several GUI/TK libraries, I find myself confused how to accomplish 
this. If anyone has any general GUI faqs/tutorials/etc please let me know.

Ken

-------Phoenix-Boundary-07081998---




From M.Faassen@vet.uu.nl  Wed Jun  2 21:29:43 1999
From: M.Faassen@vet.uu.nl (Martijn Faassen)
Date: Wed, 02 Jun 1999 22:29:43 +0200
Subject: [Tutor] Hopefully OT
References: <18510287549717@zianet.com>
Message-ID: <37559437.9DB9BE1@pop.vet.uu.nl>

K P wrote:
> 
> Disclaimer: Begining programmer question!
> 
>         How would a GUi be implemented? This is not a question about which
> GUI/TK library to use (I happen to be using wxPython), but more on, how to
> give a program more than a CLI. Mayeb a quick example with this:
 
[snip]

> Ok, dumb program. My question then would be, if I gave this 'program' a
> gui, how would I write it to use my self-made class? After looking at the
> docs for several GUI/TK libraries, I find myself confused how to accomplish
> this. If anyone has any general GUI faqs/tutorials/etc please let me know.

The basic advice I can give you here is to at all times separate the
program logic from the particular interface code you're using, unless it
is a trivial program. In general, avoid letting program code call the
GUI, try to let the GUI code call the program code instead.

Not mingling program with GUI code gives you:

* Easier to think about and maintain. This is most important; by
disconnecting GUI code from your actual program you can think about the
structure more easily. No spaghetti connections; you don't to delve
through GUI code (which isn't well known for its amazing elegance,
usually) to change the way your program works.

* Enhanced portability; you can keep the core app more portable to
different OSes at least. You can switch to a different GUI in the
future.

* Possibility for a power-user command line interface, or 'batch run'
interface

What you do in some imagined GUI (IGUI) system is this:

import IGUI
import MyReport

class ReportWindow(IGUI.Window):
    def __init__(self, start_report):
        # call the Window base class with some parameters to set things
up
        IGUI.Window.__init__(self, "Title: Report", 200, 200)
   	# add a button to the Window now, called 'Update'. Call
'self.update'
        # whenever this button is pressed
        self.mybutton = self.addButton(" Update ", self.update)
        # also put an text entry box on the window
        self.textentry = self.addTextEntry("Which report?", 
                                           self.setReport,
when=IGUI.OnChange)
        # set some labels for output
        self.labela = self.addLabel()
        self.labelb = self.addLabel()

        # the current report we show when 'Update' is pressed
        self.current_report = start_report

    def update(self):
        # always display the current report
        self.showReport(self.current_report)

    def setReport(self, text):
        # the IGUI system sends a string whenever the text entry changes
        # (if 'when' is set to OnChange)
        
        # try to find a new report object in a ReportDatabase object
that's
        # defined in the main program code
        report = MyReport.ReportDatabase.lookup(reportname = text)
        # ReportDatabase.lookup() returns the report object if a report
object
        # with that name exists, otherwise None
        # if we found a report with that name it is the new current
report
        if report != None:
            self.current_report = report

    def showReport(self, report):
        # report is some actual application object that generates a
report of
        # whatever
        spamtext = report.getSpamInfo()        
        # show it in label a
        labela.setText(spamtext)
        if report.reportIsGood():
            labelb.setText("This report is good!")
        else:
            labelb.setText("Dreadful spam statistics!")

The main idea is that you assemble a GUI window or form by placing some
GUI widgets (like buttons and text and so on) onto it. You connect some
widgets with special methods or objects in your program that catch the
event messages they sent (for instance when a button is pressed). The
output widgets generally are changed by calling special methods in them
(like .setText() for the label, for instance).

Okay, aside from this basic advice I'm no expert on GUI design. It seems
that one of the most elegant structures is the 'model-control-view'
approach, so look that one up.

I hope this helps some, good luck!

Regards,

Martijn


From danstar@execpc.com  Wed Jun  2 22:14:26 1999
From: danstar@execpc.com (Dan Star)
Date: Wed, 02 Jun 1999 16:14:26 -0500
Subject: [Tutor] Hopefully OT
References: <18510287549717@zianet.com> <37559437.9DB9BE1@pop.vet.uu.nl>
Message-ID: <37559EB2.229889C4@execpc.com>

Martijn Faassen wrote:

<snip>

> 
> The basic advice I can give you here is to at all times separate the
> program logic from the particular interface code you're using, unless it
> is a trivial program. In general, avoid letting program code call the
> GUI, try to let the GUI code call the program code instead.
> 

<snip>

> Okay, aside from this basic advice I'm no expert on GUI design. It seems
> that one of the most elegant structures is the 'model-control-view'
> approach, so look that one up.

I am just jumping into Python myself with the intent of using a GUI
interface for some sample apps.  Is there any book that describes this
model-control-view method using Python?  Or a book that describes it
using Pseudo Code?

By the way is there an Archive of these posts?  Seems like excellent
discussion is going on and it would be a shame to loose the knowledge
being discussed.

Regards,
Dan


From da@ski.org  Wed Jun  2 22:31:26 1999
From: da@ski.org (David Ascher)
Date: Wed, 2 Jun 1999 14:31:26 -0700 (Pacific Daylight Time)
Subject: [Tutor] Hopefully OT
In-Reply-To: <37559EB2.229889C4@execpc.com>
Message-ID: <Pine.WNT.4.04.9906021429570.315-100000@rigoletto.ski.org>

On Wed, 2 Jun 1999, Dan Star wrote:

> I am just jumping into Python myself with the intent of using a GUI
> interface for some sample apps.  Is there any book that describes this
> model-control-view method using Python?  Or a book that describes it
> using Pseudo Code?

Hmm.  I can't think of one off hand, except for the discussion about the
MVC (Model-View-Controller) pattern in the "Design Patterns" book, which
is a worthwhile but maybe a bit verbose book -- many of the patterns are
relatively complicated by the use of languages like C++ =).

> By the way is there an Archive of these posts?  Seems like excellent
> discussion is going on and it would be a shame to loose the knowledge
> being discussed.

Yes.  Each post ends with the lines:

> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor

If you click on that link, you should be able to get to an archive of all
of the posts.

--david



From todd@royalbastard.com  Thu Jun  3 07:37:11 1999
From: todd@royalbastard.com (Todd Martin)
Date: Wed, 2 Jun 1999 23:37:11 -0700
Subject: [Tutor] creating files and writing to them
Message-ID: <19990602233711.A25601@royalbastard.com>

Ok so I can do these things in perl and shell but I'm just now learning
python and am a little confused.

What I want to do is pass a username to a script as an argument like so:

% script username

Then write a file named "username.startup".

This is where I'm at right now:

#! /usr/bin/python

file = open('/home/todd/docname', 'w')
file.write('The create script in its infancy\n')
file.close()

def docname ():
        username = "todd"
        startup = ".startup"
        doc = username + startup
        print "%s" % doc

docname()

I know its lame so far but I'm new :)

Ok so that last tidbit there is how I figured I could take the username and 
append ".startup" to it. But now I need to create a file by that name, rather 
than the way its being done now, where I have to declare the file name in
advance (does that make sense?).

Now I know I will need to pass the username argument to argv, but that can wait untill I find out how to pass file = open() a variable rather than a file name.

Is this clear? I'm not entirely sure I know how to word this right.

Any help would be very appreciated!

-- 
Todd Martin
todd@royalbastard.com
http://royalbastard.com/~todd


From tim_one@email.msn.com  Thu Jun  3 09:16:38 1999
From: tim_one@email.msn.com (Tim Peters)
Date: Thu, 3 Jun 1999 04:16:38 -0400
Subject: [Tutor] creating files and writing to them
In-Reply-To: <19990602233711.A25601@royalbastard.com>
Message-ID: <000901bead99$67418020$d09e2299@tim>

[Todd Martin]
> Ok so I can do these things in perl and shell but I'm just now learning
> python and am a little confused.

That won't last -- you're doing fine!

> What I want to do is pass a username to a script as an argument like so:
>
> % script username
>
> Then write a file named "username.startup".

No problem.  You'll find the arguments to your script in Python's sys.argv.
That is,

import sys
print sys.argv

It's a list of strings, very much like you're used to from Perl.  Except
Python generally gives sensible *names* to things <wink>.

> This is where I'm at right now:
>
> #! /usr/bin/python
>
> file = open('/home/todd/docname', 'w')
> file.write('The create script in its infancy\n')
> file.close()
>
> def docname ():
>         username = "todd"
>         startup = ".startup"
>         doc = username + startup
>         print "%s" % doc

That last line is easier as

    print doc

and does the same thing.  Python automatically converts the expressions in a
"print" stmt to strings for you, and doc started life as a string anyway.

> docname()
>
> I know its lame so far but I'm new :)

Not lame at all:  that's how you start!  Get something (anything) that
works, and play with it.  Believe it or not, you're almost done with it.

> Ok so that last tidbit there is how I figured I could take the
> username and  append ".startup" to it. But now I need to create a file
> by that  name, rather than the way its being done now, where I have to
> declare the file name in advance (does that make sense?).

Yes, you want username to be taken from the command line, instead of
hardcoded.  So, assuming you did

import sys

at the top of your program, just change your username definition to

        username = sys.argv[1]

Then username will become whatever string you passed as the first argument
on the command line.

> Now I know I will need to pass the username argument to argv, but
> that can wait untill I find out how to pass file = open() a
> variable rather than a file name.

open() simply wants a string, and will accept any *expression* that
*evaluates* to a string.  A string literal like you have is one kind of
expression that evaluates to a string.  You could have written

file = open('/home/todd/docname', 'w')

as

somename = '/home/todd/docname'
file = open(somename, 'w')

instead, or as

def somename():
    return '/home/' + 'todd/' + 'doc' + 'junkname'[-4:]
file = open(somename(), 'w')

or in a million other ways.

So try moving your docname function to the top of your file (so that your
function gets defined before you try to call it!), change it to return doc
instead of just printing it, and replace your literal filename with a call
to docname:

file = open(docname(), 'w')

Python doesn't have a lot of special syntax to learn (and especially not
compared to Perl), and the general rule is it doesn't matter how you spell
things just as long as the expressions you pass to functions evaluate to the
*types* of things the function expects.  Try open(3) or even open(open).
What happens?  Python will yell at you when it can't make sense out of what
you're doing.  This is also unlike Perl, although running Perl with -w is
much closer to Python.

most-of-all-have-fun-ly y'rs  - tim




From teroc@zianet.com  Thu Jun  3 14:20:46 1999
From: teroc@zianet.com (K P)
Date: Thu, 3 Jun 1999 08:20:46 -0500
Subject: [Tutor] Hopefully OT
Message-ID: <13171781231316@zianet.com>

-------Phoenix-Boundary-07081998-
Content-type: text/plain; charset=ISO-8859-1
Content-transfer-encoding: Quoted-printable

<Huge snip of useful tips and spam-realted coding :)>

Thank you for that. It gives me a lot to consider, and a lot of help! Now 
maybe I'll find some small program with a GUI to use as a brief reference 
with all this info.
Ken

-------Phoenix-Boundary-07081998---




From ivanlan@callware.com  Thu Jun  3 14:57:54 1999
From: ivanlan@callware.com (Ivan Van Laningham)
Date: Thu, 03 Jun 1999 07:57:54 -0600
Subject: [Tutor] creating files and writing to them
References: <19990602233711.A25601@royalbastard.com>
Message-ID: <375689E2.5218B1@callware.com>

Hi Todd etc.--

Todd Martin wrote:
> 
> Ok so I can do these things in perl and shell but I'm just now learning
> python and am a little confused.
> 
> What I want to do is pass a username to a script as an argument like so:
> 
> % script username
> 
> Then write a file named "username.startup".
> 
> This is where I'm at right now:
> 
> #! /usr/bin/python
> 
> file = open('/home/todd/docname', 'w')
> file.write('The create script in its infancy\n')
> file.close()
> 
> def docname ():
>         username = "todd"
>         startup = ".startup"
>         doc = username + startup
>         print "%s" % doc
> 
> docname()
> 
> I know its lame so far but I'm new :)
> 
> Ok so that last tidbit there is how I figured I could take the username and
> append ".startup" to it. But now I need to create a file by that name, rather
> than the way its being done now, where I have to declare the file name in
> advance (does that make sense?).
> 
> Now I know I will need to pass the username argument to argv, but that can wait untill I find out how to pass file = open() a variable rather than a file name.
> 
> Is this clear? I'm not entirely sure I know how to word this right.
> 
> Any help would be very appreciated!
> 

#!/usr/bin/python
# I see that you're on RedHat Linux;-)
if len ( sys.argv ) > 1 :
  homedir = "/home/"
  username = sys.argv[1]
  startup = "/.startup"

  startupfile = open ( homedir + username + startup, 'w' )
  file.write('The create script in its infancy\n')
  file.close()
else :
  print "Usage:  %s username" % ( sys.argv[0] )

<ask-us-something-hard>-ly y'rs,
Ivan
----------------------------------------------
Ivan Van Laningham
Callware Technologies, Inc.
ivanlan@callware.com
http://www.pauahtun.org
See also: 
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
----------------------------------------------


From arcege@shore.net  Thu Jun  3 15:40:15 1999
From: arcege@shore.net (Michael P. Reilly)
Date: Thu, 3 Jun 1999 10:40:15 -0400 (EDT)
Subject: [Tutor] creating files and writing to them
In-Reply-To: <375689E2.5218B1@callware.com> from Ivan Van Laningham at "Jun 3, 99 07:57:54 am"
Message-ID: <199906031440.KAA16224@northshore.shore.net>

> Hi Todd etc.--
> 
> Todd Martin wrote:
> > 
> > Ok so I can do these things in perl and shell but I'm just now learning
> > python and am a little confused.
> > 
> > What I want to do is pass a username to a script as an argument like so:
> > 
> > % script username
> > 
> > Then write a file named "username.startup".
> > 
> > This is where I'm at right now:
> > 
> > #! /usr/bin/python
> > 
> > file = open('/home/todd/docname', 'w')
> > file.write('The create script in its infancy\n')
> > file.close()
> > 
> > def docname ():
> >         username = "todd"
> >         startup = ".startup"
> >         doc = username + startup
> >         print "%s" % doc
> > 
> > docname()
> > 
> > I know its lame so far but I'm new :)
> > 
> > Ok so that last tidbit there is how I figured I could take the username and
> > append ".startup" to it. But now I need to create a file by that name, rather
> > than the way its being done now, where I have to declare the file name in
> > advance (does that make sense?).
> > 
> > Now I know I will need to pass the username argument to argv, but that can wait untill I find out how to pass file = open() a variable rather than a file name.
> > 
> > Is this clear? I'm not entirely sure I know how to word this right.
> > 
> > Any help would be very appreciated!
> > 
> 
> #!/usr/bin/python
> # I see that you're on RedHat Linux;-)
> if len ( sys.argv ) > 1 :
>   homedir = "/home/"
>   username = sys.argv[1]
>   startup = "/.startup"
> 
>   startupfile = open ( homedir + username + startup, 'w' )
>   file.write('The create script in its infancy\n')
>   file.close()
> else :
>   print "Usage:  %s username" % ( sys.argv[0] )

Just for a little, more portable, change (on UNIX): the expanduser()
function in the os.path module resolves "~username" from the
/etc/passwd file.

  if len(sys.argv) > 1:
    username = sys.argv[1]
    homedir = os.path.expanduser('~' + username)
    doc_filename = os.path.join(homedir, 'docname')
    doc_file = open(doc_filename, 'w')

    startupfile = open(username + '.startup', 'w')
    ...

Not all systems/users may have their home directories in "/home/".

  -Arcege



From todd@royalbastard.com  Thu Jun  3 18:11:30 1999
From: todd@royalbastard.com (Todd Martin)
Date: Thu, 3 Jun 1999 10:11:30 -0700
Subject: [Tutor] another couple of questions
Message-ID: <19990603101130.A2338@royalbastard.com>

Ok so I can now create a file and name it what I want to name it, I can
write to it and all seems ok. 

Now I have this shell script that I use for dealing with IP address's and
what it does essentially is takes an IP, breaks it down to its 4 octets like
255.255.255.255 and stores each octet into its own variable, like $OCT1, $OCT2,
$OCT3, and $OCT4. By doing that I can add and subtract from $OCT4 and glue it 
all bake together again.

So if I have 111.111.111.111 and I want to give a list of usuable IP's for a
customer I can just add to $OCT4 and produce 111.111.111.112 etc......

How can I do this in python?

-----------------------------
Second question
-----------------------------

I can print to a file, but how do I read a template into a file? For instance
I want to have a file called "foc" that I can read into a file. I would also
like to be able to change certain fields in the template, for instance

Name: 		username
Address: 	address

I would like the program to prompt the user for the variable address (username
is given as an argument via argv[1]) then fill in the appropriet field in the
template.

-- 
Todd Martin
todd@royalbastard.com
http://royalbastard.com/~todd


From M.Faassen@vet.uu.nl  Thu Jun  3 18:37:23 1999
From: M.Faassen@vet.uu.nl (Martijn Faassen)
Date: Thu, 03 Jun 1999 19:37:23 +0200
Subject: [Tutor] another couple of questions
References: <19990603101130.A2338@royalbastard.com>
Message-ID: <3756BD53.71D25118@pop.vet.uu.nl>

Todd Martin wrote:
> 
> Ok so I can now create a file and name it what I want to name it, I can
> write to it and all seems ok.

Great!

> Now I have this shell script that I use for dealing with IP address's and
> what it does essentially is takes an IP, breaks it down to its 4 octets like
> 255.255.255.255 and stores each octet into its own variable, like $OCT1, $OCT2,
> $OCT3, and $OCT4. By doing that I can add and subtract from $OCT4 and glue it
> all bake together again.
> 
> So if I have 111.111.111.111 and I want to give a list of usuable IP's for a
> customer I can just add to $OCT4 and produce 111.111.111.112 etc......
> 
> How can I do this in python?

I'm not sure I get entirely what you want, but perhaps something like
this helps you get started:

# warning, untested code!
import string

# basic & dumb exception thing
class Error(Exception): 
   pass

ip_address = "111.111.111.111" # or read this as an argument or from a
file
# split the string at the .
octets = string.split(ip_address, ".")
# we get a list, if it contains more or less than 4 elements, we bail
out
if len(octets) != 4:
    raise Error, "There should be 4 octets, not more, not less!"
# convert the octets to numbers (should actually do more error checking)
# yeah, I know you can write this more compactly with map and such
numerical_octets = []
for octet in octets:
    numerical_octets.append(int(octet))
numerical_octets[3] = numerical_octets[3] + 1 # add one to the 4th octet
# now turn octets back into strings
new_octets = []
for octet in numerical_octets:
    new_octets.append(int(octet))
# now make a nice ip address
final_address = string.join(new_octets, ".")
 
> -----------------------------
> Second question
> -----------------------------
> 
> I can print to a file, but how do I read a template into a file? For instance
> I want to have a file called "foc" that I can read into a file. I would also
> like to be able to change certain fields in the template, for instance
> 
> Name:           username
> Address:        address
> 
> I would like the program to prompt the user for the variable address (username
> is given as an argument via argv[1]) then fill in the appropriet field in the
> template.

I'm not quite sure what you want here either, but perhaps this'll help:

import string

username = "luser"
# construct string 
foo = "%s%s\n" % (string.ljust("Name:", 10), username)
# then write this line to the file
f = open("foofile.txt", "w")
f.write(foo)
f.close()

Of course you can come up with a set of functions or classes than
handles the same thing in a more sophisticated way, too.

Regards and good luck!

Martijn


From M.Faassen@vet.uu.nl  Thu Jun  3 20:02:15 1999
From: M.Faassen@vet.uu.nl (Martijn Faassen)
Date: Thu, 03 Jun 1999 21:02:15 +0200
Subject: [Tutor] another couple of questions
References: <19990603101130.A2338@royalbastard.com> <3756BD53.71D25118@pop.vet.uu.nl>
Message-ID: <3756D137.74E48337@pop.vet.uu.nl>

Martijn Faassen wrote:
[snip]
> for octet in numerical_octets:
>     new_octets.append(int(octet))

# oops, this should read:
new_octets.append(str(octet))

I'm trying to turn these things back into strings, after all.

It's still untested code, but at least one bug is fixed. :)

Regards,

Martijn


From deirdre@deirdre.net  Thu Jun  3 21:51:45 1999
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Thu, 3 Jun 1999 16:51:45 -0400 (EDT)
Subject: [Tutor] another couple of questions
In-Reply-To: <19990603101130.A2338@royalbastard.com>
Message-ID: <Pine.LNX.3.96.990603164349.21164B-100000@localhost.deirdre.org>

On Thu, 3 Jun 1999, Todd Martin wrote:

> Now I have this shell script that I use for dealing with IP address's and
> what it does essentially is takes an IP, breaks it down to its 4 octets like
> 255.255.255.255 and stores each octet into its own variable, like $OCT1, $OCT2,
> $OCT3, and $OCT4. By doing that I can add and subtract from $OCT4 and glue it 
> all bake together again.
> 
> So if I have 111.111.111.111 and I want to give a list of usuable IP's for a
> customer I can just add to $OCT4 and produce 111.111.111.112 etc......
> 
> How can I do this in python?

There are several ways of doing this, I'll give an example:

ipaddr = '111.111.111.111'
a = string.split(ipaddr, '.') # split the string on the periods
b = int(a[3])
for i in xrange(b, 255):
 a[3] = string.zfill(i, 3)
 newip = string.join(a, '.')
 print newip

_Deirdre   *   http://www.linuxcabal.org   *   http://www.deirdre.net
"I enjoy playing whack-a-mole with my mind" -- Rick Moen



From Marek Polanski" <junior@supermedia.pl  Thu Jun  3 15:55:14 1999
From: Marek Polanski" <junior@supermedia.pl (Marek Polanski)
Date: 03 Jun 1999 14:55:14
Subject: [Tutor] help window in Tkinter
Message-ID: <19990603210821Z539356-7056+808@mail.supermedia.pl>

I have script like that:

from Tkinter import *

class App:
    def __init__(self, master):
        window=Frame(master)
        window.pack()

        self.help_butt=Button(window, text="Help", command=[here I don't know])
        self.help_butt.grid(row=1, column=1)

and now I need to make this button open another window with widget Label
which would display some text with help. I tried to make it in another class
and in another function, but it doesn't work... Only way I could get it to work
by another script (cutton called function, which called another script). It's
kind of stupid to make everything in another file, so I have question. How to
make it work from the same script? I know I can do something like that calling
tkMessageBox.showinfo (or whatever), but that's not really what I want to do.

Second thing is that I would like to make another button clearing current
window, and displaying there something else (kind of 'Next' button) dependent
on which option was ckecked in original window. Problem is, I don't even know
how to start.

If you would have script which would contain things like that, please send me
on e-mail. I think I'll be able to understand how does it work.

system: W98
python: 1.5.2
Tkinter: from python instalation (I think it was 8.0?!?)

  Marek Polanski

e-mail: junior@supermedia.pl                              fidonet: 2:480/112.12
--- GoldED/W32 3.0.1
 * Origin: I am comming back in 11 days. (2:480/112.12)



From deirdre@deirdre.net  Thu Jun  3 22:51:14 1999
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Thu, 3 Jun 1999 17:51:14 -0400 (EDT)
Subject: [Tutor] creating files and writing to them
In-Reply-To: <199906031440.KAA16224@northshore.shore.net>
Message-ID: <Pine.LNX.3.96.990603174552.21361B-100000@localhost.deirdre.org>

On Thu, 3 Jun 1999, Michael P. Reilly wrote:

> Not all systems/users may have their home directories in "/home/".

On MacOS X Server (derived from NeXTtep), it's /Local/Users/username
except, of course, root, who gets /Local/Users/Administrator

So you can't even expect the username to be the same.

Furthermore, you can't necessarily expect to get it out of /etc/passwd
(lookupd is a more portable approach).

In call cases, you can write a file foo to your home directory from
anywhere by opening it as "~/foo"

_Deirdre   *   http://www.linuxcabal.org   *   http://www.deirdre.net
"I enjoy playing whack-a-mole with my mind" -- Rick Moen



From todd@royalbastard.com  Fri Jun  4 01:26:53 1999
From: todd@royalbastard.com (Todd Martin)
Date: Thu, 3 Jun 1999 17:26:53 -0700
Subject: [Tutor] Thanks everyone
Message-ID: <19990603172653.B8550@royalbastard.com>

Thanks to everyone who has sent me tips and put up with my never ending
stream of questions! I've learned a lot today and more than accomplished 
a few of my goals in large part because of all the great help I got from
this list.

Thanks to you all!


-- 
Todd Martin
todd@royalbastard.com
http://royalbastard.com/~todd


From priest@sfu.ca  Fri Jun  4 07:40:16 1999
From: priest@sfu.ca (David Priest)
Date: Thu, 03 Jun 1999 23:40:16 -0700
Subject: [Tutor] Re: Hopefully OT (?) / GUI
In-Reply-To: <199906040505.BAA18630@python.org>
Message-ID: <4.1.19990603233800.009883a0@mailserver.sfu.ca>

http://www.sfu.ca/~priest should connect you to some frameworks I've been
working on (er... at least was, a couple months ago.  Life then got busy.
Sigh.)  Hopefully they'll be of some use.

If someone wants to tear them to shreds and identify weaknesses and errors,
I'm all ears, too.  Probably better to do that on the wxPython listserv,
though.

I think it's mainly KP that's been wanting this sort of thing, but you're
all welcome to have at it.  :-)




From adeline_j_wilcox@ccMail.Census.GOV  Fri Jun  4 21:28:15 1999
From: adeline_j_wilcox@ccMail.Census.GOV (adeline_j_wilcox@ccMail.Census.GOV)
Date: Fri, 04 Jun 1999 16:28:15 -0400
Subject: [Tutor] Re[2]: [Tutor] ksh and SAS questions
Message-ID: <9906049285.AA928528327@smtp-gw1.census.gov>

     Well, I can't see the error in the following script. Running 
     SunOS 5.5.1. When I run my Python script, I get this error 
     message:
     
Traceback (innermost last):
  File "recheck.py", line 14, in ?
    month = os.environ['CATI']
  File "/usr/local/lib/python1.5/UserDict.py", line 12, in __getitem__
    def __getitem__(self, key): return self.data[key]
KeyError: CATI

     The script is:
     
     1  #!/usr/local/bin/python
     2  #PROGRAM: recheck.py
     3  #FUNCTION: execute Barbara's RECHECK program
     4  #INPUTS: rofr.txt
     5  #OUTPUTS: rofr.sas, ccMail message
     6  #CALLS TO: Python os, sys, and string modules, recheck.sas
     7  #SPECIAL NOTES: Have not yet figured out how to automate input of the 
rofr file
     8  #AUTHOR: Adeline Wilcox         DATE: 05Apr99
     9  #Written with the assistance of Andrew Kuchling and especially Tim 
Peters
    10  #UPDATED:                       DATE: 
    11  import os, sys 
    12  os.system('/op/ctl/prod/scripts/setcm.ksh')
    13  #get CATI month from environment
    14  month = os.environ['CATI']
    15  import string
    16  sys.stdin = open('/op/ctl/prod/data/ro' + month +'.txt','r')
    17  lines = sys.stdin.readlines()
    18  for i in range(len(lines)):
    19      line = lines[i]
    20      lines[i] = "'" + string.rstrip(line) + "'"
    21  sys.stdout= open('/op/ctl/test/data/rofr.sas','w')
    22  print "if rofr in (" + string.join(lines, ", ") + ") then output;"
    23  #if I dont close the file, SAS does not get quotes around last value of 
rofr
    24  sys.stdout.close()
    25  #os.system("$SASDIR/sas /op/ctl/prod/prgms/recheck.sas -sysparm " + 
month + \ " -log /op/ctl/prod/logs/recheck.log." + month ")
    26  #os.system("mailx -s 'Recheck " + month + " run for you \' 
Adeline.J.Wilcox@ccmail.census.gov ")


Adeline



______________________________ Reply Separator _________________________________
Subject: Re: [Tutor] ksh and SAS questions 
Author:  Corran Webster <Corran.Webster@math.tamu.edu> at SMTP-GATEWAY
Date:    5/12/1999 5:52 PM


> Using a script named recheck.py, I call a ksh script named 
> setcm.ksh. That script exports some shell variables. I would like to
> substitute the value of one shell variable in particular, named CATI,
> for the value 199904 in lines 14, 23 and 24. Please note that
> I want to pass the value of this shell variable to a SAS program with the
> SYSPARM option in line 23.

The os.environ variable gives you access to the UNIX environment variables,
so:

import os
month = os.environ['CATI']

puts the value as a string in the variable month.

> Can anyone tell me how to get ksh, Python and SAS working together here?

I've appended an updated version of the program which should do what I think
you want.  I've also fixed up what I think was a major inefficiency by moving
the write to the file "rofr.sas" out of the for loop (if this isn't what you
want, then you can easily put it back into the loop).  I also prettified
it a bit.

> I have neither C programming nor OOP experience. Also very new to Python.
> Have done a little reading of Lutz 1996 Programming Python. Reference
> to the Python documentation on the Web could be helpful.

The library documentation on www.python.org whould tell you what you need
to know about the os module and the os.environ variable.  If you have
questions about what's going on in the script, please ask.

Corran

----
#!/usr/local/bin/python
#PROGRAM: recheck.py
#FUNCTION: execute Barbara's RECHECK program
#INPUTS: rofr.txt
#OUTPUTS: rofr.sas, ccMail message
#CALLS TO: Python os, sys, and string modules, recheck.sas
#AUTHOR: Adeline Wilcox         DATE: 05Apr99
#Written with the assistance of Andrew Kuchling and especially Tim Peters
#UPDATED:                       DATE: 

import os, sys 
os.system('/op/ctl/prod/scripts/setcm.ksh')

# get value of CATI from environment
month = os.environ['CATI']

import string

sys.stdin = open('/op/ctl/prod/data/ro' + month + '.txt','r')

lines = sys.stdin.readlines()
for i in range(len(lines)):
    line = lines[i]
    lines[i] = "'" + string.rstrip(line) + "'"

sys.stdout= open('/op/ctl/prod/data/rofr.sas','w')
print "if rofr in (" + string.join(lines, ", ") + ") then output;"
#if I dont close the file, SAS does not get quotes around last value of rofr
sys.stdout.close()

os.system("$SASDIR/sas /op/ctl/prod/prgms/recheck.sas -sysparm " + month + \
        " -log /op/ctl/prod/logs/recheck.log." + month)
os.system("mailx -s '" + month + " for you' " + \
        "Adeline.J.Wilcox@ccmail.census.gov < rc" + month + ".txt")







From da@ski.org  Fri Jun  4 21:46:33 1999
From: da@ski.org (David Ascher)
Date: Fri, 4 Jun 1999 13:46:33 -0700 (Pacific Daylight Time)
Subject: [Tutor] Re[2]: [Tutor] ksh and SAS questions
In-Reply-To: <9906049285.AA928528327@smtp-gw1.census.gov>
Message-ID: <Pine.WNT.4.04.9906041345020.46-100000@rigoletto.ski.org>

On Fri, 4 Jun 1999 adeline_j_wilcox@ccMail.Census.GOV wrote:

>      Well, I can't see the error in the following script. Running 
>      SunOS 5.5.1. When I run my Python script, I get this error 
>      message:
>      
> Traceback (innermost last):
>   File "recheck.py", line 14, in ?
>     month = os.environ['CATI']
>   File "/usr/local/lib/python1.5/UserDict.py", line 12, in __getitem__
>     def __getitem__(self, key): return self.data[key]
> KeyError: CATI

This means that there is no environment variable called CATI when you run
line 14 -- if that was supposed to be set by

>     12  os.system('/op/ctl/prod/scripts/setcm.ksh')

then there's something wrong with that script.  I don't know the Korn
shell, but it could be that you need to specify something in that shell to
make the environment variables "stick" after execution.  In bash, I
believe it's the "export" command.

--david



From guido@CNRI.Reston.VA.US  Fri Jun  4 22:09:00 1999
From: guido@CNRI.Reston.VA.US (Guido van Rossum)
Date: Fri, 04 Jun 1999 17:09:00 -0400
Subject: [Tutor] Re[2]: [Tutor] ksh and SAS questions
In-Reply-To: Your message of "Fri, 04 Jun 1999 13:46:33 PDT."
 <Pine.WNT.4.04.9906041345020.46-100000@rigoletto.ski.org>
References: <Pine.WNT.4.04.9906041345020.46-100000@rigoletto.ski.org>
Message-ID: <199906042109.RAA10154@eric.cnri.reston.va.us>

> From: David Ascher <da@ski.org>

> On Fri, 4 Jun 1999 adeline_j_wilcox@ccMail.Census.GOV wrote:
> 
> >      Well, I can't see the error in the following script. Running 
> >      SunOS 5.5.1. When I run my Python script, I get this error 
> >      message:
> >      
> > Traceback (innermost last):
> >   File "recheck.py", line 14, in ?
> >     month = os.environ['CATI']
> >   File "/usr/local/lib/python1.5/UserDict.py", line 12, in __getitem__
> >     def __getitem__(self, key): return self.data[key]
> > KeyError: CATI
> 
> This means that there is no environment variable called CATI when you run
> line 14 -- if that was supposed to be set by
> 
> >     12  os.system('/op/ctl/prod/scripts/setcm.ksh')
> 
> then there's something wrong with that script.  I don't know the Korn
> shell, but it could be that you need to specify something in that shell to
> make the environment variables "stick" after execution.  In bash, I
> believe it's the "export" command.

Continuing David's assumption that this script is supposed to set the
CATI env.variable, calling the script using os.system() will never
work: it is "child process" (in Unix terminology) and a child process
can never change an environment variable of the parent (here the
executing Python program).  One solution is to run the script
(manually) *before* the Python program.  Another might be to get the
script to print the value of CATI and suck it out of there using
os.popen(); I'll leave it to another tutor to explain how to do this
in more detail.  Hint: maybe this would work:

 output = os.popen('/op/ctl/prod/scripts/setcm.ksh; echo $CATI').read()
 month = string.strip(OUTPUT)

--Guido van Rossum (home page: http://www.python.org/~guido/)


From cwebster@math.tamu.edu  Fri Jun  4 22:09:58 1999
From: cwebster@math.tamu.edu (Corran Webster)
Date: Fri, 4 Jun 1999 16:09:58 -0500 (CDT)
Subject: [Tutor] Re[2]: [Tutor] ksh and SAS questions
In-Reply-To: <9906049285.AA928528327@smtp-gw1.census.gov>
Message-ID: <199906042110.QAA04873@radon.math.tamu.edu>

Hi,

>      Well, I can't see the error in the following script. Running 
>      SunOS 5.5.1. When I run my Python script, I get this error 
>      message:
>      
> Traceback (innermost last):
>   File "recheck.py", line 14, in ?
>     month = os.environ['CATI']
>   File "/usr/local/lib/python1.5/UserDict.py", line 12, in __getitem__
>     def __getitem__(self, key): return self.data[key]
> KeyError: CATI

It looks like the environment doesn't have 'CATI' defined.  I think I
might need to know a bit more about what the environment is, and what
the ksh script '/op/ctl/prod/scripts/setcm.ksh' does.  If it changes or
creates the 'CATI' environment variable, then this might be the
problem - any changes to the environment inside an os.system call do
not cause changes in the environment of the python program.

One solution (assuming you are using ksh as your shell) would be to
manually execute the ksh script, and then manually execute the python
program (but with the first os.system call removed).

A better solution might be to re-write the setcm.ksh script as part of
the python program - assuming that it's not very complex.

Unfortunately, I don't think I can give any more suggestions without
knowing what the first ksh script does.

>      The script is:
>      
>      1  #!/usr/local/bin/python
>      2  #PROGRAM: recheck.py
>      3  #FUNCTION: execute Barbara's RECHECK program
>      4  #INPUTS: rofr.txt
>      5  #OUTPUTS: rofr.sas, ccMail message
>      6  #CALLS TO: Python os, sys, and string modules, recheck.sas
>      7  #SPECIAL NOTES: Have not yet figured out how to automate input of the 
> rofr file
>      8  #AUTHOR: Adeline Wilcox         DATE: 05Apr99
>      9  #Written with the assistance of Andrew Kuchling and especially Tim 
> Peters
>     10  #UPDATED:                       DATE: 
>     11  import os, sys 
>     12  os.system('/op/ctl/prod/scripts/setcm.ksh')
>     13  #get CATI month from environment
>     14  month = os.environ['CATI']
>     15  import string
>     16  sys.stdin = open('/op/ctl/prod/data/ro' + month +'.txt','r')
>     17  lines = sys.stdin.readlines()
>     18  for i in range(len(lines)):
>     19      line = lines[i]
>     20      lines[i] = "'" + string.rstrip(line) + "'"
>     21  sys.stdout= open('/op/ctl/test/data/rofr.sas','w')
>     22  print "if rofr in (" + string.join(lines, ", ") + ") then output;"
>     23  #if I dont close the file, SAS does not get quotes around last value of 
> rofr
>     24  sys.stdout.close()
>     25  #os.system("$SASDIR/sas /op/ctl/prod/prgms/recheck.sas -sysparm " + 
> month + \ " -log /op/ctl/prod/logs/recheck.log." + month ")
>     26  #os.system("mailx -s 'Recheck " + month + " run for you \' 
> Adeline.J.Wilcox@ccmail.census.gov ")


Corran



From cwebster@math.tamu.edu  Fri Jun  4 22:13:51 1999
From: cwebster@math.tamu.edu (Corran Webster)
Date: Fri, 4 Jun 1999 16:13:51 -0500 (CDT)
Subject: [Tutor] Re[2]: [Tutor] ksh and SAS questions
In-Reply-To: <Pine.WNT.4.04.9906041345020.46-100000@rigoletto.ski.org>
Message-ID: <199906042113.QAA05726@radon.math.tamu.edu>

On  4 Jun, David Ascher wrote:
> On Fri, 4 Jun 1999 adeline_j_wilcox@ccMail.Census.GOV wrote:
> 
>>     12  os.system('/op/ctl/prod/scripts/setcm.ksh')
> 
> then there's something wrong with that script.  I don't know the Korn
> shell, but it could be that you need to specify something in that shell to
> make the environment variables "stick" after execution.  In bash, I
> believe it's the "export" command.

This won't work - changes to the environment by a command called via
os.system do not change the environment of the python program - and I
suspect that the setcm.ksh program already uses "export".

Corran




From AFlinsch@njeb.att.com  Mon Jun  7 17:01:28 1999
From: AFlinsch@njeb.att.com (Flinsch, Alex)
Date: Mon, 7 Jun 1999 12:01:28 -0400
Subject: [Tutor] raw_input / idle problems
Message-ID: <199906071602.MAA20289@ckmso1.proxy.att.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_01BEB0FE.90BC0318
Content-Type: text/plain

I posted the following to comp.lang.python a few days ago, but have not
received a good answer yet. I thought that I would try here also.

If I enter the following code (or any other using raw_input for that matter)
into idle's shell it works, when trying to run it from a file (new window,
edit it, save it then run it, nada)

def f():
    x=raw_input("ladida:")
    print x

f()


If typed directly or imported into idle it does work. When doing the
following it did not work (specifically the print statement was never
executed)

Ctrl-N (New Window)
type in the code
Ctrl-S (Save)
F5    (Run module)

The systems involved are a win98 and an nt4 machines, tcl version 8.0.5,
Python 1.5.2. The same code works under the plain Python interactive shell,
and pythonwin, but not idle. Any ideas, or is this just a bug in idle?

-- 
Alex Flinsch
Wefos Bar Bill Render - Development
732-519-4843


------_=_NextPart_001_01BEB0FE.90BC0318
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2448.0">
<TITLE>raw_input / idle problems</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2 FACE=3D"Arial">I posted the following to =
comp.lang.python a few days ago, but have not received a good answer =
yet. I thought that I would try here also.</FONT></P>

<P><FONT SIZE=3D2 FACE=3D"Arial">If I enter the following code (or any =
other using raw_input for that matter) into idle's shell it works, when =
trying to run it from a file (new window, edit it, save it then run it, =
nada)</FONT></P>

<P><FONT SIZE=3D2 FACE=3D"Arial">def f():</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">&nbsp;&nbsp;&nbsp; =
x=3Draw_input(&quot;ladida:&quot;)</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">&nbsp;&nbsp;&nbsp; print x</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">f()</FONT>
</P>
<BR>

<P><FONT SIZE=3D2 FACE=3D"Arial">If typed directly or imported into =
idle it does work. When doing the following it did not work =
(specifically the print statement was never executed)</FONT></P>

<P><FONT SIZE=3D2 FACE=3D"Arial">Ctrl-N (New Window)</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">type in the code</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">Ctrl-S (Save)</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">F5&nbsp;&nbsp;&nbsp; (Run =
module)</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">The systems involved are a win98 and =
an nt4 machines, tcl version 8.0.5, Python 1.5.2. The same code works =
under the plain Python interactive shell, and pythonwin, but not idle. =
Any ideas, or is this just a bug in idle?</FONT></P>

<P><FONT SIZE=3D2 FACE=3D"Arial">-- </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">Alex Flinsch</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">Wefos Bar Bill Render - =
Development</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">732-519-4843</FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01BEB0FE.90BC0318--


From guido@CNRI.Reston.VA.US  Mon Jun  7 17:30:02 1999
From: guido@CNRI.Reston.VA.US (Guido van Rossum)
Date: Mon, 07 Jun 1999 12:30:02 -0400
Subject: [Tutor] raw_input / idle problems
In-Reply-To: Your message of "Mon, 07 Jun 1999 12:01:28 EDT."
 <199906071602.MAA20289@ckmso1.proxy.att.com>
References: <199906071602.MAA20289@ckmso1.proxy.att.com>
Message-ID: <199906071630.MAA12573@eric.cnri.reston.va.us>

> I posted the following to comp.lang.python a few days ago, but have not
> received a good answer yet. I thought that I would try here also.
> 
> If I enter the following code (or any other using raw_input for that matter)
> into idle's shell it works, when trying to run it from a file (new window,
> edit it, save it then run it, nada)
> 
> def f():
>     x=raw_input("ladida:")
>     print x
> 
> f()
> 
> 
> If typed directly or imported into idle it does work. When doing the
> following it did not work (specifically the print statement was never
> executed)
> 
> Ctrl-N (New Window)
> type in the code
> Ctrl-S (Save)
> F5    (Run module)
> 
> The systems involved are a win98 and an nt4 machines, tcl version 8.0.5,
> Python 1.5.2. The same code works under the plain Python interactive shell,
> and pythonwin, but not idle. Any ideas, or is this just a bug in idle?

It's a bug in IDLE 0.4.  This is fixed in my working copy of the
code.  Please just work around it for now...  (e.g. saving it as a
module and typeing "import <module>" should work).

--Guido van Rossum (home page: http://www.python.org/~guido/)


From adeline_j_wilcox@ccMail.Census.GOV  Mon Jun  7 17:29:42 1999
From: adeline_j_wilcox@ccMail.Census.GOV (adeline_j_wilcox@ccMail.Census.GOV)
Date: Mon, 07 Jun 1999 12:29:42 -0400
Subject: [Tutor] Re[2]: [Tutor] Re[2]: [Tutor] ksh and SAS questions
Message-ID: <9906079287.AA928773269@smtp-gw1.census.gov>

     
     While you all were quickly responding to my last inquiry I was 
     renewing my acquaintance with the business that parents cannot 
     inherit from child processes. The script setcm.ksh exports CATI.
     
     Guido's suggestion to run setcm.ksh manually as a dot script is 
     dangerously impractical in our environment. I don't own setcm.ksh 
     and don't care to seek to change it.
     
     The latest version of my script follows. It hangs after running 
     setcm.ksh. No doubt the fix is simple but here at the Bureau of 
     the Census we are too busy now for leisurely study of manuals.
     
     Adeline
     
#!/usr/local/bin/python
#PROGRAM: recheck.py
#FUNCTION: execute Barbara's RECHECK program
#INPUTS: rofr.txt
#OUTPUTS: rofr.sas, ccMail message
#CALLS TO: Python os, sys, and string modules, recheck.sas
#SPECIAL NOTES: Have not yet figured out how to automate input of the rofr file
#AUTHOR: Adeline Wilcox         DATE: 05Apr99
#Written with the assistance of Andrew Kuchling and especially Tim Peters
#UPDATED:                       DATE: 
import os, sys 
os.system('/op/ctl/prod/scripts/setcm.ksh')
os.system('sed \'1,4d\' setcm.out > setcm.txt')
os.system('awk \'{print $2}\' > rccatimo.txt')
import string
output = os.popen('rccatimo.txt; print $CATI').read()
month = string.strip(OUTPUT)

sys.stdin = open('/op/ctl/prod/data/ro' + month +'.txt','r')
lines = sys.stdin.readlines()
for i in range(len(lines)):
    line = lines[i]
    lines[i] = "'" + string.rstrip(line) + "'"
sys.stdout= open('/op/ctl/test/data/rofr.sas','w')
print "if rofr in (" + string.join(lines, ", ") + ") then output;"

file = open("/op/ctl/test/reports/mg" + month + ".txt", 'w')
file.write("Output is /op/ctl/test/data/rc" + month + ".txt and ready for your 
review\n")
file.close()

#if I dont close the file, SAS does not get quotes around last value of rofr
sys.stdout.close()
#os.system("$SASDIR/sas /op/ctl/prod/prgms/recheck.sas -sysparm " + month + \ " 
-log /op/ctl/prod/logs/recheck.log." + month ")
os.system("mailx -s 'Recheck " + month + " run for you \' 
Adeline.J.Wilcox@ccmail.census.gov < /op/ctl/test/reports/mg" + month + ".txt")

     


______________________________ Reply Separator _________________________________
Subject: Re: [Tutor] Re[2]: [Tutor] ksh and SAS questions 
Author:  David Ascher <da@ski.org> at SMTP-GATEWAY
Date:    6/4/1999 1:46 PM


On Fri, 4 Jun 1999 adeline_j_wilcox@ccMail.Census.GOV wrote:

>      Well, I can't see the error in the following script. Running 
>      SunOS 5.5.1. When I run my Python script, I get this error 
>      message:
>      
> Traceback (innermost last):
>   File "recheck.py", line 14, in ?
>     month = os.environ['CATI']
>   File "/usr/local/lib/python1.5/UserDict.py", line 12, in __getitem__
>     def __getitem__(self, key): return self.data[key]
> KeyError: CATI

This means that there is no environment variable called CATI when you run
line 14 -- if that was supposed to be set by

>     12  os.system('/op/ctl/prod/scripts/setcm.ksh')

then there's something wrong with that script.  I don't know the Korn
shell, but it could be that you need to specify something in that shell to
make the environment variables "stick" after execution.  In bash, I
believe it's the "export" command.

--david





From arcege@shore.net  Mon Jun  7 18:13:57 1999
From: arcege@shore.net (Michael P. Reilly)
Date: Mon, 7 Jun 1999 13:13:57 -0400 (EDT)
Subject: [Tutor] Re[2]: [Tutor] Re[2]: [Tutor] ksh and SAS questions
In-Reply-To: <9906079287.AA928773269@smtp-gw1.census.gov> from "adeline_j_wilcox@ccMail.Census.GOV" at "Jun 7, 99 12:29:42 pm"
Message-ID: <199906071713.NAA15091@northshore.shore.net>

>      
>      While you all were quickly responding to my last inquiry I was 
>      renewing my acquaintance with the business that parents cannot 
>      inherit from child processes. The script setcm.ksh exports CATI.
>      
>      Guido's suggestion to run setcm.ksh manually as a dot script is 
>      dangerously impractical in our environment. I don't own setcm.ksh 
>      and don't care to seek to change it.
>      
>      The latest version of my script follows. It hangs after running 
>      setcm.ksh. No doubt the fix is simple but here at the Bureau of 
>      the Census we are too busy now for leisurely study of manuals.
>      
>      Adeline

Adeline,

I would suggest calling the setcm.ksh script as a dot file as Guido
suggests, but within the Python script as you are doing:

  # source the ksh script and output the CATI variable
  # with the double quotes in echo, we'll get a last line no matter
  # what implimentation of echo or shell
  sh_cmd = '. /op/ctl/prod/scripts/setcm.ksh 2>/dev/null; echo "${CATI}"'
  # the last line is the output of the CATI variable, other output is
  # ignored
  CATI=os.popen(sh_cmd, 'r').readlines()[-1]
  CATI=string.strip(CATI)

You can get other envvars from the execution in a similar fashion.

  -Arcege

> #!/usr/local/bin/python
> #PROGRAM: recheck.py
> #FUNCTION: execute Barbara's RECHECK program
> #INPUTS: rofr.txt
> #OUTPUTS: rofr.sas, ccMail message
> #CALLS TO: Python os, sys, and string modules, recheck.sas
> #SPECIAL NOTES: Have not yet figured out how to automate input of the rofr file
> #AUTHOR: Adeline Wilcox         DATE: 05Apr99
> #Written with the assistance of Andrew Kuchling and especially Tim Peters
> #UPDATED:                       DATE: 
> import os, sys 
> os.system('/op/ctl/prod/scripts/setcm.ksh')
> os.system('sed \'1,4d\' setcm.out > setcm.txt')
> os.system('awk \'{print $2}\' > rccatimo.txt')
> import string
> output = os.popen('rccatimo.txt; print $CATI').read()
> month = string.strip(OUTPUT)
> 
> sys.stdin = open('/op/ctl/prod/data/ro' + month +'.txt','r')
> lines = sys.stdin.readlines()
> for i in range(len(lines)):
>     line = lines[i]
>     lines[i] = "'" + string.rstrip(line) + "'"
> sys.stdout= open('/op/ctl/test/data/rofr.sas','w')
> print "if rofr in (" + string.join(lines, ", ") + ") then output;"
> 
> file = open("/op/ctl/test/reports/mg" + month + ".txt", 'w')
> file.write("Output is /op/ctl/test/data/rc" + month + ".txt and ready for your 
> review\n")
> file.close()
> 
> #if I dont close the file, SAS does not get quotes around last value of rofr
> sys.stdout.close()
> #os.system("$SASDIR/sas /op/ctl/prod/prgms/recheck.sas -sysparm " + month + \ " 
> -log /op/ctl/prod/logs/recheck.log." + month ")
> os.system("mailx -s 'Recheck " + month + " run for you \' 
> Adeline.J.Wilcox@ccmail.census.gov < /op/ctl/test/reports/mg" + month + ".txt")


-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Engineer | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From TomJenkins@zentuit.com  Mon Jun  7 19:09:22 1999
From: TomJenkins@zentuit.com (Tom Jenkins)
Date: Mon, 7 Jun 1999 14:09:22 -0400
Subject: [Tutor] Re[2]: [Tutor] Re[2]: [Tutor] ksh and SAS questions
In-Reply-To: <199906071713.NAA15091@northshore.shore.net>
References: <9906079287.AA928773269@smtp-gw1.census.gov> from "adeline_j_wilcox@ccMail.Census.GOV" at "Jun 7, 99 12:29:42 pm"
Message-ID: <199906071706.NAA01066@penguin.zentuit.com>

Hi Mike, just curious if this is a typo...

>   # source the ksh script and output the CATI variable
>   # with the double quotes in echo, we'll get a last line no matter
>   # what implimentation of echo or shell
>   sh_cmd = '. /op/ctl/prod/scripts/setcm.ksh 2>/dev/null; echo "${CATI}"'

should sh_cmd be = '. /op/ctl/prod/scripts/setcm.ksh $2>/dev/null; echo 
"${CATI}"'? (notice the $ before 2)
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Tom Jenkins                    DevIS (http://www.devis.com)
python is executable pseudo-code; perl is executable line-noise


From teroc@zianet.com  Mon Jun  7 22:49:59 1999
From: teroc@zianet.com (K P)
Date: Mon, 7 Jun 1999 16:49:59 -0500
Subject: [Tutor] OK, dumb question
Message-ID: <21594270314177@zianet.com>

-------Phoenix-Boundary-07081998-
Content-type: text/plain; charset=ISO-8859-1
Content-transfer-encoding: Quoted-printable

I seem to be stuck on the littlest of problems, how do I do this in Python:
	iterate through a 'list' (term used loosely) of twelve class variables, 
check each for changes
I know how to do this in C++, but for the life of me cannot make the 
connection in Python. Here is an example(with my infamous spam):

class Meat:
   def __init__(self, colour, type):
      self.colour =3D colour
      self.type =3D type
      self.flavor =3D ' '

class Spam:
   def __init__(self):
      self.beef =3D Meat('red', 'beef')
      self.chicken =3D Meat('white', 'fowl')
   def quality(self):
      #In this function I would check the type and colour versus a 'chart' 
(probably a dictionary look-up)
      #e.g. if self.beef.colour =3D 'red' and self.beef.type =3D 'beef' 
then self.beef.flavor =3D 'good'
      #In my 'real' script I would be testing 12-20 class member variables 
against a small set of immutable variables
      #what would be the simplest/fastest/most effective way to code that 
in python=3F


Ken


-------Phoenix-Boundary-07081998---




From arcege@shore.net  Mon Jun  7 23:20:41 1999
From: arcege@shore.net (Michael P. Reilly)
Date: Mon, 7 Jun 1999 18:20:41 -0400 (EDT)
Subject: [Tutor] Re[2]: [Tutor] Re[2]: [Tutor] ksh and SAS questions
In-Reply-To: <199906071706.NAA01066@penguin.zentuit.com> from Tom Jenkins at "Jun 7, 99 02:09:22 pm"
Message-ID: <199906072220.SAA25939@northshore.shore.net>

TomJenkins@zentuit.com (Tom Jenkins) asks:
> Hi Mike, just curious if this is a typo...
> 
> >   # source the ksh script and output the CATI variable
> >   # with the double quotes in echo, we'll get a last line no matter
> >   # what implimentation of echo or shell
> >   sh_cmd = '. /op/ctl/prod/scripts/setcm.ksh 2>/dev/null; echo "${CATI}"'
> 
> should sh_cmd be = '. /op/ctl/prod/scripts/setcm.ksh $2>/dev/null; echo 
> "${CATI}"'? (notice the $ before 2)

No, the '2>/dev/null' is to redirect standard error to the bit bucket.
Inserting the dollar sign would make it evaluated within the popen
(inside /bin/sh in most cases), where there are no arguments ($2 ==
arg2, but not sys.argv[2]).  You would end up with

  '. /op/ctl/....  >/dev/null; echo ...'

which is not what you want.  In popen, the stderr stream does not get
redirected; if there were error messages from setcm.ksh, they would
still be seen, Python could not capture them.  Redirecting stderr in
the popen avoids that.

Unfortunately, there are few nicely portable methods to redirecting
standard error.  I wasn't going to get into that tho. :)

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Engineer | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------


From da@ski.org  Mon Jun  7 23:50:32 1999
From: da@ski.org (David Ascher)
Date: Mon, 7 Jun 1999 15:50:32 -0700 (Pacific Daylight Time)
Subject: [Tutor] OK, dumb question
In-Reply-To: <21594270314177@zianet.com>
Message-ID: <Pine.WNT.4.04.9906071547010.193-100000@rigoletto.ski.org>

On Mon, 7 Jun 1999, K P wrote:

> I seem to be stuck on the littlest of problems, how do I do this in Python:
> 	iterate through a 'list' (term used loosely) of twelve class variables,
> check each for changes

> class Meat:
>    def __init__(self, colour, type):
>       self.colour = colour
>       self.type = type
>       self.flavor = ' '
> 
> class Spam:
>    def __init__(self):
>       self.beef = Meat('red', 'beef')
>       self.chicken = Meat('white', 'fowl')
>    def quality(self):
>       #In this function I would check the type and colour versus a 'chart'
> (probably a dictionary look-up)
>       #e.g. if self.beef.colour = 'red' and self.beef.type = 'beef'
> then self.beef.flavor = 'good'
>       #In my 'real' script I would be testing 12-20 class member variables
> against a small set of immutable variables
>       #what would be the simplest/fastest/most effective way to code that
> in python?

Use getattr()/setattr(), as in:

class Spam:

  ingredient_list = ['beef', 'chicken']

  #...

  def quality(self):
    for ingredient_name in self.ingredient_list:
      ingredient = getattr(self, ingredient_name)
      colour = getattr(ingredient, 'colour')
      type = getattr(ingredient, 'beef')
      if colour == 'red' and type == 'beef':
        ingredient.flavor = 'good'
        # or setattr(ingredient, 'flavor', 'good')

Hope this helps.

--david ascher



From alan.gauld@bt.com  Tue Jun  8 11:02:30 1999
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 8 Jun 1999 11:02:30 +0100
Subject: [Tutor] Hopefully OT
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB24E09E8@mbtlipnt02.btlabs.bt.co.uk>

> > that one of the most elegant structures is the 'model-control-view'
> > approach, so look that one up.
> 
> I am just jumping into Python myself with the intent of using a GUI
> interface for some sample apps.  Is there any book that describes this
> model-control-view method using Python?  Or a book that describes it
> using Pseudo Code?

Theres a good description/tutorial on MVC (actually they call it 
something else!) at the Object Arts Web site. Its in Smalltalk but
the concepts translate well.

http://www.object-arts.com/

specifically:

http://www.object-arts.com/EducationCentre/Patterns/MVP.htm

Alan G


From alan.gauld@bt.com  Tue Jun  8 11:52:04 1999
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 8 Jun 1999 11:52:04 +0100
Subject: [Tutor] OK, dumb question
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB24E09EA@mbtlipnt02.btlabs.bt.co.uk>

> I seem to be stuck on the littlest of problems, how do I do 
> this in Python:
> 	iterate through a 'list' (term used loosely) of twelve 
> class variables, 
> check each for changes
> I know how to do this in C++, but for the life of me cannot make the 
> connection in Python. Here is an example(with my infamous spam):

Just a minor nit pick, but I assume you mean a list of class instances?
(since I don't think the concept of class variables exists in C++)

ie you have a list of instances of Meat or Spam? 

m = Meat()
s = Spam()
ObjList = [m,s]

Not a list of classes:

classlist = [Meat, Spam]

Just to be clear about what we're trying to do...

>       #In my 'real' script I would be testing 12-20 class 
> member variables 

Uh, this is different again - class member variables? (aka static in C++) 
or instance variables?

slightly confused about what your trying to do here.

Alan g.


From josh.wasserman@worldnet.att.net  Tue Jun  8 20:30:41 1999
From: josh.wasserman@worldnet.att.net (JOSH WASSERMAN)
Date: Tue, 8 Jun 1999 15:30:41 -0400
Subject: [Tutor] PATH configuration for windows 98
Message-ID: <000201beb1e5$6b8d44c0$49ae4e0c@h71mr>

This is a multi-part message in MIME format.

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

Trouble running module files, and I believe its due to PATH or =
PYTHONPATH configuration for my system.  Just downloaded python 152 and =
win 32 files, which supposedly set this config themselves.  New to =
programming, so any detailed, but easy to follow responses would be =
greatly appreciated.  Thanks.

------=_NextPart_000_0005_01BEB1C3.DE4BC800
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.2314.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Trouble running module files, and I believe its due =
to PATH or=20
PYTHONPATH configuration for my system.&nbsp; Just downloaded python 152 =
and win=20
32 files, which supposedly set this config themselves.&nbsp; New to =
programming,=20
so any detailed, but easy to follow responses would be greatly=20
appreciated.&nbsp; Thanks.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0005_01BEB1C3.DE4BC800--



From josh.wasserman@worldnet.att.net  Tue Jun  8 21:29:23 1999
From: josh.wasserman@worldnet.att.net (JOSH WASSERMAN)
Date: Tue, 8 Jun 1999 16:29:23 -0400
Subject: [Tutor] re: windows 98 PATH config
Message-ID: <004101beb1ed$a35e8a00$ef684e0c@h71mr>

This is a multi-part message in MIME format.

------=_NextPart_000_003C_01BEB1CC.112C1920
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

here's my autoexec.bat configuration:

@PATH C:\PROGRA~1\MSOFFICE;%PATH%;C:PROGRA~1\PYTHON

Can now run python from my DOS prompt, but still can't execute module =
file on my desktop.



------=_NextPart_000_003C_01BEB1CC.112C1920
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.2314.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>here's my autoexec.bat configuration:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>@PATH=20
C:\PROGRA~1\MSOFFICE;%PATH%;C:PROGRA~1\PYTHON</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Can now run python from my DOS prompt, but still =
can't execute=20
module file on my desktop.<BR><BR></DIV></FONT></BODY></HTML>

------=_NextPart_000_003C_01BEB1CC.112C1920--



From alan.gauld@bt.com  Wed Jun  9 10:05:04 1999
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 9 Jun 1999 10:05:04 +0100
Subject: [Tutor] re: windows 98 PATH config
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB24E09F4@mbtlipnt02.btlabs.bt.co.uk>

> Can now run python from my DOS prompt, but still can't 
> execute module file on my desktop.

Hmm, have you set the file association so that Windows knows 
that a .py file needs to run python?

Done thru' the View|Options|FileTypes from Explorer or MyComputer

Also have your modules got the

if __name__ == '__main__':

line set up?

Alan G.


From chupecabra@excite.com  Wed Jun  9 15:34:10 1999
From: chupecabra@excite.com (CHUPECABRA)
Date: Wed, 09 Jun 1999 07:34:10 PDT
Subject: [Tutor] PATH for windows 98
Message-ID: <928938850.7283.123@excite.com>

Problem solved.  Needed to change PATH and create module file subdirectory
under under DOS home directory.  Thanks to all.




_______________________________________________________
Get your free, private email at http://mail.excite.com/


From teroc@zianet.com  Wed Jun  9 16:12:37 1999
From: teroc@zianet.com (Kenneth M. Power)
Date: Wed, 09 Jun 1999 10:12:37 -0500
Subject: [Tutor] OK, let me revamp my earlier question
Message-ID: <375E8464.3F5BFDAF@zianet.com>

My previous question was a bomb. The consequences of not thinking a
matter through before posting :)/ Anyway, here is a more thorough, and
spamless, example of what I want to accomplish, along with a small
example in C++ (since I know how to accomplish it easily in that
language):

class Dial:
   def __init__(self, bar):
      self.current = 0
      self.limit = bar
      self.normal = 0
      self.misc1 = 0
      self.misc2 = 0
      self.total = self.normal + self.misc1 + self.misc2

class Panel:
   def __init__(self):
      dial1 = Dial(100)
      dial2 = Dial(75)
      dial3 = Dial(90)
      dial4 = Dial(60)
      dial5 = Dial(65)
#This arrangment 'simulates' dials and their settings. The range limit
is passed to the
#class instance on creation.
   def setInitial(self, start):
      dial1.current, dial2.current, dial3.current, dial4.current,
dial5.current = start
      #Here the user set the starting position for each dial, that is
sent to the class
      #instance 'variables'(? I always get some of these therms
confused).
      updateNormal()
   def updateNormal():
      #Here is where I have problems. This function should take each
dial instance
      #and compute the normal setting based on the current setting. In
c++ I could
      #accomplish this very simply by using arrays and a for loop:
      #c++ example-
      #class Panel{
      #   private:
      #     Dial dial[6];
      #   ..../buch of other class junk
      #void Panel::updateNormal(){
      #   for(int i = 0; i<6; i++)
      #     dial[i].setNormal(data.getNormal(dial[i].showCurrent());
      #
      # Please no comments on the strangeness of that c++ code. It's
horrible I know,
      #but it is a quick way of doing it. So my question at this point,
how do I iterate
      #through each dial instance (dial1-5), setting the 'normal'
varable. A note-I
      #know I could just hardcode this, but I am looking for a way to do
this no
      #matter the number of dials I have(one time I may have 5 dials,
another time
      #100!) Please any suggestions.

Ken



From DOUGS@oceanic.com  Wed Jun  9 16:53:38 1999
From: DOUGS@oceanic.com (Doug Stanfield)
Date: Wed, 9 Jun 1999 05:53:38 -1000
Subject: [Tutor] OK, let me revamp my earlier question
Message-ID: <5650A1190E4FD111BC7E0000F8034D26A0EE24@HUINA>

If you want to iterate over your dials, you need to get them in a data
structure, in the Panel class, that can be iterated over with a for
statement.

 class Panel:
    def __init__(self):
       dial1 = Dial(100)
       dial2 = Dial(75)
       dial3 = Dial(90)
       dial4 = Dial(60)
       dial5 = Dial(65)
       self.dials = [dial1, dial2, dial3, dial4, dial5]

    def updateNormal():
       for dial in self.dials:
           <some code to do what you want, uses the variable 'dial' to
            reference each of the Dial class instances in the list>

-Doug-

> -----Original Message-----
> From: Kenneth M. Power [mailto:teroc@zianet.com]
> Sent: Wednesday, June 09, 1999 5:13 AM
> To: tutor@python.org
> Subject: [Tutor] OK, let me revamp my earlier question
> 
> 
> My previous question was a bomb. The consequences of not thinking a
> matter through before posting :)/ Anyway, here is a more thorough, and
> spamless, example of what I want to accomplish, along with a small
> example in C++ (since I know how to accomplish it easily in that
> language):
> 
> class Dial:
>    def __init__(self, bar):
>       self.current = 0
>       self.limit = bar
>       self.normal = 0
>       self.misc1 = 0
>       self.misc2 = 0
>       self.total = self.normal + self.misc1 + self.misc2
> 
> class Panel:
>    def __init__(self):
>       dial1 = Dial(100)
>       dial2 = Dial(75)
>       dial3 = Dial(90)
>       dial4 = Dial(60)
>       dial5 = Dial(65)
> #This arrangment 'simulates' dials and their settings. The range limit
> is passed to the
> #class instance on creation.
>    def setInitial(self, start):
>       dial1.current, dial2.current, dial3.current, dial4.current,
> dial5.current = start
>       #Here the user set the starting position for each dial, that is
> sent to the class
>       #instance 'variables'(? I always get some of these therms
> confused).
>       updateNormal()
>    def updateNormal():
>       #Here is where I have problems. This function should take each
> dial instance
>       #and compute the normal setting based on the current setting. In
> c++ I could
>       #accomplish this very simply by using arrays and a for loop:
>       #c++ example-
>       #class Panel{
>       #   private:
>       #     Dial dial[6];
>       #   ..../buch of other class junk
>       #void Panel::updateNormal(){
>       #   for(int i = 0; i<6; i++)
>       #     dial[i].setNormal(data.getNormal(dial[i].showCurrent());
>       #
>       # Please no comments on the strangeness of that c++ code. It's
> horrible I know,
>       #but it is a quick way of doing it. So my question at 
> this point,
> how do I iterate
>       #through each dial instance (dial1-5), setting the 'normal'
> varable. A note-I
>       #know I could just hardcode this, but I am looking for 
> a way to do
> this no
>       #matter the number of dials I have(one time I may have 5 dials,
> another time
>       #100!) Please any suggestions.
> 
> Ken
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor
> 


From TomJenkins@zentuit.com  Wed Jun  9 17:01:10 1999
From: TomJenkins@zentuit.com (Tom Jenkins)
Date: Wed, 9 Jun 1999 12:01:10 -0400
Subject: [Tutor] OK, let me revamp my earlier question
In-Reply-To: <375E8464.3F5BFDAF@zianet.com>
Message-ID: <199906091458.KAA04902@penguin.zentuit.com>

Hi Ken,
You're really close on the C++ code.  Here is what I came up with

#!/usr/bin/python

# unchanged from original
class Dial:
	def __init__(self, bar):
		self.current = 0
		self.limit = bar
		self.normal = 0
		self.misc1 = 0
		self.misc2 = 0
		self.total = self.normal + self.misc1 + self.misc2

class Panel:
	def __init__(self):
		# make dials a list... here they are hard coded
		# I'll leave it to the student <g> to add a method to add dials
		self.Dials = [Dial(100), Dial(75), Dial(90), Dial(60), Dial(65)]

	def setInitial(self, start):
		# loop over the dials and set the 'current' attribute
		for aDial in self.Dials:
			aDial.current = start

		self.updateNormal()

	def updateNormal(self):
		# loop over the dials and set the 'normal' attribute based on some
		# function involving the 'current' attribute
		for aDial in self.Dials:
			aDial.normal = aDial.current+5

 
if __name__ == "__main__":
	# if we're running this from the command line
	# test it
	aPanel = Panel()

	aPanel.setInitial(12)
	for aDial in aPanel.Dials:
		print "Bar: %d  Normal: %d  Current: %d" % (aDial.limit, 
aDial.normal, aDial.current)


> My previous question was a bomb. The consequences of not thinking a
> matter through before posting :)/ Anyway, here is a more thorough, and
> spamless, example of what I want to accomplish, along with a small
> example in C++ (since I know how to accomplish it easily in that
> language):
> 

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Tom Jenkins                    DevIS (http://www.devis.com)
python is executable pseudo-code; perl is executable line-noise


From teroc@zianet.com  Wed Jun  9 17:21:19 1999
From: teroc@zianet.com (Kenneth M. Power)
Date: Wed, 09 Jun 1999 11:21:19 -0500
Subject: [Tutor] Just a compliment
Message-ID: <375E947F.D8296FAB@zianet.com>

After reviewing my success rate with this email-list, I would like to
thank everyone for their suggestions, help, tid-bits, and especially the
quick repsonse. This is the only list where I receive info within a few
minutes of a post! That is very commendable and tells me a lot about the
Python community. Again thank you.
ken



From jocose_2@hotmail.com  Fri Jun 11 00:37:14 1999
From: jocose_2@hotmail.com (Greg Gardinier)
Date: Thu, 10 Jun 1999 23:37:14 GMT
Subject: [Tutor] (no subject)
Message-ID: <19990610233715.36987.qmail@hotmail.com>

Is there any way that I can learn the langauge from a tutor or book?


_______________________________________________________________
Get Free Email and Do More On The Web. Visit http://www.msn.com


From todd@royalbastard.com  Fri Jun 11 01:07:15 1999
From: todd@royalbastard.com (Todd Martin)
Date: Thu, 10 Jun 1999 17:07:15 -0700
Subject: [Tutor] (no subject)
In-Reply-To: <19990610233715.36987.qmail@hotmail.com>; from Greg Gardinier on Thu, Jun 10, 1999 at 11:37:14PM +0000
References: <19990610233715.36987.qmail@hotmail.com>
Message-ID: <19990610170715.A9818@royalbastard.com>

Sure, buy a book at amazon.com


On Thu, Jun 10, 1999 at 11:37:14PM +0000, Greg Gardinier wrote:
> Is there any way that I can learn the langauge from a tutor or book?
> 
> 
> _______________________________________________________________
> Get Free Email and Do More On The Web. Visit http://www.msn.com
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor

-- 
Todd Martin
todd@royalbastard.com
http://royalbastard.com/~todd


From alan.gauld@bt.com  Fri Jun 11 09:57:32 1999
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 11 Jun 1999 09:57:32 +0100
Subject: [Tutor] (no subject)
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB24E09FC@mbtlipnt02.btlabs.bt.co.uk>

Yes.

Try:
the online trutorial that comes with the download or is online at:

http://www.python.org/

Or in paper:

Learning Python by O'Reilly
Programming Python by O'Reilly
Internet Programming with Python by M&iT books

There's another one too but I forget the name... try
a search on Amazon.

All available from Amazon and possibly from
PSA too.

Alan G

> Is there any way that I can learn the langauge from a tutor or book?


From johnh@phm.gov.au  Sun Jun 13 19:32:00 1999
From: johnh@phm.gov.au (John Hirsch)
Date: Sun, 13 Jun 99 13:32:00 EST
Subject: [Tutor] Playing audio CD's with Python
Message-ID: <3763B2DB@pcmgw.phm.gov.au>

Hi
Is there a way of playing audio CD's with Python on a windows machine.
I have seen that you can do it on SGI Irix but nothing on windows.

Thanks in advance
 ----------------------------------------
Jonathan Hirsch
Powerhouse Museum
Sydney, Australia
E-mail : johnh@phm.gov.au
Phone: (02) 92170233
 ----------------------------------------  


From ivnowa@hvision.nl  Sun Jun 13 10:39:51 1999
From: ivnowa@hvision.nl (Hans Nowak)
Date: Sun, 13 Jun 1999 11:39:51 +0200
Subject: [Tutor] Playing audio CD's with Python
In-Reply-To: <3763B2DB@pcmgw.phm.gov.au>
Message-ID: <199906130938.LAA00915@axil.hvision.nl>

On 13 Jun 99, John Hirsch wrote:

> 
> Hi
> Is there a way of playing audio CD's with Python on a windows machine.
> I have seen that you can do it on SGI Irix but nothing on windows.

Hmm, my DOS Python can do this; I don't know about the Windows 
version though...

--Hans Nowak (ivnowa@hvision.nl)
Homepage: http://fly.to/zephyrfalcon


From jcosby@wolfenet.com  Sun Jun 13 16:07:27 1999
From: jcosby@wolfenet.com (Jon Cosby)
Date: Sun, 13 Jun 1999 08:07:27 -0700
Subject: [Tutor] "return" and recursive functions
Message-ID: <000501beb5ae$743acc60$9d129fce@wolfenet.com>

Problem: I need the following code to return search results for the given
directory and it's sub-directories. As it is, it's returning "hits" only for
the root directory. Any ideas as to how to work around this?

Jon Cosby

def getFile(text, dir):
    hits = []
    dl = os.listdir(dir)
    text = string.lower(text)
    for d in dl:
        d = dir + '\\' + d
        if os.path.isfile(d):
            hits.extend(searchtext(text, d))     # Search file for word
        elif os.path.isdir(d):
            getFile(text, d)         # Do sub-directories
    return hits



From jcosby@wolfenet.com  Sun Jun 13 16:55:50 1999
From: jcosby@wolfenet.com (Jon Cosby)
Date: Sun, 13 Jun 1999 08:55:50 -0700
Subject: [Tutor] Second problem
Message-ID: <000501beb5b5$4adf2a80$a6159fce@wolfenet.com>

Another problem: The following prints out keys and values multiple times,
once for each key with the same value; if three keys have the same value, it
will print each three times. Is there some condition I can add to prevent
this?

Jon Cosby


keys = dict.keys()
vals = dict.values()
vals.sort(comp)
for v in vals:
    for k in keys:
        if dict[k] == v:
            k = string.replace(k, dir + '\\', url)
            print '<a href=\"' + k + '\">'
            print '<b>', k, '</b></a>&nbsp;', v, counter(v), 'hits<br>'



From ivnowa@hvision.nl  Sun Jun 13 17:25:22 1999
From: ivnowa@hvision.nl (Hans Nowak)
Date: Sun, 13 Jun 1999 18:25:22 +0200
Subject: [Tutor] "return" and recursive functions
In-Reply-To: <000501beb5ae$743acc60$9d129fce@wolfenet.com>
Message-ID: <199906131624.SAA09859@axil.hvision.nl>

Jon Coby wrote:

> Problem: I need the following code to return search results for the given
> directory and it's sub-directories. As it is, it's returning "hits" only for
> the root directory. Any ideas as to how to work around this?
> 
> Jon Cosby
> 
> def getFile(text, dir):
>     hits = []
>     dl = os.listdir(dir)
>     text = string.lower(text)
>     for d in dl:
>         d = dir + '\\' + d
>         if os.path.isfile(d):
>             hits.extend(searchtext(text, d))     # Search file for word
>         elif os.path.isdir(d):
>             getFile(text, d)         # Do sub-directories
>     return hits

'hits' is a local variable... every time getFile is called 
recursively, a new instance is created locally *and* discarded upon 
return. Calls to getFile do not influence the hits list in the 
calling function, they only create a new hits locally in the callee. 
What you need to do it make 'hits' accumulate search results... maybe 
like this:

change this line:

    getFile(text, d)         # Do sub-directories

to:

    hits.append(getFile(text,d))

I haven't really tested it so this might or might not work the way 
you want it. 

Veel liefs,

--Hans Nowak (ivnowa@hvision.nl)
Homepage: http://fly.to/zephyrfalcon


From tim_one@email.msn.com  Sun Jun 13 19:55:34 1999
From: tim_one@email.msn.com (Tim Peters)
Date: Sun, 13 Jun 1999 14:55:34 -0400
Subject: [Tutor] Second problem
In-Reply-To: <000501beb5b5$4adf2a80$a6159fce@wolfenet.com>
Message-ID: <000601beb5ce$514c5500$ae9e2299@tim>

[Jon Cosby]
> Another problem: The following prints out keys and values multiple times,
> once for each key with the same value; if three keys have the
> same value, it will print each three times.
> ...
>
> keys = dict.keys()
> vals = dict.values()
> vals.sort(comp)
> for v in vals:
>     for k in keys:
>         if dict[k] == v:
>             k = string.replace(k, dir + '\\', url)
>             print '<a href=\"' + k + '\">'
>             print '<b>', k, '</b></a>&nbsp;', v, counter(v), 'hits<br>'

It does that, of course, because that's what you told it to do <wink>:  for
each value, print out every key that maps to that value.  Let's make it
simpler (in part because you didn't give us your comp function or your dict,
so we *can't* run the code as posted):

>>> d = {'a': 1, 'b': 1, 'c':1}
>>> for v in d.values():
        for k in d.keys():
            if d[k] == v:
                print k, v

b 1
c 1
a 1
b 1
c 1
a 1
b 1
c 1
a 1
>>>

Think about what it does line by line, and you'll see it can't do anything
other than that.  If you want to see each pair only once, you need to get
away from nested loops:

>>> for k, v in d.items():
        print k, v

b 1
c 1
a 1
>>>

Now you're almost done:  wrap another function around your comp:

def paircomp(p1, p2):
    return comp(p1[1], p2[1])

and apply that to the items list:

x = d.items()
x.sort(paircomp)
for k, v in x:
    # Do your string fiddling and printing; the (k, v) pairs arrive
    # in increasing order of v, but in "random" order of k for equal
    # v; if that's not what you want, make paircomp smarter (the one
    # above simply ignores the k part).

orderedly y'rs  - tim




From da@ski.org  Sun Jun 13 21:08:37 1999
From: da@ski.org (David Ascher)
Date: Sun, 13 Jun 1999 13:08:37 -0700 (Pacific Daylight Time)
Subject: [Tutor] Second problem
In-Reply-To: <000501beb5b5$4adf2a80$a6159fce@wolfenet.com>
Message-ID: <Pine.WNT.4.05.9906131304490.74-100000@david.ski.org>

On Sun, 13 Jun 1999, Jon Cosby wrote:

> Another problem: The following prints out keys and values multiple times,
> once for each key with the same value; if three keys have the same value, it
> will print each three times. Is there some condition I can add to prevent
> this?

> keys = dict.keys()
> vals = dict.values()
> vals.sort(comp)
> for v in vals:
>     for k in keys:
>         if dict[k] == v:
>            print k, v  # for simplicity

What I'd do is to sort on the items with a custom sort which did the
equivalent of sorting on keys:

def sort_items((k1,v1), (k2,v2)):
  return cmp(v1, v2)  # sort on values

# or written just slightly differently, but equivalently
# def sort_items(a, b):
#   return cmp(a[1], b[1])  # sort on values

items = dict.items()
items.sort(sort_items)
for key, value in items:
   print key, value  # or whatever

Cheers,

--david



From tim_one@email.msn.com  Sun Jun 13 23:56:08 1999
From: tim_one@email.msn.com (Tim Peters)
Date: Sun, 13 Jun 1999 18:56:08 -0400
Subject: [Tutor] Second problem
In-Reply-To: <000501beb5b5$4adf2a80$a6159fce@wolfenet.com>
Message-ID: <000101beb5ef$ecc07680$f09e2299@tim>

[Jon Cosby]
> Another problem: The following prints out keys and values multiple times,
> once for each key with the same value; if three keys have the
> same value, it will print each three times.
> ...
>
> keys = dict.keys()
> vals = dict.values()
> vals.sort(comp)
> for v in vals:
>     for k in keys:
>         if dict[k] == v:
>             k = string.replace(k, dir + '\\', url)
>             print '<a href=\"' + k + '\">'
>             print '<b>', k, '</b></a>&nbsp;', v, counter(v), 'hits<br>'

It does that, of course, because that's what you told it to do <wink>:  for
each value, print out every key that maps to that value.  Let's make it
simpler (in part because you didn't give us your comp function or your dict,
so we *can't* run the code as posted):

>>> d = {'a': 1, 'b': 1, 'c':1}
>>> for v in d.values():
        for k in d.keys():
            if d[k] == v:
                print k, v

b 1
c 1
a 1
b 1
c 1
a 1
b 1
c 1
a 1
>>>

Think about what it does line by line, and you'll see it can't do anything
other than that.  If you want to see each pair only once, you need to get
away from nested loops:

>>> for k, v in d.items():
        print k, v

b 1
c 1
a 1
>>>

Now you're almost done:  wrap another function around your comp:

def paircomp(p1, p2):
    return comp(p1[1], p2[1])

and apply that to the items list:

x = d.items()
x.sort(paircomp)
for k, v in x:
    # Do your string fiddling and printing; the (k, v) pairs arrive
    # in increasing order of v, but in "random" order of k for equal
    # v; if that's not what you want, make paircomp smarter (the one
    # above simply ignores the k part).

orderedly y'rs  - tim




From teroc@zianet.com  Wed Jun 16 13:29:11 1999
From: teroc@zianet.com (Kenneth M. Power)
Date: Wed, 16 Jun 1999 07:29:11 -0500
Subject: [Tutor] Ummmmmm, suggestions please?
Message-ID: <37679897.288A2764@zianet.com>

Here is my program:

class Item:
   def __init__(self, name, volume):
      self.code = name
      self.cube = volume

class Inven:
   def __init__(self, limit):
      self.contents = []
      self.cubeLimit = limit
      self.currentCube = 0
   def insert(self, item):
      if (item.cube + self.currentCube) > self.cubeLimit:
         print item.name, "will not fit."
      else:
         self.currentCube = self.currentCube + self.item.cube
         self.contents.append(item)
   def remove(self, item):
      self.currentCube = self.currentCube - item.cube
      self.contents.remove(item)
   def show(self):
      print "Item\t\tVolume"
      for x in xrange(0, len(self.contents)):
         print self.contents[x].name, "\t\t", self.contents[x].cube
      print "Total cube: ", self.currentCube

OK, now getting closer to where I want/need help or suggestions.

first create an item and an inven object:

box = Item('Box', 5)
room1 = Inven(15)

room1.insert(box)
room1.show()
Item        Volume
Box        5
Total Volume: 5

room1.insert(box)
room1.show()
Item        Volume
Box        5
Box        5
Total Volume: 10

What I want is to accumulate like items into a group. Thus by putting
two (2) boxes into my Inven(tory), I would get this result:

room1.show()
Item        Volume
Box(2)    10			#Or something similar
Total Volume: 10

Any suggestions on how to accomplish this?

Ken



From Cepl@fpm.cz  Wed Jun 16 15:18:44 1999
From: Cepl@fpm.cz (Matej Cepl)
Date: Wed, 16 Jun 1999 15:18:44 +0100
Subject: [Tutor] HTML bettering?
Message-ID: <1318D78C9072D11195C9006094EA98A72C214C@ocesrv>

How to make as simple as tool which would make some simple operation
over HTML (e.g., headings numbering)? If I would use htmllib.py, I would
have to build HTMLformatter or I am wrong and it is easy?

		Thanks

				Matthew


From joe@strout.net  Wed Jun 16 17:03:38 1999
From: joe@strout.net (Joseph J. Strout)
Date: Wed, 16 Jun 1999 09:03:38 -0700
Subject: [Tutor] Ummmmmm, suggestions please?
In-Reply-To: <37679897.288A2764@zianet.com>
Message-ID: <v04020a0eb38d7a5909e9@[198.202.70.213]>

At 5:29 AM -0700 06/16/99, Kenneth M. Power wrote:

>What I want is to accumulate like items into a group. Thus by putting
>two (2) boxes into my Inven(tory), I would get this result:
>
>room1.show()
>Item        Volume
>Box(2)    10			#Or something similar
>Total Volume: 10
>
>Any suggestions on how to accomplish this?

This is what dictionaries are for.  Each unique key in a dictionary maps to
some value.  Basically, try this (untested code):

    def show(self):
	qtys = {}	# empty dictionary mapping items to qty of that item
	totals = {}	# empty dictionary mapping items to their total volume
	for item in self.contents:
	    if item in qtys.keys():
		# something we've seen already!
		qtys[item] = qtys[item] + 1
		totals[item] = totals[item] + item.cube
	    else:
		# not something we've seen already
		qtys[item] = 1
		totals[item] = item.cube
	# now we have totals, print 'em out
	for item in qtys.keys():
	    print "%s(%d)\t\t%f" % (item.name, qtys[item], totals[item])

If you don't want a (1) after single items, then you'll need to use an if
statement to get you to a different print format.

If anything in the above isn't clear, just let me know...

Cheers,
-- Joe
,------------------------------------------------------------------.
|    Joseph J. Strout           Biocomputing -- The Salk Institute |
|    joe@strout.net             http://www.strout.net              |
`------------------------------------------------------------------'


From tismer@appliedbiometrics.com  Wed Jun 16 18:26:10 1999
From: tismer@appliedbiometrics.com (Christian Tismer)
Date: Wed, 16 Jun 1999 19:26:10 +0200
Subject: [Tutor] Ummmmmm, suggestions please?
References: <37679897.288A2764@zianet.com>
Message-ID: <3767DE32.DA33E88D@appliedbiometrics.com>


"Kenneth M. Power" wrote:

> room1.show()
> Item        Volume
> Box(2)    10                    #Or something similar
> Total Volume: 10
> 
> Any suggestions on how to accomplish this?

You might want to add a summary function, like so:

   def summary(self):
      collector = {}
      countall, spaceall = (0,0)
      for thing in self.contents:
          name = thing.code
          cube = thing.cube
          count, sofar = collector.get(name, (0,0) )
          collector[name] = count+1, sofar + cube
          countall, spaceall = countall+1, spaceall+cube
      result = collector.items()
      result.sort()
      print "Item\t\tVolume"
      for name, (manifold, space) in result:
          print "%s(%d)\t\t%d" % (name, manifold, space)
      print "%d Objects, total volume=%d" % (countall, spaceall)

And please, next time submit tested code.
Yours had about three bugs.

ciao - chris

-- 
Christian Tismer             :^)   <mailto:tismer@appliedbiometrics.com>
Applied Biometrics GmbH      :     Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101   :    *Starship* http://starship.python.net
10553 Berlin                 :     PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
     we're tired of banana software - shipped green, ripens at home


From teroc@zianet.com  Wed Jun 16 20:42:34 1999
From: teroc@zianet.com (Kenneth M. Power)
Date: Wed, 16 Jun 1999 14:42:34 -0500
Subject: [Tutor] Ummmmmm, suggestions please?
References: <37679897.288A2764@zianet.com> <3767DEC0.576A4975@appliedbiometrics.com>
Message-ID: <3767FE2A.F9C0E2AC@zianet.com>

Sorry about that, the original code was 'bug-free'. Problem was when I went to
paste it into my email client. Apparently the editor I use (which is in beta
stage) has not reached the point of acutally using windows cliboard! Well find
this the hard way. I am surprised there was only three bugs with ym typing :)

Just a note, is there a reason some people send multiple messages with the
same content to this list? Christian Tismer did this, and there are two or
three others. Just curious.
ken

Christian Tismer wrote:
> And please, next time submit tested code.
> Yours had about three bugs.



From joe@strout.net  Wed Jun 16 21:06:44 1999
From: joe@strout.net (Joseph J. Strout)
Date: Wed, 16 Jun 1999 13:06:44 -0700
Subject: [Tutor] Ummmmmm, suggestions please?
In-Reply-To: <3767FE2A.F9C0E2AC@zianet.com>
References: <37679897.288A2764@zianet.com>
 <3767DEC0.576A4975@appliedbiometrics.com>
Message-ID: <v04020a00b38db4375b63@[198.202.70.213]>

At 12:42 PM -0700 06/16/99, Kenneth M. Power wrote:

>Just a note, is there a reason some people send multiple messages with the
>same content to this list? Christian Tismer did this, and there are two or
>three others. Just curious.

I don't think they do.  Are you sure they're not just sending it both to
you personally and to the list, so that you (but nobody else) gets two
copies, as I'm doing right now?

Cheers,
-- Joe
,------------------------------------------------------------------.
|    Joseph J. Strout           Biocomputing -- The Salk Institute |
|    joe@strout.net             http://www.strout.net              |
`------------------------------------------------------------------'


From tismer@appliedbiometrics.com  Thu Jun 17 11:20:05 1999
From: tismer@appliedbiometrics.com (Christian Tismer)
Date: Thu, 17 Jun 1999 12:20:05 +0200
Subject: [Tutor] Ummmmmm, suggestions please?
References: <37679897.288A2764@zianet.com> <3767DEC0.576A4975@appliedbiometrics.com> <3767FE2A.F9C0E2AC@zianet.com>
Message-ID: <3768CBD5.AC66F2E0@appliedbiometrics.com>


"Kenneth M. Power" wrote:
> 
> Sorry about that, the original code was 'bug-free'. Problem was when I went to
> paste it into my email client. Apparently the editor I use (which is in beta
> stage) has not reached the point of acutally using windows cliboard! Well find
> this the hard way. I am surprised there was only three bugs with ym typing :)

There is no reason to use the clipboard. An email client
usually is able to attach a file. This is better than to
retype the code, since it costs your time to put the bugs
in and mine to pull them out :-)

> Just a note, is there a reason some people send multiple messages with the
> same content to this list? Christian Tismer did this, and there are two or
> three others. Just curious.

I always send single messages back to the list *and* the
receiver. You might notice that your two messages
are not identical: One has the tutor list footer,
the other has not.
The one without came from me, directly. The other one from Mailman.

what's-the-name-of-that-email-client - ly y'rs - chris

-- 
Christian Tismer             :^)   <mailto:tismer@appliedbiometrics.com>
Applied Biometrics GmbH      :     Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101   :    *Starship* http://starship.python.net
10553 Berlin                 :     PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
     we're tired of banana software - shipped green, ripens at home


From teroc@zianet.com  Thu Jun 17 15:04:57 1999
From: teroc@zianet.com (Kenneth M. Power)
Date: Thu, 17 Jun 1999 09:04:57 -0500
Subject: [Tutor] Ummmmmm, suggestions please?
References: <37679897.288A2764@zianet.com>
 <3767DEC0.576A4975@appliedbiometrics.com> <v04020a00b38db4375b63@[198.202.70.213]>
Message-ID: <37690089.9E622920@zianet.com>

Can we all tell me 'duh!' right now :)

"Joseph J. Strout" wrote:

> At 12:42 PM -0700 06/16/99, Kenneth M. Power wrote:
>
> >Just a note, is there a reason some people send multiple messages with the
> >same content to this list? Christian Tismer did this, and there are two or
> >three others. Just curious.
>
> I don't think they do.  Are you sure they're not just sending it both to
> you personally and to the list, so that you (but nobody else) gets two
> copies, as I'm doing right now?
>



From teroc@zianet.com  Thu Jun 17 15:06:52 1999
From: teroc@zianet.com (Kenneth M. Power)
Date: Thu, 17 Jun 1999 09:06:52 -0500
Subject: [Tutor] Ummmmmm, suggestions please?
References: <37679897.288A2764@zianet.com> <3767DEC0.576A4975@appliedbiometrics.com> <3767FE2A.F9C0E2AC@zianet.com> <3768CBD5.AC66F2E0@appliedbiometrics.com>
Message-ID: <376900FB.4456EE25@zianet.com>

Sheesh, I am on a roll this week, first I forget to check my mail headers, now I
forget about the other way to send previously typed info through email. Today I
shall practice my abc's to see if I remember them!
Ken


> There is no reason to use the clipboard. An email client
> usually is able to attach a file. This is better than to
> retype the code, since it costs your time to put the bugs
> in and mine to pull them out :-)



From emile@fenx.com  Thu Jun 17 17:54:32 1999
From: emile@fenx.com (Emile van Sebille)
Date: Thu, 17 Jun 1999 09:54:32 -0700
Subject: [Tutor] Ummmmmm, suggestions please?
References: <37679897.288A2764@zianet.com>
Message-ID: <049201beb8e7$27752f60$01ffffc0@direcpc.com>

Hi Kenneth,

I started with your code, and ended like this:

HTH - Emile

Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from samplecubes import *
>>> test()
Item  Qty TtlVol
Ham    6    18
Egg    4     8
Spam    6    30
Total cube:  56
>>> test()
Item  Qty TtlVol
Ham    7    21
Egg    5    10
Spam    4    20
Total cube:  51
>>> 


Source:


class Item:
   def __init__(self, name, volume):
      self.name = name
      self.cube = volume

class Inven:
   def __init__(self, limit):
      self.contents = []
      self.cubeLimit = limit
      self.currentCube = 0
   def insert(self, item):
      if (item.cube + self.currentCube) > self.cubeLimit:
         print item.name, "will not fit."
      else:
         self.currentCube = self.currentCube + item.cube
         self.contents.append(item)
   def remove(self, item):
      self.currentCube = self.currentCube - self.item.cube
      self.contents.remove(item)
   def show(self):
      print "Item\t\tQty\tTtlVol"
      self.contents.sort()
      xpos = 0
      while xpos < len(self.contents):
         x = self.contents[xpos]
         testname, qty, ttlvol, xpos= x.name, 1, x.cube, xpos + 1
         try:
            while self.contents[xpos].name == testname:
               x = self.contents[xpos]
               qty, ttlvol, xpos = qty + 1, ttlvol + x.cube, xpos + 1
            else:
               print "%s\t\t% 3i\t% 5i" % (testname, qty, ttlvol)
         except:
            print "%s\t\t% 3i\t% 5i" % (testname, qty, ttlvol)
      print "Total cube: ", self.currentCube

def test():
   from whrandom import randint
   box1 = Item('Ham', 3)
   box2 = Item('Egg', 2)
   box3 = Item('Spam', 5)
   room1 = Inven(100)
   for i in range(randint(2,7)):
      room1.insert(box1)
   for i in range(randint(2,7)):
      room1.insert(box2)
   for i in range(randint(2,7)):
      room1.insert(box3)
      
   room1.show()


Emile van Sebille
emile@fenx.com
-------------------


----- Original Message ----- 
From: Kenneth M. Power <teroc@zianet.com>
To: <tutor@python.org>
Sent: Wednesday, June 16, 1999 5:29 AM
Subject: [Tutor] Ummmmmm, suggestions please?


> Here is my program:
> 
> class Item:
>    def __init__(self, name, volume):
>       self.code = name
>       self.cube = volume
> 
> class Inven:
>    def __init__(self, limit):
>       self.contents = []
>       self.cubeLimit = limit
>       self.currentCube = 0
>    def insert(self, item):
>       if (item.cube + self.currentCube) > self.cubeLimit:
>          print item.name, "will not fit."
>       else:
>          self.currentCube = self.currentCube + self.item.cube
>          self.contents.append(item)
>    def remove(self, item):
>       self.currentCube = self.currentCube - item.cube
>       self.contents.remove(item)
>    def show(self):
>       print "Item\t\tVolume"
>       for x in xrange(0, len(self.contents)):
>          print self.contents[x].name, "\t\t", self.contents[x].cube
>       print "Total cube: ", self.currentCube
> 
> OK, now getting closer to where I want/need help or suggestions.
> 
> first create an item and an inven object:
> 
> box = Item('Box', 5)
> room1 = Inven(15)
> 
> room1.insert(box)
> room1.show()
> Item        Volume
> Box        5
> Total Volume: 5
> 
> room1.insert(box)
> room1.show()
> Item        Volume
> Box        5
> Box        5
> Total Volume: 10
> 
> What I want is to accumulate like items into a group. Thus by putting
> two (2) boxes into my Inven(tory), I would get this result:
> 
> room1.show()
> Item        Volume
> Box(2)    10 #Or something similar
> Total Volume: 10
> 
> Any suggestions on how to accomplish this?
> 
> Ken
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor
> 
> 



From sdgoh@hotmail.com  Thu Jun 17 22:35:10 1999
From: sdgoh@hotmail.com (SweeDoon Goh)
Date: Thu, 17 Jun 1999 14:35:10 -0700
Subject: [Tutor] Python CGI on windows NT
Message-ID: <19990617213419.15724.qmail@hotmail.com>

This is a multi-part message in MIME format.

------=_NextPart_000_0029_01BEB8CE.9A509A60
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,=20

I'm new to Python and would like to know how to run python cgi scripts. =
I was having a difficulty in looking for this info on the web. Does =
anybody has any site recommendation? I'd really appreciate any direction =
in finding about python cgi on windows. Thank you.

SweeDoon

------=_NextPart_000_0029_01BEB8CE.9A509A60
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.2314.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D1>Hi, </FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D1>I'm new to Python and would like to know how to run =
python cgi=20
scripts. I was having a difficulty in looking for this info on the web. =
Does=20
anybody has any site recommendation? I'd really appreciate any direction =
in=20
finding about python cgi on windows. Thank you.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D1>SweeDoon</FONT></DIV></BODY></HTML>

------=_NextPart_000_0029_01BEB8CE.9A509A60--


From Emile van Sebille" <emile@fenx.com  Thu Jun 17 23:16:30 1999
From: Emile van Sebille" <emile@fenx.com (Emile van Sebille)
Date: Thu, 17 Jun 1999 15:16:30 -0700
Subject: [Tutor] Python CGI on windows NT
References: <19990617213419.15724.qmail@hotmail.com>
Message-ID: <005601beb90f$0fe3fc00$01ffffc0@direcpc.com>

This is a multi-part message in MIME format.

------=_NextPart_000_0051_01BEB8D4.608A3380
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

try

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

Emile van Sebille
emile@fenx.com
-------------------


----- Original Message -----=20
From: SweeDoon Goh=20
To: tutor@python.org=20
Sent: Thursday, June 17, 1999 2:35 PM
Subject: [Tutor] Python CGI on windows NT


Hi,=20

I'm new to Python and would like to know how to run python cgi scripts. =
I was having a difficulty in looking for this info on the web. Does =
anybody has any site recommendation? I'd really appreciate any direction =
in finding about python cgi on windows. Thank you.

SweeDoon

------=_NextPart_000_0051_01BEB8D4.608A3380
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.2014.210" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3D"Courier New" size=3D2>try</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D3><A=20
href=3D"http://www.python.org/topics/web/">http://www.python.org/topics/w=
eb/</A></FONT></DIV>
<DIV><BR>Emile van Sebille<BR><A=20
href=3D"mailto:emile@fenx.com">emile@fenx.com</A><BR>-------------------<=
/DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV style=3D"FONT: 10pt arial">----- Original Message -----=20
<DIV style=3D"BACKGROUND: #e4e4e4; font-color: black"><B>From:</B> <A=20
href=3D"mailto:sdgoh@hotmail.com" title=3Dsdgoh@hotmail.com>SweeDoon =
Goh</A> </DIV>
<DIV><B>To:</B> <A href=3D"mailto:tutor@python.org"=20
title=3Dtutor@python.org>tutor@python.org</A> </DIV>
<DIV><B>Sent:</B> Thursday, June 17, 1999 2:35 PM</DIV>
<DIV><B>Subject:</B> [Tutor] Python CGI on windows NT</DIV></DIV>
<DIV><BR></DIV>
<DIV><FONT size=3D1>Hi, </FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D1>I'm new to Python and would like to know how to run =
python cgi=20
scripts. I was having a difficulty in looking for this info on the web. =
Does=20
anybody has any site recommendation? I'd really appreciate any direction =
in=20
finding about python cgi on windows. Thank you.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D1>SweeDoon</FONT></DIV></BODY></HTML>

------=_NextPart_000_0051_01BEB8D4.608A3380--



From alan.gauld@bt.com  Wed Jun 23 18:44:18 1999
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 23 Jun 1999 18:44:18 +0100
Subject: [Tutor] hello???
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB24E0A2E@mbtlipnt02.btlabs.bt.co.uk>

I haven't received any pythonmail for 3 days 
- has it just gone quiet or is my feed broke?

Alan g.


From spaceram@earthlink.net  Thu Jun 24 02:57:06 1999
From: spaceram@earthlink.net (spaceram@earthlink.net)
Date: Wed, 23 Jun 1999 18:57:06 -0700
Subject: [Tutor] PYTHONPATH problem
Message-ID: <001901bebde4$dd585760$729bb3d1@grscomputer>

This is a multi-part message in MIME format.

------=_NextPart_000_0016_01BEBDAA.30393CA0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I'm having trouble using the PYTHONPATH command to open modules in the =
current window. Can anyone help me. I'm trying to open modules that i =
keep in the My Documents folder in windows.
I have the latest version of python and am using windows 98 second =
edition.

Please email me with help at spaceram@earthlink.net=20

------=_NextPart_000_0016_01BEBDAA.30393CA0
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>I'm having trouble using the PYTHONPATH =
command to=20
open modules in the current window. Can anyone help me. I'm trying to =
open=20
modules that i keep in the My Documents folder in windows.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I have the latest version of python and =
am using=20
windows 98 second edition.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Please email me with help at <A=20
href=3D"mailto:spaceram@earthlink.net">spaceram@earthlink.net</A>=20
</FONT></DIV></BODY></HTML>

------=_NextPart_000_0016_01BEBDAA.30393CA0--



From gerrit.holl@pobox.com  Thu Jun 24 14:44:05 1999
From: gerrit.holl@pobox.com (Gerrit Holl)
Date: Thu, 24 Jun 1999 15:44:05 +0200
Subject: [Tutor] hello???
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB24E0A2E@mbtlipnt02.btlabs.bt.co.uk>; from alan.gauld@bt.com on Wed, Jun 23, 1999 at 06:44:18PM +0100
References: <5104D4DBC598D211B5FE0000F8FE7EB24E0A2E@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <19990624154405.A18281@optiplex.palga.uucp>

On Wed, Jun 23, 1999 at 06:44:18PM +0100, alan.gauld@bt.com wrote:
> From: alan.gauld@bt.com
> Date: 	Wed, 23 Jun 1999 18:44:18 +0100
> X-Mailer: Internet Mail Service (5.5.2448.0)
> Subject: [Tutor] hello???
> 
> I haven't received any pythonmail for 3 days 
> - has it just gone quiet or is my feed broke?
> 

Can you read this?
If yes, it just gone quiet.
If no, your feed is broke.

regards,
Gerrit.

-- 
The Dutch Linuxgames homepage:	http://linuxgames.nl.linux.org
Personal homepage:		http://www.nl.linux.org/~gerrit/

Discoverb is a python program in Dutch and English which tests the words you
learned by asking it. Homepage: http://www.nl.linux.org/~gerrit/discoverb/


From 010.Werkstudent@MCHF.SIEMENS.DE  Thu Jun 24 17:56:59 1999
From: 010.Werkstudent@MCHF.SIEMENS.DE (Werkstudent 010)
Date: Thu, 24 Jun 1999 18:56:59 +0200
Subject: [Tutor] (no subject)
Message-ID: <809AE76DB183D111BE1300005A40E070CA53D7@mail.mchf.siemens.de>