From alan.gauld@bt.com  Mon Jul  3 12:04:33 2000
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 3 Jul 2000 12:04:33 +0100
Subject: [Tutor] Having trouble with a form mail script.
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D1F6@mbtlipnt02.btlabs.bt.co.uk>

>  My problem is that I am trying to edit a script that creates 
> a html page

This doesn't address your issue but...

>     print "Content-type: text/html\n"
>     
>     print "<HTML>\n"
>     print "<HEAD>\n"
>     print "<TITLE>Submission successful</TITLE>"
> ....
>     print "</BODY>\n";
>     print "</HTML>\n"


Triple quoted strings are great for this...

print """<HTML>
<HEAD>
<TITLE>Submission successful</TITLE>
   etc...
</BODY>
</HTML>"""

Saves some typing and presumably a bit of performance thru only 
calling print once.

Alan G.


From borgulya@pons.sote.hu  Mon Jul  3 21:53:42 2000
From: borgulya@pons.sote.hu (Borgulya Gabor)
Date: Mon, 3 Jul 2000 22:53:42 +0200 (CEST)
Subject: [Tutor] mirroring databases
In-Reply-To: <Pine.GSO.4.10.10006291643450.8078-100000@isis.visi.com>
Message-ID: <Pine.LNX.3.96.1000703225007.10211B-100000@Pons.sote.hu>

Hi!
Unfortunately I can not help you with the databases - the answersd to your
question would interest me too.
But if I remember well, there exists a database SIG too, it might help
if you reposted your message to that list.
Gabor



From dlaskey@laskeycpa.com  Mon Jul  3 22:19:18 2000
From: dlaskey@laskeycpa.com (Daniel D. Laskey, CPA)
Date: Mon, 3 Jul 2000 17:19:18 -0400
Subject: [Tutor] DoubleTalk
Message-ID: <01BFE512.DC9B4AC0@DAN>

I completed Josh Cogliati's "Non-Programmers Tutorial For Python", Alan =
Gauld's "Learning to Program".   My objective is to develop some =
accounting software with Python.  I picked up the book Hammond's and =
Robinson's book "Python, Programming on Win32".  It appears to have =
exactly what I have wanted using "DoubleTalk"

The book talks about the DoubleTalk class and that it can be downloaded. =
 I've been looking around and can't find anything on this.  Could =
someone please tell me where I can download DoubleTalk.

Thanks,
Dan
-------------------------------------------------------------------------=
----------------------
| Daniel D. Laskey, CPA--------------------dlaskey@laskeycpa.com
| Daniel D. Laskey Company, P.C.--------231-723-8305  / Fax 231-723-6097
| Certified Public Accountants
| 507 Water Street
| Manistee, MI  49660
-------------------------------------------------------------------------=
----------------------




From djansen@pobox.com  Tue Jul  4 06:22:26 2000
From: djansen@pobox.com (David Jansen)
Date: Tue, 4 Jul 2000 14:22:26 +0900
Subject: [Tutor] "TypeError: open, argument 1: expected string, file found"
Message-ID: <LPBBJDDFLFLMCKPODBMLAEELCIAA.djansen@pobox.com>

Mr. Gauld and everyone else on the list,

I am sure someone can offer a quick solution to this one...

I am working my way through the last half of Alan Gauld's "Case Study"
section in his Learning to Program tutorial and I am having a problem with
the document module. I've posted my slightly altered version at the address
below.

http://www.asahi-net.or.jp/~ns7s-ickw/python/document.py

When I try to run it I get the following error:

>>> Traceback (innermost last):
  File "C:\Program Files\Python\Pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "D:\Python\document.py", line 124, in ?
    D = HTMLDocument(file)
  File "D:\Python\document.py", line 12, in __init__
    self.infile = open(filename, "r")
TypeError: open, argument 1: expected string, file found
>>>

If you see any other problems I am going to run into, I would of course
appreciate the head's up.

Thank you in advance,


--
David Jansen
Tsukuba, Japan



From pm@dis.ro  Tue Jul  4 08:48:27 2000
From: pm@dis.ro (Marcel Preda)
Date: Tue, 4 Jul 2000 09:48:27 +0200
Subject: [Tutor] "TypeError: open, argument 1: expected string, file found"
References: <LPBBJDDFLFLMCKPODBMLAEELCIAA.djansen@pobox.com>
Message-ID: <006501bfe58c$457d87a0$1301000a@punto.it>

> Mr. Gauld and everyone else on the list,
>
> I am sure someone can offer a quick solution to this one...
>
> I am working my way through the last half of Alan Gauld's "Case Study"
> section in his Learning to Program tutorial and I am having a problem with
> the document module. I've posted my slightly altered version at the address
> below.
>
> http://www.asahi-net.or.jp/~ns7s-ickw/python/document.py
>
> When I try to run it I get the following error:
>
> >>> Traceback (innermost last):
>   File "C:\Program Files\Python\Pythonwin\pywin\framework\scriptutils.py",
> line 310, in RunScript
>     exec codeObject in __main__.__dict__
>   File "D:\Python\document.py", line 124, in ?
>     D = HTMLDocument(file)
>   File "D:\Python\document.py", line 12, in __init__
>     self.infile = open(filename, "r")
> TypeError: open, argument 1: expected string, file found
> >>>
>
> If you see any other problems I am going to run into, I would of course
> appreciate the head's up.
>
> Thank you in advance,


Your class HTMLDocument inherits class TextDocument which inherits Document
class

The __init__ method in Document class expect a string (filename)
def __init__(self, filename):
        self.filename = filename
        self.infile = open(filename, "r")

On the other side when you create the `D' object you pass a `file' object

enterfile = raw_input("Enter file: ")
file = open(enterfile, "r")
D = HTMLDocument(file)
So, at the end you will call __init__(self,file)  (and file is a `file type' not
a `string')

What  could you do?

#1 Modify the __init_ method in Document class is not a good idea

#2 create `D' like this:
enterfile = raw_input("Enter file: ")
D = HTMLDocument(enterfile)
#`enterfile' is a string


PM





From denis_mir@hotmail.com  Tue Jul  4 15:59:29 2000
From: denis_mir@hotmail.com (Denis Mironenko)
Date: Tue, 04 Jul 2000 14:59:29 GMT
Subject: [Tutor] E-mailing
Message-ID: <20000704145929.86934.qmail@hotmail.com>

I am trying to create a simple script that would allow users to send an 
e-mail from an intranet page. I know of two ways of doing it, first is to 
send an email some external program and second is to open my own connection. 
Could you give me an example of how can I do it? Or is there some resources 
on the net that explain the whole process?
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com



From pm@dis.ro  Tue Jul  4 16:10:17 2000
From: pm@dis.ro (Marcel Preda)
Date: Tue, 4 Jul 2000 17:10:17 +0200
Subject: R: [Tutor] E-mailing
References: <20000704145929.86934.qmail@hotmail.com>
Message-ID: <01ce01bfe5c9$fc33bea0$1301000a@punto.it>


----- Original Message ----- 
From: Denis Mironenko <denis_mir@hotmail.com>
To: <tutor@python.org>
Sent: Tuesday, July 04, 2000 4:59 PM
Subject: [Tutor] E-mailing


> I am trying to create a simple script that would allow users to send an 
> e-mail from an intranet page. I know of two ways of doing it, first is to 
> send an email some external program and second is to open my own connection. 
> Could you give me an example of how can I do it? Or is there some resources 
> on the net that explain the whole process?


import smtplib

server = smtplib.SMTP('aMailhost.com')
server.sendmail(mailFROM,toAddress,message)
server.quit()


PM

_______________________________
"Will I be using Python today?"
 and if the answer is "yes"
 I know that it's going to be a good day.




From da_woym@hotmail.com  Wed Jul  5 21:57:17 2000
From: da_woym@hotmail.com (Jacob Williams)
Date: Wed, 05 Jul 2000 13:57:17 PDT
Subject: [Tutor] python cgi
Message-ID: <20000705205717.81035.qmail@hotmail.com>

This is kinda python related....but here it goes!  Do you know of a free 
webspace provider that supports python cgi?  If there aren't any free ones, 
are there any at all?
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com



From deirdre@deirdre.net  Thu Jul  6 09:35:21 2000
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Thu, 6 Jul 2000 01:35:21 -0700 (PDT)
Subject: [Tutor] python cgi
In-Reply-To: <20000705205717.81035.qmail@hotmail.com>
Message-ID: <Pine.LNX.4.10.10007060133200.2519-100000@rockhopper.deirdre.org>

On Wed, 5 Jul 2000, Jacob Williams wrote:

> This is kinda python related....but here it goes!  Do you know of a
> free webspace provider that supports python cgi?  If there aren't any
> free ones, are there any at all?

I am 99.5% certain that he.net supports python CGIs. At least, they used
to. They're not free, but I believe they're about $9.95 a month. As they
aim more for developers, they're a nice outfit, pretty well-known in the
bay area and not known elsewhere. :)

he.net is the company that does the hosting for deirdre.net (I am a paying
customer and have been for a couple of years). I do my own hosting for my
other dozen or so domains, but it's nice to have a place to move my mail
to if I have to take my box down.

-- 
_Deirdre   *   http://www.sfknit.org   *   http://www.deirdre.net
"Linux means never having to delete your love mail." -- Don Marti



From denis_mir@hotmail.com  Thu Jul  6 18:35:32 2000
From: denis_mir@hotmail.com (Denis Mironenko)
Date: Thu, 06 Jul 2000 17:35:32 GMT
Subject: [Tutor] e-mailing
Message-ID: <20000706173532.85643.qmail@hotmail.com>

> > I am trying to create a simple script that would allow users to send an
> > e-mail from an intranet page. I know of two ways of doing it, first is 
>to
> > send an email some external program and second is to open my own 
>connection.
> > Could you give me an example of how can I do it? Or is there some 
>resources
> > on the net that explain the whole process?
>
>
>import smtplib
>
>server = smtplib.SMTP('aMailhost.com')
>server.sendmail(mailFROM,toAddress,message)
>server.quit()
>
>
>PM
>
>_______________________________
>"Will I be using Python today?"
>  and if the answer is "yes"
>  I know that it's going to be a good day.

What if I need to send a message with an attachement?
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com



From arcege@shore.net  Thu Jul  6 19:30:30 2000
From: arcege@shore.net (Michael P. Reilly)
Date: Thu, 6 Jul 2000 14:30:30 -0400 (EDT)
Subject: [Tutor] e-mailing
In-Reply-To: <20000706173532.85643.qmail@hotmail.com> from "Denis Mironenko" at Jul 06, 2000 05:35:32 PM
Message-ID: <200007061830.OAA17380@northshore.shore.net>

> What if I need to send a message with an attachement?

You can use the standard module, MimeWriter, or, IMO, the mimecntl
module <URL:http://starship.python.net/crew/arcege/modules/mimecntl.py>

For example with mimecntl, to include an image in an outgoing email:

>>> f = MIME_document('''\
Hi there, mom.  I just wanted to tell you that I enjoyed Christmas.  Thank
you for the mittens, they fit well.
''',
...   type='text/plain',
...   From='arcege@shore.net', To='my.mom@home.net'
... )
>>> print f.read()
>>> f['subject'] = 'Many thanks and holiday wishes'  # add a header
>>> f.write('Love,\n\tMichael')  # I forgot the signature
>>> from_addr = str(f['from'])   # who is sending it?
>>> majortype = f['content-type'].majortype()  # 'text'
>>> # send a picture
>>> imagefilename = 'card.gif'
>>> image = open(imagefilename).read()
>>> image = MIME_recoder(
...     image,
...     ( Field('content-type', 'image/gif', name=imagefilename),
...       Field('content-length', len(image)),
...       Field('content-disposition', 'attachment', filename=imagefilename),
...     )
...   )
>>> # now we encode it
>>> image.encode('base64')
>>> # make a new enclosing document instance
>>> # get f's headers to put into the new document
>>> f_fields = f.values()
>>> # we need to remove the content-type header field
>>> f_fields.remove('content-type')
>>> g = MIME_document( ( f, image ), fields=f_fields )
>>> 
>>> from smtplib import SMTP
>>> sender = SMTP('localhost')
>>> sender.sendmail(from_addr, (str(g['to']),), str(g))
>>> sender.quit()

The MimeWriter, in my mind is a bit more complicated to create the
same.

  -Arcege


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


From cliffu@earthlink.net  Thu Jul  6 22:53:22 2000
From: cliffu@earthlink.net (cliffu@earthlink.net)
Date: Thu, 6 Jul 2000 17:53:22 -0400
Subject: [Tutor] Saving Files in PythonWin
Message-ID: <E13AJYG-0003dh-00@dfw-mmp4.email.verio.net>

Here's a real newbie question: when I am in Pythonwin in 
interactive mode and go to the "File" section, I am offered the 
option to "Save as" after writing some code. I type in a file name 
with a .py extention, and save it. When I exit out, no file with the 
name I saved appears anywhere in my machine. What happened? 
Can't I save while in interactibe mode when using PythonWin?

- Cliff


From cliffu@earthlink.net  Thu Jul  6 22:53:22 2000
From: cliffu@earthlink.net (cliffu@earthlink.net)
Date: Thu, 6 Jul 2000 17:53:22 -0400
Subject: [Tutor] Saving Files in PythonWin
Message-ID: <E13AJYH-0003dh-00@dfw-mmp4.email.verio.net>

Here's a real newbie question: when I am in Pythonwin in 
interactive mode and go to the "File" section, I am offered the 
option to "Save as" after writing some code. I type in a file name 
with a .py extention, and save it. When I exit out, no file with the 
name I saved appears anywhere in my machine. What happened? 
Can't I save while in interactibe mode when using PythonWin?

- Cliff


From dlaskey@laskeycpa.com  Fri Jul  7 03:23:34 2000
From: dlaskey@laskeycpa.com (Daniel D. Laskey, CPA)
Date: Thu, 6 Jul 2000 22:23:34 -0400
Subject: [Tutor] DoubleTalk
Message-ID: <01BFE798.DA905300@DAN>

Can anyone tell me where I can download the DoubleTalk class module with
the sample transaction?

Dan

-----------------------------------------------------------------------------------------------
| Daniel D. Laskey, CPA--------------------dlaskey@laskeycpa.com
| Daniel D. Laskey Company, P.C.--------231-723-8305  / Fax 231-723-6097
| Certified Public Accountants
| 507 Water Street
| Manistee, MI  49660
-----------------------------------------------------------------------------------------------




From dyoo@hkn.EECS.Berkeley.EDU  Fri Jul  7 05:24:21 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Thu, 6 Jul 2000 21:24:21 -0700 (PDT)
Subject: [Tutor] Saving Files in PythonWin
In-Reply-To: <E13AJYH-0003dh-00@dfw-mmp4.email.verio.net>
Message-ID: <Pine.LNX.4.21.0007062118250.6745-100000@hkn.EECS.Berkeley.EDU>

On Thu, 6 Jul 2000 cliffu@earthlink.net wrote:

> Here's a real newbie question: when I am in Pythonwin in 
> interactive mode and go to the "File" section, I am offered the 
> option to "Save as" after writing some code. I type in a file name 
> with a .py extention, and save it. When I exit out, no file with the 
> name I saved appears anywhere in my machine. What happened? 
> Can't I save while in interactibe mode when using PythonWin?

It's usually more helpful to open up another window (besides the
interpreter window) to do your coding.  The reason for this is because if
you save the interpreter window, you'll have to later edit all the prompts
and the messy stuff out.  The interpreter window is really for viewing the
output of your programs and doing exploration through the system.

Your file is probably saved, but in one of your directories.  You'll
probably need to do a little navigation to find it.  You can always use
the Find command on your Start Menu --- hopefully, that will find it for
you. 

Also, it might be good to save your files on the Desktop: that should make
it easy to find again, and your file will appear immediately as an icon on
your screen after you save it.



From dlaskey@laskeycpa.com  Fri Jul  7 06:49:38 2000
From: dlaskey@laskeycpa.com (Daniel D. Laskey)
Date: Fri, 7 Jul 2000 01:49:38 -0400
Subject: [Tutor] DoubleTalk
Message-ID: <01BFE7B5.A95B6820@o1c-120.i2k.com>

I found the DoubleTalk - a financial Modeling Toolkit at:
http://www.robanal.demon.co.uk/doubletalk/index.html

Dan

-----------------------------------------------------------------------------------------------
| Daniel D. Laskey, CPA--------------------dlaskey@laskeycpa.com
| Daniel D. Laskey Company, P.C.--------231-723-8305  / Fax 231-723-6097
| Certified Public Accountants
| 507 Water Street
| Manistee, MI  49660
-----------------------------------------------------------------------------------------------



From Greg.Furmanek@hit.cendant.com  Fri Jul  7 23:29:53 2000
From: Greg.Furmanek@hit.cendant.com (Furmanek, Greg)
Date: Fri, 7 Jul 2000 18:29:53 -0400
Subject: [Tutor] Writing a web bot.
Message-ID: <F491D788C8F6D3119D5A009027B0D42B207964@hit-phx-mail-2.hfscorp.com>

Hi all.

It appears I have found myself in a position
where I could use some help.

The task I am trying to perform is write an
internet bot.  I was going to use urllib for
this project however one of the requirements
is for the connection to be continuous during
the session.  

Connect to a site.
Get page, parse.
Get another page, parse.
use POST method, get another page, parse.
Disconnect from the site.

The connection is not supposed to be dropped
between the requests.

Is there a simple way to do this task???

thanks.



From dyoo@hkn.EECS.Berkeley.EDU  Sat Jul  8 10:37:13 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Sat, 8 Jul 2000 02:37:13 -0700 (PDT)
Subject: [Tutor] Writing a web bot.
In-Reply-To: <F491D788C8F6D3119D5A009027B0D42B207964@hit-phx-mail-2.hfscorp.com>
Message-ID: <Pine.LNX.4.21.0007080227270.23571-100000@hkn.EECS.Berkeley.EDU>

On Fri, 7 Jul 2000, Furmanek, Greg wrote:

> The task I am trying to perform is write an
> internet bot.  I was going to use urllib for
> this project however one of the requirements
> is for the connection to be continuous during
> the session.  

Since HTTP is inherently stateless, there's no real continuity between
requests.  Perl's webbots, for example, simulate it by keeping track of
where they are.  I couldn't find an exact equivalent to LWP::UserAgent in
the core library.  But then, I'm completely unfamiliar with this, so
perhaps others can give better advice.  However, I did find something that
might be useful:

  http://starship.python.net/crew/jrush/Webbot/

It contains source to an implementation of a python webbot.  With luck,
you should be able to adjust it to suit your needs.  I found it using the
Vaults of Parnassus:

  http://www.vex.net/parnassus/

Sorry I couldn't give a more definite answer on this.



From jazariel@libero.it  Sat Jul  8 13:56:55 2000
From: jazariel@libero.it (Thomas Schulze)
Date: Sat, 8 Jul 2000 14:56:55 +0200
Subject: [Tutor] Overloading in UserList
Message-ID: <00070815070100.00483@CorelLinux>

Ciao,

after reading the book 'Learning Python', I started to write a simple game
programm.
I extended the UserList with some simple new methods which seem to work
fine. However I lost the slicing capability for the list.  

I am curious what the reson might be.

Thomas
_____________________________________________________________

The following code:

from UserList import UserList

class TestList(UserList):
    """ Class TestList based on class UserList """
    def __init__(self, list):
        UserList.__init__(self, list)
    def purge(self, value):
        """ Method to check if a value is in list and remove all its entries """
        while value in self.data:
            self.data.remove(value)
    def ensure(self, value):
        """ Method to add a value if it is not already in list """
        if not value in self.data:
            self.data.append(value)
    def copy(self):
        """ Makes a copy of the instance """
        return TestList(self.data[:])

produced after loading it:

>>> a = [1,2,3,4]
>>> A1 = UserList(a)
>>> A2 = TestList(a)

>>> A1[:]
[1, 2, 3, 4]
>>> A2[:]
Traceback (innermost last):
  File "<pyshell#14>", line 1, in ?
    A2[:]
  File "C:\Programmi\Python\Lib\UserList.py", line 23, in __getslice__
    userlist = self.__class__()
TypeError: not enough arguments; expected 2, got 1
>>> A2.copy()
[1, 2, 3, 4]


From jazariel@libero.it  Sat Jul  8 15:04:39 2000
From: jazariel@libero.it (jazariel@libero.it)
Date: Sat,  8 Jul 2000 16:04:39 +0200
Subject: [Tutor] Overloading in UserList  - Corrected
Message-ID: <FXDTRR$IG7eHPMY45CCtuqMe7h7N60eL4Zyfiqpc3b_P7o0VPi23ns@libero.it>

I=20just=20discovered=20that=20the=20Linux=20e-mail=20client=20kmail=0D=0A=
lost=20all=20the=20identation.=20Hope=20it=20works=20from=20the=20web.=0D=
=0ASo=20the=20code=20is:=0D=0A=0D=0Afrom=20UserList=20import=20UserList=0D=
=0A=0D=0Aclass=20TestList(UserList):=0D=0A=20=20=20=20"""=20Class=20TestL=
ist=20based=20on=20class=20UserList=20"""=0D=0A=20=20=20=20def=20__init__=
(self,=20list):=0D=0A=20=20=20=20=20=20=20=20UserList.__init__(self,=20li=
st)=0D=0A=0D=0A=20=20=20=20def=20purge(self,=20value):=0D=0A=20=20=20=20=20=
=20=20=20"""=20Method=20to=20check=20if=20a=20value=20is=20in=20list=20an=
d=20remove=20all=20its=0D=0A=20=20=20=20=20=20=20=20=20=20=20=20entries=20=
=20"""=0D=0A=09while=20value=20in=20self.data:=0D=0A=20=20=20=20=20=20=20=
=20self.data.remove(value)=0D=0A=0D=0A=20=20=20=20def=20ensure(self,=20va=
lue):=0D=0A=20=20=20=20=20=20=20=20"""=20Method=20to=20add=20a=20value=20=
if=20it=20is=20not=20already=20in=20list=20"""=0D=0A=09if=20not=20value=20=
in=20self.data:=0D=0A=20=20=20=20=09self.data.append(value)=0D=0A=0D=0A=20=
=20=20=20def=20copy(self):=0D=0A=20=20=20=20=20=20=20=20"""=20Makes=20a=20=
copy=20of=20the=20instance=20"""=0D=0A=20=20=20=20=20=20=20=20return=20Te=
stList(self.data[:])=0D=0A=0D=0A>>>=20a=20=3D=20[1,2,3,4]=0D=0A>>>=20A1=20=
=3D=20UserList(a)=0D=0A>>>=20A2=20=3D=20TestList(a)=0D=0A=0D=0A>>>=20A1[:=
]=0D=0A[1,=202,=203,=204]=0D=0A>>>=20A2[:]=0D=0ATraceback=20(innermost=20=
last):=0D=0A=20=20File=20"<pyshell#14>",=20line=201,=20in=20?=0D=0A=20=20=
=20=20A2[:]=0D=0A=20=20File=20"C:\Programmi\Python\Lib\UserList.py",=20li=
ne=2023,=20in=20__getslice__=0D=0A=20=20=20=20userlist=20=3D=20self.__cla=
ss__()=0D=0ATypeError:=20not=20enough=20arguments;=20expected=202,=20got=20=
1=0D=0A>>>=20A2.copy()=0D=0A[1,=202,=203,=204]=0D=0A=0D=0ASorry,=20Thomas=
=0A=0A=



From jazariel@libero.it  Sat Jul  8 15:17:42 2000
From: jazariel@libero.it (jazariel@libero.it)
Date: Sat,  8 Jul 2000 16:17:42 +0200
Subject: [Tutor] Inheritance in UserList - Embarrased
Message-ID: <FXDUDI$IG7eHPMY45CCtuqMe7h7N60eL4Zyfiqpc3b_P7o0VPi23ns@libero.it>

Well=20it's=20still=20wrong=20and=20i=20can=20only=20assure=20you=20that=20=
the=20original=20=0D=0Aidentation=20is=20correct=20and=20apologize=20for=20=
making=20you=20read=20three=20mails=0D=0Afor=20one=20inheritance=20proble=
m.=0D=0A=0D=0AThomas=0A=0A=



From dyoo@hkn.EECS.Berkeley.EDU  Sat Jul  8 21:04:13 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Sat, 8 Jul 2000 13:04:13 -0700 (PDT)
Subject: [Tutor] Overloading in UserList  - Corrected
In-Reply-To: <FXDTRR$IG7eHPMY45CCtuqMe7h7N60eL4Zyfiqpc3b_P7o0VPi23ns@libero.it>
Message-ID: <Pine.LNX.4.21.0007081231210.25690-100000@hkn.EECS.Berkeley.EDU>

On Sat, 8 Jul 2000, jazariel@libero.it wrote:

> I just discovered that the Linux e-mail client kmail
> lost all the identation. Hope it works from the web.

It didn't quite work --- the web email slightly mangled your
ensure() method:

>     def ensure(self, value):
>         """ Method to add a value if it is not already in list """
> 	if not value in self.data:
>     	self.data.append(value)


But in any case, we need to look at part of UserList, specifically, the
__getslice__() method to see why this is happening:

###
    def __getslice__(self, i, j):
        i = max(i, 0); j = max(j, 0)
        userlist = self.__class__()
        userlist.data[:] = self.data[i:j]
        return userlist
###

So it's creating a new instance of the list called userlist, and then
after that it copies the data.  This is where the code is breaking.  The
reason is because your __init__ method in TestList works only if you pass
it a list --- you need to make it work so that:

  mylist = TestList()

is possible.  The way that they made it work in UserList is to give the
parameter a default value:

###
    def __init__(self, list=None):
###

It should be a quick fix to have your TestList have similar
behavior.  Good luck!



From scarblac@pino.selwerd.nl  Sat Jul  8 22:49:09 2000
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Sat, 8 Jul 2000 23:49:09 +0200
Subject: [Tutor] Writing a web bot.
In-Reply-To: <F491D788C8F6D3119D5A009027B0D42B207964@hit-phx-mail-2.hfscorp.com>; from Greg.Furmanek@hit.cendant.com on Fri, Jul 07, 2000 at 06:29:53PM -0400
References: <F491D788C8F6D3119D5A009027B0D42B207964@hit-phx-mail-2.hfscorp.com>
Message-ID: <20000708234909.B23759@pino.selwerd.nl>

On Fri, Jul 07, 2000 at 06:29:53PM -0400, Furmanek, Greg wrote:
> Hi all.
> 
> It appears I have found myself in a position
> where I could use some help.
> 
> The task I am trying to perform is write an
> internet bot.  I was going to use urllib for
> this project however one of the requirements
> is for the connection to be continuous during
> the session.  
> 
> Connect to a site.
> Get page, parse.
> Get another page, parse.
> use POST method, get another page, parse.
> Disconnect from the site.
> 
> The connection is not supposed to be dropped
> between the requests.
> 
> Is there a simple way to do this task???

I've never needed to do this and I haven't studied urllib. But can't
you change urllib so that it uses an existing connection if it has used
a connection before? Find it out it opens connections, then redefine the
functions or inherit a class in your own module, something like that.

Also, websucker.py and webchecker.py have already been written (they're
in Python's Tools/ directory, maybe you need to download the source
distribution to get them). These tools download a whole site or check links
in a whole site. You probably want something like that. A script to parse
robots.txt files is also included.

But they use seperate connections for each file, I think...

-- 
Remco Gerlich,  scarblac@pino.selwerd.nl


From dandare@micoks.net  Sun Jul  9 00:08:17 2000
From: dandare@micoks.net (Daniel W Wobker)
Date: Sat, 8 Jul 2000 18:08:17 -0500
Subject: [Tutor] Help
Message-ID: <000a01bfe931$6b2ace60$2ec4bed0@micoks.net>

This is a multi-part message in MIME format.

------=_NextPart_000_0007_01BFE907.7F8C3080
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Can someone tell me why I am getting an error on this line of code. The =
totural says it will work but it dose not on my computer.

>>> string.strip('str') + 'ing'=20
Traceback(innermost last):
  File "<interactive input>", line 1, in ?
NameError: string

Thanks=20
Dan

------=_NextPart_000_0007_01BFE907.7F8C3080
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.3018.900" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Can someone tell me why I am getting an error on =
this line of=20
code. The totural says it will work but it dose not on my =
computer.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>&gt;&gt;&gt; string.strip('str') + 'ing' =
</FONT></DIV>
<DIV><FONT size=3D2>Traceback(innermost last):<BR>&nbsp; File =
"&lt;interactive=20
input&gt;", line 1, in ?<BR>NameError: string<BR></FONT></DIV>
<DIV><FONT size=3D2>Thanks </FONT></DIV>
<DIV><FONT size=3D2>Dan</DIV></FONT></BODY></HTML>

------=_NextPart_000_0007_01BFE907.7F8C3080--



From scarblac@pino.selwerd.nl  Sun Jul  9 00:13:26 2000
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Sun, 9 Jul 2000 01:13:26 +0200
Subject: [Tutor] Help
In-Reply-To: <000a01bfe931$6b2ace60$2ec4bed0@micoks.net>; from dandare@micoks.net on Sat, Jul 08, 2000 at 06:08:17PM -0500
References: <000a01bfe931$6b2ace60$2ec4bed0@micoks.net>
Message-ID: <20000709011326.A23851@pino.selwerd.nl>

On Sat, Jul 08, 2000 at 06:08:17PM -0500, Daniel W Wobker wrote:
> Can someone tell me why I am getting an error on this line of code. The totural says it will work but it dose not on my computer.
> 
> >>> string.strip('str') + 'ing' 
> Traceback(innermost last):
>   File "<interactive input>", line 1, in ?
> NameError: string

You need to do 'import string' first.

You call function 'strip' in module 'string'. To use things in a module, you
always have to import it first.

-- 
Remco Gerlich,  scarblac@pino.selwerd.nl


From deirdre@deirdre.net  Sun Jul  9 01:40:17 2000
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Sat, 8 Jul 2000 17:40:17 -0700 (PDT)
Subject: [Tutor] Help
In-Reply-To: <000a01bfe931$6b2ace60$2ec4bed0@micoks.net>
Message-ID: <Pine.LNX.4.10.10007081739300.12622-100000@rockhopper.deirdre.org>

You forgot to import the string module:

import string

On Sat, 8 Jul 2000, Daniel W Wobker wrote:

> Can someone tell me why I am getting an error on this line of code.
> The totural says it will work but it dose not on my computer.
> 
> >>> string.strip('str') + 'ing' 
> Traceback(innermost last):
>   File "<interactive input>", line 1, in ?
> NameError: string
> 
> Thanks 
> Dan
> 

-- 
_Deirdre   *   http://www.sfknit.org   *   http://www.deirdre.net
"Trust me, I'm a science fiction writer" -- Larry Niven @ Conolulu



From ewe2@can.org.au  Sat Jul  8 23:56:58 2000
From: ewe2@can.org.au (Sean Dwyer)
Date: Sun, 9 Jul 2000 08:56:58 +1000
Subject: [Tutor] display-related questions
Message-ID: <20000709085658.A1189@can.org.au>

I have two questions:

1. I'm writing an innocuous command-line fibonacci numbers program. So that
users can input almost any size number to determine the length of the
sequence, I've had to use long integers. 

Unfortunately this also output every number with a long integer indicator (eg
987L). Is it possible to avoid this in output, and how?

2. my second question is Tkinter-related, and is probably simpler: what's the
best way to right-justify a main menu item, such as Help?

thanks,

sean
 
-- 
The Mdate Development Team
Project Admin : Sean Dwyer <ewe2@users.sourceforge.net>
Web: http://mdate.sourceforge.net/


From richard_chamberlain@ntlworld.com  Sun Jul  9 07:59:31 2000
From: richard_chamberlain@ntlworld.com (Richard Chamberlain)
Date: Sun, 9 Jul 2000 07:59:31 +0100
Subject: [Tutor] display-related questions
References: <20000709085658.A1189@can.org.au>
Message-ID: <001b01bfe973$6a03ad80$b061fea9@richardc>

1:

mylong=12190912912L
print `mylong`[:-1]

2:
from Tkinter import *
root=Tk()
mbar=Frame(root)

filebutton=Menubutton(mbar,text='File')
filemenu = Menu(filebutton, tearoff=0)
filebutton['menu']=filemenu
filemenu.add('command', label = 'Open etc')
filebutton.pack(side=LEFT)

helpbutton = Menubutton(mbar, text = 'Help')
helpmenu=Menu(helpbutton,tearoff=0)
helpbutton['menu']=helpmenu
helpmenu.add('command',label='Help things')
helpbutton.pack(side = RIGHT)

mbar.pack(side=TOP,fill=X,expand=1,anchor=N)
root.mainloop()


Richard
----- Original Message -----
From: Sean Dwyer <ewe2@can.org.au>
To: <tutor@python.org>
Sent: Saturday, July 08, 2000 11:56 PM
Subject: [Tutor] display-related questions


> I have two questions:
>
> 1. I'm writing an innocuous command-line fibonacci numbers program. So
that
> users can input almost any size number to determine the length of the
> sequence, I've had to use long integers.
>
> Unfortunately this also output every number with a long integer indicator
(eg
> 987L). Is it possible to avoid this in output, and how?
>
> 2. my second question is Tkinter-related, and is probably simpler: what's
the
> best way to right-justify a main menu item, such as Help?
>
> thanks,
>
> sean
>
> --
> The Mdate Development Team
> Project Admin : Sean Dwyer <ewe2@users.sourceforge.net>
> Web: http://mdate.sourceforge.net/
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor



From dyoo@hkn.EECS.Berkeley.EDU  Sun Jul  9 08:19:10 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Sun, 9 Jul 2000 00:19:10 -0700 (PDT)
Subject: [Tutor] display-related questions
In-Reply-To: <20000709085658.A1189@can.org.au>
Message-ID: <Pine.LNX.4.21.0007090012590.30442-100000@hkn.EECS.Berkeley.EDU>

On Sun, 9 Jul 2000, Sean Dwyer wrote:

> 1. I'm writing an innocuous command-line fibonacci numbers program. So
> that users can input almost any size number to determine the length of
> the sequence, I've had to use long integers.
> 
> Unfortunately this also output every number with a long integer
> indicator (eg 987L). Is it possible to avoid this in output, and how?

Richard has already posted a way of removing the 'L' at the end of the
output string.  However, you should be aware that the next version of
Python (2.0) coming up will not append the 'L' on long ints, so be
prepared to switch back... *grin*  Here's a quote from the new-features
commentary:

"The subtlest long integer change of all is that the str() of a long
integer no longer has a trailing 'L' character, though repr() still
includes it. The 'L' annoyed many people who wanted to print long integers
that looked just like regular integers, since they had to go out of their
way to chop off the character. This is no longer a problem in 2.0, but
code which assumes the 'L' is there, and does str(longval)[:-1] will now
lose the final digit."

This comes from:

  http://starship.python.net/crew/amk/python/writing/new-python/




From mlfloren@bulldog.unca.edu  Mon Jul 10 05:27:03 2000
From: mlfloren@bulldog.unca.edu (Marcella Louise Florence)
Date: Mon, 10 Jul 2000 00:27:03 -0400 (EDT)
Subject: [Tutor] Teach Yourself Python (in 24 Hours)
Message-ID: <Pine.OSF.4.20.0007100020420.280832-100000@bulldog.unca.edu>

My name is Marcella, and I wrote to the list awhile
ago asking for resources in learning Python as my
first language.  I had a lot of reccomendations for
Ivan Van Laningham's book, "Teach Yourself Python
in 24 Hours".

Sometimes I'm an awful procrastinator, and so I
admit that I only picked up the book a few days ago
when I found it in a local bookstore. So far, 
however, I've found it very helpful and interesting.

I write to this list now to make an offer and a
request. If there is anyone else on the list new to
Python and/or programming in general, I would love
to have some mutual motivation, meet a neat person
(or people), and perhaps design a basic project
together.  If anyone's interested, let me know at
this email address (mlfloren@bulldog.unca.edu).

I'd also appreciate it if Ivan would drop me his
email address.  I have a couple questions I would
love to oppurtunity to ask him.

Thanks!

-Marcella

***
"Me like stardust on your shoulders, friend..."
-Yoko of Planet Rondo
***



From ivanlan@home.com  Mon Jul 10 05:45:03 2000
From: ivanlan@home.com (Ivan Van Laningham)
Date: Sun, 09 Jul 2000 22:45:03 -0600
Subject: [Tutor] Teach Yourself Python (in 24 Hours)
References: <Pine.OSF.4.20.0007100020420.280832-100000@bulldog.unca.edu>
Message-ID: <396954CF.40CC204@home.com>

Hi All--

Marcella Louise Florence wrote:
> 
[snip]

> I'd also appreciate it if Ivan would drop me his
> email address.  I have a couple questions I would
> love to oppurtunity to ask him.
> 

Here I am.  I took a new job with Axent since the book was published. 
I've moved my primary email address to

	ivanlan@home.com

Metta,
Ivan
----------------------------------------------
Ivan Van Laningham
Axent Technologies, Inc.
http://www.pauahtun.org/
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
Author:  Teach Yourself Python in 24 Hours


From shaleh@valinux.com  Mon Jul 10 19:16:24 2000
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Mon, 10 Jul 2000 11:16:24 -0700
Subject: [Tutor] Writing a web bot.
In-Reply-To: <F491D788C8F6D3119D5A009027B0D42B207964@hit-phx-mail-2.hfscorp.com>; from Greg.Furmanek@hit.cendant.com on Fri, Jul 07, 2000 at 06:29:53PM -0400
References: <F491D788C8F6D3119D5A009027B0D42B207964@hit-phx-mail-2.hfscorp.com>
Message-ID: <20000710111624.B4041@valinux.com>

On Fri, Jul 07, 2000 at 06:29:53PM -0400, Furmanek, Greg wrote:
> Hi all.
> 
> It appears I have found myself in a position
> where I could use some help.
> 
> The task I am trying to perform is write an
> internet bot.  I was going to use urllib for
> this project however one of the requirements
> is for the connection to be continuous during
> the session.  
> 

For http, I am not aware that this is possible.  Unless HTTP 1.1 changed
something.  After the browser sends you a page, it disconnects.

HELO
DATA
BYE

as another poster mentioned, you can keep an internal state of where you are,
but short of there being a special HTTP command for this, I do not think you
can do it as you think.


From mouali@wanadoo.fr  Mon Jul 10 20:49:09 2000
From: mouali@wanadoo.fr (Mouali rabii sbai)
Date: Mon, 10 Jul 2000 21:49:09 +0200
Subject: [Tutor] (no subject)
Message-ID: <000801bfeaa7$ec5cb580$0a00000a@wanadoo.fr>

C'est un message de format MIME en plusieurs parties.

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

subcribe

------=_NextPart_000_0005_01BFEAB8.AD3E8160
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.2919.6307" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>subcribe</FONT></DIV></BODY></HTML>

------=_NextPart_000_0005_01BFEAB8.AD3E8160--



From djansen@pobox.com  Tue Jul 11 00:37:14 2000
From: djansen@pobox.com (David Jansen)
Date: Tue, 11 Jul 2000 08:37:14 +0900
Subject: [Tutor] another newbie question
Message-ID: <LPBBJDDFLFLMCKPODBMLAEHJCIAA.djansen@pobox.com>

In A. Gauld's document.py (a copy of which is posted at
http://www.sky.sannet.ne.jp/si75/document.py) in his Learning to Program
tutorial there is the following function:

def generateStats(self):
>>>>self.c_words = len(self.groups)
>>>>sentences, clauses = 0, 0
>>>>for c in self.stop_tokens:
>>>>>>>>sentences = sentences + self.c_punctuation[c]
>>>>self.c_sentence = sentences
>>>>for c in self.c_punctuation.keys():
>>>>>>>>clauses = clauses + self.c_punctuation[c]
>>>>self.c_clause = clauses

Now my question is why it is necessary to add the sentences = sentences +...
and clauses = clauses +... lines? Why not just:

self.c_sentence = self.c_sentence + self.c_punctuation[c]

and

self.c_clause = self.c_clause + self.c_punctuation[c]

Thank you,
David



From scarblac@pino.selwerd.nl  Tue Jul 11 00:57:40 2000
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 11 Jul 2000 01:57:40 +0200
Subject: [Tutor] another newbie question
In-Reply-To: <LPBBJDDFLFLMCKPODBMLAEHJCIAA.djansen@pobox.com>; from djansen@pobox.com on Tue, Jul 11, 2000 at 08:37:14AM +0900
References: <LPBBJDDFLFLMCKPODBMLAEHJCIAA.djansen@pobox.com>
Message-ID: <20000711015740.A28410@pino.selwerd.nl>

On Tue, Jul 11, 2000 at 08:37:14AM +0900, David Jansen wrote:
> 
> In A. Gauld's document.py (a copy of which is posted at
> http://www.sky.sannet.ne.jp/si75/document.py) in his Learning to Program
> tutorial there is the following function:
> 
> def generateStats(self):
> >>>>self.c_words = len(self.groups)
> >>>>sentences, clauses = 0, 0
> >>>>for c in self.stop_tokens:
> >>>>>>>>sentences = sentences + self.c_punctuation[c]
> >>>>self.c_sentence = sentences
> >>>>for c in self.c_punctuation.keys():
> >>>>>>>>clauses = clauses + self.c_punctuation[c]
> >>>>self.c_clause = clauses
> 
> Now my question is why it is necessary to add the sentences = sentences +...
> and clauses = clauses +... lines? Why not just:
> 
> self.c_sentence = self.c_sentence + self.c_punctuation[c]
> 
> and
> 
> self.c_clause = self.c_clause + self.c_punctuation[c]

Yes, that will work too. It's mostly a matter of style. It's cleaner to use
a local variable for the computation and only set the result in the instance
variable. c_sentence holds the count of sentences, period. It never holds
any intermediate results. Don't use one variable for two different things,
if you need to keep temporary results, use a temporary variable.

Also, if there are lots of tokens, using a local variable is slightly faster
than an instance variable inside the loop (it saves a lookup).

But it's not "necessary" to do it this way, no.

-- 
Remco Gerlich,  scarblac@pino.selwerd.nl


From Steven Gilmore" <srGilmore@sprintmail.com  Tue Jul 11 06:03:53 2000
From: Steven Gilmore" <srGilmore@sprintmail.com (Steven Gilmore)
Date: Tue, 11 Jul 2000 01:03:53 -0400
Subject: [Tutor] trying to learn python
Message-ID: <000e01bfeaf5$6acbee20$0d72f4d1@srgilmor>

 I hope you guys/gals can help me out.  You see, I'm trying to learn python
but there is a catch.  I have a physical disability which makes it
impossible to hold, much less flip through, a book.  I was hoping /wondering
where I can get books in some sort of alternative format that I can read it
on screen.  If anybody has any ideas or know somebody who does please post a
reply.  I've read the Python Tutorial that comes with the interpreter.

Another issue of mine is I have to use dictation software (DragonDictate).
Does anybody know of any sources of information on programming by voice?

Thanks in advance,
Steven Gilmore



From python-tutor@teleo.net  Tue Jul 11 06:41:33 2000
From: python-tutor@teleo.net (Patrick Phalen)
Date: Mon, 10 Jul 2000 22:41:33 -0700
Subject: [Tutor] trying to learn python
In-Reply-To: <000e01bfeaf5$6acbee20$0d72f4d1@srgilmor>
References: <000e01bfeaf5$6acbee20$0d72f4d1@srgilmor>
Message-ID: <0007102307470W.03526@quadra.teleo.net>

[Steven Gilmore, on Mon, 10 Jul 2000]
:: I hope you guys/gals can help me out.  You see, I'm trying to learn python
:: but there is a catch.  I have a physical disability which makes it
:: impossible to hold, much less flip through, a book.  I was hoping /wondering
:: where I can get books in some sort of alternative format that I can read it
:: on screen.  If anybody has any ideas or know somebody who does please post a
:: reply.  I've read the Python Tutorial that comes with the interpreter.
:: 
:: Another issue of mine is I have to use dictation software (DragonDictate).
:: Does anybody know of any sources of information on programming by voice?


Wow. Challenging questions.

I'm afraid I know nothing about dictation software and programming, but
here are a few possibilities pertinent to your first query.

The Quick Python Book (excellent), was, during its development
(prior to paper publication), available for free in the form of a Word
document on the Manning Publications web site. It has since been
removed and I happily bought the book, but I still have a copy of the
Word files and an HTML conversion. If you can get permission from the
authors or publisher to me, I'd be happy to email either version to you.
http://www.manning.com/harms/.

Fredrik Lundh's (The effbot Guide to) The Standard Python Library is
available for only $12.00 in eMatter form from http://www.fatbrain.com.

You've mentioned the Python Tutorial, which is great. Be mindful also
that the Python Library Reference and Language Reference are available
in digital form. http://www.python.org/doc. I also keep copies of these
in Rocket eBook form. ;)








From shaleh@valinux.com  Tue Jul 11 09:28:48 2000
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Tue, 11 Jul 2000 01:28:48 -0700
Subject: [Tutor] trying to learn python
In-Reply-To: <000e01bfeaf5$6acbee20$0d72f4d1@srgilmor>; from srGilmore@sprintmail.com on Tue, Jul 11, 2000 at 01:03:53AM -0400
References: <000e01bfeaf5$6acbee20$0d72f4d1@srgilmor>
Message-ID: <20000711012848.C4768@valinux.com>

On Tue, Jul 11, 2000 at 01:03:53AM -0400, Steven Gilmore wrote:
> 
> Another issue of mine is I have to use dictation software (DragonDictate).
> Does anybody know of any sources of information on programming by voice?
>

An issue you will have to deal with is Python's grammar is based on whitespace.
This means that:

if foo:
  something
different

the different is not under the else.  So, the software would have to allow you
control of where the code goes or really understand python.


From SBrunning@trisystems.co.uk  Tue Jul 11 09:50:31 2000
From: SBrunning@trisystems.co.uk (Simon Brunning)
Date: Tue, 11 Jul 2000 09:50:31 +0100
Subject: [Tutor] trying to learn python
Message-ID: <31575A892FF6D1118F5800600846864D4C700D@intrepid>

>[Steven Gilmore, on Mon, 10 Jul 2000]
>The Quick Python Book (excellent), was, during its development
>(prior to paper publication), available for free in the form of a Word
>document on the Manning Publications web site. It has since been
>removed and I happily bought the book, but I still have a copy of the
>Word files and an HTML conversion. If you can get permission from the
>authors or publisher to me, I'd be happy to email either version to you.
>http://www.manning.com/harms/.

I can also recommend The Quick Python Book. I'd point out, though, that it's
aimed at people who already know how to program and want to learn Python,
rather than those totally new to programming.

There is a lot of good stuff on-line, too. See
<http://www.cetus-links.de/oo_python.html> for the best set of links that I
have yet come across.

Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning@trisystems.co.uk





-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.


From shr78_2000@yahoo.com  Tue Jul 11 10:28:51 2000
From: shr78_2000@yahoo.com (Sahrin HAR)
Date: Tue, 11 Jul 2000 02:28:51 -0700 (PDT)
Subject: [Tutor] Learning for begginer about PYTHON
Message-ID: <20000711092851.17912.qmail@web5103.mail.yahoo.com>

Hi!

I`m Sahrin from Brunei and i`m new in this
industry....
well for your information i`m not good at this
programming but i`ve trying a lot of thing that make
me feel comfortable with the python...

I want to learn more about python, all about it`s
command which is very useful...please teach me more
about python and i don`t have it`s software, and i
really like this programs other then Perl...

Please teach me more...

p/s: How if i Want to create a password with a
different user and also how to make a form within the
python command..would you give me what command it`s
gonna be use I`m blur in this..please i getting
interested with this language

Email me:shr78_2000@yahoo.com

__________________________________________________
Do You Yahoo!?
Get Yahoo! Mail – Free email you can access from anywhere!
http://mail.yahoo.com/


From geoffbays@mindspring.com  Tue Jul 11 18:30:55 2000
From: geoffbays@mindspring.com (Geoffrey Bays)
Date: Tue, 11 Jul 2000 10:30:55 -0700
Subject: [Tutor] Running Python from Windows command line
Message-ID: <4.3.2.7.0.20000711101737.00a913e0@pop.mindspring.com>

How do I run Python from the Windows 98 'run' line?  When I try to do so, 
the MS-DOS window pops up for a flash and then vanishes.
I have been working through 'Learning Python' running all modules from the 
interactive interpreter using the 'import' command. I want to try the " 
if__name__ == "__main__': " test in the book, but can't do so without 
running modules from the command line.
My apologies for such a newbie and windows related question. Thanks



From borgulya@pons.sote.hu  Tue Jul 11 16:12:04 2000
From: borgulya@pons.sote.hu (Borgulya Gabor)
Date: Tue, 11 Jul 2000 17:12:04 +0200 (CEST)
Subject: [Tutor] Running Python from Windows command line
In-Reply-To: <4.3.2.7.0.20000711101737.00a913e0@pop.mindspring.com>
Message-ID: <Pine.LNX.3.96.1000711170523.5909A-100000@Pons.sote.hu>


> How do I run Python from the Windows 98 'run' line?  When I try to do so, 
> the MS-DOS window pops up for a flash and then vanishes.

Type "command" to the run line. It starts command.com, in a "DOS-window".
Now you can start the interpreter typing "python" (or something like
"C:\Programs\Python\python" if the python.exe is not in the path).
To run your python program maintest.py type "python maintest.py".

You can close the dos window with the exit command. It might be useful to
set the number of rows in the window buffer high (eg. 100) so as to be
able to scroll up in the window.


Yours,
Gabor Borgulya



From scarblac@pino.selwerd.nl  Tue Jul 11 16:17:21 2000
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 11 Jul 2000 17:17:21 +0200
Subject: [Tutor] Running Python from Windows command line
In-Reply-To: <4.3.2.7.0.20000711101737.00a913e0@pop.mindspring.com>; from geoffbays@mindspring.com on Tue, Jul 11, 2000 at 10:30:55AM -0700
References: <4.3.2.7.0.20000711101737.00a913e0@pop.mindspring.com>
Message-ID: <20000711171721.A29066@pino.selwerd.nl>

On Tue, Jul 11, 2000 at 10:30:55AM -0700, Geoffrey Bays wrote:
> How do I run Python from the Windows 98 'run' line?  When I try to do so, 
> the MS-DOS window pops up for a flash and then vanishes.
> I have been working through 'Learning Python' running all modules from the 
> interactive interpreter using the 'import' command. I want to try the " 
> if__name__ == "__main__': " test in the book, but can't do so without 
> running modules from the command line.
> My apologies for such a newbie and windows related question. Thanks

You can just open a DOS box and give the Python command from there, so that
the window stays when the program is finished.

Or end your program with a 'raw_input("Hit enter to leave...")'.

There may be more sophisticated ways to do it, but I don't use Windows so 
I don't know :)

-- 
Remco Gerlich,  scarblac@pino.selwerd.nl


From Thomas_A._Williams@NEWYORKLIFE.COM  Tue Jul 11 17:37:51 2000
From: Thomas_A._Williams@NEWYORKLIFE.COM (Thomas A. Williams)
Date: Tue, 11 Jul 2000 12:37:51 -0400
Subject: [Tutor] Queens, NY - PYTHON Programming for Kids
Message-ID: <85256919.005B60CE.00@Email.NewYorkLife.com>

Hi Y'all,
I'm looking at the prospect of starting a programming
class for youth at the YMCA on Pasons Blvd. in
Jamaica, Queens.  I will definitely be building the class
around PYTHON.  Does anyone have any suggestions
or directions?

Also, MUCH THANKS to those who responded with suggestions
on how to go about constructing a Coke Vending Machine
from an object perspective in PYTHON.  This is still a work in
progress.

Enjoy The Journey,
TomW




From alan.gauld@freenet.co.uk  Tue Jul 11 18:01:03 2000
From: alan.gauld@freenet.co.uk (Alan Gauld)
Date: Tue, 11 Jul 2000 17:01:03 +0000
Subject: [Tutor] Re: newbie question
Message-ID: <3.0.1.32.20000711170103.00837750@mail.freenet.co.uk>

Hi, Just back from a short vacation and found your 
query....

> Now my question is why it is necessary to add 
> the sentences = sentences +...
> and clauses = clauses +... lines? Why not just:
>
> self.c_sentence = self.c_sentence + self.c_punctuation[c]

Nope, I don't know why I used a local variable 
- I don't in the non OO version. Maybe I was tired!

Another poster generously suggested it was a 
possible performance improvement but I honestly 
doubt I was that alert. It certainly doesn't help 
a newbie...

I'll change it in the next update to the site, 
thanks for pointing it out! (If I do find a valid 
reason I'll let you know!)

That whole case study is getting a revisited as part 
of my book project, so that should get reflected 
back into the web site,

The good news is that the fact you raised the question 
shows you have picked up a lot about programming Python! 
:-)

Thanks agan,

Alan G.



From scarblac@pino.selwerd.nl  Tue Jul 11 18:16:14 2000
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 11 Jul 2000 19:16:14 +0200
Subject: [Tutor] Re: newbie question
In-Reply-To: <3.0.1.32.20000711170103.00837750@mail.freenet.co.uk>; from alan.gauld@freenet.co.uk on Tue, Jul 11, 2000 at 05:01:03PM +0000
References: <3.0.1.32.20000711170103.00837750@mail.freenet.co.uk>
Message-ID: <20000711191614.A29168@pino.selwerd.nl>

On Tue, Jul 11, 2000 at 05:01:03PM +0000, Alan Gauld wrote:
> Hi, Just back from a short vacation and found your 
> query....
> 
> > Now my question is why it is necessary to add 
> > the sentences = sentences +...
> > and clauses = clauses +... lines? Why not just:
> >
> > self.c_sentence = self.c_sentence + self.c_punctuation[c]
> 
> Nope, I don't know why I used a local variable 
> - I don't in the non OO version. Maybe I was tired!
> 
> Another poster generously suggested it was a 
> possible performance improvement but I honestly 
> doubt I was that alert. It certainly doesn't help 
> a newbie...

Grin. I already had the feeling I was seeing too much into it when I thought
up some explanations :).

I don't know, I think I still like using the local better. But that's just a
matter of taste, of course :)

-- 
Remco Gerlich,  scarblac@pino.selwerd.nl


From arthur.watts@gbst.com  Wed Jul 12 02:56:05 2000
From: arthur.watts@gbst.com (Arthur Watts)
Date: Wed, 12 Jul 2000 11:56:05 +1000
Subject: [Tutor] Implementing data hiding in Python
Message-ID: <1CDB101F0CB6D311882F0000F806392401507C34@aquarius.bne.star.com.au>

Guys,

	I don't want to get into religious wars re the benefits of
encapsulation and the use of 'private', 'const' or whatever. I know that I
can use 'name-mangling' via '__foo' from Python 1.5 to give me a limited
form of privacy and I have seen allusions to extensions that enforce data
hiding :

There is little direct support for data hiding within Python itself, but
extensions and embeddings of Python can provide rock solid interfaces that
expose only permitted foreign operations to the Python interpreter. Python's
restricted execution mode may also provide some (usually extreme) protection
within the interpreter itself.             

	I need to know if anyone has written said extensions, as I am unable
to find anything at the Vaults of Parnassus archive. I suspect that the
above quote may indicate that we need to write our own extensions to enforce
data-hiding on a class-by-class basis, but I'm open to suggestions. The
issue is *not* coding to prevent breaking modules by trampling one anothers
namespaces, it is convincing management that Python is the right tool for
the bulk of the project. 

Thanks,

Arthur 

Arthur Watts
Systems Integrator
GBST Pty Ltd

'Good programmers know what to use, great programmers know what to re-use' :
Old Jungle Saying



From shaleh@valinux.com  Wed Jul 12 03:08:33 2000
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Tue, 11 Jul 2000 19:08:33 -0700
Subject: [Tutor] Implementing data hiding in Python
In-Reply-To: <1CDB101F0CB6D311882F0000F806392401507C34@aquarius.bne.star.com.au>; from arthur.watts@gbst.com on Wed, Jul 12, 2000 at 11:56:05AM +1000
References: <1CDB101F0CB6D311882F0000F806392401507C34@aquarius.bne.star.com.au>
Message-ID: <20000711190833.B5845@valinux.com>

On Wed, Jul 12, 2000 at 11:56:05AM +1000, Arthur Watts wrote:
> 
> 	I need to know if anyone has written said extensions, as I am unable
> to find anything at the Vaults of Parnassus archive. I suspect that the
> above quote may indicate that we need to write our own extensions to enforce
> data-hiding on a class-by-class basis, but I'm open to suggestions. The
> issue is *not* coding to prevent breaking modules by trampling one anothers
> namespaces, it is convincing management that Python is the right tool for
> the bulk of the project. 
> 

I do not know of any working code for this.  That said, do you NEED data
privacy as granted by things like C++'s private?  If you implement an object,
document the ways to access and set data the languages support is there only
to stop someone from misbehaving.


From arcege@shore.net  Wed Jul 12 03:27:11 2000
From: arcege@shore.net (Michael P. Reilly)
Date: Tue, 11 Jul 2000 22:27:11 -0400 (EDT)
Subject: [Tutor] Implementing data hiding in Python
In-Reply-To: <1CDB101F0CB6D311882F0000F806392401507C34@aquarius.bne.star.com.au> from "Arthur Watts" at Jul 12, 2000 11:56:05 AM
Message-ID: <200007120227.WAA12214@northshore.shore.net>

>    I don't want to get into religious wars re the benefits of
> encapsulation and the use of 'private', 'const' or whatever. I know that I
> can use 'name-mangling' via '__foo' from Python 1.5 to give me a limited
> form of privacy and I have seen allusions to extensions that enforce data
> hiding :
> 
> There is little direct support for data hiding within Python itself, but
> extensions and embeddings of Python can provide rock solid interfaces that
> expose only permitted foreign operations to the Python interpreter. Python's
> restricted execution mode may also provide some (usually extreme) protection
> within the interpreter itself.             
> 
>    I need to know if anyone has written said extensions, as I am unable
> to find anything at the Vaults of Parnassus archive. I suspect that the
> above quote may indicate that we need to write our own extensions to enforce
> data-hiding on a class-by-class basis, but I'm open to suggestions. The
> issue is *not* coding to prevent breaking modules by trampling one anothers
> namespaces, it is convincing management that Python is the right tool for
> the bulk of the project. 

There is _no_ support for data hiding.  The philosophy is based on
introspection, not hiding.  There are means that can "hide" values, but
it gets into carefully constructed __getattr__ and __setattr__
methods (there are issues with subclassing).

Extensions enforce nothing in terms of data hiding, but..  as much or
as little as the developer decides can be exposed.  Extensions create
Python types, not classes.  You can make wrapper classes around the
types (like UserList and UserDict).

For documentation on making extensions you can read:

"Extending and Embedding"
  http://www.python.org/doc/current/ext/ext.html
"Python/C API"
  http://www.python.org/doc/current/api/api.html
and (listed in the Vaults) "How to Write a Python Extension"
  http://starship.python.net/crew/arcege/extwriting/pyext.html

SWIG can make this happen a little better, but with a little overhead
and limitations.

If you are looking for easy data hiding, Python might not be the
language to go with.  But then, data hiding is rarely a good reason to
go with a language.

  -Arcege

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


From peterc@brosystems.com  Wed Jul 12 17:35:53 2000
From: peterc@brosystems.com (peter church)
Date: Wed, 12 Jul 2000 17:35:53 +0100
Subject: [Tutor] DCOracle module build !  Newbie in much trouble =-(
Message-ID: <396C9E69.566D3DBD@brosystems.com>

--------------DFE1FE2B1D10FEC9DF40E89F
Content-Type: text/plain; charset=iso-8859-15
Content-Transfer-Encoding: 7bit

Hi
    I am trying to setup to Oracle DB interface for python
(DCOracle-1.3.1b1)
however when I try runing the make commmand i get this error ....

bash$ cp Setup-8.1.5 Setup.in

bash$ cp Makefile.pre.in-1.5 Makefile.pre.in

bash$  make -f Makefile.pre.in boot
rm -f *.o *~
rm -f *.a tags TAGS config.c Makefile.pre python sedscript
rm -f *.so *.sl so_locations
VERSION=`python -c "import sys; print sys.version[:3]"`; \
installdir=`python -c "import sys; print sys.prefix"`; \
exec_installdir=`python -c "import sys; print sys.exec_prefix"`; \
make -f ./Makefile.pre.in VPATH=. srcdir=. \
        VERSION=$VERSION \
        installdir=$installdir \
        exec_installdir=$exec_installdir \
        Makefile
make[1]: Entering directory
`/home/peterc/python-mods/DCOracle-1.3.1b1/src'
make[1]: *** No rule to make target
`/usr/lib/python1.5/config/Makefile', needed by `sedscript'.  Stop.
make[1]: Leaving directory
`/home/peterc/python-mods/DCOracle-1.3.1b1/src'
make: *** [boot] Error 2

my environment variables are set as

USERNAME=
COLORTERM=
HISTSIZE=1000
HOSTNAME=ghostdog
LOGNAME=peterc
ORACLE_SID=petersdb
NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
MON=/usr/local/mon
MAIL=/var/spool/mail/peterc
PYTHON=/home/peterc/PYTHON
DBA=/usr/scripts/dba
ORACLE_BASE=/home/oracle
TERM=xterm
HOSTTYPE=i386
PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/peterc/bin:/usr/sbin:/home/peterc/bin:/usr/sbin:/home/peterc/bin:/usr/sbin:/home/oracle/product/8.1.6/bin:/usr/scripts/dba:/usr/scripts/tools

KDEDIR=/usr
HOME=/home/peterc
INPUTRC=/etc/inputrc
SHELL=/bin/bash
MAILOUT=/home/peterc/perl_dev/mailout
USER=peterc
TOOLS=/usr/scripts/tools
BASH_ENV=/home/peterc/.bashrc
QTDIR=/usr/lib/qt-2.1.0
DISPLAY=:0
ORACLE_HOME=/home/oracle/product/8.1.6
LANG=en_US
OSTYPE=Linux
SHLVL=1
PERL=/home/peterc/perl_dev
LS_COLORS=
CVSROOT=/samurai/cvs/CVSROOT

Has anyone had the same problems or have any idea what it is that I am
doing
to deserve this output ?

Thankyou

Peter Church

--------------DFE1FE2B1D10FEC9DF40E89F
Content-Type: text/html; charset=iso-8859-15
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<b>Hi</b>
<br><b>&nbsp;&nbsp;&nbsp; I am trying to setup to Oracle DB interface for
python (DCOracle-1.3.1b1)</b>
<br><b>however when I try runing the make commmand i get this error ....</b><b></b>
<p>bash$ cp Setup-8.1.5 Setup.in
<p>bash$ cp Makefile.pre.in-1.5 Makefile.pre.in
<p>bash$&nbsp; make -f Makefile.pre.in boot
<br>rm -f *.o *~
<br>rm -f *.a tags TAGS config.c Makefile.pre python sedscript
<br>rm -f *.so *.sl so_locations
<br>VERSION=`python -c "import sys; print sys.version[:3]"`; \
<br>installdir=`python -c "import sys; print sys.prefix"`; \
<br>exec_installdir=`python -c "import sys; print sys.exec_prefix"`; \
<br>make -f ./Makefile.pre.in VPATH=. srcdir=. \
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VERSION=$VERSION \
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; installdir=$installdir \
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exec_installdir=$exec_installdir
\
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Makefile
<br>make[1]: Entering directory `/home/peterc/python-mods/DCOracle-1.3.1b1/src'
<br>make[1]: *** No rule to make target `/usr/lib/python1.5/config/Makefile',
needed by `sedscript'.&nbsp; Stop.
<br>make[1]: Leaving directory `/home/peterc/python-mods/DCOracle-1.3.1b1/src'
<br>make: *** [boot] Error 2<b></b>
<p><b>my environment variables are set as</b>
<p>USERNAME=
<br>COLORTERM=
<br>HISTSIZE=1000
<br>HOSTNAME=ghostdog
<br>LOGNAME=peterc
<br>ORACLE_SID=petersdb
<br>NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
<br>MON=/usr/local/mon
<br>MAIL=/var/spool/mail/peterc
<br>PYTHON=/home/peterc/PYTHON
<br>DBA=/usr/scripts/dba
<br>ORACLE_BASE=/home/oracle
<br>TERM=xterm
<br>HOSTTYPE=i386
<br>PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/peterc/bin:/usr/sbin:/home/peterc/bin:/usr/sbin:/home/peterc/bin:/usr/sbin:/home/oracle/product/8.1.6/bin:/usr/scripts/dba:/usr/scripts/tools
<br>KDEDIR=/usr
<br>HOME=/home/peterc
<br>INPUTRC=/etc/inputrc
<br>SHELL=/bin/bash
<br>MAILOUT=/home/peterc/perl_dev/mailout
<br>USER=peterc
<br>TOOLS=/usr/scripts/tools
<br>BASH_ENV=/home/peterc/.bashrc
<br>QTDIR=/usr/lib/qt-2.1.0
<br>DISPLAY=:0
<br>ORACLE_HOME=/home/oracle/product/8.1.6
<br>LANG=en_US
<br>OSTYPE=Linux
<br>SHLVL=1
<br>PERL=/home/peterc/perl_dev
<br>LS_COLORS=
<br>CVSROOT=/samurai/cvs/CVSROOT
<p><b>Has anyone had the same problems or have any idea what it is that
I am doing</b>
<br><b>to deserve this output ?</b><b></b>
<p><b>Thankyou</b><b></b>
<p><b>Peter Church</b></html>

--------------DFE1FE2B1D10FEC9DF40E89F--



From Isaac@compuserve.com  Wed Jul 12 21:54:29 2000
From: Isaac@compuserve.com (Isaac)
Date: Wed, 12 Jul 2000 13:54:29 -0700
Subject: [Tutor] os.spawnv OSError errno 2 No such file or directory
Message-ID: <396CDB05.8156E0C7@compuserve.com>

On win98, with python 1.5.2 for win32, I'm trying to run os.spawnv
(and/or os.spawnve), and I get an

OSError: [Errno 2] No such file or directory

I assume it's referring to the command file I'm trying to run, or
possibly the command processor (command.com), but I can't get it
past this error!  Even if I just try to run command.com and give it an
absolute path name.

Incidentally, os.system( ) works ok, but I need a longer, more flexible
command line, so I thought spawn would be the solution.

Here's one example of what i've tried.

t = ['c:\\', "/w", "/p"]
mycmd = 'ls.bat'
import os
os.spawnv(os.P_WAIT, mycmd, t)

Traceback (innermost last):
  File "<pyshell#4>", line 1, in ?
    os.spawnv(0, mycmd, t)
OSError: [Errno 2] No such file or directory

Any help would be much appreciated.  This is my first post to the list
-- please let me know if there is a preferred forum for this type of
question.

Thanks!

Best,
Isaac,




From trilport@teleline.es  Wed Jul 12 22:24:36 2000
From: trilport@teleline.es (Bob Moranes)
Date: Wed, 12 Jul 2000 23:24:36 +0200
Subject: [Tutor] Forum...
Message-ID: <4.3.2.7.2.20000712232123.00baf590@pop3.teleline.es>

Hi All,

I'm beginner in python, and I'd like to create a user FORUM in our Co 
intranet..
And idea where to find a good sample (or base)...

For Win32/Apache Env.

Thanks in advance

BM

PS: If you wrote it, you could also send it to my mailbox 
trilport@teleline.es...



From arthur.watts@gbst.com  Wed Jul 12 23:23:08 2000
From: arthur.watts@gbst.com (Arthur Watts)
Date: Thu, 13 Jul 2000 08:23:08 +1000
Subject: [Tutor] RE: Tutor digest, Vol 1 #359 - 6 msgs
Message-ID: <1CDB101F0CB6D311882F0000F806392401507C3C@aquarius.bne.star.com.au>

Tom,

	I'm sure that you have seen the work that Guido and the others have
done for CNRI, where he maintains that Python lends itself well to
'intuitive' learning, whereby the class doesn't need to be given the basics
of OO theory before being able to use OO concepts. This is in stark contract
to languages like C++, where we have to jump through a lot hoops before
being able to create anything non-trivial. I fear that my own experience
with Python has been tainted by the need to see 'under the hood' a little
too early ! Hope this helps.

Regards,
Arthur

> -----Original Message-----
> From:	tutor-request@python.org 
> Sent:	Thursday, 13 July 2000 2:01
> To:	tutor@python.org
> Subject:	Tutor digest, Vol 1 #359 - 6 msgs
> 
> Send Tutor mailing list submissions to
> 	tutor@python.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://www.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> 	tutor-request@python.org
> 
> You can reach the person managing the list at
> 	tutor-admin@python.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> 
> 
> Today's Topics:
> 
>   1. Queens, NY - PYTHON Programming for Kids (Thomas A. Williams)
>   2. Re: newbie question (Alan Gauld)
>   3. Re: Re: newbie question (Remco Gerlich)
>   4. Implementing data hiding in Python (Arthur Watts)
>   5. Re: Implementing data hiding in Python (Sean 'Shaleh' Perry)
>   6. Re: Implementing data hiding in Python (Michael P. Reilly)
> 
> --__--__--
> 
> Message: 1
> From: "Thomas A. Williams" <Thomas_A._Williams@NEWYORKLIFE.COM>
> To: tutor@python.org
> Date: Tue, 11 Jul 2000 12:37:51 -0400
> Subject: [Tutor] Queens, NY - PYTHON Programming for Kids
> 
> Hi Y'all,
> I'm looking at the prospect of starting a programming
> class for youth at the YMCA on Pasons Blvd. in
> Jamaica, Queens.  I will definitely be building the class
> around PYTHON.  Does anyone have any suggestions
> or directions?
> 
> Also, MUCH THANKS to those who responded with suggestions
> on how to go about constructing a Coke Vending Machine
> from an object perspective in PYTHON.  This is still a work in
> progress.
> 
> Enjoy The Journey,
> TomW
> 
> 
> 
> 
> --__--__--
> 
> Message: 2
> Date: Tue, 11 Jul 2000 17:01:03 +0000
> To: djansen@pobox.com
> From: Alan Gauld <alan.gauld@freenet.co.uk>
> Cc: tutor@python.org
> Subject: [Tutor] Re: newbie question
> 
> Hi, Just back from a short vacation and found your 
> query....
> 
> > Now my question is why it is necessary to add 
> > the sentences = sentences +...
> > and clauses = clauses +... lines? Why not just:
> >
> > self.c_sentence = self.c_sentence + self.c_punctuation[c]
> 
> Nope, I don't know why I used a local variable 
> - I don't in the non OO version. Maybe I was tired!
> 
> Another poster generously suggested it was a 
> possible performance improvement but I honestly 
> doubt I was that alert. It certainly doesn't help 
> a newbie...
> 
> I'll change it in the next update to the site, 
> thanks for pointing it out! (If I do find a valid 
> reason I'll let you know!)
> 
> That whole case study is getting a revisited as part 
> of my book project, so that should get reflected 
> back into the web site,
> 
> The good news is that the fact you raised the question 
> shows you have picked up a lot about programming Python! 
> :-)
> 
> Thanks agan,
> 
> Alan G.
> 
> 
> 
> --__--__--
> 
> Message: 3
> Date: Tue, 11 Jul 2000 19:16:14 +0200
> From: Remco Gerlich <scarblac@pino.selwerd.nl>
> To: tutor@python.org
> Subject: Re: [Tutor] Re: newbie question
> 
> On Tue, Jul 11, 2000 at 05:01:03PM +0000, Alan Gauld wrote:
> > Hi, Just back from a short vacation and found your 
> > query....
> > 
> > > Now my question is why it is necessary to add 
> > > the sentences = sentences +...
> > > and clauses = clauses +... lines? Why not just:
> > >
> > > self.c_sentence = self.c_sentence + self.c_punctuation[c]
> > 
> > Nope, I don't know why I used a local variable 
> > - I don't in the non OO version. Maybe I was tired!
> > 
> > Another poster generously suggested it was a 
> > possible performance improvement but I honestly 
> > doubt I was that alert. It certainly doesn't help 
> > a newbie...
> 
> Grin. I already had the feeling I was seeing too much into it when I
> thought
> up some explanations :).
> 
> I don't know, I think I still like using the local better. But that's just
> a
> matter of taste, of course :)
> 
> -- 
> Remco Gerlich,  scarblac@pino.selwerd.nl
> 
> 
> --__--__--
> 
> Message: 4
> From: Arthur Watts <arthur.watts@gbst.com>
> To: "'tutor@python.org'" <tutor@python.org>
> Date: Wed, 12 Jul 2000 11:56:05 +1000
> Subject: [Tutor] Implementing data hiding in Python
> 
> Guys,
> 
> 	I don't want to get into religious wars re the benefits of
> encapsulation and the use of 'private', 'const' or whatever. I know that I
> can use 'name-mangling' via '__foo' from Python 1.5 to give me a limited
> form of privacy and I have seen allusions to extensions that enforce data
> hiding :
> 
> There is little direct support for data hiding within Python itself, but
> extensions and embeddings of Python can provide rock solid interfaces that
> expose only permitted foreign operations to the Python interpreter.
> Python's
> restricted execution mode may also provide some (usually extreme)
> protection
> within the interpreter itself.             
> 
> 	I need to know if anyone has written said extensions, as I am unable
> to find anything at the Vaults of Parnassus archive. I suspect that the
> above quote may indicate that we need to write our own extensions to
> enforce
> data-hiding on a class-by-class basis, but I'm open to suggestions. The
> issue is *not* coding to prevent breaking modules by trampling one
> anothers
> namespaces, it is convincing management that Python is the right tool for
> the bulk of the project. 
> 
> Thanks,
> 
> Arthur 
> 
> Arthur Watts
> Systems Integrator
> GBST Pty Ltd
> 
> 'Good programmers know what to use, great programmers know what to re-use'
> :
> Old Jungle Saying
> 
> 
> 
> --__--__--
> 
> Message: 5
> Date: Tue, 11 Jul 2000 19:08:33 -0700
> From: Sean 'Shaleh' Perry <shaleh@valinux.com>
> To: Arthur Watts <arthur.watts@gbst.com>
> Cc: "tutor@python.org" <tutor@python.org>
> Subject: Re: [Tutor] Implementing data hiding in Python
> 
> On Wed, Jul 12, 2000 at 11:56:05AM +1000, Arthur Watts wrote:
> > 
> > 	I need to know if anyone has written said extensions, as I am unable
> > to find anything at the Vaults of Parnassus archive. I suspect that the
> > above quote may indicate that we need to write our own extensions to
> enforce
> > data-hiding on a class-by-class basis, but I'm open to suggestions. The
> > issue is *not* coding to prevent breaking modules by trampling one
> anothers
> > namespaces, it is convincing management that Python is the right tool
> for
> > the bulk of the project. 
> > 
> 
> I do not know of any working code for this.  That said, do you NEED data
> privacy as granted by things like C++'s private?  If you implement an
> object,
> document the ways to access and set data the languages support is there
> only
> to stop someone from misbehaving.
> 
> 
> --__--__--
> 
> Message: 6
> From: "Michael P. Reilly" <arcege@shore.net>
> Subject: Re: [Tutor] Implementing data hiding in Python
> To: arthur.watts@gbst.com (Arthur Watts)
> Date: Tue, 11 Jul 2000 22:27:11 -0400 (EDT)
> Cc: tutor@python.org ('tutor@python.org')
> Reply-To: arcege@shore.net
> 
> >    I don't want to get into religious wars re the benefits of
> > encapsulation and the use of 'private', 'const' or whatever. I know that
> I
> > can use 'name-mangling' via '__foo' from Python 1.5 to give me a limited
> > form of privacy and I have seen allusions to extensions that enforce
> data
> > hiding :
> > 
> > There is little direct support for data hiding within Python itself, but
> > extensions and embeddings of Python can provide rock solid interfaces
> that
> > expose only permitted foreign operations to the Python interpreter.
> Python's
> > restricted execution mode may also provide some (usually extreme)
> protection
> > within the interpreter itself.             
> > 
> >    I need to know if anyone has written said extensions, as I am unable
> > to find anything at the Vaults of Parnassus archive. I suspect that the
> > above quote may indicate that we need to write our own extensions to
> enforce
> > data-hiding on a class-by-class basis, but I'm open to suggestions. The
> > issue is *not* coding to prevent breaking modules by trampling one
> anothers
> > namespaces, it is convincing management that Python is the right tool
> for
> > the bulk of the project. 
> 
> There is _no_ support for data hiding.  The philosophy is based on
> introspection, not hiding.  There are means that can "hide" values, but
> it gets into carefully constructed __getattr__ and __setattr__
> methods (there are issues with subclassing).
> 
> Extensions enforce nothing in terms of data hiding, but..  as much or
> as little as the developer decides can be exposed.  Extensions create
> Python types, not classes.  You can make wrapper classes around the
> types (like UserList and UserDict).
> 
> For documentation on making extensions you can read:
> 
> "Extending and Embedding"
>   http://www.python.org/doc/current/ext/ext.html
> "Python/C API"
>   http://www.python.org/doc/current/api/api.html
> and (listed in the Vaults) "How to Write a Python Extension"
>   http://starship.python.net/crew/arcege/extwriting/pyext.html
> 
> SWIG can make this happen a little better, but with a little overhead
> and limitations.
> 
> If you are looking for easy data hiding, Python might not be the
> language to go with.  But then, data hiding is rarely a good reason to
> go with a language.
> 
>   -Arcege
> 
> -- 
> ------------------------------------------------------------------------
> | Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
> | Salem, Mass. USA  01970             |                                |
> ------------------------------------------------------------------------
> 
> 
> 
> --__--__--
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor
> 
> 
> End of Tutor Digest_______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor


From pm@dis.ro  Thu Jul 13 09:41:35 2000
From: pm@dis.ro (Marcel Preda)
Date: Thu, 13 Jul 2000 10:41:35 +0200
Subject: R: [Tutor] os.spawnv OSError errno 2 No such file or directory
References: <396CDB05.8156E0C7@compuserve.com>
Message-ID: <012101bfeca8$f5427f60$1301000a@punto.it>


> On win98, with python 1.5.2 for win32, I'm trying to run os.spawnv
> (and/or os.spawnve), and I get an
> 
> OSError: [Errno 2] No such file or directory
> 
> I assume it's referring to the command file I'm trying to run, or
> possibly the command processor (command.com), but I can't get it
> past this error!  Even if I just try to run command.com and give it an
> absolute path name.
> 
> Incidentally, os.system( ) works ok, but I need a longer, more flexible
> command line, so I thought spawn would be the solution.
> 
> Here's one example of what i've tried.
> 
> t = ['c:\\', "/w", "/p"]
> mycmd = 'ls.bat'
> import os
> os.spawnv(os.P_WAIT, mycmd, t)
> 
> Traceback (innermost last):
>   File "<pyshell#4>", line 1, in ?
>     os.spawnv(0, mycmd, t)
> OSError: [Errno 2] No such file or directory


Maybe is better to put the complet path to the  batch file
mycmd='c:\\path_to\\ls.bat'
this must be the reason

PM



From Isaac@compuserve.com  Thu Jul 13 19:00:33 2000
From: Isaac@compuserve.com (Isaac)
Date: Thu, 13 Jul 2000 11:00:33 -0700
Subject: R: [Tutor] os.spawnv OSError errno 2 No such file or directory
References: <396CDB05.8156E0C7@compuserve.com> <012101bfeca8$f5427f60$1301000a@punto.it>
Message-ID: <396E03C0.EC05E5EE@compuserve.com>

Hey, Marcel, thank you for the suggestion.

It's definitely a good one, but alas, I've tried giving an absolute pathname
several times, in several ways, including using "c:\\bat\\ls.bat",
"c:\\command.com," and putting the batch file in other directories, including
the root of the drive and also the python directories.  Always getting the
same result.

I'm wondering if it's not a weirdness of win95/98 as opposed to NT, but since
the os.system() call works, I would think spawnv should, too.

I've even tried using spawnve and including os.environment in the hopes that
would help it process the path, but no luck.

Time constraints have forced me to begin a workaround using os.system(), but
it's far from ideal.

Thanks again!

Best,
Isaac

Marcel Preda wrote:

>
>
> > On win98, with python 1.5.2 for win32, I'm trying to run os.spawnv
> > (and/or os.spawnve), and I get an
> >
> > OSError: [Errno 2] No such file or directory
> >
> > I assume it's referring to the command file I'm trying to run, or
> > possibly the command processor (command.com), but I can't get it
> > past this error!  Even if I just try to run command.com and give it an
> > absolute path name.
> >
> > Incidentally, os.system( ) works ok, but I need a longer, more flexible
> > command line, so I thought spawn would be the solution.
> >
> > Here's one example of what i've tried.
> >
> > t = ['c:\\', "/w", "/p"]
> > mycmd = 'ls.bat'
> > import os
> > os.spawnv(os.P_WAIT, mycmd, t)
> >
> > Traceback (innermost last):
> >   File "<pyshell#4>", line 1, in ?
> >     os.spawnv(0, mycmd, t)
> > OSError: [Errno 2] No such file or directory
>
> Maybe is better to put the complet path to the  batch file
> mycmd='c:\\path_to\\ls.bat'
> this must be the reason
>
> PM
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor



From bulginbergster@hotmail.com  Thu Jul 13 19:10:52 2000
From: bulginbergster@hotmail.com (tom bergan)
Date: Thu, 13 Jul 2000 18:10:52 GMT
Subject: [Tutor] I NEED A LENGTHY TUTORIAL FOR A BEGINNER!!!
Message-ID: <20000713181052.61707.qmail@hotmail.com>

i am a beginner to python (programming in general) and need a good, 
easy-to-understand python tutorial that will help me become a proficient 
python programmer!!

                       from tom.

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com



From mwpfab5@collins.rockwell.com  Thu Jul 13 19:28:20 2000
From: mwpfab5@collins.rockwell.com (mwpfab5@collins.rockwell.com)
Date: Thu, 13 Jul 2000 13:28:20 -0500
Subject: [Tutor] I NEED A LENGTHY TUTORIAL FOR A BEGINNER!!!
Message-ID: <OFB01B0A75.C461A6E8-ON8625691B.006402A4@collins.rockwell.com>

Tom
I have found this to be the best site for newcomers to Python who aren't
already fluent in programming.

http://www.honors.montana.edu/~jjc/easytut/easytut/

I hope this helps,
Mark W. Pfab
Software Engineer
Rockwell Collins
mwpfab5@collins.rockwell.com




"tom bergan" <bulginbergster@hotmail.com>@python.org on 07/13/2000 01:10:52
PM

Sent by:  tutor-admin@python.org


To:   tutor@python.org
cc:

Subject:  [Tutor] I NEED A LENGTHY TUTORIAL FOR A BEGINNER!!!


i am a beginner to python (programming in general) and need a good,
easy-to-understand python tutorial that will help me become a proficient
python programmer!!

                       from tom.

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com


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





From richard_chamberlain@ntlworld.com  Fri Jul 14 12:06:15 2000
From: richard_chamberlain@ntlworld.com (Richard Chamberlain)
Date: Fri, 14 Jul 2000 12:06:15 +0100
Subject: [Tutor] os.spawnv OSError errno 2 No such file or directory
References: <396CDB05.8156E0C7@compuserve.com> <012101bfeca8$f5427f60$1301000a@punto.it>
Message-ID: <001201bfed83$9f566040$b061fea9@richardc>

Hi Marcel,

The first parameter of your argument list needs to be the file path/name.

So as an example:

os.spawnv(os.P_WAIT,'c:\\autoexec.bat',('c:\\autoexec.bat',))

Read MSDN for details.

Richard
----- Original Message ----- 
From: Marcel Preda <pm@dis.ro>
To: <Tutor@python.org>
Sent: Thursday, July 13, 2000 9:41 AM
Subject: R: [Tutor] os.spawnv OSError errno 2 No such file or directory


> 
> 
> > On win98, with python 1.5.2 for win32, I'm trying to run os.spawnv
> > (and/or os.spawnve), and I get an
> > 
> > OSError: [Errno 2] No such file or directory
> > 
> > I assume it's referring to the command file I'm trying to run, or
> > possibly the command processor (command.com), but I can't get it
> > past this error!  Even if I just try to run command.com and give it an
> > absolute path name.
> > 
> > Incidentally, os.system( ) works ok, but I need a longer, more flexible
> > command line, so I thought spawn would be the solution.
> > 
> > Here's one example of what i've tried.
> > 
> > t = ['c:\\', "/w", "/p"]
> > mycmd = 'ls.bat'
> > import os
> > os.spawnv(os.P_WAIT, mycmd, t)
> > 
> > Traceback (innermost last):
> >   File "<pyshell#4>", line 1, in ?
> >     os.spawnv(0, mycmd, t)
> > OSError: [Errno 2] No such file or directory
> 
> 
> Maybe is better to put the complet path to the  batch file
> mycmd='c:\\path_to\\ls.bat'
> this must be the reason
> 
> PM
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor
> 



From vfdvdp@correo.cybermedia.com.ve  Fri Jul 14 10:09:22 2000
From: vfdvdp@correo.cybermedia.com.ve (vfdvdp@correo.cybermedia.com.ve)
Date: Fri, 14 Jul 2000 09:09:22
Subject: [Tutor] (no subject)
Message-ID: <645.52503.172089@mail.mindspring.com>

GET YOUR OWN 5 MEG WEBSITE FOR ONLY $11.95 PER MONTH TODAY!

STOP PAYING $19.95 or more TODAY for your web site, WHEN YOU CAN 
GET ONE FOR ONLY $11.95 PER MONTH!

DO YOU ALREADY HAVE A WEBSITE? ALL YOU HAVE TO DO IS TRANSFER THE 
DOMAIN TO OUR SERVERS AND UPLOAD YOUR DATA AND YOU ARE READY TO 
GO! YOUR NEW WEB SPACE CAN BE CREATED INSTANTLY WITH JUST A 
SIMPLE PHONE CALL TO  OUR OFFICE.

YOU CAN CHANGE THE DESIGN OF YOUR SITE AS MUCH AS YOU WANT with 
no extra charge!  UNLIMITED TRAFFIC -- no extra charge!

WE HAVE BOTH UNIX AND NT MACHINES WITH FRONT PAGE EXTENSIONS 
FULLY SUPPORTED.

A SET UP FEE OF $40.00 APPLIES for FIRST TIME CUSTOMERS.

ALL FEES PREPAID IN ADVANCE FOR THE YEAR PLUS A $40.00 SET UP 
CHARGE.

FOR DETAILS CALL 1 888 248 0765  or fax 240 337 8325

PES WEB HOSTING -- 
_______________________________________________________________

Want to do bulk email?

Ask us how today!

GET YOUR MESSAGE DELIVERED TO 500,000 PEOPLE FOR ONLY $550.00.

OR HAVE YOUR MESSAGE DELIVERED TO OVER 1 MILLION 
PEOPLE FOR ONLY $1200.00.

Call 1888 248 0765 for FURTHER INFORMATION today!
  or fax 240 337 8325

_________________________________________________________________

Get your own offshore trust! 
PROTECT YOUR PERSONAL ASSETS FROM LAWSUITS or Do SOME ESTATE 
PLANNING TO MINIMIZE THOSE INHERITANCE TAXES!
GET THAT OFFSHORE BANK ACCOUNT YOU ALWAYS WANTED!

For further information please fax 240 337 8325




THANK YOU




 
 
 
 
 


From Greg.Furmanek@hit.cendant.com  Fri Jul 14 18:27:57 2000
From: Greg.Furmanek@hit.cendant.com (Furmanek, Greg)
Date: Fri, 14 Jul 2000 13:27:57 -0400
Subject: [Tutor] (no subject)
Message-ID: <F491D788C8F6D3119D5A009027B0D42B207970@hit-phx-mail-2.hfscorp.com>

Interesting post, however ....
It did not have anything to do with python!!
BTW It looks someone hijacked the DNS server
on cybermedia.com I would be kind of 
wary about using servers of someone who
hijacks someone elses dns.

Another thing:
Has anyone written automatic phone dailer?
The kind that dials 800 and 888 numbers 
and disconnects at the first connect.

I bet they would love this kind of business.

-> Call 1888 248 0765 for FURTHER INFORMATION today!
->   or fax 240 337 8325


From vgreen@hotmail.com  Fri Jul 14 19:00:11 2000
From: vgreen@hotmail.com (Vanessa Green)
Date: Fri, 14 Jul 2000 11:00:11 -0700
Subject: [Tutor] DeleteNode
Message-ID: <396F552B.C5A0FB25@hotmail.com>

I have a question concerning how to delete a node using python.  I am
new to programming and python is the first language that I am slowly
learning.  Would you please let me know the best way to go about
deleting a node that contains both strings and integers.  Also is it
neccessary for me to create a key.
thanks
vgreen



From dyoo@hkn.EECS.Berkeley.EDU  Fri Jul 14 21:29:17 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Fri, 14 Jul 2000 13:29:17 -0700 (PDT)
Subject: [Tutor] (no subject)
In-Reply-To: <F491D788C8F6D3119D5A009027B0D42B207970@hit-phx-mail-2.hfscorp.com>
Message-ID: <Pine.LNX.4.21.0007141314180.27200-100000@hkn.EECS.Berkeley.EDU>

On Fri, 14 Jul 2000, Furmanek, Greg wrote:

> Interesting post, however ....
> It did not have anything to do with python!!

Well, it is pretty funny: it has to be the first time I've seen
_lowercase_ used to emphasize phrases.

>>> YOU CAN CHANGE THE DESIGN OF YOUR SITE AS MUCH AS YOU WANT with 
>>> no extra charge!  UNLIMITED TRAFFIC -- no extra charge!


I guess we could use their post and raise it's Python content by turning
it into a Python example.  Hmmm... let's give it a shot.

###
import string
import sys

def reverseCaser(word):
  if string.upper(word) == word:
    return string.lower(word)
  if string.lower(word) == word:
    return string.upper(word)
  return word

if __name__ == '__main__':
  words = string.split(sys.stdin, ' ')
  words = map(reverseCaser, words)
  print words
###


Let's try it on this sample (because anything longer will cause my head to
explode.)

>>> you can change the design of your site as much as you want WITH
>>> NO EXTRA CHARGE!  unlimited traffic -- NO EXTRA CHARGE!


Well, I admit, it's not much of an improvement.  But even spams must yield
to Python.  *grin*



From dyoo@hkn.EECS.Berkeley.EDU  Fri Jul 14 21:39:21 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Fri, 14 Jul 2000 13:39:21 -0700 (PDT)
Subject: [Tutor] DeleteNode
In-Reply-To: <396F552B.C5A0FB25@hotmail.com>
Message-ID: <Pine.LNX.4.21.0007141329500.27200-100000@hkn.EECS.Berkeley.EDU>

On Fri, 14 Jul 2000, Vanessa Green wrote:

> I have a question concerning how to delete a node using python.  I am
> new to programming and python is the first language that I am slowly
> learning.  Would you please let me know the best way to go about
> deleting a node that contains both strings and integers.  Also is it
> neccessary for me to create a key.

Hello!  Can you explain what you mean by a node?  I'm familiar with the
term 'node' when it's applied to linked-lists, but since you're doing
beginning programming, I'm not sure if that's what you mean.  I'll try to
guess what you mean, but if I starts sounding silly, you can ignore
me.  *grin*


If you mean an element in a hashtable like:

  names_ages = { "al" : 23, "sandy" : 29, "goofy" : 3 }

then the way to remove 'goofy' from the hashtable is to use the 'del'
operator.

  del names_ages["goofy"]

If you do this, names_ages will just contain values for 'al' and 'sandy':

  >>> names_ages
  {'sandy': 29, 'al': 23}


Oh, when you reply, make sure you reply to tutor@python.org.  (I haven't
been able to figure out how to fix 'reply-to' in pine yet.)



From wilson@visi.com  Fri Jul 14 23:41:43 2000
From: wilson@visi.com (Timothy Wilson)
Date: Fri, 14 Jul 2000 17:41:43 -0500 (CDT)
Subject: [Tutor] connecting classes
Message-ID: <Pine.GSO.4.10.10007141732430.19606-100000@isis.visi.com>

Hi everyone,

My fledgling Python abilities are growning, but I've run into a puzzle as a
try to figure out OO techniques. Some may remember that I posted a while ago
about creating a simple program to play tic tac toe. I've finally gotten
back to it, and I have the following framework:

class Game:
	def __init__(self):
		self.board = [1, 2, 3, 4, 5, 6, 7, 8, 9]
		self.winningLines = [(1, 2, 3), (4, 5, 6), (7, 8, 9), (1, 4,
7), \
		(2, 5, 8), (3, 6, 9), (1, 5, 9), (3, 5, 7)]
	def play(self):
		self.displayOpening
		self.drawBoard
	def displayOpening(self):
		print "Let's play Tic Tac Toe!"
	def drawBoard(self):
		for i in range(0, 8, 3):
			for j in range(3):
				print self.board[(i+j)],
			print
	def updateBoard(self, position, marker):
		self.board[position - 1] = marker
	def gameWon(self, player1, player2):
		for lines in self.winningLines:
			player1Count = 0
			player2Count = 0
			for i in lines:
				if self.board[i-1] == player1.marker:
					player1Count = player1Count + 1
				elif self.board[i-1] == player2.marker:
					player2Count = player2Count + 1
			if player1Count == 3 or player2Count == 3:
				return 1
		return 0

class Player:
	def __init__(self, name, marker):
		self.name = name
		self.marker = marker
	def move(self, choice):
		pass

class HumanPlayer(Player):
	def __init__(self, name, marker):
		Player.__init__(self, name, marker)
	def chooseMove(self):
		choice = raw_input("Where would you like to put your
marker?")
		Game.updateBoard(int(choice), self.marker)

class ComputerPlayer(Player):
	def __init__(self, name, marker):
		Player.__init__(self, name, marker)
	def chooseMove(self):
		pass
		#  Computer chooses a move based on the following criteria:
        #  1. win the game if possible
        #  2. block opposing player if necessary
        #  3. take center square if available
        #  4. take corner square if available
        #  5. pick available square at random


A lot of things work already, but I don't understand how I can get one class
to interact with another (it may be that my classes don't make any sense as
they're currently designed). Here's an example:

Python 1.5.2 (#1, May  9 2000, 15:05:56)  [GCC 2.95.3 19991030 (prerelease)]
on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import ttt
>>> game = ttt.Game()
>>> player1 = ttt.HumanPlayer("Joe", "X")
>>> player2 = ttt.ComputerPlayer("HAL-9000", "O")
>>> game.drawBoard()
1 2 3
4 5 6
7 8 9
>>> player1.chooseMove()
Where would you like to put your marker?6
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "ttt.py", line 47, in chooseMove
    Game.updateBoard(int(choice), self.marker)
TypeError: unbound method must be called with class instance 1st argument
>>>

Suggestions?

I'd also love to hear any feedback about the overall design of this little
program. I still haven't settled on the best data structure for handling the
tic tac toe board. Also, I think the gameWon method is ugly.

-Tim

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



From dyoo@hkn.EECS.Berkeley.EDU  Sat Jul 15 09:47:07 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Sat, 15 Jul 2000 01:47:07 -0700 (PDT)
Subject: [Tutor] connecting classes
In-Reply-To: <Pine.GSO.4.10.10007141732430.19606-100000@isis.visi.com>
Message-ID: <Pine.LNX.4.21.0007150120210.4188-100000@hkn.EECS.Berkeley.EDU>

> A lot of things work already, but I don't understand how I can get one class
> to interact with another (it may be that my classes don't make any sense as
> they're currently designed). Here's an example:
> 
> Python 1.5.2 (#1, May  9 2000, 15:05:56)  [GCC 2.95.3 19991030 (prerelease)]
> on linux-i386
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> import ttt
> >>> game = ttt.Game()
> >>> player1 = ttt.HumanPlayer("Joe", "X")
> >>> player2 = ttt.ComputerPlayer("HAL-9000", "O")
> >>> game.drawBoard()
> 1 2 3
> 4 5 6
> 7 8 9
> >>> player1.chooseMove()
> Where would you like to put your marker?6
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
>   File "ttt.py", line 47, in chooseMove
>     Game.updateBoard(int(choice), self.marker)
> TypeError: unbound method must be called with class instance 1st argument
> >>>
> 
> Suggestions?


I'll try to look at this from an OOP perspective, so this will be slightly
indirect.

You have two players, 'player1' and 'player2'.  However, which game board
are they playing on?  It's entirely conceivable that you could hold a
whole tournament of tic-tac-toe games, so each player needs to know which
game they're sitting in front of.  That's why saying:

>     Game.updateBoard(int(choice), self.marker)

is ambiguous to the system.  It's doing an updateBoard, but on what
particular game?  That's why the system's complaining about an 'unbound'
method: updateBoard() only works if its associated with a particular Game
instance.

However, you've created a Game instance from the line:

> >>> game = ttt.Game()

so, 'game' must be involved.  You'll probably need to pass off 'game' to
the player initializer, so that each player knows where to sit down and
start playing.


This becomes more clear if you can imagine the situation:

### setting up the game
  game1 = ttt.Game()
  game2 = ttt.Game()

  player1 = ttt.HumanPlayer("Joe", "X")
  player2 = ttt.HumanPlayer("Jill", "O")
  player3 = ttt.ComputerPlayer("Deep Thought", "X")
  player4 = ttt.ComputerPlayer("HAL-9000", "O")

  player1.sitAt(game1)
  player2.sitAt(game1)
  player3.sitAt(game2)
  player4.sitAt(game2)
  ...

or something like that, where we can define sitAt() as:

  def sitAt(self, g):
    self.game = g

and slightly change your chooseMove to use the self.game instance instead
of the Game class.  It would look something like:

   self.game.updateBoard(...)

Setting up self.game inside __init__ might be better than having an
explicit sitAt().  I just like imagining them sitting down imposingly like
Gary Kasparov.  *grin* If this reply is ambigous, it's probably because
I'm too drowsy to see the keyboard. In any case, email tutor@python.org
again if this is unclear --- I should be more awake by then.  Good luck!



From steve@spvi.com  Sat Jul 15 12:20:30 2000
From: steve@spvi.com (Steve Spicklemire)
Date: Sat, 15 Jul 2000 06:20:30 -0500 (EST)
Subject: [Tutor] connecting classes
In-Reply-To: <Pine.GSO.4.10.10007141732430.19606-100000@isis.visi.com>
 (message from Timothy Wilson on Fri, 14 Jul 2000 17:41:43 -0500 (CDT))
References: <Pine.GSO.4.10.10007141732430.19606-100000@isis.visi.com>
Message-ID: <200007151120.GAA55568@mercury.spvi.com>

Hi Tim,

>>>>> "TW" == Timothy Wilson <wilson@visi.com> writes:

    TW> Hi everyone,

    TW> My fledgling Python abilities are growning, but I've run into
    TW> a puzzle as a try to figure out OO techniques. Some may
    TW> remember that I posted a while ago about creating a simple
    TW> program to play tic tac toe. I've finally gotten back to it,
    TW> and I have the following framework:

class Game:
	def __init__(self):
		self.board = [1, 2, 3, 4, 5, 6, 7, 8, 9]
		self.winningLines = [(1, 2, 3), (4, 5, 6), (7, 8, 9), (1, 4,
7), \
		(2, 5, 8), (3, 6, 9), (1, 5, 9), (3, 5, 7)]
	def play(self):
		self.displayOpening
		self.drawBoard
	def displayOpening(self):
		print "Let's play Tic Tac Toe!"
	def drawBoard(self):
		for i in range(0, 8, 3):
			for j in range(3):
				print self.board[(i+j)],
			print
	def updateBoard(self, position, marker):
		self.board[position - 1] = marker
	def gameWon(self, player1, player2):
		for lines in self.winningLines:
			player1Count = 0
			player2Count = 0
			for i in lines:
				if self.board[i-1] == player1.marker:
					player1Count = player1Count + 1
				elif self.board[i-1] == player2.marker:
					player2Count = player2Count + 1
			if player1Count == 3 or player2Count == 3:
				return 1
		return 0

class Player:
	def __init__(self, name, marker):
		self.name = name
		self.marker = marker
	def move(self, choice):
		pass

class HumanPlayer(Player):
	def __init__(self, name, marker):
		Player.__init__(self, name, marker)
	def chooseMove(self):
		choice = raw_input("Where would you like to put your
marker?")
		Game.updateBoard(int(choice), self.marker)

class ComputerPlayer(Player):
	def __init__(self, name, marker):
		Player.__init__(self, name, marker)
	def chooseMove(self):
		pass
		#  Computer chooses a move based on the following criteria:
        #  1. win the game if possible
        #  2. block opposing player if necessary
        #  3. take center square if available
        #  4. take corner square if available
        #  5. pick available square at random


Python 1.5.2 (#1, May  9 2000, 15:05:56)  [GCC 2.95.3 19991030 (prerelease)]
on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import ttt
>>> game = ttt.Game()
>>> player1 = ttt.HumanPlayer("Joe", "X")
>>> player2 = ttt.ComputerPlayer("HAL-9000", "O")
>>> game.drawBoard()
1 2 3
4 5 6
7 8 9
>>> player1.chooseMove()
Where would you like to put your marker?6
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "ttt.py", line 47, in chooseMove
    Game.updateBoard(int(choice), self.marker)
TypeError: unbound method must be called with class instance 1st argument
>>>

    TW> Suggestions?

Hmmm  'Game' is a class, 'game' is an instance of the class. The
human Player needs his 'game' instance, not the 'Game' class. ;-)

    TW> I'd also love to hear any feedback about the overall design of
    TW> this little program. I still haven't settled on the best data
    TW> structure for handling the tic tac toe board. Also, I think
    TW> the gameWon method is ugly.

What if you made the board a 'bitmap', rather than a list, so that
having won could be checked with a binary 'and'.. of course
this would complicate your 'drawBoard' logic.. but maybe
not too much, (e.g., you could shift, and check to print the
board....)

-steve

    TW> -Tim



From djansen@pobox.com  Sun Jul 16 03:44:21 2000
From: djansen@pobox.com (David Jansen)
Date: Sun, 16 Jul 2000 11:44:21 +0900
Subject: [Tutor] iterate problem
Message-ID: <LPBBJDDFLFLMCKPODBMLIEKFCIAA.djansen@pobox.com>

While I read tutorials I am playing around with what I have learned. I am
trying to write a simple script that removes the >>>'s from the beginning of
lines in a text file (for example  an email message that has been forwarded
a number of times). Removing the first > from the beginning of a line is no
problem but I seem to enter an endless loop when I attempt to iterate over
the line to get rid of second and third >'s if they exist.  The problem line
is obviously the while line in strip() but I can't figure out what is wrong
with it.

Any help greatly appreciated.

David Jansen

import string, sys

groups = []
alphas = string.letters + string.digits

file = raw_input("enter file: ")
inp = open(file, "r")

def strip(input):
____while (len(input) > 0) and (input[0] not in alphas):
________if input[0] == ">":
____________input = input[1:]
____return input

for line in inp.readlines():
____result = strip(line)
____print result


sample text file:

>Interesting Stuff.
>
> > >The citrus soda 7-UP was created in 1929; "7" was selected because the
> > >original containers were 7 ounces. "UP" indicated the direction of the
> > >bubbles.
> > >
> > > Mosquito repellents don't repel. They hide you. The spray blocks the
> > >mosquito's sensors so they don't know you're there.
> > >
> > > Dentists have recommended that a toothbrush be kept at least 6 feet
>away



From Isaac@compuserve.com  Sat Jul 15 21:57:12 2000
From: Isaac@compuserve.com (Isaac)
Date: Sat, 15 Jul 2000 13:57:12 -0700
Subject: [Tutor] DeleteNode
References: <Pine.LNX.4.21.0007141329500.27200-100000@hkn.EECS.Berkeley.EDU>
Message-ID: <3970D028.4B99AEA@compuserve.com>

I try to use my "reply-all" button when on an e-mail list (unless I don't
think the list should see what I'm saying) since most lists don't set a
reply-to field with the list name (which keeps some unwanted traffic off the
lists, but sometimes ends up keeping wanted traffic off, too.)

Daniel Yoo wrote:

>
> On Fri, 14 Jul 2000, Vanessa Green wrote:
>
> > I have a question concerning how to delete a node using python.  I am
> > new to programming and python is the first language that I am slowly
> > learning.  Would you please let me know the best way to go about
> > deleting a node that contains both strings and integers.  Also is it
> > neccessary for me to create a key.
>
> Hello!  Can you explain what you mean by a node?  I'm familiar with the
> term 'node' when it's applied to linked-lists, but since you're doing
> beginning programming, I'm not sure if that's what you mean.  I'll try to
> guess what you mean, but if I starts sounding silly, you can ignore
> me.  *grin*
>
> If you mean an element in a hashtable like:
>
>   names_ages = { "al" : 23, "sandy" : 29, "goofy" : 3 }
>
> then the way to remove 'goofy' from the hashtable is to use the 'del'
> operator.
>
>   del names_ages["goofy"]
>
> If you do this, names_ages will just contain values for 'al' and 'sandy':
>
>   >>> names_ages
>   {'sandy': 29, 'al': 23}
>
> Oh, when you reply, make sure you reply to tutor@python.org.  (I haven't
> been able to figure out how to fix 'reply-to' in pine yet.)
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor





From Isaac@compuserve.com  Sun Jul 16 04:10:20 2000
From: Isaac@compuserve.com (Isaac)
Date: Sat, 15 Jul 2000 20:10:20 -0700
Subject: [Tutor] os.spawnv OSError errno 2 No such file or directory
References: <396CDB05.8156E0C7@compuserve.com> <012101bfeca8$f5427f60$1301000a@punto.it> <001201bfed83$9f566040$b061fea9@richardc>
Message-ID: <3971279C.CEB718CC@compuserve.com>

Wow Richard. Thank you.  You're a lifesaver.

Now I just need to decide if I have time to re-do the workaround I built using
os.system().

I'm going to post this on dejanews -- someone there had the same problem and
never got it figured out, I believe.  (back in February)

(BTW, I did look at my version of msdn, and didn't see anything about this.  My
version came with VS 6.0, and is probably not up to date.)

Thanks again!

Best,
Isaac

Richard Chamberlain wrote:

>
> Hi Marcel,
>
> The first parameter of your argument list needs to be the file path/name.
>
> So as an example:
>
> os.spawnv(os.P_WAIT,'c:\\autoexec.bat',('c:\\autoexec.bat',))
>
> Read MSDN for details.
>
> Richard
> ----- Original Message -----
> From: Marcel Preda <pm@dis.ro>
> To: <Tutor@python.org>
> Sent: Thursday, July 13, 2000 9:41 AM
> Subject: R: [Tutor] os.spawnv OSError errno 2 No such file or directory
>
> >
> >
> > > On win98, with python 1.5.2 for win32, I'm trying to run os.spawnv
> > > (and/or os.spawnve), and I get an
> > >
> > > OSError: [Errno 2] No such file or directory
> > >
> > > I assume it's referring to the command file I'm trying to run, or
> > > possibly the command processor (command.com), but I can't get it
> > > past this error!  Even if I just try to run command.com and give it an
> > > absolute path name.
> > >
> > > Incidentally, os.system( ) works ok, but I need a longer, more flexible
> > > command line, so I thought spawn would be the solution.
> > >
> > > Here's one example of what i've tried.
> > >
> > > t = ['c:\\', "/w", "/p"]
> > > mycmd = 'ls.bat'
> > > import os
> > > os.spawnv(os.P_WAIT, mycmd, t)
> > >
> > > Traceback (innermost last):
> > >   File "<pyshell#4>", line 1, in ?
> > >     os.spawnv(0, mycmd, t)
> > > OSError: [Errno 2] No such file or directory
> >
> >
> > Maybe is better to put the complet path to the  batch file
> > mycmd='c:\\path_to\\ls.bat'
> > this must be the reason
> >
> > PM
> >
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://www.python.org/mailman/listinfo/tutor
> >
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor



From dyoo@hkn.EECS.Berkeley.EDU  Sun Jul 16 05:03:42 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Sat, 15 Jul 2000 21:03:42 -0700 (PDT)
Subject: [Tutor] iterate problem
In-Reply-To: <LPBBJDDFLFLMCKPODBMLIEKFCIAA.djansen@pobox.com>
Message-ID: <Pine.LNX.4.21.0007152054240.15300-100000@hkn.EECS.Berkeley.EDU>

On Sun, 16 Jul 2000, David Jansen wrote:

> a number of times). Removing the first > from the beginning of a line is no
> problem but I seem to enter an endless loop when I attempt to iterate over
> the line to get rid of second and third >'s if they exist.  The problem line
> is obviously the while line in strip() but I can't figure out what is wrong
> with it.

Ah!  You're not going to like this one: it's the spaces in your test file.  
For example, take a look at what happens in this line:

> > >The citrus soda 7-UP was created in 1929; "7" was selected because the

If you look at your terminating condition:

> ____while (len(input) > 0) and (input[0] not in alphas):

you'll see that after your loop cuts off the first '>' character, 'input'
gets stuck with a leading space in front.  After that, the loop goes
infinite since ' ' isn't alphanumeric, and nothing in the body's loop
deals with it.


###
def spoiler_alert:
   """By the way, a simpler way to state your condition and avoid the
      infinite loop is:"""

    while (len(input) > 0) and (input[0] == '<'):
      input = input[1:]



From Isaac@compuserve.com  Sat Jul 15 21:57:12 2000
From: Isaac@compuserve.com (Isaac)
Date: Sat, 15 Jul 2000 13:57:12 -0700
Subject: [Tutor] DeleteNode
References: <Pine.LNX.4.21.0007141329500.27200-100000@hkn.EECS.Berkeley.EDU>
Message-ID: <3970D028.4B99AEA@compuserve.com>

I try to use my "reply-all" button when on an e-mail list (unless I don't
think the list should see what I'm saying) since most lists don't set a
reply-to field with the list name (which keeps some unwanted traffic off the
lists, but sometimes ends up keeping wanted traffic off, too.)

Daniel Yoo wrote:

>
> On Fri, 14 Jul 2000, Vanessa Green wrote:
>
> > I have a question concerning how to delete a node using python.  I am
> > new to programming and python is the first language that I am slowly
> > learning.  Would you please let me know the best way to go about
> > deleting a node that contains both strings and integers.  Also is it
> > neccessary for me to create a key.
>
> Hello!  Can you explain what you mean by a node?  I'm familiar with the
> term 'node' when it's applied to linked-lists, but since you're doing
> beginning programming, I'm not sure if that's what you mean.  I'll try to
> guess what you mean, but if I starts sounding silly, you can ignore
> me.  *grin*
>
> If you mean an element in a hashtable like:
>
>   names_ages = { "al" : 23, "sandy" : 29, "goofy" : 3 }
>
> then the way to remove 'goofy' from the hashtable is to use the 'del'
> operator.
>
>   del names_ages["goofy"]
>
> If you do this, names_ages will just contain values for 'al' and 'sandy':
>
>   >>> names_ages
>   {'sandy': 29, 'al': 23}
>
> Oh, when you reply, make sure you reply to tutor@python.org.  (I haven't
> been able to figure out how to fix 'reply-to' in piX-Mozilla-Status: 0009________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor





From Isaac@compuserve.com  Sun Jul 16 05:42:12 2000
From: Isaac@compuserve.com (Isaac)
Date: Sat, 15 Jul 2000 21:42:12 -0700
Subject: [Tutor] iterate problem
References: <Pine.LNX.4.21.0007152054240.15300-100000@hkn.EECS.Berkeley.EDU>
Message-ID: <39713D23.6A9AD37B@compuserve.com>


Daniel Yoo wrote:

>
> On Sun, 16 Jul 2000, David Jansen wrote:
>
> > a number of times). Removing the first > from the beginning of a line is no
> > problem but I seem to enter an endless loop when I attempt to iterate over
> > the line to get rid of second and third >'s if they exist.  The problem line
> > is obviously the while line in strip() but I can't figure out what is wrong
> > with it.
>
> Ah!  You're not going to like this one: it's the spaces in your test file.
> For example, take a look at what happens in this line:
>
> > > >The citrus soda 7-UP was created in 1929; "7" was selected because the
>
> If you look at your terminating condition:
>
> > ____while (len(input) > 0) and (input[0] not in alphas):
>
> you'll see that after your loop cuts off the first '>' character, 'input'
> gets stuck with a leading space in front.  After that, the loop goes
> infinite since ' ' isn't alphanumeric, and nothing in the body's loop
> deals with it.
>
> ###
> def spoiler_alert:
>    """By the way, a simpler way to state your condition and avoid the
>       infinite loop is:"""
>
>     while (len(input) > 0) and (input[0] == '<'):
>       input = input[1:]

Good one.  And if you want to deal with the '> > ' sitch, you could add

while (len(input) > 0) and (input[0] == '>'):
    if input[1] == ' ':
        input = input[2:]
    else:
        input = input[1:]

You do run the risk of deleting a desired blank at the beginning of the line this
way, but I'm sure you could work around that.

Another option, if the "in alphas" test is anticipating further analysis and
editing within the loop, is to put a break in an else clause.  eg. something like:

     while (len(input) > 0) and (input[0] not in alphas):
          if input[0] == ">":
               input = input[1:]
          elif input[0] == "!":
              input = "(please don't yell - " + input[1:]   # or whatever
          elif (etc.)
          else:
               break



From Isaac@compuserve.com  Sun Jul 16 19:05:29 2000
From: Isaac@compuserve.com (Isaac)
Date: Sun, 16 Jul 2000 11:05:29 -0700
Subject: [Tutor] properties
Message-ID: <3971F969.20E840F9@compuserve.com>

Is there a more or less standard way for python progs to store
configuration options / property sheets (and display them for
modification by a user?)  Like in a text .ini file, or just writing out
a Properties dictionary?  I see that pythonwin uses it's interface to
windows dlls to do it, but what's the more platform independent method?

Thanks!

Best,
Isaac



From Isaac@compuserve.com  Sun Jul 16 19:18:54 2000
From: Isaac@compuserve.com (Isaac)
Date: Sun, 16 Jul 2000 11:18:54 -0700
Subject: [Tutor] iterate problem
References: <LPBBJDDFLFLMCKPODBMLOEKICIAA.djansen@pobox.com>
Message-ID: <3971FC8E.CCED080C@compuserve.com>

You're welcome, David.

I shouldn't offer suggestions on Saturday night though.  The code I sent is
buggy, 'cuz I reference input[1] when it might be out of range (if the string
is just one char long.)

To make it safe, would need to do an additional check on len(input) to make
sure it's > 1 instead of 0.

eg. something like
if len(input)>1 and input[1] == ' ':
    input=input[2:]

oops.

oh, well.  Have fun.

Best,
Isaac

> while (len(input) > 0) and (input[0] == '>'):
>     if input[1] == ' ':
>         input = input[2:]
>     else:
>         input = input[1:]

I don't know how python handles this, but to test for len(input) > 0, and then
to examine input[1] and do a slice at input

David Jansen wrote:

>
> Thank you very much.
>
> David Jansen
>
> > -----Original Message-----
> > From: tutor-admin@python.org [mailto:tutor-admin@python.org]On
> > Behalf Of Isaac
> > Sent: Sunday, July 16, 2000 1:42 PM
> > To: Daniel Yoo
> > Cc: David Jansen; tutor@python.org
> > Subject: Re: [Tutor] iterate problem
> >
> >
> >
> >
> > Daniel Yoo wrote:
> >
> > >
> > > On Sun, 16 Jul 2000, David Jansen wrote:
> > >
> > > > a number of times). Removing the first > from the beginning
> > of a line is no
> > > > problem but I seem to enter an endless loop when I attempt to
> > iterate over
> > > > the line to get rid of second and third >'s if they exist.
> > The problem line
> > > > is obviously the while line in strip() but I can't figure out
> > what is wrong
> > > > with it.
> > >
> > > Ah!  You're not going to like this one: it's the spaces in your
> > test file.
> > > For example, take a look at what happens in this line:
> > >
> > > > > >The citrus soda 7-UP was created in 1929; "7" was selected
> > because the
> > >
> > > If you look at your terminating condition:
> > >
> > > > ____while (len(input) > 0) and (input[0] not in alphas):
> > >
> > > you'll see that after your loop cuts off the first '>'
> > character, 'input'
> > > gets stuck with a leading space in front.  After that, the loop goes
> > > infinite since ' ' isn't alphanumeric, and nothing in the body's loop
> > > deals with it.
> > >
> > > ###
> > > def spoiler_alert:
> > >    """By the way, a simpler way to state your condition and avoid the
> > >       infinite loop is:"""
> > >
> > >     while (len(input) > 0) and (input[0] == '<'):
> > >       input = input[1:]
> >
> > Good one.  And if you want to deal with the '> > ' sitch, you could add
> >
> > while (len(input) > 0) and (input[0] == '>'):
> >     if input[1] == ' ':
> >         input = input[2:]
> >     else:
> >         input = input[1:]
> >
> > You do run the risk of deleting a desired blank at the beginning
> > of the line this
> > way, but I'm sure you could work around that.
> >
> > Another option, if the "in alphas" test is anticipating further
> > analysis and
> > editing within the loop, is to put a break in an else clause.
> > eg. something like:
> >
> >      while (len(input) > 0) and (input[0] not in alphas):
> >           if input[0] == ">":
> >                input = input[1:]
> >           elif input[0] == "!":
> >               input = "(please don't yell - " + input[1:]   # or whatever
> >           elif (etc.)
> >           else:
> >                break
> >
> >



From dyoo@hkn.EECS.Berkeley.EDU  Sun Jul 16 19:17:18 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Sun, 16 Jul 2000 11:17:18 -0700 (PDT)
Subject: [Tutor] properties
In-Reply-To: <3971F969.20E840F9@compuserve.com>
Message-ID: <Pine.LNX.4.21.0007161109500.28251-100000@hkn.EECS.Berkeley.EDU>

On Sun, 16 Jul 2000, Isaac wrote:

> Is there a more or less standard way for python progs to store
> configuration options / property sheets (and display them for
> modification by a user?)  Like in a text .ini file, or just writing out
> a Properties dictionary?  I see that pythonwin uses it's interface to
> windows dlls to do it, but what's the more platform independent method?

I haven't personally tried out the ConfigParser module, but it's supposed
to parse out .ini style files.  Here's the link to the reference
documentation:

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

However, this thing only reads in .ini files.  I'm not sure if there's a
module to write your config out, but it might look like a simple loop
through your configuration hashtable:

for k in config.keys():
  file.write("%s: %s\n" % (k, config[k]))



From Isaac@compuserve.com  Sat Jul 15 21:57:12 2000
From: Isaac@compuserve.com (Isaac)
Date: Sat, 15 Jul 2000 13:57:12 -0700
Subject: [Tutor] DeleteNode
References: <Pine.LNX.4.21.0007141329500.27200-100000@hkn.EECS.Berkeley.EDU>
Message-ID: <3970D028.4B99AEA@compuserve.com>

I try to use my "reply-all" button when on an e-mail list (unless I don't
think the list should see what I'm saying) since most lists don't set a
reply-to field with the list name (which keeps some unwanted traffic off the
lists, but sometimes ends up keeping wanted traffic off, too.)

Daniel Yoo wrote:

>
> On Fri, 14 Jul 2000, Vanessa Green wrote:
>
> > I have a question concerning how to delete a node using python.  I am
> > new to programming and python is the first language that I am slowly
> > learning.  Would you please let me know the best way to go about
> > deleting a node that contains both strings and integers.  Also is it
> > neccessary for me to create a key.
>
> Hello!  Can you explain what you mean by a node?  I'm familiar with the
> term 'node' when it's applied to linked-lists, but since you're doing
> beginning programming, I'm not sure if that's what you mean.  I'll try to
> guess what you mean, but if I starts sounding silly, you can ignore
> me.  *grin*
>
> If you mean an element in a hashtable like:
>
>   names_ages = { "al" : 23, "sandy" : 29, "goofy" : 3 }
>
> then the way to remove 'goofy' from the hashtable is to use the 'del'
> operator.
>
>   del names_ages["goofy"]
>
> If you do this, names_ages will just contain values for 'al' and 'sandy':
>
>   >>> names_ages
>   {'sandy': 29, 'al': 23}
>
> Oh, when you reply, make sure you reply to tutor@python.org.  (I haven't
> been able to figure out how to fix 'reply-to' in piX-Mozilla-Status: 0009________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor





From brianpcallahan@hotmail.com  Mon Jul 17 20:50:13 2000
From: brianpcallahan@hotmail.com (brian callahan)
Date: Mon, 17 Jul 2000 19:50:13 GMT
Subject: [Tutor] referencing a dictionary
Message-ID: <20000717195013.13198.qmail@hotmail.com>

hi,

hows it going.  i had a quick (hopefully) question about using a dictionary. 
  my idea is to use a raw_input string, to search a dictionary that contains 
all the characters in the raw_input string with a value, and then i want to 
sum the values.  my script is used to take a the amino acid sequence of a 
protein and then give back the molecular weight.  i've been using the 
'learning python' book but im getting impatient.

thanks for your help,

brian c.
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com



From sblakey@freei.com  Mon Jul 17 21:08:41 2000
From: sblakey@freei.com (Sean Blakey)
Date: Mon, 17 Jul 2000 13:08:41 -0700
Subject: [Tutor] referencing a dictionary
In-Reply-To: <20000717195013.13198.qmail@hotmail.com>; from brianpcallahan@hotmail.com on Mon, Jul 17, 2000 at 07:50:13PM +0000
References: <20000717195013.13198.qmail@hotmail.com>
Message-ID: <20000717130841.A770@freei.com>

On Mon, Jul 17, 2000 at 07:50:13PM +0000, brian callahan wrote:
> hi,
> 
> hows it going.  i had a quick (hopefully) question about using a dictionary. 
>   my idea is to use a raw_input string, to search a dictionary that contains 
> all the characters in the raw_input string with a value, and then i want to 
> sum the values.  my script is used to take a the amino acid sequence of a 
> protein and then give back the molecular weight.  i've been using the 
> 'learning python' book but im getting impatient.
> 
> thanks for your help,
> 
> brian c.
> ________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor

Not sure exactly what your question is, but I'll try to give you some sample
code:

import string
weights = {'A': 5, 'B': 7, 'C': 3}
acids = string.upper(raw_input("Enter the amino acid sequence"))
weight = 0
for acid in acids:
    weight = weight + weights[acid]
print "The molecular weight of this protein is", weight

Is this what you were looking for?
    -Sean

-- 
Sean Blakey, sblakey@freei.com
Software Developer, FreeInternet.com
(253)796-6500x1025
Decaffeinated coffee?  Just Say No.


From scarblac@pino.selwerd.nl  Mon Jul 17 21:13:44 2000
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 17 Jul 2000 22:13:44 +0200
Subject: [Tutor] referencing a dictionary
In-Reply-To: <20000717195013.13198.qmail@hotmail.com>; from brianpcallahan@hotmail.com on Mon, Jul 17, 2000 at 07:50:13PM +0000
References: <20000717195013.13198.qmail@hotmail.com>
Message-ID: <20000717221344.A12489@pino.selwerd.nl>

On Mon, Jul 17, 2000 at 07:50:13PM +0000, brian callahan wrote:
> hows it going.  i had a quick (hopefully) question about using a dictionary. 
>   my idea is to use a raw_input string, to search a dictionary that contains 
> all the characters in the raw_input string with a value, and then i want to 
> sum the values.  my script is used to take a the amino acid sequence of a 
> protein and then give back the molecular weight.  i've been using the 
> 'learning python' book but im getting impatient.

So you have a dict of values, like {'a':3.1,'b':17.0,'c':1.0} etc and want
to sum a string using that dictionary?

dict = {....}
sum = 0
s = raw_input('enter the string:')
for char in s:
  if not dict.has_key(char):
    continue
  sum = sum+dict[char]

Should do it.

-- 
Remco Gerlich,  scarblac@pino.selwerd.nl


From dyoo@hkn.EECS.Berkeley.EDU  Mon Jul 17 21:25:40 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Mon, 17 Jul 2000 13:25:40 -0700 (PDT)
Subject: [Tutor] referencing a dictionary
In-Reply-To: <20000717195013.13198.qmail@hotmail.com>
Message-ID: <Pine.LNX.4.21.0007171313080.15227-100000@hkn.EECS.Berkeley.EDU>

On Mon, 17 Jul 2000, brian callahan wrote:

>   my idea is to use a raw_input string, to search a dictionary that contains 
> all the characters in the raw_input string with a value, and then i want to 
> sum the values.  my script is used to take a the amino acid sequence of a 
> protein and then give back the molecular weight.  i've been using the 
> 'learning python' book but im getting impatient.

Can you give an example of what sort of input you're going to parse out of
raw_input()?

I'll assume that you're already familiar with dictionaries from another
language.  As a crash course, here are some the basic operations on
dictionaries ("hashtables"):


Creating an empty hashtable:

  myhash = {}


Creating a hashtable with initial entries:

  myhash = {'tryptophan' : 0.3, 'lysine': 0.44, 'methionine': 0.76}


Looking up an entry, given a known key:

  myhash['tryptophan']


Adding a new key/value pair into a dictionary:

  myhash['glutamic acid'] = 0.90


Getting all the keys as a list:

  myhash.keys()


Checking if a key exists in the hash:

  if myhash.has_key('tyrosine'):  ...


With these, you should be able to use dictionaries productively.  If you
have any questions, or would like to see an extended example, just email
tutor@python.org again.  Good luck!



From timc@ans.net  Mon Jul 17 22:17:41 2000
From: timc@ans.net (Tim Condit)
Date: Mon, 17 Jul 2000 17:17:41 -0400 (EDT)
Subject: [Tutor] perl's chomp equivalent?
Message-ID: <Pine.GSO.4.05.10007171713140.4978-100000@neutrino.aa.ans.net>

Hi, 

Is there anything similar to perl's chomp, which removes newline
characters from the end of a line? I'm using this, which works just fine
if not..

--

def main():
    file1 = re_proc(sys.argv[1], p1)
    file2 = re_proc(sys.argv[2], p1)
    merge_file = union(a, b)	

    for i in range(len(merge_file)):
        if merge_file[i][-1] == "\n":
            print merge_file[i][:-1]
        else:
            print merge_file[i]

--

thanks, 
Tim Condit
UUNet Network Quality Services
734-214-7548
tcondit@uu.net




From timc@ans.net  Mon Jul 17 22:21:35 2000
From: timc@ans.net (Tim Condit)
Date: Mon, 17 Jul 2000 17:21:35 -0400 (EDT)
Subject: [Tutor] Re: perl's chomp equivalent?
In-Reply-To: <Pine.GSO.4.05.10007171713140.4978-100000@neutrino.aa.ans.net>
Message-ID: <Pine.GSO.4.05.10007171719070.4978-100000@neutrino.aa.ans.net>

oops, one small typo.. should be:
merge_file = union(file1, file2)

(not that it's terribly relevant to the question anyway.. :)

thanks, 

Tim Condit
UUNet Network Quality Services
734-214-7548
tcondit@uu.net


On Mon, 17 Jul 2000, Tim Condit wrote:

> 
> Hi, 
> 
> Is there anything similar to perl's chomp, which removes newline
> characters from the end of a line? I'm using this, which works just fine
> if not..
> 
> --
> 
> def main():
>     file1 = re_proc(sys.argv[1], p1)
>     file2 = re_proc(sys.argv[2], p1)
>     merge_file = union(a, b)	
> 
>     for i in range(len(merge_file)):
>         if merge_file[i][-1] == "\n":
>             print merge_file[i][:-1]
>         else:
>             print merge_file[i]
> 
> --
> 
> thanks, 
> Tim Condit
> UUNet Network Quality Services
> 734-214-7548
> tcondit@uu.net
> 
> 
> 




From dyoo@hkn.EECS.Berkeley.EDU  Mon Jul 17 22:22:52 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Mon, 17 Jul 2000 14:22:52 -0700 (PDT)
Subject: [Tutor] perl's chomp equivalent?
In-Reply-To: <Pine.GSO.4.05.10007171713140.4978-100000@neutrino.aa.ans.net>
Message-ID: <Pine.LNX.4.21.0007171420420.1448-100000@hkn.EECS.Berkeley.EDU>

On Mon, 17 Jul 2000, Tim Condit wrote:

> Is there anything similar to perl's chomp, which removes newline
> characters from the end of a line? I'm using this, which works just fine
> if not..

string.strip() will chomp off newlines.  Here's what the built-in
documentation says about it:


>>> from string import strip
>>> print strip.__doc__
strip(s) -> string

Return a copy of the string s with leading and trailing
whitespace removed.


So it does a little bit more than chomp --- it goes at it from both ends.



From cangeles@mail.com  Mon Jul 17 22:22:09 2000
From: cangeles@mail.com (Carlos Angeles)
Date: Mon, 17 Jul 2000 17:22:09 -0400 (EDT)
Subject: [Tutor] RE: Tutor digest, Vol 1 #363 - 6 msgs
Message-ID: <384623976.963868941095.JavaMail.root@web421-mc.mail.com>

Message: 1
Reply-To: <djansen@pobox.com>
From: "David Jansen" <djansen@pobox.com>
To: <tutor@python.org>
Date: Sun, 16 Jul 2000 11:44:21 +0900
charset="iso-2022-jp"
Subject: [Tutor] iterate problem


While I read tutorials I am playing around with what I have learned. I am
trying to write a simple script that removes the >>>'s from the beginning of
lines in a text file (for example  an email message that has been forwarded
a number of times). Removing the first > from the beginning of a line is no
problem but I seem to enter an endless loop when I attempt to iterate over
the line to get rid of second and third >'s if they exist.  The problem line
is obviously the while line in strip() but I can't figure out what is wrong
with it.

Any help greatly appreciated.

David Jansen

import string, sys

groups = []
alphas = string.letters + string.digits

file = raw_input("enter file: ")
inp = open(file, "r")

def strip(input):
____while (len(input) > 0) and (input[0] not in alphas):
________if input[0] == ">":
____________input = input[1:]
____return input

for line in inp.readlines():
____result = strip(line)
____print result


sample text file:

>Interesting Stuff.
>
> > >The citrus soda 7-UP was created in 1929; "7" was selected because the
> > >original containers were 7 ounces. "UP" indicated the direction of the
> > >bubbles.
> > >
> > > Mosquito repellents don't repel. They hide you. The spray blocks the
> > >mosquito's sensors so they don't know you're there.
> > >
> > > Dentists have recommended that a toothbrush be kept at least 6 feet
>away


David,

Have you tried making strip recursive?  Change it to look like this:

def strip(input):
____while (len(input) > 0)
________if input[0] == ">" or input [0]==" ":
____________input = strip(input[1:])
____return input

I didn't have a chance to test it with a file.  I just did a quick check in IDLE and it stripped off the leading "> > > >"'s that if fed it.  Let me know if that works.

Carlos

______________________________________________
FREE Personalized Email at Mail.com
Sign up at http://www.mail.com/?sr=signup



From scarblac@pino.selwerd.nl  Mon Jul 17 22:26:05 2000
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 17 Jul 2000 23:26:05 +0200
Subject: [Tutor] perl's chomp equivalent?
In-Reply-To: <Pine.GSO.4.05.10007171713140.4978-100000@neutrino.aa.ans.net>; from timc@ans.net on Mon, Jul 17, 2000 at 05:17:41PM -0400
References: <Pine.GSO.4.05.10007171713140.4978-100000@neutrino.aa.ans.net>
Message-ID: <20000717232605.A12599@pino.selwerd.nl>

On Mon, Jul 17, 2000 at 05:17:41PM -0400, Tim Condit wrote:
> Is there anything similar to perl's chomp, which removes newline
> characters from the end of a line? I'm using this, which works just fine
> if not..

Something similar. string.strip() removes trailing and leading whitespace
from a string, rstrip() only trailing whitespace. So spaces and stuff too.

>         if merge_file[i][-1] == "\n":
>             print merge_file[i][:-1]
>         else:
>             print merge_file[i]

But this works as well, of course.

-- 
Remco Gerlich,  scarblac@pino.selwerd.nl


From dyoo@hkn.EECS.Berkeley.EDU  Mon Jul 17 22:36:22 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Mon, 17 Jul 2000 14:36:22 -0700 (PDT)
Subject: [Tutor] RE: Tutor digest, Vol 1 #363 - 6 msgs
In-Reply-To: <384623976.963868941095.JavaMail.root@web421-mc.mail.com>
Message-ID: <Pine.LNX.4.21.0007171430500.1634-100000@hkn.EECS.Berkeley.EDU>

> Have you tried making strip recursive?  Change it to look like this:
> 
> def strip(input):
> ____while (len(input) > 0):
> ________if input[0] == ">" or input [0]==" ":
> ____________input = strip(input[1:])
> ____return input
> 
> I didn't have a chance to test it with a file.  I just did a quick
> check in IDLE and it stripped off the leading "> > > >"'s that if fed
> it.  Let me know if that works.

This is dangerous because it runs into a similar problem if the input line
contains something like "||| Another infinite loop |||" or some other
non-numeric characters.  In fact, it only works if your line consists of
nothing but '>' or ' ' characters!  You probably meant to put:


###
def strip(input):
  if input[0] == ">" or input [0]==" ":
    input = strip(input[1:])
  return input
###

instead.  Be careful with mixing recursion with 'while' statement; believe
me, I've had plenty of bad experiences with this bug.



From Isaac@compuserve.com  Mon Jul 17 20:13:32 2000
From: Isaac@compuserve.com (Isaac)
Date: Mon, 17 Jul 2000 12:13:32 -0700
Subject: [Tutor] self self self
Message-ID: <39735ADC.59784C9@compuserve.com>

in java classes, the 'self' namespace is automatically
available.  instance methods automatically include the self ('this' in
java) as the first argument, so we don't have to worry about it.  And
the same goes for accessing instance vars and methods.

Is there any good and reasonable way to circumvent having to include
'self.' in front of every instance attribute reference in python?  Or if
not, what's the likelihood of the language adding an automatic search in
the class' (object's) namespace in the future?



From scarblac@pino.selwerd.nl  Mon Jul 17 23:41:45 2000
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Tue, 18 Jul 2000 00:41:45 +0200
Subject: [Tutor] self self self
In-Reply-To: <39735ADC.59784C9@compuserve.com>; from Isaac@compuserve.com on Mon, Jul 17, 2000 at 12:13:32PM -0700
References: <39735ADC.59784C9@compuserve.com>
Message-ID: <20000718004145.A12695@pino.selwerd.nl>

On Mon, Jul 17, 2000 at 12:13:32PM -0700, Isaac wrote:
> in java classes, the 'self' namespace is automatically
> available.  instance methods automatically include the self ('this' in
> java) as the first argument, so we don't have to worry about it.  And
> the same goes for accessing instance vars and methods.
> 
> Is there any good and reasonable way to circumvent having to include
> 'self.' in front of every instance attribute reference in python?  Or if
> not, what's the likelihood of the language adding an automatic search in
> the class' (object's) namespace in the future?

Well, you could use 's.' instead of 'self.'...

I don't think it will go. It makes code clear (you can tell the difference
between instance and local variables immediately). How would Python tell the
difference between the local namespace, the global namespace and the
instance's namespace? In Java it's necessary to declare variables and that
info can be used, but as Python is so dynamic, I don't see that happen.

It would be irritating if every loop counter or so you used in a method
would be added to the instance...

-- 
Remco Gerlich,  scarblac@pino.selwerd.nl


From cangeles@mail.com  Tue Jul 18 00:35:16 2000
From: cangeles@mail.com (Carlos Angeles)
Date: Mon, 17 Jul 2000 19:35:16 -0400 (EDT)
Subject: [Tutor] RE: Tutor digest, Vol 1 #363 - 6 msgs
Message-ID: <383514083.963876916863.JavaMail.root@web431-mc.mail.com>

------Original Message------
From: Daniel Yoo <dyoo@hkn.EECS.Berkeley.EDU>
To: Carlos Angeles <cangeles@mail.com>
Sent: July 17, 2000 9:36:22 PM GMT
Subject: Re: [Tutor] RE: Tutor digest, Vol 1 #363 - 6 msgs


> Have you tried making strip recursive?  Change it to look like this:
> 
> def strip(input):
> ____while (len(input) > 0):
> ________if input[0] == ">" or input [0]==" ":
> ____________input = strip(input[1:])
> ____return input
> 
> I didn't have a chance to test it with a file.  I just did a quick
> check in IDLE and it stripped off the leading "> > > >"'s that if fed
> it.  Let me know if that works.

This is dangerous because it runs into a similar problem if the input line
contains something like "||| Another infinite loop |||" or some other
non-numeric characters.  In fact, it only works if your line consists of
nothing but '>' or ' ' characters!  You probably meant to put:


###
def strip(input):
  if input[0] == ">" or input [0]==" ":
    input = strip(input[1:])
  return input
###

instead.  Be careful with mixing recursion with 'while' statement; believe
me, I've had plenty of bad experiences with this bug.

Daniel,
The way you suggestion is the way I tried it in IDLE but I wasn't sure how an empty line would be treated.  Now that I think about it more a blank line wouldn't meet the two if's so it would skip the recursion and return the empty line.

Is my thinking correct?

Carlos

______________________________________________
FREE Personalized Email at Mail.com
Sign up at http://www.mail.com/?sr=signup



From wesc@alpha.ece.ucsb.edu  Tue Jul 18 01:40:45 2000
From: wesc@alpha.ece.ucsb.edu (Wesley J. Chun)
Date: Mon, 17 Jul 2000 17:40:45 -0700 (PDT)
Subject: [Tutor] Re: perl's chomp equivalent?
Message-ID: <200007180040.RAA05899@alpha.ece.ucsb.edu>

    > Date: Mon, 17 Jul 2000 17:21:35 -0400 (EDT)
    > From: Tim Condit <timc@ans.net>
    > 
    > > Is there anything similar to perl's chomp, which removes newline
    > > characters from the end of a line? I'm using this, which works just fine
    > > if not..
    > > 
    > >     for i in range(len(merge_file)):
    > >         if merge_file[i][-1] == "\n":
    > >             print merge_file[i][:-1]
    > >         else:
    > >             print merge_file[i]


tim,

there are a variety of solutions for your question.  it all depends
on what your application is and how you want to approach it.  as
some folks have already mentioned, there are the *strip() routines:

- - -
import string

string.lstrip()		removes leading whitespace
string.rstrip()		removes trailing whitespace

or a combo of the two...

string.strip()		removes both leading and trailing whitespace
- - -

for i in range(len(merge_file)):
    print string.strip(merge_file[i])

... or ...

for i in merge_file:
    print string.strip(i)


also, as of Python 1.6/2.0, strings now have methods,
so you could do something like merge_file.rstrip(), etc.


finally, i noticed that the name of your variable has
the word "file" in it.  i don't know about your situation
but many times, i have to read in files with extra whitespace
and in these situations, i always seem to have to do some
kind of postprocessing on them.

i found it quite useful to use *strip() along with map()
in these cases.  rather than doing something like...

import string
f = open('foo.txt', 'r')
data = f.readlines()
f.close()

for eachLine in data:
    eachLine = string.strip(eachLine)

... i can save some code using map():

import string
f = open('foo.txt', 'r')
data = map(string.strip, f.readlines())
f.close()

hope this helps!!

-wesley

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

"Core Python Programming", Prentice Hall PTR, TBP Summer 2000
    http://www.phptr.com/ptrbooks/ptr_0130260363.html
    http://www.softpro.com/languages-python.html

wesley.j.chun :: wesc@alpha.ece.ucsb.edu
cyberweb.consulting :: silicon.valley, ca
http://www.roadkill.com/~wesc/cyberweb/


From bwinton@tor.dhs.org  Tue Jul 18 02:36:52 2000
From: bwinton@tor.dhs.org (Blake Winton)
Date: Mon, 17 Jul 2000 21:36:52 -0400
Subject: [Tutor] self self self
In-Reply-To: <20000718004145.A12695@pino.selwerd.nl>
References: <39735ADC.59784C9@compuserve.com> <20000718004145.A12695@pino.selwerd.nl>
Message-ID: <20000717213652.A4014@tor.dhs.org>

* Remco Gerlich <scarblac@pino.selwerd.nl> [000717 20:04]:
> On Mon, Jul 17, 2000 at 12:13:32PM -0700, Isaac wrote:
> > in java classes, the 'self' namespace is automatically available.
> > instance methods automatically include the self ('this' in java)
> > as the first argument, so we don't have to worry about it.  And
> > the same goes for accessing instance vars and methods.
> Well, you could use 's.' instead of 'self.'...
> 
> I don't think it will go. It makes code clear (you can tell the
> difference between instance and local variables immediately). How
> would Python tell the difference between the local namespace, the
> global namespace and the instance's namespace? In Java it's
> necessary to declare variables and that info can be used, but as
> Python is so dynamic, I don't see that happen.

In most of the Java coding standards I've seen, it is strongly
recommended that you use "this." in front of every instance variable.
For precisely the reasons stated above.  It's far easier to see what
variables in a function are local, and what variables belong to the
object.

> It would be irritating if every loop counter or so you used in a
> method would be added to the instance...

It's not on assignment, just on reference.  So stuff you create in a
method is local to that method, but if you use a variable that's not
local to the method, Java automatically checks the instance for you.

Later,
Blake.
-- 
9:28pm up 2 days, 20:55, 1 user, load average: 0.00, 0.00, 0.00


From dyoo@hkn.EECS.Berkeley.EDU  Tue Jul 18 04:06:49 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Mon, 17 Jul 2000 20:06:49 -0700 (PDT)
Subject: [Tutor] RE: Tutor digest, Vol 1 #363 - 6 msgs
In-Reply-To: <383514083.963876916863.JavaMail.root@web431-mc.mail.com>
Message-ID: <Pine.LNX.4.21.0007171958400.6531-100000@hkn.EECS.Berkeley.EDU>

> The way you suggestion is the way I tried it in IDLE but I wasn't sure
> how an empty line would be treated.  Now that I think about it more a
> blank line wouldn't meet the two if's so it would skip the recursion
> and return the empty line.
> 
> Is my thinking correct?

The problem which Issac pointed out before is that the very act of looking
at the first character of the string breaks if the string is empty.  For
example:

  mystring = ""
  print mystring[0]

will cause an IndexError.  This makes sense: it's a string of length zero,
so trying to look at its first element should be an error.  One safe way
to avoid these problems is to check the length of the string using len()
before attempting to work with the string.



From dyoo@hkn.EECS.Berkeley.EDU  Tue Jul 18 18:03:09 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Tue, 18 Jul 2000 10:03:09 -0700 (PDT)
Subject: [Tutor] referencing a dictionary
In-Reply-To: <20000718155331.89406.qmail@hotmail.com>
Message-ID: <Pine.LNX.4.21.0007180957510.17630-100000@hkn.EECS.Berkeley.EDU>

On Tue, 18 Jul 2000, brian callahan wrote:

> thankyou for the advice, my input would look like
> 
> afhalkjdsahlahf
> 
> and then the dictionary looks like {a : 123} etc.
> 
> i think i need to go somthing like 'sum = sum + dict [char]'


That sounds like a good way to do it.

Strings, too, are a sequence type, so you can iterate through each letter
of a string using a for loop:

for acid in "afhalkjdsahlahf":
  ...


Good luck!



From jeremiasg@bigfoot.com  Tue Jul 18 04:22:34 2000
From: jeremiasg@bigfoot.com (Jeremias Galletti)
Date: Tue, 18 Jul 2000 00:22:34 -0300
Subject: [Tutor] Is Python suitable for my project?
Message-ID: <3973A34A.2578.47AD0@localhost>

Hello,

I need to develop a new version of the program my dad uses to 
handle the medical data of all his patients. The previous version 
was done using MS Visual Basic 3.0, and it still works quite well. 
The problem is that this application was programmed under 
Windows 3.1 and has never been upgraded.

Now I'm planning to develop a new version from scratch. I like 
Visual Basic because it is easy to program with and you can get 
what you want fast. But with my application I got to the limits of 
this programming environment. I had to use thousands of nasty 
tricks to overcome them, and that resulted in a loss of productivity 
and made the code harder to debug, modify and maintain.

This time I'd like to work with a better language, with no such 
limitations. I have worked with C, Pascal, Basic, Visual Basic, 
FoxPro and I even worked with Assembler during summer 
vacations a couple of years ago (as you can see, I had a lot of time 
in my hands...). I know the basics of C++ object-oriented 
programming, but I have never undertaken a serious project with 
this paradigm. I come from the old structured-programming school...

To use any of the languages I already know for my project would 
require too much time. The application I need to develop doesn't 
need any low-level code, so using Pascal or C would be a waste of 
power. C++ is just a modified version of C. This time I would like to 
try the real object-oriented programming. Python springs to mind, 
and I've been reading the introductory course and so far I like what 
I've seen. I think it is a good compromise between programming 
power and productivity.

However, the Win32 API programming interfase seems rather 
crude. I haven't examined it exhaustively, but I could only find 
Python functions and classes which directly call their API 
counterparts. How is all the Win32 API stuff normally handled? Is 
there such a productive interfase-design environment as the one of 
Visual Basic? Or should I start learning the Win32 API with all its 
hWnd, brushes, and related things? Is there a high-level 
encapsulation of this API available for Python? And what about a 
WYSIWYG design environment?

Is anyone working on a project which runs under Windows? How 
do you people work with the API? Is Python a good option for my 
project? I like its great support groups and all the modules that are 
available to use, but without an easy way to work with all the 
window management code, I guess Python is not a viable option for 
me. Am I right? What do you suggest?

Thanks in advance,

Jerem=EDas Galletti
jeremiasg@crosswinds.net


From alan.gauld@bt.com  Tue Jul 18 18:10:43 2000
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Tue, 18 Jul 2000 18:10:43 +0100
Subject: [Tutor] iterate problem
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D207@mbtlipnt02.btlabs.bt.co.uk>

> trying to write a simple script that removes the >>>'s from 
> the beginning of lines in a text file 

Sounds like a job for reg expressions to me.

the regexp will be something like:

>[> ]+

which means a '>' followed by one or more '>' or spaces.

The sub function/method in the re module should replace 
that with an empty string.

Alan G.


From shaleh@valinux.com  Tue Jul 18 23:57:40 2000
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Tue, 18 Jul 2000 15:57:40 -0700 (PDT)
Subject: [Tutor] Is Python suitable for my project?
In-Reply-To: <3973A34A.2578.47AD0@localhost>
Message-ID: <XFMail.20000718155740.shaleh@valinux.com>

Python as a language is great.  You will enjoy using it.  Python the GUI tool
however will leave you wanting, especially on Windows.

Things to consider:

wxPython.  Rather nice, cross platform, hides all the uglies of GUI code. 
www.wxwindows.org if I recall.  I believe there is a GUI environment to progrma
in there as well.

tkinter.


From bwinton@tor.dhs.org  Wed Jul 19 03:10:42 2000
From: bwinton@tor.dhs.org (Blake Winton)
Date: Tue, 18 Jul 2000 22:10:42 -0400
Subject: [Tutor] Is Python suitable for my project?
In-Reply-To: <NDBBIEJNCLGNFFKFNAJMIECACAAA.samus@feudalkingdoms.tzo.org>
References: <3973A34A.2578.47AD0@localhost> <NDBBIEJNCLGNFFKFNAJMIECACAAA.samus@feudalkingdoms.tzo.org>
Message-ID: <20000718221042.A5703@tor.dhs.org>

* samus <samus@feudalkingdoms.tzo.org> [000718 21:58]:
> Modularity is key to large projects.  In the case of OOP its a mater of
> keeping your objects as independent of each other as possible.  Generic is
> good.  Then you inherit from those or write specialized wrappers to do the
> special case stuff.

I completely agree.  And add that if you want to (and are able to)
email me with your design, I'll see if I can suggest any improvements.

> >programming, but I have never undertaken a serious project with
> >this paradigm. I come from the old structured-programming school...
> Get aquainted with it.  Once you get into it its hard to think of writing
> software any other way.

I started trying to write a VI clone in C, but had to give it up
because I didn't remember enough about function pointers to mimic
all the OO-Design stuff I wanted to do...  :)

> I would suggest learning about how to do COM
> objects.  VB is a decent enough way to start to get a feel of how it works.
[...]
> there isn't really any RAD tool for gui design with Python.

Given the above two statements, I'm now going to make the possibly
heretical statement that perhaps VB is the best RAD tool for gui
design with Python.  Write up a bunch of VB forms, and use Python
to script them.  Of course, portability gets thrown out the window.

Later,
Blake.
-- 
10:00pm up 3 days, 21:27, 2 users, load average: 0.31, 0.13, 0.03


From alan.gauld@bt.com  Wed Jul 19 11:40:27 2000
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 19 Jul 2000 11:40:27 +0100
Subject: [Tutor] self self self
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D208@mbtlipnt02.btlabs.bt.co.uk>

> in java classes, the 'self' namespace is automatically
> available.  instance methods automatically include the self ('this' in

> Is there any good and reasonable way to circumvent having to include

No.

> not, what's the likelihood of the language adding an 
> automatic search in
> the class' (object's) namespace in the future?

Low, I should imagine. A goodly proportion of Python programmers value 
the extra clarity that explicitly using self provides. In my case to 
the point that I now routinely use 'this->' in front of all self 
messaging in C++. 

Of course in Java it's possibly less confusing since you can't have 
global functions so theres no uncertainty about where the 
function/method resides. But in C++ self messaging looks 
exactly like calling a global function and it gets very confusing 
for the poor maintenance programmer! explicit self/this avoids 
the ambiguity.

Alan G.


From alan.gauld@bt.com  Wed Jul 19 17:38:37 2000
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 19 Jul 2000 17:38:37 +0100
Subject: [Tutor] Is Python suitable for my project?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D211@mbtlipnt02.btlabs.bt.co.uk>

> was done using MS Visual Basic 3.0, and it still works quite well. 
> The problem is that this application was programmed under 
> Windows 3.1 and has never been upgraded.
> ...
> what you want fast. But with my application I got to the limits of 
> this programming environment. I had to use thousands of nasty 
> tricks to overcome them, and that resulted in a loss of productivity 
> and made the code harder to debug, modify and maintain.
> 
> This time I'd like to work with a better language, with no such 
> limitations. I have worked with C, Pascal, Basic, Visual Basic, 

Sounds like the natural choice would be Borlands Delphi. 
The UI design features of VB with a full OO model and in Pascal 
which you know. Faster executables than VB but you need to buy it.
A=Standard edition should be adequate tho' at <$100?

> To use any of the languages I already know for my project would 
> require too much time. 

Delphi would probably be faster than learning Python and the 
Win32 MFC stuff. Even learning Tkinter would take a while and
then you have the database access too...

> need any low-level code, so using Pascal or C would be a waste of 
> power. 

Pascal isn't intended to be a low level language although Borland's 
versions can certainly do that. Its not as high level as Python 
but its a lot higher than C or C++.

> try the real object-oriented programming. Python springs to mind, 
> and I've been reading the introductory course and so far I like what 
> I've seen. I think it is a good compromise between programming 
> power and productivity.

Agreed on that score.

> However, the Win32 API programming interfase seems rather 
> crude. 

Its very low level. Fine if you are an experienced VC++ developer 
but for you I'd advise going to Tkinter or PyWin.

> there such a productive interfase-design environment as the one of 
> Visual Basic? 

The nearest I've found is the Tcl tool specTcl which is a GUI 
builder but the eitor for the code is very crude and its a long 
way short of Delphi or VB. Glade and Boa may get there some day 
but not yet.

> Is anyone working on a project which runs under Windows? How 
> do you people work with the API? Is Python a good option for my 
> project? 

For windows apps I use Python as a prototype language for the 
core functionality but I use Delphi for the GUI unless its 
very simple - in which case Tkinter is fine.

> available to use, but without an easy way to work with all the 
> window management code, I guess Python is not a viable option for 
> me. Am I right? What do you suggest?

I would agree for this particular case. Now if you wanted to build 
an app that ran on Linux and windows Python would be a real option. 
But as it stands I'd recommend deplhi for its better GUI builder, 
good database connectivity, good RAD support and fast executables

Alan G.


From arcege@shore.net  Wed Jul 19 17:43:58 2000
From: arcege@shore.net (Michael P. Reilly)
Date: Wed, 19 Jul 2000 12:43:58 -0400 (EDT)
Subject: [Tutor] iterate problem
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D207@mbtlipnt02.btlabs.bt.co.uk> from "alan.gauld@bt.com" at Jul 18, 2000 06:10:43 PM
Message-ID: <200007191643.MAA09938@northshore.shore.net>

> > trying to write a simple script that removes the >>>'s from 
> > the beginning of lines in a text file 
> 
> Sounds like a job for reg expressions to me.
> 
> the regexp will be something like:
> 
> >[> ]+
> 
> which means a '>' followed by one or more '>' or spaces.

I think a more accurate one would be:
  r'^(> ?)+'

You want to anchor the regular expression to the beginning, and to
only strip off zero or one space (">" or "> "), still leaving the
other whitespace from the text (indentations for example).

  -Arcege

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


From deirdre@deirdre.net  Wed Jul 19 17:41:27 2000
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Wed, 19 Jul 2000 09:41:27 -0700 (PDT)
Subject: [Tutor] Is Python suitable for my project?
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D211@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <Pine.LNX.4.10.10007190935590.23330-100000@rockhopper.deirdre.org>

On Wed, 19 Jul 2000 alan.gauld@bt.com wrote:

> > available to use, but without an easy way to work with all the 
> > window management code, I guess Python is not a viable option for 
> > me. Am I right? What do you suggest?
> 
> I would agree for this particular case. Now if you wanted to build 
> an app that ran on Linux and windows Python would be a real option. 
> But as it stands I'd recommend deplhi for its better GUI builder, 
> good database connectivity, good RAD support and fast executables

I like Glade as a GUI builder but dunno if it's ported to Windows (though
Gtk+ is). Very cool with Python.

I just don't like being tied to a proprietary language as Delphi is, no
matter how cool it may be.

-- 
_Deirdre   *   http://www.sfknit.org   *   http://www.deirdre.net
"Trust me, I'm a science fiction writer" -- Larry Niven @ Conolulu



From alan.gauld@bt.com  Wed Jul 19 18:05:15 2000
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Wed, 19 Jul 2000 18:05:15 +0100
Subject: [Tutor] Is Python suitable for my project?
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D214@mbtlipnt02.btlabs.bt.co.uk>

> On Wed, 19 Jul 2000 alan.gauld@bt.com wrote:
> > > available to use, but without an easy way to work with all the 
> > > window management code, I guess Python is not a viable option for 
> > > me. Am I right? What do you suggest?
> > 
> > I would agree for this particular case. Now if you wanted to build 
> > an app that ran on Linux and windows Python would be a real option. 
> > But as it stands I'd recommend deplhi for its better GUI builder, 
> > good database connectivity, good RAD support and fast executables
> 
> I like Glade as a GUI builder but dunno if it's ported to 
> Windows (though Gtk+ is). Very cool with Python.

Yes, but no port last time I looked.

> I just don't like being tied to a proprietary language as 
> Delphi is, no matter how cool it may be.

The language is available via the Free Pascal Compiler which 
supports 90% of delphi. BUT not the GUI components.... There 
used to be an OpenSource project to port the Delphi VCL to 
Linux(Megiddo?) but it seems to9mhave died - maybe because 
Borland have suggested that they will be releasing Delphi 
for Linux... But not as Open Source of course :-(

But if I have to program in a Win32 environment Delphi is 
my favourite tool overVB and the execrable VC++ (and even 
over C++Builder).

There is a web page about melding Delphi and Python but 
I've never found an excuse to try yet...
'Snakes in the Temple' I think it was called - great name :-)


Alan G.


From jeremiasg@bigfoot.com  Wed Jul 19 21:44:55 2000
From: jeremiasg@bigfoot.com (Jeremias Galletti)
Date: Wed, 19 Jul 2000 17:44:55 -0300
Subject: [Tutor] Pythonwin crashes when editing...
Message-ID: <3975E917.16009.12CC0@localhost>

Hello,

I'm having an strange problem with Pythonwin. Every time I type in 
single or double quotes, the editor crashes. I have used it before in 
previous installations, and had no problems of this type. Is this a 
known incompatibility of Pythonwin? Do I have a wrong system 
setting?

Does anyone recommend a better text editor for Python? I like all 
the fancy stuff like source code highlighting and direct access to 
the Python Manuals. Any tips?

Jerem=EDas Galletti
jeremiasg@crosswinds.net


From insyte@emt-p.org  Wed Jul 19 23:09:07 2000
From: insyte@emt-p.org (Ben Beuchler)
Date: Wed, 19 Jul 2000 17:09:07 -0500
Subject: [Tutor] Python equiv of Perl's 'or die()' syntax
Message-ID: <20000719170907.B30143@emt-p.org>

Is there a simple equivalent to Perl's 'or die()' syntax?

Similar to this:

open( MYFILE, 'filethatdoesnotexist') or die "Help me!!:$!"

Gracias,
Ben

-- 
Ben Beuchler                                         insyte@bitstream.net
MAILER-DAEMON                                         (612)-321-9290 x101
Bitstream Underground                                   www.bitstream.net


From scarblac@pino.selwerd.nl  Wed Jul 19 23:22:42 2000
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 20 Jul 2000 00:22:42 +0200
Subject: [Tutor] Python equiv of Perl's 'or die()' syntax
In-Reply-To: <20000719170907.B30143@emt-p.org>; from insyte@emt-p.org on Wed, Jul 19, 2000 at 05:09:07PM -0500
References: <20000719170907.B30143@emt-p.org>
Message-ID: <20000720002242.A16212@pino.selwerd.nl>

On Wed, Jul 19, 2000 at 05:09:07PM -0500, Ben Beuchler wrote:
> Is there a simple equivalent to Perl's 'or die()' syntax?
> 
> Similar to this:
> 
> open( MYFILE, 'filethatdoesnotexist') or die "Help me!!:$!"

In Python, error handling is based on the concept of exceptions.

If you try to read a non-existant file with open, open will raise an
exception. If you don't do anything about it, your program will terminate
with "No such file" and a line number. Nothing special to do there.

Dying is hardly ever a useful solution, unless you have a very small script.
(don't know what that means about Perl idioms, don't know enough Perl).

To catch exceptions, you use the try: except: construct, like

try:
  f = open("filethatdoesnotexist","r")
except IOError:
  print "File open failed!"
  # Do the rest of your error handling...
  

In general, don't look for direct equivalents. Perl is Perl, Python is
Python, they don't do everything in a similar way.

So, I think the answer is "no".
-- 
Remco Gerlich,  scarblac@pino.selwerd.nl


From insyte@emt-p.org  Wed Jul 19 23:47:47 2000
From: insyte@emt-p.org (Ben Beuchler)
Date: Wed, 19 Jul 2000 17:47:47 -0500
Subject: [Tutor] Python equiv of Perl's 'or die()' syntax
In-Reply-To: <20000720002242.A16212@pino.selwerd.nl>; from scarblac@pino.selwerd.nl on Thu, Jul 20, 2000 at 12:22:42AM +0200
References: <20000719170907.B30143@emt-p.org> <20000720002242.A16212@pino.selwerd.nl>
Message-ID: <20000719174747.A30234@emt-p.org>

On Thu, Jul 20, 2000 at 12:22:42AM +0200, Remco Gerlich wrote:

> To catch exceptions, you use the try: except: construct, like
> 
> try:
>   f = open("filethatdoesnotexist","r")
> except IOError:
>   print "File open failed!"
>   # Do the rest of your error handling...

Hmmm... OK.  I understand how that works.  Now, since I would like to
include that kind of syntax on almost every file I open, any thoughts on
doing something like this:

def safeopen(filename):
	try:
		handle = open(filename)
		return handle
	except IOError:
		print "Opening", filename, "failed!!"

And calling it thusly:

safeopen('worthlessfile')

Would that make sense as a shortcut?

Ben

-- 
Ben Beuchler                                         insyte@bitstream.net
MAILER-DAEMON                                         (612)-321-9290 x101
Bitstream Underground                                   www.bitstream.net


From deirdre@deirdre.net  Wed Jul 19 23:37:27 2000
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Wed, 19 Jul 2000 15:37:27 -0700 (PDT)
Subject: [Tutor] Python equiv of Perl's 'or die()' syntax
In-Reply-To: <20000719170907.B30143@emt-p.org>
Message-ID: <Pine.LNX.4.10.10007191536330.24411-100000@rockhopper.deirdre.org>

On Wed, 19 Jul 2000, Ben Beuchler wrote:

> Is there a simple equivalent to Perl's 'or die()' syntax?
> 
> Similar to this:
> 
> open( MYFILE, 'filethatdoesnotexist') or die "Help me!!:$!"

sure:

def die(printme):
 print printme
 exit(1)

:)

-- 
_Deirdre   *   http://www.sfknit.org   *   http://www.deirdre.net
"Trust me, I'm a science fiction writer" -- Larry Niven @ Conolulu



From insyte@emt-p.org  Wed Jul 19 23:53:23 2000
From: insyte@emt-p.org (Ben Beuchler)
Date: Wed, 19 Jul 2000 17:53:23 -0500
Subject: [Tutor] Python equiv of Perl's 'or die()' syntax
In-Reply-To: <Pine.LNX.4.10.10007191536330.24411-100000@rockhopper.deirdre.org>; from deirdre@deirdre.net on Wed, Jul 19, 2000 at 03:37:27PM -0700
References: <20000719170907.B30143@emt-p.org> <Pine.LNX.4.10.10007191536330.24411-100000@rockhopper.deirdre.org>
Message-ID: <20000719175323.B30234@emt-p.org>

On Wed, Jul 19, 2000 at 03:37:27PM -0700, Deirdre Saoirse wrote:

> > Is there a simple equivalent to Perl's 'or die()' syntax?
> > 
> > Similar to this:
> > 
> > open( MYFILE, 'filethatdoesnotexist') or die "Help me!!:$!"
> 
> sure:
> 
> def die(printme):
>  print printme
>  exit(1)
> 
> :)

Heh... Very nice.  Now if I could get that gosh-darn "do something or
die()" working...

8-)

Gracias,
Ben

-- 
Ben Beuchler                                         insyte@bitstream.net
MAILER-DAEMON                                         (612)-321-9290 x101
Bitstream Underground                                   www.bitstream.net


From shaleh@valinux.com  Wed Jul 19 23:52:53 2000
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Wed, 19 Jul 2000 15:52:53 -0700 (PDT)
Subject: [Tutor] Python equiv of Perl's 'or die()' syntax
In-Reply-To: <20000719174747.A30234@emt-p.org>
Message-ID: <XFMail.20000719155253.shaleh@valinux.com>

> 
> Hmmm... OK.  I understand how that works.  Now, since I would like to
> include that kind of syntax on almost every file I open, any thoughts on
> doing something like this:
> 
> def safeopen(filename):
>       try:
>               handle = open(filename)
>               return handle
>       except IOError:
>               print "Opening", filename, "failed!!"
> 
> And calling it thusly:
> 
> safeopen('worthlessfile')
> 
> Would that make sense as a shortcut?
> 

well, the caller would not get a return value, so unless you exit in
safeopen(), the next line of your script will have issues:

file = safeopen('myfile') # file does not exist
for line in file.readlines: # oops, file is not set to anything
        print line


From scarblac@pino.selwerd.nl  Thu Jul 20 00:00:03 2000
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Thu, 20 Jul 2000 01:00:03 +0200
Subject: [Tutor] Python equiv of Perl's 'or die()' syntax
In-Reply-To: <20000719174747.A30234@emt-p.org>; from insyte@emt-p.org on Wed, Jul 19, 2000 at 05:47:47PM -0500
References: <20000719170907.B30143@emt-p.org> <20000720002242.A16212@pino.selwerd.nl> <20000719174747.A30234@emt-p.org>
Message-ID: <20000720010003.A16280@pino.selwerd.nl>

On Wed, Jul 19, 2000 at 05:47:47PM -0500, Ben Beuchler wrote:
> Hmmm... OK.  I understand how that works.  Now, since I would like to
> include that kind of syntax on almost every file I open, any thoughts on
> doing something like this:
> 
> def safeopen(filename):
> 	try:
> 		handle = open(filename)
> 		return handle
> 	except IOError:
> 		print "Opening", filename, "failed!!"
> 
> And calling it thusly:
> 
> safeopen('worthlessfile')
> 
> Would that make sense as a shortcut?

Depends on what you want to do if it fails, I suppose. If you do f =
safeopen('bla'), you still have to handle the case where f is None, so
the function didn't help, really.

You should use the the try: except: construct at the place where you want to
handle the error condition.

If it's ok to quit the program when an error occurs (that's what "or die"
does, right?) just ignore the error, the program will halt with an error
message.

Well, that's my two cents, have to go sleep now :)
-- 
Remco Gerlich,  scarblac@pino.selwerd.nl


From deirdre@deirdre.net  Wed Jul 19 23:46:38 2000
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Wed, 19 Jul 2000 15:46:38 -0700 (PDT)
Subject: [Tutor] Python equiv of Perl's 'or die()' syntax
In-Reply-To: <20000719174747.A30234@emt-p.org>
Message-ID: <Pine.LNX.4.10.10007191546060.24411-100000@rockhopper.deirdre.org>

On Wed, 19 Jul 2000, Ben Beuchler wrote:

> Hmmm... OK.  I understand how that works.  Now, since I would like to
> include that kind of syntax on almost every file I open, any thoughts on
> doing something like this:
> 
> def safeopen(filename):
> 	try:
> 		handle = open(filename)
> 		return handle
> 	except IOError:
> 		print "Opening", filename, "failed!!"
> 
> And calling it thusly:
> 
> safeopen('worthlessfile')
> 
> Would that make sense as a shortcut?

Sure, as long as you didn't later assume that the file was open. The die
syntax of perl stops execution.

-- 
_Deirdre   *   http://www.sfknit.org   *   http://www.deirdre.net
"Trust me, I'm a science fiction writer" -- Larry Niven @ Conolulu



From Steven Gilmore" <srGilmore@sprintmail.com  Thu Jul 20 04:34:27 2000
From: Steven Gilmore" <srGilmore@sprintmail.com (Steven Gilmore)
Date: Wed, 19 Jul 2000 23:34:27 -0400
Subject: [Tutor] trying to learn python update
Message-ID: <007a01bff1fb$84cee4a0$2cbdf6d1@srgilmor>

I would like to update everybody who replied to my inquiry about Python
books in alternative electronic formats.  Thanks Patrick Phelan for
mentioning the Quick Python Book.  After reading your/his post I did as
suggested and emailed the author to get permission to allow Mr.Phelan to
send an electronic copy of the book, which was free before the book was
released.  Well, the book's authors did more than give their respective
permission, they allowed me to download it in PDF format!  I'm well on my
way to learning this great language, thanks guys/gals :-D

Steven






From Steven Gilmore" <srGilmore@sprintmail.com  Thu Jul 20 04:46:44 2000
From: Steven Gilmore" <srGilmore@sprintmail.com (Steven Gilmore)
Date: Wed, 19 Jul 2000 23:46:44 -0400
Subject: [Tutor] question about cgi and, guess what, Python
Message-ID: <007b01bff1fd$203928a0$2cbdf6d1@srgilmor>

 You guys have been really helpful.  I have another question, this time
about CGI programming.  I would like to continue my education and learn more
about CGI.  My first question is I need a server for Windows strictly for
testing purposes.  Does anybody know of a free, open source  or just free
server?  I don't plan to have any hits, other than mine, of course <Grin>
And maybe some inscriptions on installing Python for CGI.  Is Apache for
win32 stable enough for this purpose?

Thanks in advance,
Steven Gilmore



From Steven Gilmore" <srGilmore@sprintmail.com  Thu Jul 20 05:56:01 2000
From: Steven Gilmore" <srGilmore@sprintmail.com (Steven Gilmore)
Date: Thu, 20 Jul 2000 00:56:01 -0400
Subject: [Tutor] Quick python book
Message-ID: <000e01bff206$cdd9ecc0$9bbbf6d1@srgilmor>

 Please don't email me asking me to send you Quick Python Book in pdf.  I
will not send any copyrighted material to anybody who doesn't have expressed
permission from the authors and/or publishing company.

Steven Gilmore



From dyoo@hkn.EECS.Berkeley.EDU  Thu Jul 20 07:30:32 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Wed, 19 Jul 2000 23:30:32 -0700 (PDT)
Subject: [Tutor] question about cgi and, guess what, Python
In-Reply-To: <007b01bff1fd$203928a0$2cbdf6d1@srgilmor>
Message-ID: <Pine.LNX.4.21.0007192325060.18835-100000@hkn.EECS.Berkeley.EDU>

On Wed, 19 Jul 2000, Steven Gilmore wrote:

>  You guys have been really helpful.  I have another question, this time
> about CGI programming.  I would like to continue my education and learn more
> about CGI.  My first question is I need a server for Windows strictly for
> testing purposes.  Does anybody know of a free, open source  or just free
> server?  I don't plan to have any hits, other than mine, of course <Grin>
> And maybe some inscriptions on installing Python for CGI.  Is Apache for
> win32 stable enough for this purpose?

Try Apache; it's free, it's fast, and it's stable.  *grin* 

To install Python for Apache, you'll probably just add or modify to the
httpd.conf the line:

####
# To use CGI scripts:
AddHandler cgi-script .cgi .py
####

and whatever other extensions you want available as CGI scripts.  This
will allow apache to recognize the '.py' extension as an executable
script.  I'm not sure what else you'll need to do on the win32 side ---
most likely, you'll need to have Python in your path.  Other people should
know more about this.



From wesc@alpha.ece.ucsb.edu  Thu Jul 20 08:30:17 2000
From: wesc@alpha.ece.ucsb.edu (Wesley J. Chun)
Date: Thu, 20 Jul 2000 00:30:17 -0700 (PDT)
Subject: [Tutor] question about cgi and, guess what, Python
Message-ID: <200007200730.AAA28911@alpha.ece.ucsb.edu>

    > From: Daniel Yoo <dyoo@hkn.eecs.berkeley.edu>
    > Date: Wed, 19 Jul 2000 23:30:32 -0700 (PDT)
    > 
    > On Wed, 19 Jul 2000, Steven Gilmore wrote:
    > 
    > > I need a server for Windows strictly for
    > > testing purposes.  Does anybody know of a
    > > free, open source  or just free server?
    > 
    > Try Apache; it's free, it's fast, and it's stable.  *grin* 

as well as the web server that runs most of the web sites out there!

but wait... shouldn't we be eating our own dog food?

use the HTTPServer class in the BaseHTTPServer module to create
the basic web server.  then use one of the following handler
classes to make your server do what you want it to:

SimpleHTTPServer.SimpleHTTPRequestHandler	(does GET, HEAD)
CGIHTTPServer.CGIHTTPRequestHandler		(does CGI)
BaseHTTPServer.BaseHTTPRequestHandler		(does nothing)

Beazley has some examples in Python Essential Reference.

hope this helps!!

-wesley

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

"Core Python Programming", Prentice Hall PTR, TBP Summer 2000
    http://www.phptr.com/ptrbooks/ptr_0130260363.html
    http://www.softpro.com/languages-python.html

wesley.j.chun :: wesc@alpha.ece.ucsb.edu
cyberweb.consulting :: silicon.valley, ca
http://www.roadkill.com/~wesc/cyberweb/


From peterc@brosystems.com  Thu Jul 20 10:10:25 2000
From: peterc@brosystems.com (peter church)
Date: Thu, 20 Jul 2000 10:10:25 +0100
Subject: [Tutor] setting variables off the command line
Message-ID: <3976C200.FA862419@brosystems.com>

Hi there
            I know this is a very simple question to answer but I cannot
find any example  of how it is done in the python docs  I have also
looked in the O'Reilly book as well

    how do I collect variables from users from within a python program
i.e

    print  what is  your name  ?
    read (name)
    print hello name !

thankyou
  Peter



From pm@dis.ro  Thu Jul 20 10:40:27 2000
From: pm@dis.ro (Marcel Preda)
Date: Thu, 20 Jul 2000 11:40:27 +0200
Subject: R: [Tutor] setting variables off the command line
References: <3976C200.FA862419@brosystems.com>
Message-ID: <008401bff22e$8a68bac0$1301000a@punto.it>

> 
>     how do I collect variables from users from within a python program
> i.e
> 
>     print  what is  your name  ?
>     read (name)
>     print hello name !
> 
> thankyou
>   Peter

The `raw_input' function...

>>> name=raw_input('What is your name?\n')
What is your name?
Larry
>>> print "Hi " +name +"\n"
Hi Larry

PM



From alan.gauld@bt.com  Thu Jul 20 17:29:10 2000
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 20 Jul 2000 17:29:10 +0100
Subject: [Tutor] question about cgi and, guess what, Python
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D21F@mbtlipnt02.btlabs.bt.co.uk>

> about CGI.  My first question is I need a server for Windows 
> strictly for testing purposes.  Does anybody know of a free, open source  
> or just free server?  

Much as I hate to promote MS - Whats wrong with Personal Web Server 
that comes free with Win98/NT4 and can be downloaded from MS?

Failing that Apache works on Win32.

Alan G.


From deirdre@deirdre.net  Thu Jul 20 17:29:32 2000
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Thu, 20 Jul 2000 09:29:32 -0700 (PDT)
Subject: [Tutor] question about cgi and, guess what, Python
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D21F@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <Pine.LNX.4.10.10007200927380.28333-100000@rockhopper.deirdre.org>

On Thu, 20 Jul 2000 alan.gauld@bt.com wrote:

> > about CGI.  My first question is I need a server for Windows 
> > strictly for testing purposes.  Does anybody know of a free, open source  
> > or just free server?  
> 
> Much as I hate to promote MS - Whats wrong with Personal Web Server 
> that comes free with Win98/NT4 and can be downloaded from MS?

I thought one of its limitations was no CGI, thus, if I'm correct, it was
not an answer to the question asked.

That said, I'm not a Windows person and I use PHP for web stuff.

-- 
_Deirdre   *   http://www.sfknit.org   *   http://www.deirdre.net
"Trust me, I'm a science fiction writer" -- Larry Niven @ Conolulu



From alan.gauld@bt.com  Thu Jul 20 17:53:11 2000
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Thu, 20 Jul 2000 17:53:11 +0100
Subject: [Tutor] question about cgi and, guess what, Python
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D221@mbtlipnt02.btlabs.bt.co.uk>

> > Much as I hate to promote MS - Whats wrong with Personal Web Server 
> > that comes free with Win98/NT4 and can be downloaded from MS?
> 
> I thought one of its limitations was no CGI, thus, if I'm 
> correct, it was not an answer to the question asked.

I confess not to having done CGI on it, only ASP but it
does have a cgi-bin directory so I kind of just assumed... :-)

Alan G.


From dyoo@hkn.EECS.Berkeley.EDU  Thu Jul 20 18:20:32 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Thu, 20 Jul 2000 10:20:32 -0700 (PDT)
Subject: [Tutor] setting variables off the command line
In-Reply-To: <3976C200.FA862419@brosystems.com>
Message-ID: <Pine.LNX.4.21.0007201009420.24904-100000@hkn.EECS.Berkeley.EDU>

On Thu, 20 Jul 2000, peter church wrote:

>             I know this is a very simple question to answer but I
> cannot find any example of how it is done in the python docs I have
> also looked in the O'Reilly book as well
> 
>     how do I collect variables from users from within a python program
> i.e
> 
>     print  what is  your name  ?
>     read (name)
>     print hello name !

There are a few ways to do this.  A simple way is to use the raw_input()
function, which will return the string the user enters, up to the newline.  
Your program above would look like:

  print "What is your name?"
  name = raw_input()
  print "Hello %s!" % name

The only thing with raw_input() is that it always returns the string
representation, so if you're doing things with numbers, you'll probably
need to do an int() or a float() on your result.


Another way to do input is with the input() function.  It'll read user
input, and evaluate it --- this takes care of having to worry about
coersing your value into a number, but makes inputting strings weirder:


###
>>> x = input()
5
>>> type(x)
<type 'int'>
>>> x
5
>>> s = input()
"hello world"
>>> s
'hello world'
>>> s = input()
hello world
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "<string>", line 1
    hello world
             ^
SyntaxError: unexpected EOF while parsing
###


Notice how inputting a string requires quotes.  However, this does allow
the user to do stuff like

###
>>> import math
>>> x = input("Enter a math function: ")
math.sin(.3)
>>> x
0.295520206661
###


since it's evaluating what you type in at the input, just as if you had
entered it from the interpreter prompt.



From bwisti@hotmail.com  Thu Jul 20 19:10:42 2000
From: bwisti@hotmail.com (Brian Wisti)
Date: Thu, 20 Jul 2000 11:10:42 PDT
Subject: [Tutor] redirect stdout and stderr?
Message-ID: <20000720181042.80024.qmail@hotmail.com>

Hi all,

I am at a bit of a loss here.  What I'm trying seems simple enough: make my 
application send stdout (debug) messages to one file, and stderr (error) 
messages to a different file.

The Python Essential Reference tells me that sys.stdout and sys.stderr hold 
file objects, and all you need to do for redirection is make them hold 
different file objects.

Thinking myself clever, I applied the following code:

(I'm not sure how Hotmail will treat this, so I'll wrap it in pre tags)

<pre>
class MyHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer):
        def __init__(self, server_address, RequestHandlerClass):
                BaseHTTPServer.HTTPServer.__init__(self, server_address, 
RequestHandlerClass)

		# Open files for output redirection
                sys.stdout = open('message.log', 'a')
                sys.stderr = open('error.log', 'a')
                print "Starting server"

        def __del__(self):
                print "Shutting down server"
		# Close redirect files
                sys.stdout.close()
                sys.stderr.close()
                BaseHTTPServer.HTTPServer.__del__(self)
</pre>

The theory is that the HTTP server, which is created as soon as the program 
starts, will send all of its messages to these two files.  It will also be 
kind enough to close those files when it shuts down.

I am obviously missing something, though.  The files are created (if they 
don't already exist), but nothing is ever written to them.  Sadly, nothing 
goes to the terminal, either.

Do I need to close and reopen these files any time the program has something 
interesting to say?  That would be annoying, but not impossible.

Please forgive my ignorance.  I know very little about file handling, and 
even less about file handling in Python.

Any guidelines or strategies would be very helpful!

Thanks in advance,
Brian Wisti

bwisti@hotmail.com
http://www.coolnamehere.com
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com



From dyoo@hkn.EECS.Berkeley.EDU  Thu Jul 20 21:58:39 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Thu, 20 Jul 2000 13:58:39 -0700 (PDT)
Subject: [Tutor] redirect stdout and stderr?
In-Reply-To: <20000720181042.80024.qmail@hotmail.com>
Message-ID: <Pine.LNX.4.21.0007201348460.28511-100000@hkn.EECS.Berkeley.EDU>

On Thu, 20 Jul 2000, Brian Wisti wrote:

> I am at a bit of a loss here.  What I'm trying seems simple enough: make my 
> application send stdout (debug) messages to one file, and stderr (error) 
> messages to a different file.

Yes, that should work fine.  Here's a small interpreter session that
demonstrates redirection:

>>> import sys
>>> sys.stdout = open("test.txt", 'a')
>>> print "Hello World!"
>>> print "This is a test!"
>>> sys.stdout = sys.__stdout__  # restore stdout back to normal
>>> print "Hello World!"
Hello World!
>>> print open("test.txt").read()
Hello World!
This is a test!


Your code looks perfectly fine; you're omitting the 'import sys' in your
code, but that should be in the front of your class definition.  
Otherwise, I can't seem to find anything that would cause a problem.  You
should definitely see a 'Starting server' line in your log.  Strange.

> Do I need to close and reopen these files any time the program has something 
> interesting to say?  That would be annoying, but not impossible.

No, you have it the right way.  They stay open till the file objects are
inaccessible.


> Please forgive my ignorance.  I know very little about file handling, and 
> even less about file handling in Python.

Try the small example above, and make sure that it works.  After that...
hmm... I can't think of a good reason why it would do that.  Hopefully
someone else on the list might give better advice.

I have to ask a silly question: do you have enough hard drive space, and
that you're not over disk quota?

Good luck to you.



From bwisti@hotmail.com  Thu Jul 20 22:24:02 2000
From: bwisti@hotmail.com (Brian Wisti)
Date: Thu, 20 Jul 2000 14:24:02 PDT
Subject: [Tutor] redirect stdout and stderr?
Message-ID: <20000720212402.46962.qmail@hotmail.com>

Thanks.  I tried out your example from the python interpreter, and got the 
same results you did, thus deepening my confusion.

>
>I have to ask a silly question: do you have enough hard drive space, and
>that you're not over disk quota?

This system has no quota, and several Gig of hard drive space available.  So 
I know that's not an issue :)

Hopefully something gets figured out.  Maybe when I get home I can muck 
around with the interpreter and see if I can duplicate the situation with 
simpler code.

Thanks,
Brian Wisti
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com



From insyte@emt-p.org  Thu Jul 20 23:29:34 2000
From: insyte@emt-p.org (Ben Beuchler)
Date: Thu, 20 Jul 2000 17:29:34 -0500
Subject: [Tutor] printing columns
Message-ID: <20000720172934.B30859@emt-p.org>

I have a list of around 650 or so items.  I would like to be able to
print them in columns, three across, like so:

item1		item2		item3
item4		item5		item6
item7		item8		item9

Any suggestions on a clean way to accomplish this?  The items will be of
varying width, so just adding tabs won't reliably format them.

Thanks,
Ben

-- 
Ben Beuchler                                         insyte@bitstream.net
MAILER-DAEMON                                         (612)-321-9290 x101
Bitstream Underground                                   www.bitstream.net


From shaleh@valinux.com  Fri Jul 21 00:28:08 2000
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Thu, 20 Jul 2000 16:28:08 -0700
Subject: [Tutor] redirect stdout and stderr?
In-Reply-To: <20000720212402.46962.qmail@hotmail.com>; from bwisti@hotmail.com on Thu, Jul 20, 2000 at 02:24:02PM -0700
References: <20000720212402.46962.qmail@hotmail.com>
Message-ID: <20000720162808.B18165@valinux.com>

On Thu, Jul 20, 2000 at 02:24:02PM -0700, Brian Wisti wrote:
> 
> This system has no quota, and several Gig of hard drive space available.  So 
> I know that's not an issue :)
> 
> Hopefully something gets figured out.  Maybe when I get home I can muck 
> around with the interpreter and see if I can duplicate the situation with 
> simpler code.
> 

Where is the line:

import sys

in your code?  If there is not too much code, send the entire py file next
time around.


From Steven Gilmore" <srGilmore@sprintmail.com  Fri Jul 21 00:31:03 2000
From: Steven Gilmore" <srGilmore@sprintmail.com (Steven Gilmore)
Date: Thu, 20 Jul 2000 19:31:03 -0400
Subject: [Tutor] I think I'm getting ahead of myself
Message-ID: <008b01bff2a2$9300f340$73b8f6d1@srgilmor>

 I am reading "How to Think like a Computer Scientist".  I can only get half
of the examples to work.  Like the recursive example below:

def countdown(n):
    if n == 0:
       print "Blastoff!"
    else:
       print n
       countdown(n-1)

  I'm saving the script in a sub directory of the python directory.  I'm
using Windows. I tried adding the directory to the path with

>>> import sys
>>>sys.path.append("d:\python\pyscript")

then I run the script in IDLE

>>> import test
>>> countdown(3)
Traceback (innermost last):
  File "<pyshell#4>", line 1, in ?
    countdown(3)
NameError: countdown

what's the deal?

Thanks
Steven Gilmore



From shaleh@valinux.com  Fri Jul 21 00:54:01 2000
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Thu, 20 Jul 2000 16:54:01 -0700
Subject: [Tutor] I think I'm getting ahead of myself
In-Reply-To: <008b01bff2a2$9300f340$73b8f6d1@srgilmor>; from srGilmore@sprintmail.com on Thu, Jul 20, 2000 at 07:31:03PM -0400
References: <008b01bff2a2$9300f340$73b8f6d1@srgilmor>
Message-ID: <20000720165401.D18165@valinux.com>

On Thu, Jul 20, 2000 at 07:31:03PM -0400, Steven Gilmore wrote:
> 
> then I run the script in IDLE
> 
> >>> import test
> >>> countdown(3)
> Traceback (innermost last):
>   File "<pyshell#4>", line 1, in ?
>     countdown(3)
> NameError: countdown
> 
> what's the deal?

I assume you named the script that contains countdown() test.py.  When you
import a module, you have to refer to it as module.object.  So in this case:

test.countdown(3)

otherwise:

from test import countdown
countdown(3)

will work.


From insyte@emt-p.org  Fri Jul 21 00:56:43 2000
From: insyte@emt-p.org (Ben Beuchler)
Date: Thu, 20 Jul 2000 18:56:43 -0500
Subject: [Tutor] I think I'm getting ahead of myself
In-Reply-To: <008b01bff2a2$9300f340$73b8f6d1@srgilmor>; from srGilmore@sprintmail.com on Thu, Jul 20, 2000 at 07:31:03PM -0400
References: <008b01bff2a2$9300f340$73b8f6d1@srgilmor>
Message-ID: <20000720185642.A32557@emt-p.org>

On Thu, Jul 20, 2000 at 07:31:03PM -0400, Steven Gilmore wrote:

> >>> import test
> >>> countdown(3)
> Traceback (innermost last):
>   File "<pyshell#4>", line 1, in ?
>     countdown(3)
> NameError: countdown
> 
> what's the deal?

Since you imported it as part of a module, you need to specify the
module thusly:

test.countdown(3)

Or import it like so:

from test import countdown

Then you would be able to call countdown directly:

countdown(3)



Ben

-- 
Ben Beuchler                                         insyte@bitstream.net
MAILER-DAEMON                                         (612)-321-9290 x101
Bitstream Underground                                   www.bitstream.net


From dyoo@hkn.EECS.Berkeley.EDU  Fri Jul 21 01:00:32 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Thu, 20 Jul 2000 17:00:32 -0700 (PDT)
Subject: [Tutor] I think I'm getting ahead of myself
In-Reply-To: <008b01bff2a2$9300f340$73b8f6d1@srgilmor>
Message-ID: <Pine.LNX.4.21.0007201649440.31891-100000@hkn.EECS.Berkeley.EDU>

On Thu, 20 Jul 2000, Steven Gilmore wrote:

> >>> import sys
> >>>sys.path.append("d:\python\pyscript")

Be careful of those backslashes --- they signal a 'control' or 'escape'
character in Python and other computer languages.  As a quick answer, try:

  sys.path.append(r"d:\python\pyscript")

instead.  (The 'r' in front of the quotes means 'raw' --- it tells Python
to treat backslashes as literal backslashes.)  Of course, this is
completely unrelated to the immediate problem, which is modules and
functions.  *grin*


> >>> import test
> >>> countdown(3)
> Traceback (innermost last):
>   File "<pyshell#4>", line 1, in ?
>     countdown(3)
> NameError: countdown
> 
> what's the deal?


Ok, the real problem is that you need to specify the module, as well as
the name of the function.  Since the countdown function is located in your
'test' module, you need to execute it as:

  test.countdown(3)

This is because importing a module doesn't make its functions directly
available --- you still have to give the name of the module in front.



If this is awkward, there is a way to get around this by using the
"from/import" syntax:

  from test import countdown  # just get countdown

or

  from test import *    # grab every function out of test


If you do this, then you can just say

  countdown(3)

and it should work.



From bwisti@hotmail.com  Fri Jul 21 01:07:53 2000
From: bwisti@hotmail.com (Brian Wisti)
Date: Thu, 20 Jul 2000 17:07:53 PDT
Subject: [Tutor] redirect stdout and stderr?
Message-ID: <20000721000753.91537.qmail@hotmail.com>

>
>Where is the line:
>
>import sys
>
>in your code?  If there is not too much code, send the entire py file next
>time around.

'import sys' is near the top of the file.  It was improper of me to assume 
that you would assume it was there ;)

Right now, the file is around 2000 lines.  I didn't quite feel like sending 
all of it (and I don't think my employers would have appreciated it either).

Thanks,
Brian Wisti
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com



From theanh@webteam.vnn.vn  Fri Jul 21 05:24:25 2000
From: theanh@webteam.vnn.vn (theanh )
Date: Fri, 21 Jul 2000 11:24:25 +0700
Subject: [Tutor] How active python file in IIS5.0
Message-ID: <200007211124.AA82378854@webteam.vnn.vn>

Hi all members,
I have just setup Python into my server, my platform is windows2000  and has IIS5.0. Now I want to active python files like cgi file but can not. I have tried to assign path of Python compile at top of script (like in Unix system), but result is the same.
Beside this, I tried to place python file in some directories (scripts or wwwroot, etc) but web server still can not execute python file.
Please give me some advises, Thank a lot.


From richard_chamberlain@ntlworld.com  Fri Jul 21 07:28:15 2000
From: richard_chamberlain@ntlworld.com (Richard Chamberlain)
Date: Fri, 21 Jul 2000 07:28:15 +0100
Subject: [Tutor] printing columns
References: <20000720172934.B30859@emt-p.org>
Message-ID: <000b01bff2dc$dade6c80$b061fea9@richardc>

Hi Ben,

Why not use:

print "%6s %6s %6s" %(thelist[item1],thelist[item2],thelist[item3])

Richard
----- Original Message ----- 
From: Ben Beuchler <insyte@emt-p.org>
To: <tutor@python.org>
Sent: Thursday, July 20, 2000 11:29 PM
Subject: [Tutor] printing columns


> I have a list of around 650 or so items.  I would like to be able to
> print them in columns, three across, like so:
> 
> item1 item2 item3
> item4 item5 item6
> item7 item8 item9
> 
> Any suggestions on a clean way to accomplish this?  The items will be of
> varying width, so just adding tabs won't reliably format them.
> 
> Thanks,
> Ben
> 
> -- 
> Ben Beuchler                                         insyte@bitstream.net
> MAILER-DAEMON                                         (612)-321-9290 x101
> Bitstream Underground                                   www.bitstream.net
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor



From wesc@alpha.ece.ucsb.edu  Fri Jul 21 09:29:49 2000
From: wesc@alpha.ece.ucsb.edu (Wesley J. Chun)
Date: Fri, 21 Jul 2000 01:29:49 -0700 (PDT)
Subject: [Tutor] printing columns
Message-ID: <200007210829.BAA04964@alpha.ece.ucsb.edu>

    > From: "Richard Chamberlain" <richard_chamberlain@ntlworld.com>
    > Date: Fri, 21 Jul 2000 07:28:15 +0100
    > 
    > Hi Ben,
    > 
    > Why not use:
    > 
    > print "%6s %6s %6s" %(thelist[item1],thelist[item2],thelist[item3])

or, to enhance this story...

i = 1
while i < 650:
    print "%6s %6s %6s" % (thelist[i], thelist[i+1], thelist[i+2])
    i = i + 3

hope this helps!!

-wesley

    > 
    > Richard
    > ----- Original Message ----- 
    > From: Ben Beuchler <insyte@emt-p.org>
    > Sent: Thursday, July 20, 2000 11:29 PM
    > 
    > > I have a list of around 650 or so items.  I would like to be able to
    > > print them in columns, three across, like so:
    > > 
    > > item1 item2 item3
    > > item4 item5 item6
    > > item7 item8 item9
    > > 
    > > Any suggestions on a clean way to accomplish this?  The items will be of
    > > varying width, so just adding tabs won't reliably format them.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Bay Area Python Users' Group:  http://www.baypiggies.org

"Core Python Programming", Prentice Hall PTR, TBP Summer 2000
    http://www.phptr.com/ptrbooks/ptr_0130260363.html
    http://www.softpro.com/languages-python.html

wesley.j.chun :: wesc@alpha.ece.ucsb.edu
cyberweb.consulting :: silicon.valley, ca
http://www.roadkill.com/~wesc/cyberweb/


From arcege@shore.net  Fri Jul 21 13:04:23 2000
From: arcege@shore.net (Michael P. Reilly)
Date: Fri, 21 Jul 2000 08:04:23 -0400 (EDT)
Subject: [Tutor] printing columns
In-Reply-To: <200007210829.BAA04964@alpha.ece.ucsb.edu> from "Wesley J. Chun" at Jul 21, 2000 01:29:49 AM
Message-ID: <200007211204.IAA07207@northshore.shore.net>

> 
>     > From: "Richard Chamberlain" <richard_chamberlain@ntlworld.com>
>     > Date: Fri, 21 Jul 2000 07:28:15 +0100
>     > 
>     > Hi Ben,
>     > 
>     > Why not use:
>     > 
>     > print "%6s %6s %6s" %(thelist[item1],thelist[item2],thelist[item3])
> 
> or, to enhance this story...
> 
> i = 1
> while i < 650:
>     print "%6s %6s %6s" % (thelist[i], thelist[i+1], thelist[i+2])
>     i = i + 3
> 
> hope this helps!!

Or even further:

ncols = 3
for i in xrange(0, len(thelist), ncols): # for small ranges, use range()
    print ...

Remember that range() and xrange() return first-class objects which can
be passed (or saved in a class instance).

  -Arcege

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


From alan.gauld@bt.com  Fri Jul 21 17:14:44 2000
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 21 Jul 2000 17:14:44 +0100
Subject: [Tutor] printing columns
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D22E@mbtlipnt02.btlabs.bt.co.uk>

> I have a list of around 650 or so items.  I would like to be able to
> print them in columns, three across, like so:
> 
> item1		item2		item3
> item4		item5		item6
> item7		item8		item9
> 
> Any suggestions on a clean way to accomplish this?  

Use format?

print "%12s%12s%12s" % (item1,item2,item3)

prints 3 items each occupying 12 spaces.

Alan G.


From alan.gauld@bt.com  Fri Jul 21 17:16:24 2000
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 21 Jul 2000 17:16:24 +0100
Subject: [Tutor] I think I'm getting ahead of myself
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D22F@mbtlipnt02.btlabs.bt.co.uk>

> >>> import sys
> >>>sys.path.append("d:\python\pyscript")
> 
> then I run the script in IDLE
> 
> >>> import test
> >>> countdown(3)
> Traceback (innermost last):
>   File "<pyshell#4>", line 1, in ?
>     countdown(3)
> NameError: countdown
> 
> what's the deal?


You need to prefix countdown with test:

>>> import test
>>> test.countdown(3)
3
2
1
Blast Off

Alan G.


From Steven Gilmore" <srGilmore@sprintmail.com  Fri Jul 21 19:17:09 2000
From: Steven Gilmore" <srGilmore@sprintmail.com (Steven Gilmore)
Date: Fri, 21 Jul 2000 14:17:09 -0400
Subject: [Tutor] I think I'm getting ahead of myself 2
Message-ID: <001d01bff33f$e37a5e40$ebb5f6d1@srgilmor>

 thanks guys/gals!  I feel humbled (dumb) to have missed that but I guess
that's how we learn.  <grin>

Hope everybody has a good weekend
Steven Gilmore



From insyte@emt-p.org  Fri Jul 21 19:24:08 2000
From: insyte@emt-p.org (Ben Beuchler)
Date: Fri, 21 Jul 2000 13:24:08 -0500
Subject: [Tutor] printing columns
In-Reply-To: <000b01bff2dc$dade6c80$b061fea9@richardc>; from richard_chamberlain@ntlworld.com on Fri, Jul 21, 2000 at 07:28:15AM +0100
References: <20000720172934.B30859@emt-p.org> <000b01bff2dc$dade6c80$b061fea9@richardc>
Message-ID: <20000721132408.B2072@emt-p.org>

On Fri, Jul 21, 2000 at 07:28:15AM +0100, Richard Chamberlain wrote:

> print "%6s %6s %6s" %(thelist[item1],thelist[item2],thelist[item3])

Thanks to everyone that replied with variations on this theme!  My
ignorance of the c printf() is showing...

Thanks again!

Ben

-- 
Ben Beuchler                                         insyte@bitstream.net
MAILER-DAEMON                                         (612) 321-9290 x101
Bitstream Underground                                   www.bitstream.net


From da_woym@hotmail.com  Fri Jul 21 19:46:36 2000
From: da_woym@hotmail.com (Jacob Williams)
Date: Fri, 21 Jul 2000 18:46:36 GMT
Subject: [Tutor] VERY newbie question
Message-ID: <LAW-F24oGTVdSmixLh50000403e@hotmail.com>

Why won't this work, and/or how can I get this to work?

import sys
name = raw_input("Enter name of the dir: ")
sys.path.append("C:\ + name")

thanks for your support, and patience with such a newbie question,


------------------------
|   Jacob Williams     |
| Da_woym@hotmail.com  |
------------------------

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com



From bear@efirms.com  Fri Jul 21 19:54:18 2000
From: bear@efirms.com (Gary Coulbourne)
Date: Fri, 21 Jul 2000 14:54:18 -0400
Subject: [Tutor] Class causing segmentation fault???
Message-ID: <39789C5A.E481644F@efirms.com>

Howdy, folks!  I'm sure there's a better way to do what I'm trying to
do, but if there is, I think it should raise an exception instead of
dumping core...  

In any case, I have the following class in a file called vector.py:

##########################3

from math import *
 
class vector:
 
        v1=0.0 # The x,y,z of the vector
        v2=0.0
        v3=0.0
 
        def __init__(self,v1Value=0.0,v2Value=0.0,v3Value=0.0):
                #Check and see if numbers or a vector was passed
                if type(v1Value)==type(1):
                        self.v1=v1Value
                        self.v2=v2Value
                        self.v3=v3Value
                elif type(v1Value)==type(vector()):
                        self.v1=v1Value.v1
                        self.v2=v1Value.v2
                        self.v3=v1Value.v3
                else:
                        raise "VectorError"
 
        def length(self):
                return
sqrt(pow(self.v1,2)+pow(self.v2,2)+pow(self.v3,2))
 
        def normalize(self):
                len=self.length()
                self.v1=self.v1/len
                self.v2=self.v2/len
                self.v3=self.v3/len
 
        def __repr__(self):
                return "[%d,%d,%d]" % (self.v1,self.v2,self.v3)     

# Build the default axis
xAxis=vector(1,0,0)
yAxis=vector(0,1,0)
zAxis=vector(0,0,1)     

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

Since python doesn't allow overloading (I don't think), I've got the
elif up there so that it checks to see if the type sent in is the same
as a vector instance, and if it is, copy the values.

So, I fire up the python interpreter, and do this:

Python 1.5.2 (#1, May  9 2000, 15:05:56)  [GCC 2.95.3 19991030
(prerelease)] onlinux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from vector import *
>>> a=xAxis
>>> b=vector(a)
Segmentation fault     <---- WOW!

It SegVs.  Drops core.  I was wondering if anyone knew why?  And if
there is a better way to write a constructor to do what I'm attempting
up there.  Thanks!

-- 
Cheers,
   Gary

     *********    *****    **                  Gary Coulbourne
    *************************.*            Director of Tech. R & D
   ****** *********** ** *******o              efirms.com, Inc.
   ******* ********* **** ****`-
   ******* ********* *****                  http://www.efirms.com
    ****** ********** ****                     bear@efirms.com
   ## *****  ***** ##  ****
   ### *****      ###   ****
   #,,, ***,,,    ##,,,  **,,,


From shaleh@valinux.com  Fri Jul 21 20:30:37 2000
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Fri, 21 Jul 2000 12:30:37 -0700 (PDT)
Subject: [Tutor] VERY newbie question
In-Reply-To: <LAW-F24oGTVdSmixLh50000403e@hotmail.com>
Message-ID: <XFMail.20000721123037.shaleh@valinux.com>

On 21-Jul-2000 Jacob Williams wrote:
> Why won't this work, and/or how can I get this to work?
> 
> import sys
> name = raw_input("Enter name of the dir: ")
> sys.path.append("C:\ + name")
> 
> thanks for your support, and patience with such a newbie question,
> 

geisha [~] $ python
Python 1.5.2 (#0, Apr  3 2000, 14:46:48)  [GCC 2.95.2 20000313 (Debian
GNU/Linux)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> a = "Hello" 
>>> b = "World"
>>> string = a + ", " + b
>>> print string
Hello, World
>>> import sys
>>> name = raw_input("Enter name of the dir: ")
Enter name of the dir: foo
>>> print name
foo
>>> print "C:\ + name" 
C:\ + name
>>> print "C:\" + name
  File "<stdin>", line 1
    print "C:\" + name
                     ^
SyntaxError: invalid token
>>> print "C:\\" + name
C:\foo

As you typed it, it should print "C:\ + name".  Also watch out for '\' it
escapes the character in front of it.  It is a good idea to always use \\ or
function(r"c:\path"), the r means do not escape things in side the string.


From dyoo@hkn.EECS.Berkeley.EDU  Fri Jul 21 21:51:39 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Fri, 21 Jul 2000 13:51:39 -0700 (PDT)
Subject: [Tutor] printing columns
In-Reply-To: <20000720172934.B30859@emt-p.org>
Message-ID: <Pine.LNX.4.21.0007201638480.31891-100000@hkn.EECS.Berkeley.EDU>

On Thu, 20 Jul 2000, Ben Beuchler wrote:

> I have a list of around 650 or so items.  I would like to be able to
> print them in columns, three across, like so:
> 
> item1		item2		item3
> item4		item5		item6
> item7		item8		item9
> 
> Any suggestions on a clean way to accomplish this?  The items will be of
> varying width, so just adding tabs won't reliably format them.


It sounds like you might want a function to pad a string to a fixed width.  
Other people have suggested using:

  print "%10s%10s%10s" % (item[i], item[i+1], item[i+2])

which will work well.  It will, however, be padded with spaces to the
left, where we actually want padding on the right.  For example:

>>> print "%10s%10s%10s" % ('hello', 'world', 'test')
     hello     world      test


If you really need to have it pad on the right side instead, you could
write a small function to do it for you.  Here's one that's really simple:

### 
def getRightPaddedString(mystring, width, padding_char=' '):
  return mystring + padding_char * (width - len(mystring))
###


Here's a demonstration of it:

>>> getRightPaddedString('item7', 10)
'item7     '
>>> getRightPaddedString('item17', 10)
'item17    '


Once you have something like getPaddedString, you can map the function
across all elements of your list:

  paddeditems = map(getPaddedString, items)

and do a simple loop through all your paddeditems, keeping track of how
many you've processed so far, and print a newline character whenever you
hit an index multiple of 3.

There are many ways of doing the output, so you might want to experiment
and see which is effective for you.



From dyoo@hkn.EECS.Berkeley.EDU  Fri Jul 21 22:02:51 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Fri, 21 Jul 2000 14:02:51 -0700 (PDT)
Subject: [Tutor] VERY newbie question
In-Reply-To: <LAW-F24oGTVdSmixLh50000403e@hotmail.com>
Message-ID: <Pine.LNX.4.21.0007211354580.15897-100000@hkn.EECS.Berkeley.EDU>

On Fri, 21 Jul 2000, Jacob Williams wrote:

> Why won't this work, and/or how can I get this to work?
> 
> import sys
> name = raw_input("Enter name of the dir: ")
> sys.path.append("C:\ + name")

There are 2 small bugs.  The most important one is the quoting of
'name'; you probably meant to do

  "C:\" + name

instead.

The other one is obscure to new users; the backslash character, '\', is
special in Python strings.  It indicates a control ("escape") sequence.  
Some of these are useful; for example, "\n" means "skip to a new
line".  Try this out, and you'll understand:

  print "Hello, this is\non another\nline.\t\tThis is tabbed a bit."

There are a few escape sequences.  The example above uses '\n'
(newline) and '\t' (tab).  To tell Python not to see the backslash as an
escape, you can trap it using "raw" string notation:

  r"C:\"

Put an 'r' in front of your string quotes, and it should be ok.

If you have any other questions, feel free to ask.  Good luck to you!



From dyoo@hkn.EECS.Berkeley.EDU  Sat Jul 22 00:07:18 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Fri, 21 Jul 2000 16:07:18 -0700 (PDT)
Subject: [Tutor] Class causing segmentation fault???
In-Reply-To: <39789C5A.E481644F@efirms.com>
Message-ID: <Pine.LNX.4.21.0007211600540.17888-100000@hkn.EECS.Berkeley.EDU>

>         def __init__(self,v1Value=0.0,v2Value=0.0,v3Value=0.0):
>                 #Check and see if numbers or a vector was passed
>                 if type(v1Value)==type(1):
>                         self.v1=v1Value
>                         self.v2=v2Value
>                         self.v3=v3Value
>                 elif type(v1Value)==type(vector()):
> >>> a=xAxis
> >>> b=vector(a)
> Segmentation fault     <---- WOW!


Ok, this scared me for a second, but there's a good reason for the
segfault --- there's an infinite loop!  Let's pretend to be the
interpreter for a second:  Since the type of v1Value isn't an integer, we
go the elif.

>                 elif type(v1Value)==type(vector()):

So we try recursively constructing the default vector, with default
arguments 0.0, 0.0, 0.0, so we can do the 'type(vector())' However, here's
the tricky part:

>>> type(0.0)
<type 'float'>
>>> type(0)
<type 'int'>

Guess what happens.  Wash, rinse, repeat.

To fix this, you need to make sure that you can construct the default
vector.  It segfaulted because it ran out of memory.  (Still, this is
quite bad, and should have been checked for by the mem-allocator routine.)



From scarblac@pino.selwerd.nl  Sat Jul 22 20:35:31 2000
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Sat, 22 Jul 2000 21:35:31 +0200
Subject: [Tutor] VERY newbie question
In-Reply-To: <Pine.LNX.4.21.0007211354580.15897-100000@hkn.EECS.Berkeley.EDU>; from dyoo@hkn.EECS.Berkeley.EDU on Fri, Jul 21, 2000 at 02:02:51PM -0700
References: <LAW-F24oGTVdSmixLh50000403e@hotmail.com> <Pine.LNX.4.21.0007211354580.15897-100000@hkn.EECS.Berkeley.EDU>
Message-ID: <20000722213531.A20524@pino.selwerd.nl>

On Fri, Jul 21, 2000 at 02:02:51PM -0700, Daniel Yoo wrote:
> The other one is obscure to new users; the backslash character, '\', is
> special in Python strings.  It indicates a control ("escape") sequence.  
> Some of these are useful; for example, "\n" means "skip to a new
> line".  Try this out, and you'll understand:
> 
>   print "Hello, this is\non another\nline.\t\tThis is tabbed a bit."
> 
> There are a few escape sequences.  The example above uses '\n'
> (newline) and '\t' (tab).  To tell Python not to see the backslash as an
> escape, you can trap it using "raw" string notation:
> 
>   r"C:\"
> 
> Put an 'r' in front of your string quotes, and it should be ok.

Ah, but this is unfortunate, it still doesn't work. Since it should still
be possible to include " signs in a raw string, they are in fact escaped
(the \-es are left in the string). Printing r"\"" prints \".
So raw strings can never end in an odd number of backslashes... Newbies
shouldn't have to deal with this stuff.

"C:\\" Does work. So does r"C:\ " (with a space).

Also, you can use / inside a path. "C:/Program Files/etc" is a completely
legal Windows path, it can use both. It looks unusual though.

-- 
Remco Gerlich,  scarblac@pino.selwerd.nl


From dyoo@hkn.EECS.Berkeley.EDU  Sat Jul 22 20:40:52 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Sat, 22 Jul 2000 12:40:52 -0700 (PDT)
Subject: [Tutor] Class causing segmentation fault???
In-Reply-To: <39798108.8030203@efirms.com>
Message-ID: <Pine.LNX.4.21.0007221228390.31707-100000@hkn.EECS.Berkeley.EDU>

> Replacing this with:
> 
>    if type(v1Value)==type(1) or type(v1Value)==type(1.0)
> 
> solved the problem.  Thanks muchly!

Sure, no problem.  One other thing you'll probably want to do is make sure
you're taking care of the Long integer type too.

Here's a convoluted function to check for numeric types.  For fun, I'm
using the 'types' module and isinstance() function:

###
def isNumeric(x):
  from types import IntType, LongType, FloatType, ComplexType
  numerics = [IntType, LongType, FloatType, ComplexType]
  for n in numerics:
    if isinstance(x, n):
      return 1
  return 0
###



From Steven Gilmore" <srGilmore@sprintmail.com  Sun Jul 23 00:42:25 2000
From: Steven Gilmore" <srGilmore@sprintmail.com (Steven Gilmore)
Date: Sat, 22 Jul 2000 19:42:25 -0400
Subject: [Tutor] account class
Message-ID: <001801bff436$7e249040$1fb4f6d1@srgilmor>

I'm trying to write a class that models a bank account. I've started simple
with a deposit method, a print statement method, and balance property (I
haven't gotten to the interest yet).  Maybe I'm missing something though I
can't figure out what.  Since you guys/gals have been helpful so far maybe
somebody could shed so light.

Tell me it I have got this right
(exaggerated comments)

class Account:
#when a new instance of this class is created,  this line is called #
     def __init__(self):
           self.balance =  0.0
 #this sets the balance property to the value of the argument#
     def deposit(self,balance):
          self.balance= balance
  #prints a statement #
     def  statement():
          print balance

>>> import account
>>> a = account.Account()
>>> a.deposit(1.0)
>>> a.statement()
Traceback (innermost last):
  File "<interactive input>", line 0, in ?
TypeError: no arguments expected

hope that's enough info for ya to help me     :)

thanks in advance
Steven Gilmore



From scarblac@pino.selwerd.nl  Sun Jul 23 00:56:52 2000
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Sun, 23 Jul 2000 01:56:52 +0200
Subject: [Tutor] account class
In-Reply-To: <001801bff436$7e249040$1fb4f6d1@srgilmor>; from srGilmore@sprintmail.com on Sat, Jul 22, 2000 at 07:42:25PM -0400
References: <001801bff436$7e249040$1fb4f6d1@srgilmor>
Message-ID: <20000723015652.A20742@pino.selwerd.nl>

On Sat, Jul 22, 2000 at 07:42:25PM -0400, Steven Gilmore wrote:
> I'm trying to write a class that models a bank account. I've started simple
> with a deposit method, a print statement method, and balance property (I
> haven't gotten to the interest yet).  Maybe I'm missing something though I
> can't figure out what.  Since you guys/gals have been helpful so far maybe
> somebody could shed so light.
> 
> Tell me it I have got this right
> (exaggerated comments)
> 
> class Account:
> #when a new instance of this class is created,  this line is called #
>      def __init__(self):
>            self.balance =  0.0
>  #this sets the balance property to the value of the argument#
>      def deposit(self,balance):
>           self.balance= balance
>   #prints a statement #
>      def  statement():
>           print balance
> 
> >>> import account
> >>> a = account.Account()
> >>> a.deposit(1.0)
> >>> a.statement()
> Traceback (innermost last):
>   File "<interactive input>", line 0, in ?
> TypeError: no arguments expected
> 
> hope that's enough info for ya to help me     :)

Just change that into 
    def statement(self):
        print self.balance
		
Every method *must* have the instance as its first arguments, since
the construct "instance.method()" (like "a.statement()") silently
sends that argument. You'll get used to it :-)

-- 
Remco Gerlich,  scarblac@pino.selwerd.nl


From dyoo@hkn.EECS.Berkeley.EDU  Sun Jul 23 01:00:25 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Sat, 22 Jul 2000 17:00:25 -0700 (PDT)
Subject: [Tutor] account class
In-Reply-To: <001801bff436$7e249040$1fb4f6d1@srgilmor>
Message-ID: <Pine.LNX.4.21.0007221654500.2066-100000@hkn.EECS.Berkeley.EDU>

On Sat, 22 Jul 2000, Steven Gilmore wrote:
>   #prints a statement #
>      def  statement():
>           print balance

Class methods need to take 'self' as its first argument.  The reason's
because Python needs to know what 'balance' you mean --- you could make a
bunch of bank statements in your program, so statement() needs that
parameter.  When you say something like:

  a.statement()

Python will pass 'a' as the first parameter in statement.  This explains
the error message "TypeError: no arguments expected".

Good luck!



From djansen@pobox.com  Sun Jul 23 01:11:51 2000
From: djansen@pobox.com (David Jansen)
Date: Sun, 23 Jul 2000 09:11:51 +0900
Subject: [Tutor] fileinput
Message-ID: <LPBBJDDFLFLMCKPODBMLEEOPCIAA.djansen@pobox.com>

I wanted to try out this idiom I came across in comp.lang.python but I am
getting an attribute error...


import fileinput

for line in fileinput.input('d:\python\test.txt'):
    print line

Traceback (innermost last):
  File "C:\Program Files\Python\Pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "D:\Python\fileInput.py", line 3, in ?
    for line in fileinput.input("D:\Python\test.txt"):
AttributeError: input

I checked the documentation and the above is typical usage...

Thank you,
David Jansen



From scarblac@pino.selwerd.nl  Sun Jul 23 01:29:40 2000
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Sun, 23 Jul 2000 02:29:40 +0200
Subject: [Tutor] fileinput
In-Reply-To: <LPBBJDDFLFLMCKPODBMLEEOPCIAA.djansen@pobox.com>; from djansen@pobox.com on Sun, Jul 23, 2000 at 09:11:51AM +0900
References: <LPBBJDDFLFLMCKPODBMLEEOPCIAA.djansen@pobox.com>
Message-ID: <20000723022940.A20837@pino.selwerd.nl>

On Sun, Jul 23, 2000 at 09:11:51AM +0900, David Jansen wrote:
> I wanted to try out this idiom I came across in comp.lang.python but I am
> getting an attribute error...
> 
> 
> import fileinput
> 
> for line in fileinput.input('d:\python\test.txt'):
>     print line

This isn't the error described, but you should be aware that \ has a special
meaning in Python strings. Use \\ instead, or / (Windows accepts paths with
slashes too).
 
> Traceback (innermost last):
>   File "C:\Program Files\Python\Pythonwin\pywin\framework\scriptutils.py",
> line 310, in RunScript
>     exec codeObject in __main__.__dict__
>   File "D:\Python\fileInput.py", line 3, in ?
>     for line in fileinput.input("D:\Python\test.txt"):
> AttributeError: input
> 
> I checked the documentation and the above is typical usage...

Unlucky. You called your module "fileInput.py". Since Windows files aren't
case sensitive, that's the same as "fileinput.py". Python imported your
module instead of the standard, and your module has no input function.
(I think this is what happened; test with a input() function in your code).

Otherwise, you must have assigned to fileinput after the import. Fileinput
has an attribute called "input", after all.

-- 
Remco Gerlich,  scarblac@pino.selwerd.nl


From nothingisgoingtochangemyworld@yahoo.com  Sun Jul 23 18:06:55 2000
From: nothingisgoingtochangemyworld@yahoo.com (Joseph Stubenrauch)
Date: Sun, 23 Jul 2000 10:06:55 -0700 (PDT)
Subject: [Tutor] newbie TK question
Message-ID: <20000723170655.19366.qmail@web1902.mail.yahoo.com>

Hello,

I am sure that the answer is sitting right under my
nose, but I've been rummaging through the oneline
Tkinter documents and can't find a straight answer or
good example.  The solution, I have a feeling, is
simple.

I am trying to create an "Entry" widget that takes its
contents and puts them in a string whenever the user
hits the enter key (or perhaps a submit button, but I
am hoping for enter).

In other words, if the user types "wakka wakka" into
the Entry widget at hits enter, it creates a string
(named answer for example) that equals wakka wakka.

The Tk tutorial page mentions get() => string but I'm
not quite sure how to incorporate that and how to make
it a command that is triggered by a button press or
the enter key.

Thanks in advance for the input!

Newbiely,
Joe

__________________________________________________
Do You Yahoo!?
Get Yahoo! Mail – Free email you can access from anywhere!
http://mail.yahoo.com/


From richard_chamberlain@ntlworld.com  Sun Jul 23 18:44:49 2000
From: richard_chamberlain@ntlworld.com (Richard Chamberlain)
Date: Sun, 23 Jul 2000 18:44:49 +0100
Subject: [Tutor] newbie TK question
References: <20000723170655.19366.qmail@web1902.mail.yahoo.com>
Message-ID: <000501bff4cd$b39c4820$b061fea9@richardc>

Hi Joseph,

from Tkinter import *
root=Tk()
myStringVar=StringVar()
entry=Entry(root,textvariable=myStringVar,width=30)
def entryReturn(event):
    str=myStringVar.get()
    print str
    myStringVar.set('')
entry.bind('<Return>',entryReturn)
entry.pack()
root.mainloop()

Entry (and a few other widgets) have a textvariable option to which you give
an instance of StringVar. After that your instance (in the case above
myStringVar) has a set and a get method. So I bind a <Return> event to the
entryReturn method and then use .get() to get the contents of the entry.

Richard
----- Original Message -----
From: Joseph Stubenrauch <nothingisgoingtochangemyworld@yahoo.com>
To: <tutor@python.org>
Sent: Sunday, July 23, 2000 6:06 PM
Subject: [Tutor] newbie TK question


> Hello,
>
> I am sure that the answer is sitting right under my
> nose, but I've been rummaging through the oneline
> Tkinter documents and can't find a straight answer or
> good example.  The solution, I have a feeling, is
> simple.
>
> I am trying to create an "Entry" widget that takes its
> contents and puts them in a string whenever the user
> hits the enter key (or perhaps a submit button, but I
> am hoping for enter).
>
> In other words, if the user types "wakka wakka" into
> the Entry widget at hits enter, it creates a string
> (named answer for example) that equals wakka wakka.
>
> The Tk tutorial page mentions get() => string but I'm
> not quite sure how to incorporate that and how to make
> it a command that is triggered by a button press or
> the enter key.
>
> Thanks in advance for the input!
>
> Newbiely,
> Joe
>
> __________________________________________________
> Do You Yahoo!?
> Get Yahoo! Mail - Free email you can access from anywhere!
> http://mail.yahoo.com/
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor



From jhtaylor2000@yahoo.com  Sun Jul 23 22:18:45 2000
From: jhtaylor2000@yahoo.com (Joseph Taylor)
Date: Sun, 23 Jul 2000 14:18:45 -0700 (PDT)
Subject: [Tutor] SUGGESTIONS  FOR  A  TRUE  BIGGINNER/LEARN  TO  PROGRAM
Message-ID: <20000723211845.24065.qmail@web4105.mail.yahoo.com>

Hello everyone, I am a true novice to the world of
programming. Can anyone direct me to the "correct"
starting point. I have one of the many things I assume
I will need; that's the "burning desire to learn and I
will", some have said Linux, Perl, what is the easiest
one for me to start with. I will go with it from
there, until I can run not walk. 27 years while
attending Cal St. Long Beach, I stumbled on a job in
the Los Angeles Harbor, as a "Longie" that's short for
Longshoreman, I was making a bundle of money, well to
keep this short, I bought a Beautiful Mercedes Benz,
that was my introduction to the finest Automobile in
the World..I later learned from several people the
intricacies of that auto. Short and sweet I am now an
accomplished Mercedes Technician/Restorer/ All with no
classes, so I figure you put your mind to something
nothing get's in the way.  Just some one point me in
the right direction to start..I would love to have a
mentor, anyone interested..?   Thanks, a trillion. 
Joseph H. Taylor,Jr.


__________________________________________________
Do You Yahoo!?
Get Yahoo! Mail – Free email you can access from anywhere!
http://mail.yahoo.com/


From InternetSeer.com  Mon Jul 24 07:12:10 2000
From: InternetSeer.com (InternetSeer.com)
Date: 24 Jul 2000 02:12:10 -0400
Subject: [Tutor] Your web site has been mapped
Message-ID: <0df201012061870MARS1@mars1.internetseer.com>

Freewire has added your web site to its map of the World Wide Web.  Freewire will continue to monitor millions of links and web sites every day during its ongoing web survey.

If it is important for you to know that your site is connected to the web at all times, Freewire has arranged with InternetSeer.com to notify you when your site does not respond.  This means that, AT NO CHARGE; InternetSeer.com will monitor your Web site every hour and send notification to you by email whenever your site is not connected to the Web. There are NO current or future charges associated with this service.

To begin your FREE monitoring NOW, activate your account at:
http://www.internetseer.com/signup.asp?email=tutor@python.org

Mark McLellan
Chief Technology Officer
Freewire.com

Is your web site status important to you? I'd love your comments. If you prefer not to receive any future notices that result from our ongoing survey please let me know by returning this email with the word "remove" in the subject line.

=============================================
##Remove: tutor@python.org##


From dyoo@hkn.EECS.Berkeley.EDU  Mon Jul 24 09:41:11 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Mon, 24 Jul 2000 01:41:11 -0700 (PDT)
Subject: [Tutor] SUGGESTIONS  FOR  A  TRUE  BIGGINNER/LEARN  TO  PROGRAM
In-Reply-To: <20000723211845.24065.qmail@web4105.mail.yahoo.com>
Message-ID: <Pine.LNX.4.21.0007240110470.25962-100000@hkn.EECS.Berkeley.EDU>

On Sun, 23 Jul 2000, Joseph Taylor wrote:

> Hello everyone, I am a true novice to the world of
> programming. Can anyone direct me to the "correct"
> starting point. I have one of the many things I assume

Nice to have you with us!  I can't say there's a _correct_ way to start
things off.  Rather, it's more rewarding in finding a _fun_ way to learn
programming.  We'll do what we can to make things easier for you.

From personal, purely subjective anecdode, Perl is an advanced language,
with many rewards; it's the design of a linguist, Larry Wall, so it mimics
many of the quirky conventions of language.  It's very powerful, but also
very tricky at times.  You can learn it as your first programming
language, yes, but it might hurt at times.  At the same time, you'll be
powerful.  *grin*

Python, I think, focuses on the simplicity of the language as well as the
expressive power.  It's designed by Guido van Rossum, who designed the
language with easy-of-learning in mind; I personally like Python because
it's "cleaner".  It doesn't have as many quirks, and I find it a lot of
fun to program in.  It, too, is powerful.

Both are much nicer compared to the alternatives: C/C++/Java, which are
like spiked straitjackets.  Not to say that spiked straitjackets are not
cool --- but they must be uncomfortable.  Do not learn Pascal, COBOL, or
FORTRAN.  Consider those dead languages, unless you need to do something
like graduate school.  Also, there are alternative languages like Scheme
or Common Lisp, which are quite nice, but you'll probably find it harder
to find mainstream support for these.


You can get the tools to download Perl and Python freely.  Perl can be
found at:

  http://www.perl.com/pub/language/info/software.html#stable

and Python can be found at:

  http://www.python.org/download/

(You'll want to get Python 1.52; 1.6 is still under development)


Because this is a Python-based mailing list, I better start focusing on
Python, else I'll incur much wrath.  You can find a lot of Python
tutorials on the web; here are links to a few of them:

The official tutorial (by Guido van Rossum):
  http://www.python.org/doc/current/tut/tut.html

Non-Programmers Tutorial for Python (by Josh Cogliati):
  http://www.honors.montana.edu/~jjc/easytut/easytut/

Learning to Program (by Alan Gauld):
  http://www.crosswinds.net/~agauld/


Finally, if ever you get stuck with problems, there's a support network of
volunteers.  You can always contact us through tutor@python.org if you
have Python questions.  (As for Perl questions... you can find stuff at
http://www.perl.com)  Good luck!



From scarblac@pino.selwerd.nl  Mon Jul 24 10:01:29 2000
From: scarblac@pino.selwerd.nl (Remco Gerlich)
Date: Mon, 24 Jul 2000 11:01:29 +0200
Subject: [Tutor] SUGGESTIONS  FOR  A  TRUE  BIGGINNER/LEARN  TO  PROGRAM
In-Reply-To: <20000723211845.24065.qmail@web4105.mail.yahoo.com>; from jhtaylor2000@yahoo.com on Sun, Jul 23, 2000 at 02:18:45PM -0700
References: <20000723211845.24065.qmail@web4105.mail.yahoo.com>
Message-ID: <20000724110129.A4307@pino.selwerd.nl>

On Sun, Jul 23, 2000 at 02:18:45PM -0700, Joseph Taylor wrote:
> Hello everyone, I am a true novice to the world of
> programming. Can anyone direct me to the "correct"
> starting point. I have one of the many things I assume
> I will need; that's the "burning desire to learn and I
> will", some have said Linux, Perl, what is the easiest
> one for me to start with.

Linux is not a programming language, but an operating system. If you're a
Windows user, there's no reason to move away from that just to learn
programming.

Perl is a powerful language. But in my opinion it has too many special cases;
it has special things for many uses, things work differently depending on
context - unnecessarily complex. I wouldn't recommend Perl.

Usually I recommend Python as the best beginners language (but hey, you
ask here, what do you expect :-)). It's as powerful as Perl, probably has
better support on Windows, but it's "simpler". No special cases everywhere.

Java, Pascal (well, Delphi, which uses Pascal) and Scheme are other reasonable
languages. In the end you will at least want to know C or C++ too (but don't
start with C++).

It depends on what you want to do with it. After the first tutorials and so
on, you learn by picking something to make, and making it. It's a lot easier
if the language you picked is suitable for what you want to do. Also, do you
want to learn programming to find a job in it? Java probably has the advantage
there, at the moment. Python is the most fun :-).

The standard starting point for Python would be the tutorials for non-
programmers, at http://www.python.org/doc/Intros.html , under "Introductions
to Python for non-programmers". Other links there may be useful too.
-- 
Remco Gerlich,  scarblac@pino.selwerd.nl


From alan.gauld@bt.com  Mon Jul 24 10:42:41 2000
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 24 Jul 2000 10:42:41 +0100
Subject: [Tutor] VERY newbie question
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D233@mbtlipnt02.btlabs.bt.co.uk>

> Why won't this work, and/or how can I get this to work?
> sys.path.append("C:\ + name")

Others have answered the question but it may be worth pointing out 
that the forward slash path separator works in DOS/Windoze as well 
as on Unix and avoids all the escaping issues:

sys.path.append('C:/' + name)

Someone told me that it also works on Macs but I can't confirm 
that since I don't have access to one. Can anyone else confirm 
the universality of '/' as a separator?

If so is this feature documented anywhere? I can't find it, but 
it sure is helpful if true. 

Alan g.


From alan.gauld@bt.com  Mon Jul 24 10:36:04 2000
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Mon, 24 Jul 2000 10:36:04 +0100
Subject: [Tutor] printing columns
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D231@mbtlipnt02.btlabs.bt.co.uk>

> Other people have suggested using:
>   print "%10s%10s%10s" % (item[i], item[i+1], item[i+2])
> 
> which will work well.  It will, however, be padded with spaces to the
> left, where we actually want padding on the right.  For example:
> 
> >>> print "%10s%10s%10s" % ('hello', 'world', 'test')
>      hello     world      test

So try using a minus sign:

>>> print "%-10s%-10s%-10s" % ('hello', 'world', 'test')
hello     world      test


Alan G.


From CKeelan@firstlinux.net  Mon Jul 24 17:52:54 2000
From: CKeelan@firstlinux.net (Christopher Keelan)
Date: Mon, 24 Jul 2000 09:52:54 -0700 (PDT)
Subject: [Tutor] SUGGESTIONS  FOR  A  TRUE  BIGGINNER/LEARN  TO  PROGRAM
Message-ID: <20000724165254.5F0F340A9@sitemail.everyone.net>

Hi Joseph,

Congrats on taking the plunge into programming. I'm pretty new to things myself but did a lot of reading before I decided to roll up my hands and get to work.

I think that a Python=>Scheme=>Perl will be a good progression for you. Python is a great first choice because it's easy to learn but powerful enough to actually *do* something. Scheme is a great next step because you practically have to learn to think like a computer scientist in order to get anything done (great discipline). Finally, Perl has a C-like syntax and can ease you into either an OOP (which you'll have been introduced to with Python)language like Java or a lower-level language like C. Once you've got a feel for Python and Scheme, things will probably take off from there.

Good luck.

- Chris

_____________________________________________________________
Want a new web-based email account ? ---> http://www.firstlinux.net


From bulginbergster@hotmail.com  Wed Jul 26 19:39:26 2000
From: bulginbergster@hotmail.com (tom bergan)
Date: Wed, 26 Jul 2000 18:39:26 GMT
Subject: [Tutor] i need help!!
Message-ID: <20000726183926.84380.qmail@hotmail.com>

i can't really find a beginner's python tutorial that i understand i've 
tried a few and i don't really understand them once i get so far down the 
line...is there any form of interactive help, if any at all for a total 
novice?

                  tom.


________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com



From timc@ans.net  Wed Jul 26 19:58:44 2000
From: timc@ans.net (Tim Condit)
Date: Wed, 26 Jul 2000 14:58:44 -0400 (EDT)
Subject: [Tutor] i need help!!
In-Reply-To: <20000726183926.84380.qmail@hotmail.com>
Message-ID: <Pine.GSO.4.05.10007261445420.20587-100000@neutrino.aa.ans.net>

Hi, 

There are several tutorials. I'm not aware of any that are truly
interactive, though. If you haven't been there yet, www.python.org has
several pointers to documentation. These are two excellent starting
points:

http://www.python.org/doc/Intros.html
http://www.python.org/doc/Hints.html

All of these links are on the python doc pages (along with several more):

http://www.idi.ntnu.no/~mlh/python/programming.html
http://www.honors.montana.edu/~jjc/easytut/easytut/
http://members.xoom.com/alan_gauld/tutor/tutindex.htm

That should be more than enough to get you started. If you get stuck, this
mailing list is a really good source of info. Post a few questions here,
and you'll get helpful, prompt and courteous responses.


Hope this helps, 

Tim Condit
UUNet Network Quality Services
734-214-7548
tcondit@uu.net


On Wed, 26 Jul 2000, tom bergan wrote:

> i can't really find a beginner's python tutorial that i understand i've 
> tried a few and i don't really understand them once i get so far down the 
> line...is there any form of interactive help, if any at all for a total 
> novice?
> 
>                   tom.
> 
> 
> ________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor
> 



From wesc@alpha.ece.ucsb.edu  Wed Jul 26 19:48:16 2000
From: wesc@alpha.ece.ucsb.edu (Wesley J. Chun)
Date: Wed, 26 Jul 2000 11:48:16 -0700 (PDT)
Subject: [Tutor] i need help!!
Message-ID: <200007261848.LAA02848@alpha.ece.ucsb.edu>

    > From: "tom bergan" <bulginbergster@hotmail.com>
    > Date: Wed, 26 Jul 2000 18:39:26 GMT
    > 
    > i can't really find a beginner's python tutorial that i understand i've 
    > tried a few and i don't really understand them once i get so far down the 
    > line...is there any form of interactive help, if any at all for a total 
    > novice?


tom,

maybe you can help clarify a few things first.

1. are you already programming now using another language?  which one(s)?
2. or are you completely new to programming period?
3. where or what parts of the other tutorials do you start getting lost?
    (out of curiosity, which ones have you tried?)

if you could answer these questions, then i think people will be able to
help you better.

-wesley

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

"Core Python Programming", Prentice Hall PTR, TBP Summer 2000
    http://www.phptr.com/ptrbooks/ptr_0130260363.html
    http://www.softpro.com/languages-python.html

wesley.j.chun :: wesc@alpha.ece.ucsb.edu
cyberweb.consulting :: silicon.valley, ca
http://www.roadkill.com/~wesc/cyberweb/


From macks" <macks@gateway.net  Tue Jul 18 21:42:04 2000
From: macks" <macks@gateway.net (macks)
Date: Tue, 18 Jul 2000 13:42:04 -0700
Subject: [Tutor] Tutor Mailing List
Message-ID: <000101bff751$66fe0b80$5bac7ed8@oemcomputer>

This is a multi-part message in MIME format.

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

I Would Like To Sign Up For The Tutor Mailing List My E-Mail Is =
Josh_Mania@yahoo.com.

------=_NextPart_000_000F_01BFF0BD.F555F680
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=3Dwindows-1252" =
http-equiv=3DContent-Type><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 =
Transitional//EN">
<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR></HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>I Would Like To Sign Up For The Tutor Mailing List =
My E-Mail=20
Is <A=20
href=3D"mailto:Josh_Mania@yahoo.com">Josh_Mania@yahoo.com</A>.</FONT></DI=
V></BODY></HTML>

------=_NextPart_000_000F_01BFF0BD.F555F680--



From dyoo@hkn.EECS.Berkeley.EDU  Wed Jul 26 22:26:43 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Wed, 26 Jul 2000 14:26:43 -0700 (PDT)
Subject: [Tutor] i need help!!
In-Reply-To: <20000726183926.84380.qmail@hotmail.com>
Message-ID: <Pine.LNX.4.21.0007261405440.11625-100000@hkn.EECS.Berkeley.EDU>

On Wed, 26 Jul 2000, tom bergan wrote:

> i can't really find a beginner's python tutorial that i understand i've 
> tried a few and i don't really understand them once i get so far down the 
> line...is there any form of interactive help, if any at all for a total 
> novice?

Could you describe some of the concepts that are confusing?  Perhaps we
might be able to help clear them up for you.


The official python tutorial might be a bit difficult for first-timers, so
I'll list out others that I pulled out of the Introductions page on
python.org.


Alan Gauld's Learning to Program:
  http://members.xoom.com/alan_gauld/tutor/tutindex.htm

Josh Cogliati's Non-Porgrammers Tutorial for Python
  http://www.honors.montana.edu/~jjc/easytut/easytut/


Don't get discouraged!  We'll try to be as helpful as we can.  Good luck!



From dyoo@hkn.EECS.Berkeley.EDU  Wed Jul 26 22:29:05 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Wed, 26 Jul 2000 14:29:05 -0700 (PDT)
Subject: [Tutor] Tutor Mailing List
In-Reply-To: <000101bff751$66fe0b80$5bac7ed8@oemcomputer>
Message-ID: <Pine.LNX.4.21.0007261427460.11625-100000@hkn.EECS.Berkeley.EDU>

On Tue, 18 Jul 2000, macks wrote:

> I Would Like To Sign Up For The Tutor Mailing List My E-Mail Is
> Josh_Mania@yahoo.com.


Good to have you with us.  tutor@python.org uses the Mailman mailing list
manager, so there's a slightly different procedure in subscribing.  
You'll want to visit:

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

which has instructions on how to join the list.



From wprotoman@wbinterline.com.br  Thu Jul 27 03:49:20 2000
From: wprotoman@wbinterline.com.br (Leonardo Boiko)
Date: Wed, 26 Jul 2000 23:49:20 -0300
Subject: [Tutor] i need help!!
References: <20000726183926.84380.qmail@hotmail.com>
Message-ID: <002d01bff775$46419280$2c8ecbc8@default>

----- Original Message -----
From: tom bergan <bulginbergster@hotmail.com>
To: <tutor@python.org>
Cc: <bulginbergster@hotmail.com>
Sent: Wednesday, July 26, 2000 3:39 PM
Subject: [Tutor] i need help!!


> i can't really find a beginner's python tutorial that i understand i've
> tried a few and i don't really understand them once i get so far down the
> line...is there any form of interactive help, if any at all for a total
> novice?
>
>                   tom.
>
>
>
Hello Tom.  I'm Leo and I'm also a very begginer in the program world. Here,
at http://www.python.org  there are some "tutorials for non-programmers" or
whatever. The easiest of all is Josh Cogliati's "Non-programmers Tutorial
for Python" (http://www.honors.montana.edu/~jjc/easytut/easytut/); some
interesting stuff is missing thought. After learn it go to Alan Gaud's
"Learning to Program"
(http://members.xoom.com/alan_gauld/tutor/tutindex.htm -a bit complex, but
also very deep). Then, we will be able to fully understand Guido's Tutorial
(I hope...). Good luck and don't give up (I willn't).

Leo

P.S.: I'm just a Brazilian teenager and I learned my English from
videogames; so please apologize any errors, bad spelling etc.

________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor
>




From kjohnston@rcsi.ie  Thu Jul 27 13:53:59 2000
From: kjohnston@rcsi.ie (Catriona Johnston)
Date: Thu, 27 Jul 2000 13:53:59 +0100
Subject: [Tutor] Calling C code in a python program
Message-ID: <9921C1171939D3119D860090278AECA2DEC606@EXCHANGE>

Hello all,
	I have just started using python for science a week ago and need to
know how to integrate a previously written program in C into my python
interface...There must be a quicker method other than SWIG or the API
methods that involves going into the C program and altering all definitions
to include API definitions...please tell me there is! I do not need to
implement separate parts of the C program individually all I need to do is
call it, feed it its input and capture its output. 
Awaiting your comment
KT


From arcege@shore.net  Thu Jul 27 14:05:43 2000
From: arcege@shore.net (Michael P. Reilly)
Date: Thu, 27 Jul 2000 09:05:43 -0400 (EDT)
Subject: [Tutor] Calling C code in a python program
In-Reply-To: <9921C1171939D3119D860090278AECA2DEC606@EXCHANGE> from "Catriona Johnston" at Jul 27, 2000 01:53:59 PM
Message-ID: <200007271305.JAA24880@northshore.shore.net>

>   I have just started using python for science a week ago and need to
> know how to integrate a previously written program in C into my python
> interface...There must be a quicker method other than SWIG or the API
> methods that involves going into the C program and altering all definitions
> to include API definitions...please tell me there is! I do not need to
> implement separate parts of the C program individually all I need to do is
> call it, feed it its input and capture its output. 

For UNIX, you would probably want to use the popen2 module (in the
standard libary), which will allow you to send data to and read data
from a program.

>>> import popen2
>>> (child_stdout, child_stdin) = popen2.popen2('myprog arg1 arg2')
>>> child_stdin.write(data)
>>> whats_there = child_stdout.read()

For Windows, you will want to look at the win32pipe module in the
Windows extensions.  I'm not sure about Macs.

  -Arcege

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


From Moshe Zadka <moshez@math.huji.ac.il>  Thu Jul 27 15:27:09 2000
From: Moshe Zadka <moshez@math.huji.ac.il> (Moshe Zadka)
Date: Thu, 27 Jul 2000 17:27:09 +0300 (IDT)
Subject: [Tutor] Calling C code in a python program
In-Reply-To: <9921C1171939D3119D860090278AECA2DEC606@EXCHANGE>
Message-ID: <Pine.GSO.4.10.10007271726530.4334-100000@sundial>

On Thu, 27 Jul 2000, Catriona Johnston wrote:

> Hello all,
> 	I have just started using python for science a week ago and need to
> know how to integrate a previously written program in C into my python
> interface...There must be a quicker method other than SWIG or the API
> methods that involves going into the C program and altering all definitions
> to include API definitions...please tell me there is! I do not need to
> implement separate parts of the C program individually all I need to do is
> call it, feed it its input and capture its output. 
> Awaiting your comment

Try os.popen or os.popen2.
--
Moshe Zadka <moshez@math.huji.ac.il>
There is no IGLU cabal.
http://advogato.org/person/moshez



From wolfkin@freedomspace.net  Thu Jul 27 18:26:11 2000
From: wolfkin@freedomspace.net (Randall Randall)
Date: Thu, 27 Jul 2000 13:26:11 -0400 (EDT)
Subject: [Tutor] Using urllib with https
Message-ID: <XFMail.20000727132611.wolfkin@freedomspace.net>

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

Hi, 

I've been using Python for some cgi, and needed
to use "https".  So I built Python1.6a2, and 
while testing my script, I got this:

- ---------begin output--------------------
Traceback (most recent call last):
  File "egsell.py", line 54, in ?
    t = urllib.urlopen('https://www.foo.bar/cgi/action.exe', encspendform)
  File "/usr/local/lib/python1.6/urllib.py", line 62, in urlopen
    return _urlopener.open(url, data)
  File "/usr/local/lib/python1.6/urllib.py", line 163, in open
    return getattr(self, name)(url, data)
TypeError: too many arguments; expected 2, got 3   
- ---------end output----------------------

Any idea why this would happen?  I'm really 
hoping that this isn't a bug in the library 
itself...  The variable "encspendform" is a 
url-encoded string passed to the cgi on the 
server.

BTW, I replaced the actual site name with 
"foo.bar", since it didn't even get that far, 
I don't think.

Thanks!

- -- 
Randall (wolfkin@freedomspace.net).
Crypto key: www.freedomspace.net/~wolfkin/crypto.text
On a visible but distant shore, a new image of man;
The shape of his own future, now in his own hands.-- Johnny Clegg.

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

iD8DBQE5gHCz8SWFrcg/i1gRAn/bAJ9wY1+7YkMB/OK99L7no4B8HlHxRgCffCnc
KjuQXiGwxgYmzUXG46SwjcE=
=p6EJ
-----END PGP SIGNATURE-----


From timc@ans.net  Thu Jul 27 23:07:29 2000
From: timc@ans.net (Tim Condit)
Date: Thu, 27 Jul 2000 18:07:29 -0400 (EDT)
Subject: [Tutor] getopt question
Message-ID: <Pine.GSO.4.05.10007271733450.20587-100000@neutrino.aa.ans.net>

Hi, I'm having some confusion with the getopt module. Is there a better
way to do this? 

--

#!/usr/local/bin/python

import getopt
import sys

try:
    options, argument = getopt.getopt(sys.argv[1:], 'hbt')
except getopt.error:
    print "getopt.error - sorry."
    sys.exit(0)

for i in range(len(options)):
    if '-h' in options[i]:
        print "You need help"
    if '-b' in options[i]:
        print "You need bash"
    if '-t' in options[i]:
        print "You need tcsh"


[timc@neutrino ~/py] ./getopt_test.py -t -h -b
You need tcsh
You need help
You need bash

--

Thanks in advance, 

Tim Condit
UUNet Network Quality Services
734-214-7548
tcondit@uu.net




From arcege@shore.net  Thu Jul 27 23:53:07 2000
From: arcege@shore.net (Michael P. Reilly)
Date: Thu, 27 Jul 2000 18:53:07 -0400 (EDT)
Subject: [Tutor] getopt question
In-Reply-To: <Pine.GSO.4.05.10007271733450.20587-100000@neutrino.aa.ans.net> from "Tim Condit" at Jul 27, 2000 06:07:29 PM
Message-ID: <200007272253.SAA23377@northshore.shore.net>

> 
> 
> Hi, I'm having some confusion with the getopt module. Is there a better
> way to do this? 
> 
> --
> 
> #!/usr/local/bin/python
> 
> import getopt
> import sys
> 
> try:
>     options, argument = getopt.getopt(sys.argv[1:], 'hbt')
> except getopt.error:
>     print "getopt.error - sorry."
>     sys.exit(0)
> 
> for i in range(len(options)):
>     if '-h' in options[i]:
>         print "You need help"
>     if '-b' in options[i]:
>         print "You need bash"
>     if '-t' in options[i]:
>         print "You need tcsh"

I would usually write:

try:
  opts, args = getopt.getopt(sys.argv[1:], 'bhts:')
except getopt.error, value:
  raise SystemExit('%s: %s' % (sys.argv[0], value))

for (opt, val) in opts:
  if opt == '--':
    break
  elif opt == '-h':
    print 'you need help'
  elif opt == '-b':
    print 'you need bash'
  elif opt == '-t':
    print 'you need tcsh (yeah, right)'
  elif opt == '-s':
    print 'you need', val

You could use a dict instead of the if-elif-elif, but that's just
style.

  -Arcege

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


From fw9189@bristol.ac.uk  Fri Jul 28 09:51:05 2000
From: fw9189@bristol.ac.uk (F Wass)
Date: Fri, 28 Jul 2000 09:51:05 +0100 (BST)
Subject: [Tutor] Creating easy-to-run files
Message-ID: <Pine.SOL.3.95q.1000728094247.1957A-100000@sis>

Hi,

I've just started using Python (and found it quite useful) for 
writing a conversion parser between two different formats. 
Is there an easy way of letting the user run the script by 
simply typing "start" or something similar at the Python prompt?
I'm currently using Windows, but it's intended to be run under
Linux.

Cheers,
Fred



From marcel@punto.it  Fri Jul 28 10:04:37 2000
From: marcel@punto.it (Marcel Preda)
Date: Fri, 28 Jul 2000 11:04:37 +0200
Subject: R: [Tutor] Creating easy-to-run files
References: <Pine.SOL.3.95q.1000728094247.1957A-100000@sis>
Message-ID: <00ee01bff872$db5c9060$1301000a@punto.it>


> Hi,
> 
Hi
> I've just started using Python (and found it quite useful) for 
> writing a conversion parser between two different formats. 
> Is there an easy way of letting the user run the script by 
> simply typing "start" or something similar at the Python prompt?
> I'm currently using Windows, but it's intended to be run under
> Linux.
> 

From comand [or shell] prompt, type :

python script_name



For linux only:
In the script the first line must be:
#!/path_to/python

And you may call just like:
script_name 

PM





From dyoo@hkn.EECS.Berkeley.EDU  Fri Jul 28 10:13:32 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Fri, 28 Jul 2000 02:13:32 -0700 (PDT)
Subject: [Tutor] Creating easy-to-run files
In-Reply-To: <Pine.SOL.3.95q.1000728094247.1957A-100000@sis>
Message-ID: <Pine.LNX.4.21.0007280206060.12700-100000@hkn.EECS.Berkeley.EDU>

On Fri, 28 Jul 2000, F Wass wrote:

> I've just started using Python (and found it quite useful) for 
> writing a conversion parser between two different formats. 
> Is there an easy way of letting the user run the script by 
> simply typing "start" or something similar at the Python prompt?
> I'm currently using Windows, but it's intended to be run under
> Linux.

If you're running NT or Win2k, then typing

  start.py

may work, although passing in arguments... just doesn't like to work.  
Don't know why.  Otherwise, the explicit:

  python start.py

should do it.  You'll probably need to add your python directory into your
PATH.  Good luck!



From alan.gauld@bt.com  Fri Jul 28 11:06:18 2000
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 28 Jul 2000 11:06:18 +0100
Subject: [Tutor] writing binary files
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D250@mbtlipnt02.btlabs.bt.co.uk>

How do I write binary data to a file?
I can open a file with 'wb' as mode but if I do:

b = open('bin.dat','wb')
for i in range(50): b.write(i)

I get an error.

I can read binary data using the size parameter 
to f.read() but I can't see how to write the stuff. 
Any ideas? Do I need to use the low level open() 
in the os module?

Alan G.


From Moshe Zadka <moshez@math.huji.ac.il>  Fri Jul 28 12:38:04 2000
From: Moshe Zadka <moshez@math.huji.ac.il> (Moshe Zadka)
Date: Fri, 28 Jul 2000 14:38:04 +0300 (IDT)
Subject: [Tutor] writing binary files
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D250@mbtlipnt02.btlabs.bt.co.uk>
Message-ID: <Pine.GSO.4.10.10007281437140.7506-100000@sundial>

On Fri, 28 Jul 2000 alan.gauld@bt.com wrote:

> How do I write binary data to a file?
> I can open a file with 'wb' as mode but if I do:
> 
> b = open('bin.dat','wb')
> for i in range(50): b.write(i)

For that, use the struct module.
Though maybe what you want to do is

for i in range(50):
	b.write(chr(i))


--
Moshe Zadka <moshez@math.huji.ac.il>
There is no IGLU cabal.
http://advogato.org/person/moshez



From arcege@shore.net  Fri Jul 28 12:39:45 2000
From: arcege@shore.net (Michael P. Reilly)
Date: Fri, 28 Jul 2000 07:39:45 -0400 (EDT)
Subject: [Tutor] writing binary files
In-Reply-To: <5104D4DBC598D211B5FE0000F8FE7EB20751D250@mbtlipnt02.btlabs.bt.co.uk> from "alan.gauld@bt.com" at Jul 28, 2000 11:06:18 AM
Message-ID: <200007281139.HAA22346@northshore.shore.net>

> 
> How do I write binary data to a file?
> I can open a file with 'wb' as mode but if I do:
> 
> b = open('bin.dat','wb')
> for i in range(50): b.write(i)
> 
> I get an error.

This is an error because the write method can only output a string.
Strings in Python are not strictly 7-bit characters, but 8-bit bytes.
So you can use the struct module to convert Python data into binary
strings, which can then be written to the file.

>>> import struct
>>> binfile = open('bin.dat', 'wb')
>>> for num in range(50):
...   data = struct.pack('i', num)
...   binfile.write(data)
...
>>> binfile = open('bin.dat', 'rb')
>>> intsize = struct.calcsize('i')
>>> while 1:
>>>   data = binfile.read(intsize)
...   if data == '':
...     break
...   num = struct.unpack('i', data)
...   print num
...

Also, you might want to look at the marshal, pickle and shelve
modules.

  -Arcege

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


From alan.gauld@bt.com  Fri Jul 28 12:45:17 2000
From: alan.gauld@bt.com (alan.gauld@bt.com)
Date: Fri, 28 Jul 2000 12:45:17 +0100
Subject: [Tutor] writing binary files
Message-ID: <5104D4DBC598D211B5FE0000F8FE7EB20751D254@mbtlipnt02.btlabs.bt.co.uk>

> > How do I write binary data to a file?
> > I can open a file with 'wb' as mode but if I do:
> > 
> > b = open('bin.dat','wb')
> > for i in range(50): b.write(i)
> > 
> > I get an error.
> 
> This is an error because the write method can only output a string.

Yes, I figured that bit.

> So you can use the struct module to convert Python data into binary
> strings, which can then be written to the file.

I knew there must be a way, but although Python has batteries 
included it can be hard to know which battery you need :-)

> Also, you might want to look at the marshal, pickle and shelve
> modules.

I don't think they'll help here, I'm trying to reproduce 
the proprietary format of an old legacy system to fix an 
operational proble, The format is well documented and I 
could just use emacs but I wanted to try Python as a more
future proof solution...

Thanks all for pointing out struct.

Alan G.


From postbox@counter4all.com  Fri Jul 28 15:27:37 2000
From: postbox@counter4all.com (postbox@counter4all.com)
Date: Fri, 28 Jul 2000 16:27:37 +0200
Subject: [Tutor] RE: Professional statistics for your homepage
Message-ID: <PLUTOGML4bf84SFqzx100000eed@www.counter4all.dk>

Hi tutor@python.org

Check http://www.counter4all.com/omcounter.asp



From insyte@emt-p.org  Fri Jul 28 16:39:40 2000
From: insyte@emt-p.org (Ben Beuchler)
Date: Fri, 28 Jul 2000 10:39:40 -0500
Subject: [Tutor] executing a program and retrieving it's output
Message-ID: <20000728103938.A7230@emt-p.org>

I'm familiar with using os.popen('command') to execute a command and
retrieve it's output. However, I rather dreadfully miss being able to do
this in Perl:

$myvariable = `/path/to/my/program`

Is there an easy equivalent in Python? 

Thanks,
Ben

-- 
Ben Beuchler                                         insyte@bitstream.net
MAILER-DAEMON                                         (612) 321-9290 x101
Bitstream Underground                                   www.bitstream.net


From da_woym@hotmail.com  Fri Jul 28 16:47:37 2000
From: da_woym@hotmail.com (Jacob Williams)
Date: Fri, 28 Jul 2000 15:47:37 GMT
Subject: [Tutor] File permissions
Message-ID: <LAW-F12CtYN13qfEGlP00000f2f@hotmail.com>

With python, can you create a folder with a write only permission?
thanks in advance!

------------------------
|   Jacob Williams     |
| Da_woym@hotmail.com  |
------------------------

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com



From dyoo@hkn.EECS.Berkeley.EDU  Fri Jul 28 17:30:31 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Fri, 28 Jul 2000 09:30:31 -0700 (PDT)
Subject: [Tutor] executing a program and retrieving it's output
In-Reply-To: <20000728103938.A7230@emt-p.org>
Message-ID: <Pine.LNX.4.21.0007280922570.16796-100000@hkn.EECS.Berkeley.EDU>

On Fri, 28 Jul 2000, Ben Beuchler wrote:

> I'm familiar with using os.popen('command') to execute a command and
> retrieve it's output. However, I rather dreadfully miss being able to do
> this in Perl:
> 
> $myvariable = `/path/to/my/program`
> 
> Is there an easy equivalent in Python? 

The most direct equivalent I can think to do this would be:

###
  myvariable = os.popen('/path/to/my/program').read()
###

However, remember, you can write a definition to make this easy on
yourself.

###
  def suckExec(program_name):
    return os.popen(program_name).read()
###

Afterwards, you should be able to just say:

###
  myvariable = suckExec('/path/to/my/program')
###

For example:

>>> suckExec('ls')
'mail\012nsmail\012'          # (Just did a reinstall.)


True, it is a little longer to write.  But it reads so beautifully...
*grin* Hope this helps!



From dyoo@hkn.EECS.Berkeley.EDU  Fri Jul 28 17:41:20 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Fri, 28 Jul 2000 09:41:20 -0700 (PDT)
Subject: [Tutor] File permissions
In-Reply-To: <LAW-F12CtYN13qfEGlP00000f2f@hotmail.com>
Message-ID: <Pine.LNX.4.21.0007280930530.16796-100000@hkn.EECS.Berkeley.EDU>

On Fri, 28 Jul 2000, Jacob Williams wrote:

> With python, can you create a folder with a write only permission?
> thanks in advance!

I think it might depend on your default umask; I might be completely
mistaken on this.  If it doesn't create with write-only, you can use
os.chmod() to change permissions to what you want.  Here's a small
function to do what you want:

###
def makeWriteOnlyDir(dir_name):
  os.mkdir(dir_name)
  os.chmod(dir_name, 0333)  # represented as octal wxwxwx
###

and a test:

>>> makeWriteOnlyDir('testtest')

[dyoo@c82114-a dyoo]$ ls -l
d-wx-wx-wx    2 dyoo     dyoo         4096 Jul 28 09:40 testtest


So this works ok.  Good luck!



From shaleh@valinux.com  Fri Jul 28 19:30:39 2000
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Fri, 28 Jul 2000 11:30:39 -0700
Subject: [Tutor] Creating easy-to-run files
In-Reply-To: <Pine.SOL.3.95q.1000728094247.1957A-100000@sis>; from fw9189@bristol.ac.uk on Fri, Jul 28, 2000 at 09:51:05AM +0100
References: <Pine.SOL.3.95q.1000728094247.1957A-100000@sis>
Message-ID: <20000728113039.B32113@valinux.com>

On Fri, Jul 28, 2000 at 09:51:05AM +0100, F Wass wrote:
> Hi,
> 
> I've just started using Python (and found it quite useful) for 
> writing a conversion parser between two different formats. 
> Is there an easy way of letting the user run the script by 
> simply typing "start" or something similar at the Python prompt?
> I'm currently using Windows, but it's intended to be run under
> Linux.
>

On unix based platforms like linux, place the following as the first line:

#!/usr/bin/env python

and the user can run it like any other executable on their system.  If you want
to make running from the python interactive interpreter easy add a start()
method to your objects:

#>>> import myclass
#>>> myclass.start()



From saunique@yahoo.com  Fri Jul 28 20:25:35 2000
From: saunique@yahoo.com (Ahmad Ali)
Date: Fri, 28 Jul 2000 12:25:35 -0700 (PDT)
Subject: [Tutor] please stop this
Message-ID: <20000728192535.11715.qmail@web3304.mail.yahoo.com>

Hi,
     Please stop sending python emails to me as there
is no more need of that.

thanks
saunique@yahoo.com

__________________________________________________
Do You Yahoo!?
Kick off your party with Yahoo! Invites.
http://invites.yahoo.com/


From dyoo@hkn.EECS.Berkeley.EDU  Sat Jul 29 03:23:20 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Fri, 28 Jul 2000 19:23:20 -0700 (PDT)
Subject: [Tutor] please stop this
In-Reply-To: <20000728192535.11715.qmail@web3304.mail.yahoo.com>
Message-ID: <Pine.LNX.4.21.0007281921170.28553-100000@hkn.EECS.Berkeley.EDU>

On Fri, 28 Jul 2000, Ahmad Ali wrote:

>      Please stop sending python emails to me as there
> is no more need of that.

You'll need to unsubscribe from the mailing list --- that's why you're
continuing to receive the emails.  You can do so by visiting:

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

There are instructions on that page to remove yourself from the mailing
list.  Hope to hear from you again in the future.



From JHo8@aol.com  Sun Jul 30 21:43:02 2000
From: JHo8@aol.com (JHo8@aol.com)
Date: Sun, 30 Jul 2000 16:43:02 EDT
Subject: [Tutor] join
Message-ID: <71.560aa58.26b5ed56@aol.com>

 


From kjohnston@rcsi.ie  Mon Jul 31 10:53:07 2000
From: kjohnston@rcsi.ie (Catriona Johnston)
Date: Mon, 31 Jul 2000 10:53:07 +0100
Subject: [Tutor] binding a callback to an event on a Canvas Oval
Message-ID: <9921C1171939D3119D860090278AECA2DEC612@EXCHANGE>

Help!
I have written an application which draws a simple 2D graph drawn on a
canvas widget by create_line and create_oval...the ovals are the points of
the graph. I need to associate a callback to an event of a double click of
the mouse button when over any of the points on the graph. How do I use the
.bind() method on the oval widget extensions of the canvas class?
Thanks
KT


From richard_chamberlain@ntlworld.com  Mon Jul 31 12:57:10 2000
From: richard_chamberlain@ntlworld.com (Richard Chamberlain)
Date: Mon, 31 Jul 2000 12:57:10 +0100
Subject: [Tutor] binding a callback to an event on a Canvas Oval
References: <9921C1171939D3119D860090278AECA2DEC612@EXCHANGE>
Message-ID: <001301bffae6$94a003c0$b061fea9@richardc>

Hi Catriona,

The following script demonstrates what you're after:

from Tkinter import *
root=Tk()
canvas=Canvas(root,width=100,height=100)
canvas.pack()
canvas.create_oval(10,10,20,20,tags='oval1',fill='blue')
canvas.create_oval(50,50,80,80,tags='oval2',fill='red')
def myEvent(event):
    print "I've been hit!"
canvas.tag_bind('oval1','<Button>',func=myEvent)
canvas.tag_bind('oval2','<Button>',func=myEvent)
root.mainloop()

Richard

----- Original Message -----
From: Catriona Johnston <kjohnston@rcsi.ie>
To: <tutor@python.org>
Sent: Monday, July 31, 2000 10:53 AM
Subject: [Tutor] binding a callback to an event on a Canvas Oval


> Help!
> I have written an application which draws a simple 2D graph drawn on a
> canvas widget by create_line and create_oval...the ovals are the points of
> the graph. I need to associate a callback to an event of a double click of
> the mouse button when over any of the points on the graph. How do I use
the
> .bind() method on the oval widget extensions of the canvas class?
> Thanks
> KT
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor



From dlaskey@laskeycpa.com  Mon Jul 31 20:42:52 2000
From: dlaskey@laskeycpa.com (Daniel D. Laskey, CPA)
Date: Mon, 31 Jul 2000 15:42:52 -0400
Subject: [Tutor] Loading and writing files
Message-ID: <01BFFB06.29E03BC0@DAN>

#-----------Objective---------------------------------------
#  
#  1.  Open a file that is comma deiminated called test.csv 
#      and then print the file to the screen.
#      33.04,123196,12,421020,RVN# 179-Ernest Lonard,12528.7
#      33.04,123196,12,421020,RVN# 196-Hector Gale,2599.7
#      33.04,123196,12,421230,RVN# 249-Richard George,2300
#      33.04,123196,12,420000,Total Sales Journal,-17428.4
#
#  2.  Write the file to a file called junk2.txt and be able 
#      to "cat" or "type" the file after the program terminates.
#
#  3.  Read the data in the 5th position of the file and put " "s
#      around the data, so that the ending file lools like this:
#      33.04,123196,12,421020,"RVN# 179-Ernest Lonard",12528.7
#      33.04,123196,12,421020,"RVN# 196-Hector Gale",2599.7
#      33.04,123196,12,421230,"RVN# 249-Richard George",2300
#      33.04,123196,12,420000,"Total Sales Journal",-17428.4
#
#-----------My Code----------------------------------------------

import string 
import sys

print "Enter the name of the .CSV file to convert:"
in_file = raw_input(".CSV file name?  ")
in_file = open(x,"r")
text = in_file.read()
print text 
out_file = open("junk2.txt","w")
for line in in_file.readlines():
    out_file.write()
out_file.close()
in_file.close()

#-------------End of Code--------------------------------------------
#
#  Thanks in advance for your help.
#  Dan
#--------------------------------------------------------------------
# Daniel D. Laskey, CPA--------------------dlaskey@laskeycpa.com
# Daniel D. Laskey Company, P.C.-----231-723-8305  / Fax 231-723-6097
# Certified Public Accountants
# 507 Water Street
# Manistee, MI  49660
#--------------------------------------------------------------------




From shaleh@valinux.com  Mon Jul 31 20:53:30 2000
From: shaleh@valinux.com (Sean 'Shaleh' Perry)
Date: Mon, 31 Jul 2000 12:53:30 -0700 (PDT)
Subject: [Tutor] Loading and writing files
In-Reply-To: <01BFFB06.29E03BC0@DAN>
Message-ID: <XFMail.20000731125330.shaleh@valinux.com>

> import string 
> import sys
> 
> print "Enter the name of the .CSV file to convert:"
> in_file = raw_input(".CSV file name?  ")
> in_file = open(x,"r")
> text = in_file.read()
> print text 
> out_file = open("junk2.txt","w")
> for line in in_file.readlines():
>     out_file.write()
> out_file.close()
> in_file.close()
> 

the point? other than asking us to do the homework for you?


From dyoo@hkn.EECS.Berkeley.EDU  Mon Jul 31 21:27:52 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Mon, 31 Jul 2000 13:27:52 -0700 (PDT)
Subject: [Tutor] Loading and writing files
In-Reply-To: <01BFFB06.29E03BC0@DAN>
Message-ID: <Pine.LNX.4.21.0007311303240.5411-100000@hkn.EECS.Berkeley.EDU>

> import string 
> import sys
> 
> print "Enter the name of the .CSV file to convert:"
> in_file = raw_input(".CSV file name?  ")
> in_file = open(x,"r")
                 ^
                 |

A little bit of ASCII art... *grin* 'x' is a typo --- you want to grab the
filename stored by 'in_file' instead.

The conceptual problem is between file names and file objects.  They're
different, so perhaps it'll make it easier to give them different variable
names:

  in_filename = raw_input(".CSV file name?  ")
  in_file = open(in_filename,"r")


Next time through, it would be helpful to pinpoint to us your problem or
bug; otherwise, it makes it much harder to find a solution.



From timc@ans.net  Mon Jul 31 21:36:50 2000
From: timc@ans.net (Tim Condit)
Date: Mon, 31 Jul 2000 16:36:50 -0400 (EDT)
Subject: [Tutor] Loading and writing files
In-Reply-To: <01BFFB06.29E03BC0@DAN>
Message-ID: <Pine.GSO.4.05.10007311558091.29914-100000@neutrino.aa.ans.net>

Hi, 

I'll take a crack at it.. 

These two lines (when used together) are your first problem, I think.

in_file = raw_input(".CSV file name?  ")
in_file = open(x,"r")

You're trying to open a file with a variable x that has no associated
filename.

Next, the file you'll write to should be opened with 'a', instead of 'w',
as this is repeatedly writing each line, over the line that came before
it. That's not what you want, I'm guessing.

I'd remove a couple lines too:

import string
import sys

print "Enter the name of the .CSV file to convert:"
x = raw_input(".CSV file name?  ")
in_file = open(x,"r")
out_file = open("junk2.txt","a")
for line in in_file.readlines():
    print string.strip(line)
    out_file.write(line)
out_file.close()
in_file.close() 

--

Take a shot at the third part, and write again if you don't figure it out.
Maybe string.split the line on the commas, then use slice notation on the
string you want to modify, then paste it all back together. 

something like:

for line in in_file.readlines():
    f = string.split(line, ',')
    f[4] = add quotes
    f = f[:4] + f[4] + f[4:]

or something like that. But I'm learning myself, so there are probably
better ways to do it. But it's always a good idea to try a few things for
yourself, then ask questions when you're stuck. 

Good luck, 

Tim Condit
UUNet Network Quality Services
734-214-7548
tcondit@uu.net



On Mon, 31 Jul 2000, Daniel D. Laskey, CPA wrote:

> #-----------Objective---------------------------------------
> #  
> #  1.  Open a file that is comma deiminated called test.csv 
> #      and then print the file to the screen.
> #      33.04,123196,12,421020,RVN# 179-Ernest Lonard,12528.7
> #      33.04,123196,12,421020,RVN# 196-Hector Gale,2599.7
> #      33.04,123196,12,421230,RVN# 249-Richard George,2300
> #      33.04,123196,12,420000,Total Sales Journal,-17428.4
> #
> #  2.  Write the file to a file called junk2.txt and be able 
> #      to "cat" or "type" the file after the program terminates.
> #
> #  3.  Read the data in the 5th position of the file and put " "s
> #      around the data, so that the ending file lools like this:
> #      33.04,123196,12,421020,"RVN# 179-Ernest Lonard",12528.7
> #      33.04,123196,12,421020,"RVN# 196-Hector Gale",2599.7
> #      33.04,123196,12,421230,"RVN# 249-Richard George",2300
> #      33.04,123196,12,420000,"Total Sales Journal",-17428.4
> #
> #-----------My Code----------------------------------------------
> 
> import string 
> import sys
> 
> print "Enter the name of the .CSV file to convert:"
> in_file = raw_input(".CSV file name?  ")
> in_file = open(x,"r")
> text = in_file.read()
> print text 
> out_file = open("junk2.txt","w")
> for line in in_file.readlines():
>     out_file.write()
> out_file.close()
> in_file.close()
> 
> #-------------End of Code--------------------------------------------
> #
> #  Thanks in advance for your help.
> #  Dan
> #--------------------------------------------------------------------
> # Daniel D. Laskey, CPA--------------------dlaskey@laskeycpa.com
> # Daniel D. Laskey Company, P.C.-----231-723-8305  / Fax 231-723-6097
> # Certified Public Accountants
> # 507 Water Street
> # Manistee, MI  49660
> #--------------------------------------------------------------------
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor
> 






From dyoo@hkn.EECS.Berkeley.EDU  Mon Jul 31 22:08:49 2000
From: dyoo@hkn.EECS.Berkeley.EDU (Daniel Yoo)
Date: Mon, 31 Jul 2000 14:08:49 -0700 (PDT)
Subject: [Tutor] Loading and writing files
In-Reply-To: <Pine.GSO.4.05.10007311558091.29914-100000@neutrino.aa.ans.net>
Message-ID: <Pine.LNX.4.21.0007311355420.8759-100000@hkn.EECS.Berkeley.EDU>

> Next, the file you'll write to should be opened with 'a', instead of 'w',
> as this is repeatedly writing each line, over the line that came before
> it. That's not what you want, I'm guessing.

Since the file is being opened only once, it's probably not necessary to
use append; What append does is check to see if the file exists already
--- if so, then subsequent writes will go at the end of that file.  Append
mode is very useful if you're keeping a log of activity.

In regular writing mode, regardless if the file exists or not, that file's
going to get resized to zero.  Clean slate.  Otherwise, writing to it
subsequentially should be ok.  Here's an annotated interpreter session:

###
# I've written a test file called foo2.txt.  Let's look at it.
>>> file = open('foo2.txt')
>>> print file.read()
I am foo2.txt
This is the end of foo2.txt

# Let's test out append mode:
>>> file = open('foo2.txt', 'a')
>>> file.write("here is another line")
>>> print open('foo2.txt').read()
I am foo2.txt
This is the end of foo2.txt

# Q: Why did this happen?
# A: The file needs to be flushed properly --- I need to close()
#    it.  Whoops.

>>> file.close()
>>> print open('foo2.txt').read()
I am foo2.txt
This is the end of foo2.txthere is another line

# A little bit of strangeness, but only because the file didn't end with
# a newline  ('\n').  The append just tacks onto the end of the file.

# Let's test out regular writing
file = open('foo2.txt', 'w')
file.close()
>>> print open('foo2.txt').read()

# Empty file!  Ok, one more test.
>>> file = open('foo2.txt', 'w')
>>> file.write("testing, testing\n")
>>> file.write("one two three\n")
>>> file.write("testing writing mode\n")
>>> file.close()
>>> print open('foo2.txt').read()
testing, testing
one two three
testing writing mode
###




From carlk@argus.syscon-intl.com  Mon Jul 31 23:33:52 2000
From: carlk@argus.syscon-intl.com (Carl Kreider)
Date: Mon, 31 Jul 2000 17:33:52 -0500
Subject: [Tutor] Why doesn't this work??
Message-ID: <20000731173352.A20932@argus.syscon-intl.com>

Could some kind soul help an old C programmer and explain
what is wrong with this code?

---------8<-----------
#!/bin/env python

T = 0
dt = 0.1

def time_to_print(interval):
	num = T / dt
	den = interval / dt
	ttp = num % den
	print "ttp: T=%f num=%f den=%f ttp=%f" % (T, num, den, ttp)
	return abs(ttp) < dt


while (T < 6.0):
	if time_to_print(1):
		print "%f" % T
	T = T + dt
---------8<-----------

The output I get using:

Python 1.5.2 (#1, Jul 17 1999, 22:10:16)  [GCC egcs-2.91.66 19990314/Linux (egcs- on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>>  

is:

---------8<-----------
carlk$ python ttp.py
ttp: T=0.000000 num=0.000000 den=10.000000 ttp=0.000000
0.000000
ttp: T=0.100000 num=1.000000 den=10.000000 ttp=1.000000
  (snip)
ttp: T=0.900000 num=9.000000 den=10.000000 ttp=9.000000
ttp: T=1.000000 num=10.000000 den=10.000000 ttp=10.000000
ttp: T=1.100000 num=11.000000 den=10.000000 ttp=1.000000
  (snip)
ttp: T=2.000000 num=20.000000 den=10.000000 ttp=0.000000
2.000000
ttp: T=2.100000 num=21.000000 den=10.000000 ttp=1.000000
  (snip)
ttp: T=3.000000 num=30.000000 den=10.000000 ttp=0.000000
3.000000
ttp: T=3.100000 num=31.000000 den=10.000000 ttp=1.000000
  (snip)
ttp: T=4.000000 num=40.000000 den=10.000000 ttp=0.000000
4.000000
ttp: T=4.100000 num=41.000000 den=10.000000 ttp=1.000000
  (snip)
ttp: T=4.900000 num=49.000000 den=10.000000 ttp=9.000000
ttp: T=5.000000 num=50.000000 den=10.000000 ttp=10.000000
ttp: T=5.100000 num=51.000000 den=10.000000 ttp=1.000000
  (snip)
ttp: T=5.900000 num=59.000000 den=10.000000 ttp=9.000000
ttp: T=6.000000 num=60.000000 den=10.000000 ttp=10.000000
---------8<-----------

I agree that 0, 20, 30, and 40 mod 10 yield 0, but since
when does 10, 50, or 60 mod 10 yield 10?  Do I misremember
how mod works?

-- 
Carl Kreider
 aka
  [carlk|root]@syscon-intl.com    (219) 232-3900 Ext 207
   ckreider@gte.net  ckreider@acm.org ckreider@alumni.indiana.edu

 Do, or do not.  There is no try.
                       - Yoda, The Empire Strikes Back



From deirdre@deirdre.net  Mon Jul 31 23:48:20 2000
From: deirdre@deirdre.net (Deirdre Saoirse)
Date: Mon, 31 Jul 2000 15:48:20 -0700 (PDT)
Subject: [Tutor] Why doesn't this work??
In-Reply-To: <20000731173352.A20932@argus.syscon-intl.com>
Message-ID: <Pine.LNX.4.10.10007311547180.19981-100000@rockhopper.deirdre.org>

On Mon, 31 Jul 2000, Carl Kreider wrote:

> I agree that 0, 20, 30, and 40 mod 10 yield 0, but since
> when does 10, 50, or 60 mod 10 yield 10?  Do I misremember
> how mod works?

mod is an integer-based function, so yes, you misremembered.

You'll get quite different results if you change two lines as follows:

        num = (int) (T / dt)
        den = (int) (interval / dt)

-- 
_Deirdre   *   http://www.sfknit.org   *   http://www.deirdre.net
"We can always count on the British. Except for the Revolutionary War
they've been perfect." -- Mel Brooks, on the first Concorde flight since 
the Paris crash.